From 425385d9829f07d5791cfcc81ec5214e3bb1c653 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Apr 2017 14:44:09 -0700 Subject: [PATCH] leverage settings to remember paths used before --- libraries/shared/src/SettingHandle.h | 4 +++ libraries/shared/src/SettingInterface.h | 1 - tools/oven/CMakeLists.txt | 2 +- tools/oven/src/Oven.cpp | 5 ++++ tools/oven/src/ui/ModelBakeWidget.cpp | 39 +++++++++++++++++++++++-- tools/oven/src/ui/ModelBakeWidget.h | 7 +++++ 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/libraries/shared/src/SettingHandle.h b/libraries/shared/src/SettingHandle.h index 54694dfd0a..258d1f8491 100644 --- a/libraries/shared/src/SettingHandle.h +++ b/libraries/shared/src/SettingHandle.h @@ -106,6 +106,10 @@ namespace Setting { return (_isSet) ? _value : other; } + bool isSet() const { + return _isSet; + } + const T& getDefault() const { return _defaultValue; } diff --git a/libraries/shared/src/SettingInterface.h b/libraries/shared/src/SettingInterface.h index 082adf3e54..575641c0e7 100644 --- a/libraries/shared/src/SettingInterface.h +++ b/libraries/shared/src/SettingInterface.h @@ -21,7 +21,6 @@ namespace Setting { class Manager; void init(); - void cleanupSettings(); class Interface { public: diff --git a/tools/oven/CMakeLists.txt b/tools/oven/CMakeLists.txt index 4d64126fb8..2e40cc9de4 100644 --- a/tools/oven/CMakeLists.txt +++ b/tools/oven/CMakeLists.txt @@ -2,4 +2,4 @@ set(TARGET_NAME oven) setup_hifi_project(Widgets Gui) -link_hifi_libraries(model-baking) +link_hifi_libraries(model-baking shared) diff --git a/tools/oven/src/Oven.cpp b/tools/oven/src/Oven.cpp index 7f185a404e..1e7eb3906e 100644 --- a/tools/oven/src/Oven.cpp +++ b/tools/oven/src/Oven.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "ui/OvenMainWindow.h" #include "ui/ModelBakeWidget.h" @@ -22,6 +24,9 @@ Oven::Oven(int argc, char* argv[]) : QCoreApplication::setOrganizationName("High Fidelity"); QCoreApplication::setApplicationName("Oven"); + // init the settings interface so we can save and load settings + Setting::init(); + // check if we were passed any command line arguments that would tell us just to run without the GUI // setup the GUI diff --git a/tools/oven/src/ui/ModelBakeWidget.cpp b/tools/oven/src/ui/ModelBakeWidget.cpp index b32afa156d..a3fd874306 100644 --- a/tools/oven/src/ui/ModelBakeWidget.cpp +++ b/tools/oven/src/ui/ModelBakeWidget.cpp @@ -20,8 +20,13 @@ #include "ModelBakeWidget.h" +static const QString EXPORT_DIR_SETTING_KEY = "model_export_directory"; +static const QString MODEL_START_DIR_SETTING_KEY = "model_search_directory"; + ModelBakeWidget::ModelBakeWidget(QWidget* parent, Qt::WindowFlags flags) : - QWidget(parent, flags) + QWidget(parent, flags), + _exportDirectory(EXPORT_DIR_SETTING_KEY), + _modelStartDirectory(MODEL_START_DIR_SETTING_KEY) { setupUI(); } @@ -53,6 +58,12 @@ void ModelBakeWidget::setupUI() { _outputDirLineEdit = new QLineEdit; + // set the current export directory to whatever was last used + _outputDirLineEdit->setText(_exportDirectory.get()); + + // whenever the output directory line edit changes, update the value in settings + connect(_outputDirLineEdit, &QLineEdit::textChanged, this, &ModelBakeWidget::outputDirectoryChanged); + QPushButton* chooseOutputDirectoryButton = new QPushButton("Browse..."); connect(chooseOutputDirectoryButton, &QPushButton::clicked, this, &ModelBakeWidget::chooseOutputDirButtonClicked); @@ -76,17 +87,34 @@ void ModelBakeWidget::setupUI() { void ModelBakeWidget::chooseFileButtonClicked() { // pop a file dialog so the user can select the model file - auto selectedFile = QFileDialog::getOpenFileName(this, "Choose Model", QDir::homePath()); + + // if we have picked an FBX before, start in the folder that matches the last path + // otherwise start in the home directory + auto startDir = _modelStartDirectory.get(); + if (startDir.isEmpty()) { + startDir = QDir::homePath(); + } + + auto selectedFile = QFileDialog::getOpenFileName(this, "Choose Model", startDir); if (!selectedFile.isEmpty()) { // set the contents of the model file text box to be the path to the selected file _modelLineEdit->setText(selectedFile); + _modelStartDirectory.set(QDir(selectedFile).absolutePath()); } } void ModelBakeWidget::chooseOutputDirButtonClicked() { // pop a file dialog so the user can select the output directory - auto selectedDir = QFileDialog::getExistingDirectory(this, "Choose Output Directory", QDir::homePath()); + + // if we have a previously selected output directory, use that as the initial path in the choose dialog + // otherwise use the user's home directory + auto startDir = _exportDirectory.get(); + if (startDir.isEmpty()) { + startDir = QDir::homePath(); + } + + auto selectedDir = QFileDialog::getExistingDirectory(this, "Choose Output Directory", startDir); if (!selectedDir.isEmpty()) { // set the contents of the output directory text box to be the path to the directory @@ -94,6 +122,11 @@ void ModelBakeWidget::chooseOutputDirButtonClicked() { } } +void ModelBakeWidget::outputDirectoryChanged(const QString& newDirectory) { + // update the export directory setting so we can re-use it next time + _exportDirectory.set(newDirectory); +} + void ModelBakeWidget::bakeButtonClicked() { // make sure we have a valid output directory QDir outputDirectory(_outputDirLineEdit->text()); diff --git a/tools/oven/src/ui/ModelBakeWidget.h b/tools/oven/src/ui/ModelBakeWidget.h index adcaaf2a50..0f7efa8aad 100644 --- a/tools/oven/src/ui/ModelBakeWidget.h +++ b/tools/oven/src/ui/ModelBakeWidget.h @@ -14,6 +14,8 @@ #include +#include + #include class QLineEdit; @@ -29,6 +31,8 @@ private slots: void chooseOutputDirButtonClicked(); void bakeButtonClicked(); + void outputDirectoryChanged(const QString& newDirectory); + private: void setupUI(); @@ -38,6 +42,9 @@ private: QLineEdit* _outputDirLineEdit; QUrl modelToBakeURL; + + Setting::Handle _exportDirectory; + Setting::Handle _modelStartDirectory; }; #endif // hifi_ModelBakeWidget_h