From 551f3348f4e7831d48bf595ba5b6236cfa3065a9 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 20 Jan 2016 01:05:02 +0100 Subject: [PATCH] refs #377 usability improvements * allow to toggle between single, multi and extended selection * all DB data can be read by menu * fixed load/save (test data) from disk --- .../components/datainfoareacomponent.cpp | 17 ++++++++-- .../components/datainfoareacomponent.h | 3 ++ .../components/dbmappingcomponent.cpp | 32 +++++++++++++------ src/blackgui/components/dbmappingcomponent.h | 13 ++++++-- src/blackgui/views/viewbase.cpp | 32 ++++++++++++++++--- src/blackmisc/network/entityflags.h | 5 +-- src/swiftdata/swiftdatamenus.cpp | 7 ++-- 7 files changed, 85 insertions(+), 24 deletions(-) diff --git a/src/blackgui/components/datainfoareacomponent.cpp b/src/blackgui/components/datainfoareacomponent.cpp index 2eb9f0dc5..e52096093 100644 --- a/src/blackgui/components/datainfoareacomponent.cpp +++ b/src/blackgui/components/datainfoareacomponent.cpp @@ -82,8 +82,14 @@ namespace BlackGui bool CDataInfoAreaComponent::writeDbDataToResourceDir() const { - bool s = hasProvider() && - this->writeDbDataToDisk(CProject::getSwiftStaticDbFilesDir()); + if (!this->hasProvider() || !this->canConnectSwiftDb()) + { + CLogMessage(this).warning("No connection to DB yet, no new data loaded which can be written"); + return false; + } + + // write to disk + bool s = this->writeDbDataToDisk(CProject::getSwiftStaticDbFilesDir()); if (s) { CLogMessage(this).info("Written DB data"); @@ -103,7 +109,7 @@ namespace BlackGui // info if (s) { - CLogMessage(this).info("Read DB data: %1") << CProject::getSwiftStaticDbFilesDir(); + CLogMessage(this).info("Read DB data from directory: %1") << CProject::getSwiftStaticDbFilesDir(); this->ui->comp_DbAircraftIcao->showLoadIndicator(); this->ui->comp_DbAirlineIcao->showLoadIndicator(); this->ui->comp_DbCountries->showLoadIndicator(); @@ -155,6 +161,11 @@ namespace BlackGui } } + void CDataInfoAreaComponent::requestUpdateOfAllDbData() + { + this->triggerRead(CEntityFlags::AllDbEntities, QDateTime()); + } + void CDataInfoAreaComponent::requestUpdatedData(CEntityFlags::Entity entity) { bool requested = false; diff --git a/src/blackgui/components/datainfoareacomponent.h b/src/blackgui/components/datainfoareacomponent.h index 1394a80be..ef2b7b56a 100644 --- a/src/blackgui/components/datainfoareacomponent.h +++ b/src/blackgui/components/datainfoareacomponent.h @@ -89,6 +89,9 @@ namespace BlackGui //! Load from resource dir bool readDbDataFromResourceDir(); + //! Request update of all DB data + void requestUpdateOfAllDbData(); + //! Load new data (based on timestamp, incremental) void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entity); diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index ced58d77f..703a712d9 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -58,7 +58,7 @@ namespace BlackGui ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this)); - ui->tvp_OwnAircraftModels->setCustomMenu(new CRemoveDbModelsMenu(this)); + ui->tvp_OwnAircraftModels->setCustomMenu(new CModelStashTools(this)); ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get()); // how to display forms @@ -94,7 +94,7 @@ namespace BlackGui connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true)); - this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CRemoveDbModelsMenu(this)); + this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CModelStashTools(this)); this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); this->ui->tvp_AircraftModelsForVPilot->addFilterDialog(); const CAircraftModelList cachedModels(m_cachedVPilotModels.get()); @@ -165,6 +165,7 @@ namespace BlackGui void CDbMappingComponent::setProvider(BlackMisc::Network::IWebDataServicesProvider *provider) { CWebDataServicesAware::setProvider(provider); + this->m_autostashDialog->setProvider(provider); this->ui->editor_Livery->setProvider(provider); this->ui->editor_Distributor->setProvider(provider); this->ui->editor_AircraftIcao->setProvider(provider); @@ -309,6 +310,11 @@ namespace BlackGui } } + void CDbMappingComponent::ps_displayAutoStashingDialog() + { + this->m_autostashDialog->setVisible(true); + } + void CDbMappingComponent::ps_removeDbModelsFromView() { QStringList modelStrings(this->getModelStrings()); @@ -447,7 +453,7 @@ namespace BlackGui if (!sims.isEmpty()) { o = o.append(" ").append(sims); } } QString f = this->ui->tvp_OwnAircraftModels->derivedModel()->hasFilter() ? "F" : ""; - o = CGuiUtility::replaceTabCountValue(o, this->ui->tvp_AircraftModelsForVPilot->rowCount()) + f; + o = CGuiUtility::replaceTabCountValue(o, this->ui->tvp_OwnAircraftModels->rowCount()) + f; this->ui->tw_ModelsToBeMapped->setTabText(i, o); } @@ -628,26 +634,34 @@ namespace BlackGui return qobject_cast(this->parent()); } - void CDbMappingComponent::CRemoveDbModelsMenu::customMenu(QMenu &menu) const + void CDbMappingComponent::CModelStashTools::customMenu(QMenu &menu) const { CDbMappingComponent *mapComp = mappingComponent(); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); - int dbModels = mapComp->getModelsCount(); - if (dbModels > 0) + bool canConnectDb = mapComp->canConnectSwiftDb(); + + if (canConnectDb) { if (!mapComp->currentModelView()->isEmpty()) { this->addSeparator(menu); + int dbModels = mapComp->getModelsCount(); + if (dbModels > 0) + { + // we have keys and data where we could delete them from + const QString msgDelete("Delete " + QString::number(dbModels) + " DB model(s) from " + mapComp->currentTabText()); + menu.addAction(CIcons::delete16(), msgDelete, mapComp, SLOT(ps_removeDbModelsFromView())); + } // we have keys and data where we could delete them from - QString m("Delete " + QString::number(dbModels) + " DB model(s) from " + mapComp->currentTabText()); - menu.addAction(CIcons::delete16(), m, mapComp, SLOT(ps_removeDbModelsFromView())); + const QString msgAutoStash("Auto stashing"); + menu.addAction(CIcons::appDbStash16(), msgAutoStash, mapComp, SLOT(ps_displayAutoStashingDialog())); } } this->nestedCustomMenu(menu); } - CDbMappingComponent *CDbMappingComponent::CRemoveDbModelsMenu::mappingComponent() const + CDbMappingComponent *CDbMappingComponent::CModelStashTools::mappingComponent() const { return qobject_cast(this->parent()); } diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 6479dd43a..dc79e576d 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -19,6 +19,7 @@ #include "blackgui/menudelegate.h" #include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/components/dbautostashingcomponent.h" #include "blackgui/views/aircraftmodelview.h" #include "blackmisc/simulation/aircraftmodelloader.h" #include "blackmisc/simulation/fscommon/vpilotrulesreader.h" @@ -175,11 +176,15 @@ namespace BlackGui //! Stash current model void ps_stashCurrentModel(); + //! Display auto stashing dialog + void ps_displayAutoStashingDialog(); + //! Remove DB models from current view void ps_removeDbModelsFromView(); private: QScopedPointer ui; + QScopedArrayPointer m_autostashDialog { new CDbAutoStashingComponent(this) }; BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules BlackMisc::CData m_cachedVPilotModels { this, &CDbMappingComponent::ps_onVPilotCacheChanged }; //!< cache for latest vPilot rules std::unique_ptr m_modelLoader; //!< read own aircraft models @@ -240,13 +245,15 @@ namespace BlackGui CDbMappingComponent *mappingComponent() const; }; - //! Menu for removing DB models from current view + //! Menu for tools: + //! 1) removing DB models from current view and + //! 2) for auto stashing //! \note This is a specific menu for that very component - class CRemoveDbModelsMenu : public BlackGui::IMenuDelegate + class CModelStashTools : public BlackGui::IMenuDelegate { public: //! Constructor - CRemoveDbModelsMenu(CDbMappingComponent *mappingComponent, bool separator = true) : + CModelStashTools(CDbMappingComponent *mappingComponent, bool separator = true) : BlackGui::IMenuDelegate(mappingComponent, separator) {} diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 46fc8c3fa..a34074194 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -207,11 +207,15 @@ namespace BlackGui { if (sm == SingleSelection) { - menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode())); + QAction *a = menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode())); + a->setData("multi"); + a = menu.addAction(QIcon(), "Switch to extended selection", this, SLOT(ps_toggleSelectionMode())); + a->setData("extended"); } else if (sm == MultiSelection || sm == ExtendedSelection) { - menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode())); + QAction *a = menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode())); + a->setData("single"); } } if (sm != NoSelection) @@ -533,9 +537,29 @@ namespace BlackGui { if (this->selectionMode() == SingleSelection) { - this->setSelectionMode(this->m_originalSelectionMode); + QAction *action = qobject_cast(sender()); + if (action && action->data().canConvert()) + { + QString data(action->data().toString().toLower()); + if (data.startsWith('e')) + { + this->setSelectionMode(ExtendedSelection); + } + else if (data.startsWith('m')) + { + this->setSelectionMode(MultiSelection); + } + else + { + this->setSelectionMode(this->m_originalSelectionMode); + } + } + else + { + this->setSelectionMode(this->m_originalSelectionMode); + } } - else if (this->selectionMode() == MultiSelection) + else if (this->selectionMode() == MultiSelection || this->selectionMode() == ExtendedSelection) { this->setSelectionMode(SingleSelection); } diff --git a/src/blackmisc/network/entityflags.h b/src/blackmisc/network/entityflags.h index 1045ce6b0..84b0cb7e5 100644 --- a/src/blackmisc/network/entityflags.h +++ b/src/blackmisc/network/entityflags.h @@ -39,9 +39,10 @@ namespace BlackMisc DistributorEntity = 1 << 6, ///< distributors LiveryEntity = 1 << 7, ///< liveries ModelEntity = 1 << 8, ///< models - AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, ///< all ICAO codes + AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, ///< all ICAO codes AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, ///< all ICAO codes and countries - DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, ///< Combinded + DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, ///< Combinded + AllDbEntities = AllIcaoEntities | DistributorLiveryModel, ///< All DB stuff AllEntities = 0xFFFF ///< everything }; Q_DECLARE_FLAGS(Entity, EntityFlag) diff --git a/src/swiftdata/swiftdatamenus.cpp b/src/swiftdata/swiftdatamenus.cpp index 786ea2893..27b79c0f9 100644 --- a/src/swiftdata/swiftdatamenus.cpp +++ b/src/swiftdata/swiftdatamenus.cpp @@ -156,10 +156,11 @@ void CSwiftData::initDynamicMenus() { Q_ASSERT_X(this->ui->comp_MainInfoArea, Q_FUNC_INFO, "Missing main info area"); Q_ASSERT_X(this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), Q_FUNC_INFO, "Missing DB info area"); - this->ui->menu_Mapping->addAction(CIcons::load16(), "Load DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(readDbDataFromResourceDir())); - if (CProject::isRunningInDeveloperEnvironment() && this->m_webDataReader && this->m_webDataReader->canConnectSwiftDb()) + this->ui->menu_Mapping->addAction(CIcons::database16(), "Load all DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(requestUpdateOfAllDbData())); + this->ui->menu_Mapping->addAction(CIcons::load16(), "Load DB test data from disk", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(readDbDataFromResourceDir())); + if (CProject::isRunningInDeveloperEnvironment()) { - this->ui->menu_Mapping->addAction(CIcons::save16(), "Save DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(writeDbDataToResourceDir())); + this->ui->menu_Mapping->addAction(CIcons::save16(), "Save DB test data to disk", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(writeDbDataToResourceDir())); } } }