diff --git a/src/blackgui/components/dbownmodelscomponent.cpp b/src/blackgui/components/dbownmodelscomponent.cpp index 062ef6361..2ac638dea 100644 --- a/src/blackgui/components/dbownmodelscomponent.cpp +++ b/src/blackgui/components/dbownmodelscomponent.cpp @@ -101,6 +101,7 @@ namespace BlackGui Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simInfo)) { + this->setSaveFileName(simInfo); return true; } @@ -123,10 +124,18 @@ namespace BlackGui bool c = connect(this->m_modelLoader.get(), &IAircraftModelLoader::loadingFinished, this, &CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished); Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect for model loader"); Q_UNUSED(c); + this->setSaveFileName(simInfo); return true; } } + void CDbOwnModelsComponent::setSaveFileName(const CSimulatorInfo &sim) + { + Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); + const QString n("simulator models " + sim.toQString(true)); + this->ui->tvp_OwnAircraftModels->setSaveFileName(n); + } + void CDbOwnModelsComponent::CLoadModelsMenu::customMenu(QMenu &menu) const { CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators(); diff --git a/src/blackgui/components/dbownmodelscomponent.h b/src/blackgui/components/dbownmodelscomponent.h index ad8b1959d..7dc369e58 100644 --- a/src/blackgui/components/dbownmodelscomponent.h +++ b/src/blackgui/components/dbownmodelscomponent.h @@ -82,6 +82,9 @@ namespace BlackGui //! Init model loader bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo); + //! File name for savinf + void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim); + //! The menu for loading and handling own models for mapping tasks //! \note This is specific for that very component class CLoadModelsMenu : public BlackGui::Menus::IMenuDelegate diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 286c035b6..86e30258c 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -31,7 +31,8 @@ namespace BlackGui ui->setupUi(this); ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuStashing | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh); - ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows); + ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear); + ui->tvp_OwnModelSet->addFilterDialog(); connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); } @@ -52,6 +53,7 @@ namespace BlackGui this->ui->pb_SaveAsSetForSimulator->setText("save for " + simulator.toQString()); this->ui->pb_SaveAsSetForSimulator->setEnabled(!models.isEmpty()); this->m_simulator = simulator; + this->setSaveFileName(simulator); } void CDbOwnModelSetComponent::setMappingComponent(CDbMappingComponent *component) @@ -111,5 +113,12 @@ namespace BlackGui this->ui->tvp_OwnModelSet->showFileLoadDialog(); } } + + void CDbOwnModelSetComponent::setSaveFileName(const CSimulatorInfo &sim) + { + Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); + const QString n("modelset" + sim.toQString(true)); + this->ui->tvp_OwnModelSet->setSaveFileName(n); + } } // ns } // ns diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index 56d4aec6d..46083d360 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -62,6 +62,9 @@ namespace BlackGui void ps_buttonClicked(); private: + //! Default file name + void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim); + QScopedPointer ui; QScopedPointer m_modelSetDialog; BlackMisc::Simulation::CSimulatorInfo m_simulator; diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 7f94c9193..657d9196d 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -9,6 +9,7 @@ #include "viewbase.h" #include "blackmisc/fileutils.h" +#include "blackmisc/project.h" #include "blackgui/models/allmodels.h" #include "blackgui/stylesheetutility.h" #include "blackgui/guiutility.h" @@ -25,7 +26,6 @@ #include #include #include -#include #include #include @@ -371,29 +371,30 @@ namespace BlackGui } } - QString CViewBaseNonTemplate::getDefaultFilename() const + QString CViewBaseNonTemplate::getDefaultFilename(bool load) const { // some logic to find a useful default name - const QStringList pathes(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)); - QString name; - if (this->getDockWidgetInfoArea()) { name = this->getDockWidgetInfoArea()->windowTitle(); } - else if (!windowTitle().isEmpty()) { name = this->windowType(); } - else { name = this->metaObject()->className(); } - name += ".json"; + QString dir = CProject::getDocumentationDirectory(); - if (!pathes.isEmpty()) + if (load) { - QString p(CFileUtils::appendFilePaths(pathes.first(), "swift/" + name)); - if (!QDir(p).exists()) - { - p = CFileUtils::appendFilePaths(pathes.first(), "swift " + name); - } - return p; + return CFileUtils::appendFilePaths(dir, CFileUtils::jsonWildcardAppendix()); } - else + + // Save file path + QString name(this->m_saveFileName); + if (name.isEmpty()) { - return name; + // create a name + if (this->getDockWidgetInfoArea()) { name = this->getDockWidgetInfoArea()->windowTitle(); } + else if (!windowTitle().isEmpty()) { name = this->windowType(); } + else { name = this->metaObject()->className(); } } + if (!name.endsWith(CFileUtils::jsonAppendix(), Qt::CaseInsensitive)) + { + name += CFileUtils::jsonAppendix(); + } + return CFileUtils::appendFilePaths(dir, name); } void CViewBaseNonTemplate::menuRemoveItems(Menu menusToRemove) @@ -959,7 +960,7 @@ namespace BlackGui { static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); const QString fileName = QFileDialog::getOpenFileName(nullptr, - tr("Load data file"), getDefaultFilename(), + tr("Load data file"), getDefaultFilename(true), tr("swift (*.json *.txt)")); if (fileName.isEmpty()) { return CStatusMessage(cats, CStatusMessage::SeverityDebug, "Load canceled"); } QString json(CFileUtils::readFileToString(fileName)); @@ -978,7 +979,7 @@ namespace BlackGui { static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); const QString fileName = QFileDialog::getSaveFileName(nullptr, - tr("Save data file"), getDefaultFilename(), + tr("Save data file"), getDefaultFilename(false), tr("swift (*.json *.txt)")); if (fileName.isEmpty()) { return CStatusMessage(cats, CStatusMessage::SeverityDebug, "Save canceled"); } const QString json(this->toJsonString()); diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 62a7ae8d8..1da3b4c5c 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -203,6 +203,9 @@ namespace BlackGui //! Show file save dialog BlackMisc::CStatusMessage showFileSaveDialog() const; + //! Save file name (optional) + void setSaveFileName(const QString &saveName) { this->m_saveFileName = saveName; } + signals: //! Ask for new data from currently loaded data void requestUpdate(); @@ -305,11 +308,12 @@ namespace BlackGui void init(); //! Default file for load/save operations - QString getDefaultFilename() const; + QString getDefaultFilename(bool load) const; + QString m_saveFileName; //!< save file name (JSON) ResizeMode m_resizeMode = PresizeSubset; //!< mode RowsResizeMode m_rowResizeMode = Interactive; //!< row resize mode for row height - SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set + SelectionMode m_originalSelectionMode = this->selectionMode(); //!< Selection mode set int m_resizeCount = 0; //!< flag / counter, how many resize activities int m_skipResizeThreshold = 40; //!< when to skip resize (rows count) int m_resizeAutoNthTime = 1; //!< with ResizeAuto, resize every n-th time @@ -322,8 +326,8 @@ namespace BlackGui bool m_displayAutomatically = true; //!< display directly when loaded bool m_enableDeleteSelectedRows = false; //!< selected rows can be deleted QWidget *m_filterWidget = nullptr; //!< filter widget or dialog - Menu m_menus = MenuDefault; //!< Default menu settings - BlackGui::Menus::IMenuDelegate *m_menu = nullptr; //!< custom menu if any + Menu m_menus = MenuDefault; //!< Default menu settings + BlackGui::Menus::IMenuDelegate *m_menu = nullptr; //!< custom menu if any BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded protected slots: diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 185ee45f6..f2accf10e 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -15,6 +15,18 @@ namespace BlackMisc { + const QString &CFileUtils::jsonAppendix() + { + static const QString j(".json"); + return j; + } + + const QString &CFileUtils::jsonWildcardAppendix() + { + static const QString jw("*" + jsonAppendix()); + return jw; + } + bool CFileUtils::writeStringToFile(const QString &content, const QString &fileNameAndPath) { if (fileNameAndPath.isEmpty()) { return false; } diff --git a/src/blackmisc/fileutils.h b/src/blackmisc/fileutils.h index 6866d9987..f94b107e3 100644 --- a/src/blackmisc/fileutils.h +++ b/src/blackmisc/fileutils.h @@ -25,6 +25,12 @@ namespace BlackMisc class BLACKMISC_EXPORT CFileUtils { public: + //! Our JSON file name appendix + static const QString &jsonAppendix(); + + //! JSON wildcard + appendix + static const QString &jsonWildcardAppendix(); + //! Write string to text file static bool writeStringToFile(const QString &content, const QString &fileNameAndPath); diff --git a/src/blackmisc/project.cpp b/src/blackmisc/project.cpp index 31a4cdc3b..98c3e5324 100644 --- a/src/blackmisc/project.cpp +++ b/src/blackmisc/project.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #if !defined(BLACK_VERSION) #error Missing version @@ -349,6 +350,22 @@ namespace BlackMisc return s; } + QString getDocumentationDirectoryImpl() + { + QStringList pathes(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)); + QString d = pathes.first(); + d = CFileUtils::appendFilePaths(d, "/swift"); + QDir dir(d); + if (dir.exists()) { return dir.absolutePath(); } + return pathes.first(); + } + + const QString &CProject::getDocumentationDirectory() + { + static const QString d(getDocumentationDirectoryImpl()); + return d; + } + const QString &CProject::compiledWithInfo(bool shortVersion) { if (shortVersion) diff --git a/src/blackmisc/project.h b/src/blackmisc/project.h index b09c1ebd3..3be45b8f2 100644 --- a/src/blackmisc/project.h +++ b/src/blackmisc/project.h @@ -105,6 +105,9 @@ namespace BlackMisc //! Where images are located static const QString &getImagesDir(); + //! Directory where data can be stored + static const QString &getDocumentationDirectory(); + //! Info string about compilation static const QString &compiledWithInfo(bool shortVersion = true);