diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index a4b1555e5..26a8da68f 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -99,6 +100,7 @@ namespace BlackGui ui->comp_ModelWorkbench->view()->setCustomMenu(new CApplyDbDataMenu(this)); ui->comp_ModelWorkbench->view()->setCustomMenu(new COwnModelSetMenu(this)); ui->comp_ModelWorkbench->view()->setCustomMenu(new CStashToolsMenu(this)); + ui->comp_ModelWorkbench->view()->setCustomMenu(new CRemovedModelsMenu(this)); // connects connect(ui->editor_ModelMapping, &CModelMappingForm::requestStash, this, &CDbMappingComponent::stashCurrentModel); @@ -323,7 +325,12 @@ namespace BlackGui bool CDbMappingComponent::isStashTab() const { - return currentTabIndex() == TabStash; + return this->currentTabIndex() == TabStash; + } + + bool CDbMappingComponent::isWorkbenchTab() const + { + return this->currentTabIndex() == TabWorkbench; } bool CDbMappingComponent::canAddToModelSetTab() const @@ -531,6 +538,13 @@ namespace BlackGui ui->tvp_AircraftModelsForVPilot->hideLoadIndicator(); } + void CDbMappingComponent::loadRemovedModels() + { + if (!ui->comp_ModelWorkbench->view()) { return; } + const QString logDir = CDirectoryUtils::logDirectory(); + ui->comp_ModelWorkbench->view()->showFileLoadDialog(logDir); + } + void CDbMappingComponent::onVPilotCacheChanged() { if (ui->tvp_AircraftModelsForVPilot->displayAutomatically()) @@ -1021,6 +1035,24 @@ namespace BlackGui this->nestedCustomMenu(menuActions); } + void CDbMappingComponent::CRemovedModelsMenu::customMenu(CMenuActions &menuActions) + { + CDbMappingComponent *mapComp = mappingComponent(); + Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); + if (mapComp->isWorkbenchTab()) + { + menuActions.addMenuModelSet(); + m_menuAction = menuActions.addAction(m_menuAction, CIcons::appModels16(), "Removed models", CMenuAction::pathModel(), + this, { mapComp, &CDbMappingComponent::loadRemovedModels }); + } + this->nestedCustomMenu(menuActions); + } + + CDbMappingComponent *CDbMappingComponent::CRemovedModelsMenu::mappingComponent() const + { + return qobject_cast(this->parent()); + } + CDbMappingComponent *CDbMappingComponent::CMergeWithVPilotMenu::mappingComponent() const { return qobject_cast(this->parent()); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 080ccdef0..02d5ec754 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -105,9 +105,12 @@ namespace BlackGui //! Current tab index TabIndex currentTabIndex() const; - //! Is stashed view + //! Is stashed view? bool isStashTab() const; + //! Is workbench tab? + bool isWorkbenchTab() const; + //! Tab can contribute to model set bool canAddToModelSetTab() const; @@ -233,6 +236,9 @@ namespace BlackGui //! Data for vPilot have been loaded void onLoadVPilotDataFinished(bool success); + //! Load removed models + void loadRemovedModels(); + //! Merge with vPilot models void mergeWithVPilotModels(); @@ -413,6 +419,25 @@ namespace BlackGui QAction *m_menuAction = nullptr; }; + //! Menu for removed models + class CRemovedModelsMenu : public Menus::IMenuDelegate + { + public: + //! Constructor + CRemovedModelsMenu(CDbMappingComponent *mappingComponent) : + Menus::IMenuDelegate(mappingComponent) + {} + + //! \copydoc IMenuDelegate::customMenu + virtual void customMenu(Menus::CMenuActions &menuActions) override; + + private: + //! Mapping component + CDbMappingComponent *mappingComponent() const; + + QAction *m_menuAction = nullptr; + }; + //! Apply DB data to selected models class CApplyDbDataMenu : public Menus::IMenuDelegate { diff --git a/src/blackgui/menus/menuaction.cpp b/src/blackgui/menus/menuaction.cpp index 24bffb7e0..3b736623e 100644 --- a/src/blackgui/menus/menuaction.cpp +++ b/src/blackgui/menus/menuaction.cpp @@ -437,9 +437,9 @@ namespace BlackGui CMenuAction CMenuActions::addMenuStash() { if (this->containsMenu(CMenuAction::pathModelStash())) { return CMenuAction(); } - const bool canConnectDb = sGui->getWebDataServices()->hasSuccesfullyConnectedSwiftDb(); - const QString txt(canConnectDb ? "Stash tools" : "Stash tools (Warning: no DB!)"); - return this->addMenu(CIcons::appDbStash16(), txt, CMenuAction::pathModelStash()); + const bool canConnectDb = sGui && sGui->getWebDataServices() && sGui->getWebDataServices()->hasSuccesfullyConnectedSwiftDb(); + const QString text(canConnectDb ? "Stash tools" : "Stash tools (Warning: no DB!)"); + return this->addMenu(CIcons::appDbStash16(), text, CMenuAction::pathModelStash()); } CMenuAction CMenuActions::addMenuStashEditor()