From 991cc3463d39ecbdcfac4f8758b27476f3d8c03e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 10 Aug 2017 11:50:48 +0200 Subject: [PATCH] Ref T117, check equal models before publishing * checkbox, check can be disabled * context menu to display changed attributes in popup --- .../components/dbmappingcomponent.cpp | 41 ++-- src/blackgui/components/dbmappingcomponent.h | 31 ++- src/blackgui/components/dbstashcomponent.cpp | 26 ++- src/blackgui/components/dbstashcomponent.h | 3 + src/blackgui/components/dbstashcomponent.ui | 205 +++++++++++------- 5 files changed, 197 insertions(+), 109 deletions(-) diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 3635bea5a..b8cc570c3 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -85,15 +85,15 @@ namespace BlackGui ui->comp_OwnAircraftModels->view()->setCustomMenu(new CShowSimulatorFileMenu(ui->comp_OwnAircraftModels->view(), this, true)); ui->comp_OwnAircraftModels->view()->setCustomMenu(new CMergeWithVPilotMenu(this)); ui->comp_OwnAircraftModels->view()->setCustomMenu(new COwnModelSetMenu(this, true)); - ui->comp_OwnAircraftModels->view()->setCustomMenu(new CModelStashToolsMenu(this, false)); + ui->comp_OwnAircraftModels->view()->setCustomMenu(new CStashToolsMenu(this, false)); ui->comp_OwnModelSet->view()->setCustomMenu(new CShowSimulatorFileMenu(ui->comp_OwnModelSet->view(), this, true)); - ui->comp_OwnModelSet->view()->setCustomMenu(new CModelStashToolsMenu(this, true)); + ui->comp_OwnModelSet->view()->setCustomMenu(new CStashToolsMenu(this, true)); ui->comp_StashAircraft->view()->setCustomMenu(new CShowSimulatorFileMenu(ui->comp_StashAircraft->view(), this, true)); ui->comp_StashAircraft->view()->setCustomMenu(new CApplyDbDataMenu(this, true)); ui->comp_StashAircraft->view()->setCustomMenu(new COwnModelSetMenu(this, true)); - ui->comp_StashAircraft->view()->setCustomMenu(new CModelStashToolsMenu(this, false)); + ui->comp_StashAircraft->view()->setCustomMenu(new CStashToolsMenu(this, false)); // connects connect(ui->editor_ModelMapping, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel); @@ -161,7 +161,7 @@ namespace BlackGui connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestUpdate, this, &CDbMappingComponent::ps_requestVPilotDataUpdate); ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true)); - ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CModelStashToolsMenu(this, false)); + ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CStashToolsMenu(this, false)); ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); ui->tvp_AircraftModelsForVPilot->addFilterDialog(); @@ -328,6 +328,11 @@ namespace BlackGui return ui->comp_StashAircraft->getStashedModels(); } + bool CDbMappingComponent::hasStashedModels() const + { + return !this->getStashedModels().isEmpty(); + } + QStringList CDbMappingComponent::getStashedModelStrings() const { return ui->comp_StashAircraft->getStashedModelStrings(); @@ -422,6 +427,13 @@ namespace BlackGui } } + void CDbMappingComponent::ps_showChangedAttributes() + { + if (!this->hasStashedModels()) { return; } + if (this->currentTabIndex() != TabStash) { return; } + ui->comp_StashAircraft->showChangedAttributes(); + } + void CDbMappingComponent::ps_toggleAutoFiltering() { this->m_autoFilterInDbViews = !this->m_autoFilterInDbViews; @@ -912,11 +924,11 @@ namespace BlackGui return qobject_cast(this->parent()); } - CDbMappingComponent::CModelStashToolsMenu::CModelStashToolsMenu(CDbMappingComponent *mappingComponent, bool separator) : + CDbMappingComponent::CStashToolsMenu::CStashToolsMenu(CDbMappingComponent *mappingComponent, bool separator) : BlackGui::Menus::IMenuDelegate(mappingComponent, separator) {} - void CDbMappingComponent::CModelStashToolsMenu::customMenu(CMenuActions &menuActions) + void CDbMappingComponent::CStashToolsMenu::customMenu(CMenuActions &menuActions) { CDbMappingComponent *mapComp = mappingComponent(); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); @@ -929,10 +941,6 @@ namespace BlackGui this->m_stashFiltering->setCheckable(true); this->m_stashFiltering->setChecked(mapComp->m_autoFilterInDbViews); - // Currently disabled as the same effect can be realized by filtering than - // this->addRemoveDbModels(menuActions); - // remove if not needed in the long term (added 2016-Sep) - this->m_autoStashing = menuActions.addAction(this->m_autoStashing, CIcons::appDbStash16(), "Auto stashing", CMenuAction::pathStash(), this, { mapComp, &CDbMappingComponent::ps_displayAutoStashingDialog }); this->m_autoSimulatorStashing = menuActions.addAction(this->m_autoSimulatorStashing, CIcons::appDbStash16(), "Cross simulator updating (FSX-P3D-FS9)", CMenuAction::pathStash(), this, { mapComp, &CDbMappingComponent::ps_displayAutoSimulatorStashingDialog }); if (mapComp->m_autoStashDialog && mapComp->m_autoStashDialog->isCompleted()) @@ -942,26 +950,31 @@ namespace BlackGui } else if (mapComp->currentTabIndex() == CDbMappingComponent::TabStash) { - this->addRemoveDbModels(menuActions); + this->addStashViewSpecificMenus(menuActions); } this->nestedCustomMenu(menuActions); } - void CDbMappingComponent::CModelStashToolsMenu::addRemoveDbModels(CMenuActions &menuActions) + void CDbMappingComponent::CStashToolsMenu::addStashViewSpecificMenus(CMenuActions &menuActions) { CDbMappingComponent *mapComp = mappingComponent(); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); const int dbModels = sGui->getWebDataServices()->getModelsCount(); - if (dbModels > 0) + if (dbModels > 0 && mapComp->hasStashedModels()) { + menuActions.addMenu(CIcons::appDbStash16(), "Stash", CMenuAction::pathStash()); + // we have keys and data by which we could delete them from view const QString msgDelete("Delete " + QString::number(dbModels) + " DB model(s) from '" + mapComp->currentTabText() + "'"); menuActions.addAction(CIcons::delete16(), msgDelete, CMenuAction::pathStash(), nullptr, { mapComp, &CDbMappingComponent::ps_removeDbModelsFromView}); + + // attribute info + menuActions.addAction(CIcons::info16(), "Show changed attributes", CMenuAction::pathStash(), nullptr, { mapComp, &CDbMappingComponent::ps_showChangedAttributes}); } } - CDbMappingComponent *CDbMappingComponent::CModelStashToolsMenu::mappingComponent() const + CDbMappingComponent *CDbMappingComponent::CStashToolsMenu::mappingComponent() const { return qobject_cast(this->parent()); } diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 6ba2b5291..bc6a2cfd1 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -87,7 +87,7 @@ namespace BlackGui explicit CDbMappingComponent(QWidget *parent = nullptr); //! Destructor - ~CDbMappingComponent(); + virtual ~CDbMappingComponent(); //! Graceful shutdown void gracefulShutdown(); @@ -124,6 +124,9 @@ namespace BlackGui //! Stashed models const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const; + //! Any stashed models? + bool hasStashedModels() const; + //! Stashed model strings QStringList getStashedModelStrings() const; //! @} @@ -279,6 +282,9 @@ namespace BlackGui //! Remove DB models from current view void ps_removeDbModelsFromView(); + //! Show changed attributes of stashed + void ps_showChangedAttributes(); + //! Toggle auto filtering void ps_toggleAutoFiltering(); @@ -311,10 +317,10 @@ namespace BlackGui BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules BlackMisc::CDigestSignal m_dsStashedModelsChanged { this, &CDbMappingComponent::ps_digestStashedModelsChanged, &CDbMappingComponent::ps_onStashedModelsChangedDigest, 750, 25 }; BlackMisc::CData m_swiftDbUser { this }; - const bool vPilotSupport = true; //!< vPilot support - bool m_vPilot1stInit = true; //!< vPilot extensions initaliazed? + const bool vPilotSupport = true; //!< vPilot support (will be removed in future) + bool m_vPilot1stInit = true; //!< vPilot extensions initalized? bool m_vPilotEnabled = false; //!< use vPilot extensions - bool m_vPilotFormatted = false; //!< vPilot fomratted (workaround) + bool m_vPilotFormatted = false; //!< vPilot formatted (workaround) bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model //! Init vPilot if rights and suitable @@ -355,17 +361,18 @@ namespace BlackGui QAction *m_menuAction = nullptr; }; - //! Menu for tools: - //! -# removing DB models from current view and + //! Menu for stashing related tools: + //! -# removing DB models from stash view //! -# for auto stashing - //! -# automatically updating simulators (FSX, FS9, P3D family) - //! -# toggle auto filtering - //! \note This is a specific menu for that very component - class CModelStashToolsMenu : public BlackGui::Menus::IMenuDelegate + //! -# cross simulator updating (FSX, FS9, P3D family) + //! -# toggle stash auto filtering + //! -# show changed attributes + //! \note This is a specific menu for the CDbMappingComponent component + class CStashToolsMenu : public BlackGui::Menus::IMenuDelegate { public: //! Constructor - CModelStashToolsMenu(CDbMappingComponent *mappingComponent, bool separator = true); + CStashToolsMenu(CDbMappingComponent *mappingComponent, bool separator = true); //! \copydoc IMenuDelegate::customMenu virtual void customMenu(BlackGui::Menus::CMenuActions &menuActions) override; @@ -375,7 +382,7 @@ namespace BlackGui CDbMappingComponent *mappingComponent() const; //! Removel models existing in DB - void addRemoveDbModels(Menus::CMenuActions &menuActions); + void addStashViewSpecificMenus(Menus::CMenuActions &menuActions); QAction *m_autoStashing = nullptr; QAction *m_autoSimulatorStashing = nullptr; diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index 20b44c440..7a0a334d0 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -319,7 +319,8 @@ namespace BlackGui Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "No web services"); const CAircraftModelList models(getSelectedOrAllModels()); if (models.isEmpty()) { return CStatusMessageList(); } - const CStatusMessageList msgs(sGui->getWebDataServices()->validateForPublishing(models, validModels, invalidModels)); + const bool ignoreEqual = ui->cb_ChangedOnly->isChecked(); + const CStatusMessageList msgs(sGui->getWebDataServices()->validateForPublishing(models, ignoreEqual, validModels, invalidModels)); // OK? if (msgs.isEmpty()) @@ -423,7 +424,30 @@ namespace BlackGui return stashModel; } + void CDbStashComponent::showChangedAttributes() { + if (!sGui || !sGui->hasWebDataServices()) { return; } + if (sGui->isShuttingDown()) { return; } + const CAircraftModelList models = ui->tvp_StashAircraftModels->selectedObjects(); + if (models.isEmpty()) { return; } + + CStatusMessageList msgs; + for (const CAircraftModel &model : models) + { + CStatusMessageList modelMsgs; + const bool equal = sGui->getWebDataServices()->isDbModelEqualForPublishing(model, &modelMsgs); + if (equal) + { + msgs.push_back(CStatusMessage(this).info("Model '%1' has no change values") << model.getModelStringAndDbKey()); + } + else + { + msgs.push_back(modelMsgs); + } + } + this->showMessages(msgs); + } + void CDbStashComponent::ps_copyOverValuesToSelectedModels() { const QObject *sender = QObject::sender(); diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index 89c584d6b..89144782c 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -118,6 +118,9 @@ namespace BlackGui //! Consolidate with other available data BlackMisc::Simulation::CAircraftModel consolidateModel(const BlackMisc::Simulation::CAircraftModel &model) const; + //! Show changed attributes of selected models + void showChangedAttributes(); + public slots: //! Stash given model (includes validation and consolidation with DB data) BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model, bool replace = false, bool consolidateWithDbData = true); diff --git a/src/blackgui/components/dbstashcomponent.ui b/src/blackgui/components/dbstashcomponent.ui index e3329ad76..bac07ceee 100644 --- a/src/blackgui/components/dbstashcomponent.ui +++ b/src/blackgui/components/dbstashcomponent.ui @@ -6,7 +6,7 @@ 0 0 - 860 + 910 222 @@ -47,7 +47,7 @@ QFrame::Raised - + 0 @@ -60,94 +60,134 @@ 0 - - - - Unstash - - - - - - - Qt::Vertical - - - - - - - Validate - - - - - - - Remove invalid models - - - Rem. invalid - - - - - - - Publish - - - - - - - selected models only - - - selected - - - - - - - Qt::Vertical - - - - - - - &1: Model - - - - - - - &2: Distributor - - - - - - - &3: Aircraft ICAO - - - - + + 4 + + &4: Livery - + - - &5: Airline ICAO + + Airline ICAO + + &5: Airline + + + + + + + Unstash + + + + + + + Validate + + + + + + + Publish + + + + + + + &1: Model + + + + + + + &2: Distributor + + + + + + + Qt::Vertical + + + + + + + Remove invalid models + + + Rem. invalid + + + + + + + Qt::Vertical + + + + + + + Aircraft ICAO + + + &3: Aircraft + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + selected models only + + + selected + + + + + + + changed only + + + chg.only + + + true + + + + @@ -169,6 +209,7 @@ pb_RemoveInvalid pb_Publish cb_SelectedOnly + cb_ChangedOnly pb_Model pb_Distributor pb_AircraftIcao