mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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->setCustomMenu(new CMappingSimulatorModelMenu(this));
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CRemoveDbModelsMenu(this));
|
||||
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
|
||||
|
||||
// how to display forms
|
||||
@@ -93,6 +94,7 @@ namespace BlackGui
|
||||
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 CRemoveDbModelsMenu(this));
|
||||
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
|
||||
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
|
||||
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
|
||||
{
|
||||
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()
|
||||
{
|
||||
int h = this->height();
|
||||
@@ -545,7 +579,7 @@ namespace BlackGui
|
||||
bool noSims = sims.isNoSimulator() || sims.isUnspecified();
|
||||
if (!noSims)
|
||||
{
|
||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
||||
this->addSeparator(menu);
|
||||
QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models");
|
||||
QAction *a = nullptr;
|
||||
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
|
||||
@@ -583,7 +617,7 @@ namespace BlackGui
|
||||
bool canUseVPilot = mappingComponent()->withVPilot();
|
||||
if (canUseVPilot)
|
||||
{
|
||||
if (!menu.isEmpty()) { menu.addSeparator(); }
|
||||
this->addSeparator(menu);
|
||||
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
|
||||
}
|
||||
this->nestedCustomMenu(menu);
|
||||
@@ -593,5 +627,29 @@ namespace BlackGui
|
||||
{
|
||||
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
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace BlackGui
|
||||
//! Request to filter by distributor
|
||||
void filterByDistributor(const BlackMisc::Simulation::CDistributor &distributor);
|
||||
|
||||
//! Request new data
|
||||
//! Request latest (incrementall) data from backend
|
||||
void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities);
|
||||
|
||||
public slots:
|
||||
@@ -175,6 +175,9 @@ namespace BlackGui
|
||||
//! Stash current model
|
||||
void ps_stashCurrentModel();
|
||||
|
||||
//! Remove DB models from current view
|
||||
void ps_removeDbModelsFromView();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbMappingComponent> ui;
|
||||
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
||||
@@ -197,30 +200,54 @@ namespace BlackGui
|
||||
//! Current model view
|
||||
const BlackGui::Views::CAircraftModelView *currentModelView() const;
|
||||
|
||||
//! Current model view
|
||||
BlackGui::Views::CAircraftModelView *currentModelView();
|
||||
|
||||
//! Current tab text
|
||||
QString currentTabText() const;
|
||||
|
||||
// -------------------- 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
|
||||
class CMappingSimulatorModelMenu : public BlackGui::IMenuDelegate
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CMappingSimulatorModelMenu(CDbMappingComponent *mappingComponent) :
|
||||
BlackGui::IMenuDelegate(mappingComponent)
|
||||
CMappingSimulatorModelMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
|
||||
BlackGui::IMenuDelegate(mappingComponent, separator)
|
||||
{}
|
||||
|
||||
//! \copydoc IMenuDelegate::customMenu
|
||||
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
|
||||
class CMappingVPilotMenu : public BlackGui::IMenuDelegate
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separatorAtEnd) :
|
||||
BlackGui::IMenuDelegate(mappingComponent, separatorAtEnd)
|
||||
CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
|
||||
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
|
||||
|
||||
@@ -141,6 +141,11 @@ namespace BlackGui
|
||||
return ui->tvp_StashAircraftModels;
|
||||
}
|
||||
|
||||
Views::CAircraftModelView *CDbStashComponent::getView()
|
||||
{
|
||||
return ui->tvp_StashAircraftModels;
|
||||
}
|
||||
|
||||
bool CDbStashComponent::hasStashedModels() const
|
||||
{
|
||||
return !this->ui->tvp_StashAircraftModels->isEmpty();
|
||||
|
||||
@@ -64,6 +64,9 @@ namespace BlackGui
|
||||
//! The embedded view
|
||||
const BlackGui::Views::CAircraftModelView *getView() const;
|
||||
|
||||
//! The embedded view
|
||||
Views::CAircraftModelView *getView();
|
||||
|
||||
//! Has stashed models
|
||||
bool hasStashedModels() const;
|
||||
|
||||
|
||||
@@ -37,24 +37,26 @@ namespace BlackGui
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IMenuDelegate(QWidget *parent = nullptr, bool separatorAtEnd = false) :
|
||||
QObject(parent), m_separatorAtEnd(separatorAtEnd) {}
|
||||
IMenuDelegate(QWidget *parent = nullptr, bool separator = false) :
|
||||
QObject(parent), m_separator(separator) {}
|
||||
|
||||
//! Delegate down one level
|
||||
void nestedCustomMenu(QMenu &menu) const
|
||||
{
|
||||
if (!m_nestedDelegate)
|
||||
{
|
||||
if (m_separatorAtEnd && !menu.isEmpty()) { menu.addSeparator(); }
|
||||
return;
|
||||
}
|
||||
if (!m_nestedDelegate) { return; }
|
||||
m_nestedDelegate->customMenu(menu);
|
||||
}
|
||||
|
||||
IMenuDelegate *m_nestedDelegate = nullptr; //!< nested delegate if any
|
||||
bool m_separatorAtEnd = false; //!< at end, terminate with separator
|
||||
};
|
||||
//! Add 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
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user