From bb8a0ca3f5860ef11906f9ae3a122bb718f12e0c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 11 Aug 2016 01:45:36 +0200 Subject: [PATCH] refs #724, context menu * in stash view data from DB can be removed * it can be stashed from own model set view too --- .../components/dbmappingcomponent.cpp | 42 +++++++++++++++---- src/blackgui/components/dbmappingcomponent.h | 3 ++ .../components/dbownmodelsetcomponent.cpp | 3 +- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 5d065dcb7..254b4c0f8 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -106,6 +106,8 @@ namespace BlackGui connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished); connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetChanged); + connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); + connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged); @@ -230,6 +232,8 @@ namespace BlackGui { case TabOwnModels: return ui->comp_OwnAircraftModels->view()->hasSelectedModelsToStash(); + case TabOwnModelSet: + return ui->comp_OwnModelSet->view()->hasSelectedModelsToStash(); case TabVPilot: return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash(); default: @@ -305,6 +309,8 @@ namespace BlackGui { case TabOwnModels: return ui->comp_OwnAircraftModels->view()->selectedObjects(); + case TabOwnModelSet: + return ui->comp_OwnModelSet->view()->selectedObjects(); case TabVPilot: return ui->tvp_AircraftModelsForVPilot->selectedObjects(); default: @@ -379,9 +385,16 @@ namespace BlackGui { const QStringList modelStrings(sGui->getWebDataServices()->getModelStrings()); if (modelStrings.isEmpty()) { return; } - if (currentTabIndex() == TabVPilot || currentTabIndex() == TabOwnModels) + switch (currentTabIndex()) { + case TabVPilot: + case TabOwnModels: + case TabOwnModelSet: + case TabStash: this->currentModelView()->removeModelsWithModelString(modelStrings); + break; + default: + break; } } @@ -861,14 +874,7 @@ namespace BlackGui this->m_stashFiltering = menuActions.addAction(this->m_stashFiltering, CIcons::filter16(), "Auto filtering in DB views (on/off)", CMenuAction::pathStash(), this, { mapComp, &CDbMappingComponent::ps_toggleAutoFiltering }); this->m_stashFiltering->setCheckable(true); this->m_stashFiltering->setChecked(mapComp->m_autoFilterInDbViews); - - const int dbModels = sGui->getWebDataServices()->getModelsCount(); - if (dbModels > 0) - { - // 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}); - } + this->addRemoveDbModels(menuActions); this->m_autoStashing = menuActions.addAction(this->m_autoStashing, CIcons::appDbStash16(), "Auto stashing", CMenuAction::pathStash(), this, { mapComp, &CDbMappingComponent::ps_displayAutoStashingDialog }); if (mapComp->m_autoStashDialog && mapComp->m_autoStashDialog->isCompleted()) @@ -876,9 +882,27 @@ namespace BlackGui menuActions.addAction(CIcons::appDbStash16(), "Last auto stash run", CMenuAction::pathStash(), nullptr, { mapComp->m_autoStashDialog.data(), &CDbAutoStashingComponent::showLastResults }); } } + else if (mapComp->currentTabIndex() == CDbMappingComponent::TabStash) + { + this->addRemoveDbModels(menuActions); + } this->nestedCustomMenu(menuActions); } + void CDbMappingComponent::CModelStashToolsMenu::addRemoveDbModels(CMenuActions &menuActions) + { + CDbMappingComponent *mapComp = mappingComponent(); + Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); + + const int dbModels = sGui->getWebDataServices()->getModelsCount(); + if (dbModels > 0) + { + // 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}); + } + } + CDbMappingComponent *CDbMappingComponent::CModelStashToolsMenu::mappingComponent() const { return qobject_cast(this->parent()); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 1299da4a1..69f4043aa 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -348,6 +348,9 @@ namespace BlackGui //! Mapping component CDbMappingComponent *mappingComponent() const; + //! Removel models existing in DB + void addRemoveDbModels(Menus::CMenuActions &menuActions); + QAction *m_autoStashing = nullptr; QAction *m_stashFiltering = nullptr; }; diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index a3c951de1..e588b0938 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -53,7 +53,8 @@ namespace BlackGui { ui->setupUi(this); ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnModelSet); - ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuStashing | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh); + ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuStashing); + ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh); ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear); ui->tvp_OwnModelSet->addFilterDialog(); ui->tvp_OwnModelSet->setJsonLoad(CAircraftModelView::AllowOnlySingleSimulator | CAircraftModelView::ReduceToOneSimulator);