Ref T362, Ref T348 "removed models" context menu

This commit is contained in:
Klaus Basan
2018-09-21 17:32:43 +02:00
parent 8a5112e48d
commit 3037afabf2
3 changed files with 62 additions and 5 deletions

View File

@@ -48,6 +48,7 @@
#include <QTabWidget>
#include <QVariant>
#include <QWidget>
#include <QFileDialog>
#include <Qt>
#include <QtGlobal>
@@ -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<CDbMappingComponent *>(this->parent());
}
CDbMappingComponent *CDbMappingComponent::CMergeWithVPilotMenu::mappingComponent() const
{
return qobject_cast<CDbMappingComponent *>(this->parent());

View File

@@ -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
{

View File

@@ -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()