mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 23:05:34 +08:00
refs #568, allow to remove existing DB data from another model view
* Used with vPilot and own model views * in same step fixed separator handling in IMenuDelegate
This commit is contained in:
@@ -58,6 +58,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
|
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
|
||||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
|
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
|
||||||
|
ui->tvp_OwnAircraftModels->setCustomMenu(new CRemoveDbModelsMenu(this));
|
||||||
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
|
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
|
||||||
|
|
||||||
// how to display forms
|
// how to display forms
|
||||||
@@ -93,6 +94,7 @@ namespace BlackGui
|
|||||||
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
|
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 CMappingVPilotMenu(this, true));
|
||||||
|
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CRemoveDbModelsMenu(this));
|
||||||
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
|
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
|
||||||
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
|
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
|
||||||
const CAircraftModelList cachedModels(m_cachedVPilotModels.get());
|
const CAircraftModelList cachedModels(m_cachedVPilotModels.get());
|
||||||
@@ -208,6 +210,28 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftModelView *CDbMappingComponent::currentModelView()
|
||||||
|
{
|
||||||
|
TabIndex tab = currentTabIndex();
|
||||||
|
switch (tab)
|
||||||
|
{
|
||||||
|
case TabOwnModels:
|
||||||
|
return ui->tvp_OwnAircraftModels;
|
||||||
|
case TabVPilot:
|
||||||
|
return ui->tvp_AircraftModelsForVPilot;
|
||||||
|
case TabStash:
|
||||||
|
return ui->comp_StashAircraft->getView();
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CDbMappingComponent::currentTabText() const
|
||||||
|
{
|
||||||
|
int i = this->ui->tw_ModelsToBeMapped->currentIndex();
|
||||||
|
return this->ui->tw_ModelsToBeMapped->tabText(i);
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const
|
CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const
|
||||||
{
|
{
|
||||||
if (!hasSelectedModelsToStash()) { return CAircraftModelList(); }
|
if (!hasSelectedModelsToStash()) { return CAircraftModelList(); }
|
||||||
@@ -285,6 +309,16 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDbMappingComponent::ps_removeDbModelsFromView()
|
||||||
|
{
|
||||||
|
QStringList modelStrings(this->getModelStrings());
|
||||||
|
if (modelStrings.isEmpty()) { return; }
|
||||||
|
if (currentTabIndex() == TabVPilot || currentTabIndex() == TabOwnModels)
|
||||||
|
{
|
||||||
|
this->currentModelView()->removeModelsWithModelString(modelStrings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CDbMappingComponent::resizeForSelect()
|
void CDbMappingComponent::resizeForSelect()
|
||||||
{
|
{
|
||||||
int h = this->height();
|
int h = this->height();
|
||||||
@@ -545,7 +579,7 @@ namespace BlackGui
|
|||||||
bool noSims = sims.isNoSimulator() || sims.isUnspecified();
|
bool noSims = sims.isNoSimulator() || sims.isUnspecified();
|
||||||
if (!noSims)
|
if (!noSims)
|
||||||
{
|
{
|
||||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
this->addSeparator(menu);
|
||||||
QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models");
|
QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models");
|
||||||
QAction *a = nullptr;
|
QAction *a = nullptr;
|
||||||
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
|
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
|
||||||
@@ -583,7 +617,7 @@ namespace BlackGui
|
|||||||
bool canUseVPilot = mappingComponent()->withVPilot();
|
bool canUseVPilot = mappingComponent()->withVPilot();
|
||||||
if (canUseVPilot)
|
if (canUseVPilot)
|
||||||
{
|
{
|
||||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
this->addSeparator(menu);
|
||||||
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
|
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
|
||||||
}
|
}
|
||||||
this->nestedCustomMenu(menu);
|
this->nestedCustomMenu(menu);
|
||||||
@@ -593,5 +627,29 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
return qobject_cast<CDbMappingComponent *>(this->parent());
|
return qobject_cast<CDbMappingComponent *>(this->parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDbMappingComponent::CRemoveDbModelsMenu::customMenu(QMenu &menu) const
|
||||||
|
{
|
||||||
|
CDbMappingComponent *mapComp = mappingComponent();
|
||||||
|
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component");
|
||||||
|
int dbModels = mapComp->getModelsCount();
|
||||||
|
if (dbModels > 0)
|
||||||
|
{
|
||||||
|
if (!mapComp->currentModelView()->isEmpty())
|
||||||
|
{
|
||||||
|
this->addSeparator(menu);
|
||||||
|
|
||||||
|
// 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->nestedCustomMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
CDbMappingComponent *CDbMappingComponent::CRemoveDbModelsMenu::mappingComponent() const
|
||||||
|
{
|
||||||
|
return qobject_cast<CDbMappingComponent *>(this->parent());
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace BlackGui
|
|||||||
//! Request to filter by distributor
|
//! Request to filter by distributor
|
||||||
void filterByDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
void filterByDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
||||||
|
|
||||||
//! Request new data
|
//! Request latest (incrementall) data from backend
|
||||||
void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities);
|
void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -175,6 +175,9 @@ namespace BlackGui
|
|||||||
//! Stash current model
|
//! Stash current model
|
||||||
void ps_stashCurrentModel();
|
void ps_stashCurrentModel();
|
||||||
|
|
||||||
|
//! Remove DB models from current view
|
||||||
|
void ps_removeDbModelsFromView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CDbMappingComponent> ui;
|
QScopedPointer<Ui::CDbMappingComponent> ui;
|
||||||
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
||||||
@@ -197,30 +200,54 @@ namespace BlackGui
|
|||||||
//! Current model view
|
//! Current model view
|
||||||
const BlackGui::Views::CAircraftModelView *currentModelView() const;
|
const BlackGui::Views::CAircraftModelView *currentModelView() const;
|
||||||
|
|
||||||
|
//! Current model view
|
||||||
|
BlackGui::Views::CAircraftModelView *currentModelView();
|
||||||
|
|
||||||
|
//! Current tab text
|
||||||
|
QString currentTabText() const;
|
||||||
|
|
||||||
// -------------------- component specific menus --------------------------
|
// -------------------- component specific menus --------------------------
|
||||||
|
|
||||||
//! The menu for loading and handling own models for mapping
|
//! The menu for loading and handling own models for mapping tasks
|
||||||
//! \note This is specific for that very component
|
//! \note This is specific for that very component
|
||||||
class CMappingSimulatorModelMenu : public BlackGui::IMenuDelegate
|
class CMappingSimulatorModelMenu : public BlackGui::IMenuDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CMappingSimulatorModelMenu(CDbMappingComponent *mappingComponent) :
|
CMappingSimulatorModelMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
|
||||||
BlackGui::IMenuDelegate(mappingComponent)
|
BlackGui::IMenuDelegate(mappingComponent, separator)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! \copydoc IMenuDelegate::customMenu
|
//! \copydoc IMenuDelegate::customMenu
|
||||||
virtual void customMenu(QMenu &menu) const override;
|
virtual void customMenu(QMenu &menu) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! The menu for loading and handling VPilot rules for mapping
|
//! The menu for loading and handling VPilot rules for mapping tasks
|
||||||
//! \note This is a specific menu for that very component
|
//! \note This is a specific menu for that very component
|
||||||
class CMappingVPilotMenu : public BlackGui::IMenuDelegate
|
class CMappingVPilotMenu : public BlackGui::IMenuDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separatorAtEnd) :
|
CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
|
||||||
BlackGui::IMenuDelegate(mappingComponent, separatorAtEnd)
|
BlackGui::IMenuDelegate(mappingComponent, separator)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! \copydoc IMenuDelegate::customMenu
|
||||||
|
virtual void customMenu(QMenu &menu) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! Mapping component
|
||||||
|
CDbMappingComponent *mappingComponent() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Menu for removing DB models from current view
|
||||||
|
//! \note This is a specific menu for that very component
|
||||||
|
class CRemoveDbModelsMenu : public BlackGui::IMenuDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CRemoveDbModelsMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
|
||||||
|
BlackGui::IMenuDelegate(mappingComponent, separator)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! \copydoc IMenuDelegate::customMenu
|
//! \copydoc IMenuDelegate::customMenu
|
||||||
|
|||||||
@@ -141,6 +141,11 @@ namespace BlackGui
|
|||||||
return ui->tvp_StashAircraftModels;
|
return ui->tvp_StashAircraftModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Views::CAircraftModelView *CDbStashComponent::getView()
|
||||||
|
{
|
||||||
|
return ui->tvp_StashAircraftModels;
|
||||||
|
}
|
||||||
|
|
||||||
bool CDbStashComponent::hasStashedModels() const
|
bool CDbStashComponent::hasStashedModels() const
|
||||||
{
|
{
|
||||||
return !this->ui->tvp_StashAircraftModels->isEmpty();
|
return !this->ui->tvp_StashAircraftModels->isEmpty();
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ namespace BlackGui
|
|||||||
//! The embedded view
|
//! The embedded view
|
||||||
const BlackGui::Views::CAircraftModelView *getView() const;
|
const BlackGui::Views::CAircraftModelView *getView() const;
|
||||||
|
|
||||||
|
//! The embedded view
|
||||||
|
Views::CAircraftModelView *getView();
|
||||||
|
|
||||||
//! Has stashed models
|
//! Has stashed models
|
||||||
bool hasStashedModels() const;
|
bool hasStashedModels() const;
|
||||||
|
|
||||||
|
|||||||
@@ -37,24 +37,26 @@ namespace BlackGui
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
IMenuDelegate(QWidget *parent = nullptr, bool separatorAtEnd = false) :
|
IMenuDelegate(QWidget *parent = nullptr, bool separator = false) :
|
||||||
QObject(parent), m_separatorAtEnd(separatorAtEnd) {}
|
QObject(parent), m_separator(separator) {}
|
||||||
|
|
||||||
//! Delegate down one level
|
//! Delegate down one level
|
||||||
void nestedCustomMenu(QMenu &menu) const
|
void nestedCustomMenu(QMenu &menu) const
|
||||||
{
|
{
|
||||||
if (!m_nestedDelegate)
|
if (!m_nestedDelegate) { return; }
|
||||||
{
|
|
||||||
if (m_separatorAtEnd && !menu.isEmpty()) { menu.addSeparator(); }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_nestedDelegate->customMenu(menu);
|
m_nestedDelegate->customMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMenuDelegate *m_nestedDelegate = nullptr; //!< nested delegate if any
|
//! Add separator
|
||||||
bool m_separatorAtEnd = false; //!< at end, terminate with separator
|
void addSeparator(QMenu &menu) const
|
||||||
};
|
{
|
||||||
|
if (!m_separator || menu.isEmpty()) { return; }
|
||||||
|
menu.addSeparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IMenuDelegate *m_nestedDelegate = nullptr; //!< nested delegate if any
|
||||||
|
bool m_separator = false; //!< at end, terminate with separator
|
||||||
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user