mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #614, allow to merge own models with vPilot rules (this can be used if no DB data are available yet)
* menus * utility functions
This commit is contained in:
@@ -29,6 +29,7 @@ using namespace BlackGui;
|
||||
using namespace BlackGui::Editors;
|
||||
using namespace BlackGui::Views;
|
||||
using namespace BlackGui::Models;
|
||||
using namespace BlackGui::Menus;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -48,6 +49,7 @@ namespace BlackGui
|
||||
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
|
||||
|
||||
// own models
|
||||
ui->comp_OwnAircraftModels->view()->setCustomMenu(new CMergeWithVPilotMenu(this));
|
||||
ui->comp_OwnAircraftModels->view()->setCustomMenu(new COwnModelSetMenu(this, true));
|
||||
ui->comp_OwnAircraftModels->view()->setCustomMenu(new CModelStashToolsMenu(this, false));
|
||||
|
||||
@@ -104,8 +106,9 @@ namespace BlackGui
|
||||
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true));
|
||||
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CModelStashToolsMenu(this, false));
|
||||
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
|
||||
|
||||
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
|
||||
const CAircraftModelList vPilotModels(m_cachedVPilotModels.get());
|
||||
const CAircraftModelList vPilotModels(m_vPilotReader.getAsModelsFromCache());
|
||||
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(vPilotModels);
|
||||
int noModels = vPilotModels.size();
|
||||
CLogMessage(this).info("%1 cached vPilot models loaded") << noModels;
|
||||
@@ -413,15 +416,6 @@ namespace BlackGui
|
||||
{
|
||||
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(models);
|
||||
}
|
||||
CStatusMessage msg = m_cachedVPilotModels.set(models);
|
||||
if (msg.isWarningOrAbove())
|
||||
{
|
||||
CLogMessage::preformatted(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).info("Written %1 vPilot rules to cache") << models.size();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -434,7 +428,7 @@ namespace BlackGui
|
||||
{
|
||||
if (this->ui->tvp_AircraftModelsForVPilot->displayAutomatically())
|
||||
{
|
||||
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(this->m_cachedVPilotModels.get());
|
||||
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(this->m_vPilotReader.getAsModelsFromCache());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,6 +494,48 @@ namespace BlackGui
|
||||
CLogMessage::preformatted(m);
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_mergeWithVPilotModels()
|
||||
{
|
||||
if (!ui->comp_OwnAircraftModels->modelLoader()) { return; }
|
||||
if (this->m_vPilotReader.getModelsCount() < 1) { return; }
|
||||
const CSimulatorInfo sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator());
|
||||
if (!sim.isSingleSimulator() || !sim.isMicrosoftOrPrepare3DSimulator()) { return; }
|
||||
CAircraftModelList ownModels(getOwnModels());
|
||||
if (ownModels.isEmpty()) { return; }
|
||||
ui->comp_OwnAircraftModels->view()->showLoadIndicator();
|
||||
CAircraftModelUtilities::mergeWithVPilotData(ownModels, this->m_vPilotReader.getAsModelsFromCache(), true);
|
||||
ui->comp_OwnAircraftModels->updateViewAndCache(ownModels);
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_mergeSelectedWithVPilotModels()
|
||||
{
|
||||
if (!ui->comp_OwnAircraftModels->modelLoader()) { return; }
|
||||
if (this->m_vPilotReader.getModelsCount() < 1) { return; }
|
||||
if (!ui->comp_OwnAircraftModels->view()->hasSelection()) { return; }
|
||||
const CSimulatorInfo sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator());
|
||||
if (!sim.isSingleSimulator() || !sim.isMicrosoftOrPrepare3DSimulator()) { return; }
|
||||
CAircraftModelList ownModels(getOwnSelectedModels()); // subset
|
||||
if (ownModels.isEmpty()) { return; }
|
||||
ui->comp_OwnAircraftModels->view()->showLoadIndicator();
|
||||
CAircraftModelUtilities::mergeWithVPilotData(ownModels, this->m_vPilotReader.getAsModelsFromCache(), true);
|
||||
|
||||
// full models
|
||||
CAircraftModelList allModels = this->m_vPilotReader.getAsModelsFromCache();
|
||||
allModels.replaceOrAddModelsWithString(ownModels, Qt::CaseInsensitive);
|
||||
ui->comp_OwnAircraftModels->updateViewAndCache(allModels);
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_onCustomContextMenu(const QPoint &point)
|
||||
{
|
||||
QPoint globalPos = this->mapToGlobal(point);
|
||||
QScopedPointer<QMenu> contextMenu(new QMenu(this));
|
||||
|
||||
contextMenu->addAction("Max.data area", this, &CDbMappingComponent::resizeForSelect, QKeySequence(Qt::CTRL + Qt::Key_M, Qt::Key_D));
|
||||
contextMenu->addAction("Max.mapping area", this, &CDbMappingComponent::resizeForMapping, QKeySequence(Qt::CTRL + Qt::Key_M, Qt::Key_M));
|
||||
QAction *selectedItem = contextMenu.data()->exec(globalPos);
|
||||
Q_UNUSED(selectedItem);
|
||||
}
|
||||
|
||||
void CDbMappingComponent::ps_onStashCountChanged(int count, bool withFilter)
|
||||
{
|
||||
Q_UNUSED(count);
|
||||
@@ -603,6 +639,11 @@ namespace BlackGui
|
||||
return this->ui->comp_OwnAircraftModels->getOwnModels();
|
||||
}
|
||||
|
||||
CAircraftModelList CDbMappingComponent::getOwnSelectedModels() const
|
||||
{
|
||||
return this->ui->comp_OwnAircraftModels->getOwnSelectedModels();
|
||||
}
|
||||
|
||||
CAircraftModel CDbMappingComponent::getOwnModelForModelString(const QString &modelString) const
|
||||
{
|
||||
return this->ui->comp_OwnAircraftModels->getOwnModelForModelString(modelString);
|
||||
@@ -652,7 +693,7 @@ namespace BlackGui
|
||||
if (canUseVPilot)
|
||||
{
|
||||
this->addSeparator(menu);
|
||||
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
|
||||
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, &CDbMappingComponent::ps_loadVPilotData);
|
||||
}
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
@@ -770,5 +811,35 @@ namespace BlackGui
|
||||
{
|
||||
return qobject_cast<CDbMappingComponent *>(this->parent());
|
||||
}
|
||||
|
||||
CDbMappingComponent::CMergeWithVPilotMenu::CMergeWithVPilotMenu(CDbMappingComponent *mappingComponent, bool separator) :
|
||||
IMenuDelegate(mappingComponent, separator)
|
||||
{
|
||||
Q_ASSERT_X(mappingComponent, Q_FUNC_INFO, "Missing vPilot reader");
|
||||
}
|
||||
|
||||
void CDbMappingComponent::CMergeWithVPilotMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
const CAircraftModelView *mv = mappingComponent()->ui->comp_OwnAircraftModels->view();
|
||||
const CSimulatorInfo sim = mappingComponent()->ui->comp_OwnAircraftModels->getOwnModelsSimulator();
|
||||
if (!mappingComponent()->withVPilot() || mv->isEmpty() || !sim.isSingleSimulator() || !sim.isMicrosoftOrPrepare3DSimulator())
|
||||
{
|
||||
this->nestedCustomMenu(menu);
|
||||
return;
|
||||
}
|
||||
this->addSeparator(menu);
|
||||
QMenu *mm = menu.addMenu("Merge with vPilot data");
|
||||
mm->addAction("All", mappingComponent(), &CDbMappingComponent::ps_mergeWithVPilotModels);
|
||||
if (mv->hasSelection())
|
||||
{
|
||||
mm->addAction("Selected only", mappingComponent(), &CDbMappingComponent::ps_mergeSelectedWithVPilotModels);
|
||||
}
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
|
||||
CDbMappingComponent *CDbMappingComponent::CMergeWithVPilotMenu::mappingComponent() const
|
||||
{
|
||||
return qobject_cast<CDbMappingComponent *>(this->parent());
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -104,6 +104,9 @@ namespace BlackGui
|
||||
//! Own models
|
||||
BlackMisc::Simulation::CAircraftModelList getOwnModels() const;
|
||||
|
||||
//! Own selected models
|
||||
BlackMisc::Simulation::CAircraftModelList getOwnSelectedModels() const;
|
||||
|
||||
//! Own (installed) model for given model string
|
||||
BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const;
|
||||
|
||||
@@ -222,13 +225,21 @@ namespace BlackGui
|
||||
//! Add to own model set
|
||||
void ps_addToOwnModelSet();
|
||||
|
||||
//! Merge with vPilot models
|
||||
void ps_mergeWithVPilotModels();
|
||||
|
||||
//! Merge selected with vPilot models
|
||||
void ps_mergeSelectedWithVPilotModels();
|
||||
|
||||
//! Custom menu
|
||||
void ps_onCustomContextMenu(const QPoint &point);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbMappingComponent> ui;
|
||||
QScopedPointer<CDbAutoStashingComponent> m_autoStashDialog; //!< dialog auto stashing
|
||||
QScopedPointer<CDbModelMappingModifyComponent> m_modelModifyDialog; //!< dialog when modifying models
|
||||
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::VPilotAircraftModels> m_cachedVPilotModels { this, &CDbMappingComponent::ps_onVPilotCacheChanged }; //!< cache for latest vPilot rules
|
||||
BlackMisc::CData<BlackCore::Data::AuthenticatedDbUser> m_swiftDbUser {this, &CDbMappingComponent::ps_userChanged};
|
||||
QScopedPointer<Ui::CDbMappingComponent> ui;
|
||||
QScopedPointer<CDbAutoStashingComponent> m_autoStashDialog; //!< dialog auto stashing
|
||||
QScopedPointer<CDbModelMappingModifyComponent> m_modelModifyDialog; //!< dialog when modifying models
|
||||
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
|
||||
BlackMisc::CData<BlackCore::Data::AuthenticatedDbUser> m_swiftDbUser {this, &CDbMappingComponent::ps_userChanged};
|
||||
bool m_vPilot1stInit = true;
|
||||
bool m_withVPilot = false;
|
||||
bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model
|
||||
@@ -314,6 +325,20 @@ namespace BlackGui
|
||||
//! Mapping component
|
||||
CDbMappingComponent *mappingComponent() const;
|
||||
};
|
||||
|
||||
//! Merge with vPilot data
|
||||
class CMergeWithVPilotMenu : public BlackGui::Menus::IMenuDelegate
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CMergeWithVPilotMenu(CDbMappingComponent *mappingComponent, bool separator = true);
|
||||
|
||||
//! \copydoc IMenuDelegate::customMenu
|
||||
virtual void customMenu(QMenu &menu) const override;
|
||||
|
||||
//! Mapping component
|
||||
CDbMappingComponent *mappingComponent() const;
|
||||
};
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackGui
|
||||
this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly);
|
||||
}
|
||||
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnAircraftModels, this->m_modelLoader.get(), false));
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnAircraftModels, this->modelLoader(), false));
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CLoadModelsMenu(this, true));
|
||||
}
|
||||
|
||||
@@ -64,6 +64,11 @@ namespace BlackGui
|
||||
return ui->tvp_OwnAircraftModels->derivedModel();
|
||||
}
|
||||
|
||||
IAircraftModelLoader *CDbOwnModelsComponent::modelLoader() const
|
||||
{
|
||||
return this->m_modelLoader.get();
|
||||
}
|
||||
|
||||
CAircraftModel CDbOwnModelsComponent::getOwnModelForModelString(const QString &modelString) const
|
||||
{
|
||||
if (!this->m_modelLoader) { return CAircraftModel(); }
|
||||
@@ -77,6 +82,11 @@ namespace BlackGui
|
||||
return this->m_modelLoader->getAircraftModels();
|
||||
}
|
||||
|
||||
CAircraftModelList CDbOwnModelsComponent::getOwnSelectedModels() const
|
||||
{
|
||||
return ui->tvp_OwnAircraftModels->selectedObjects();
|
||||
}
|
||||
|
||||
const CSimulatorInfo &CDbOwnModelsComponent::getOwnModelsSimulator() const
|
||||
{
|
||||
static const CSimulatorInfo noSim;
|
||||
@@ -90,6 +100,16 @@ namespace BlackGui
|
||||
return this->m_modelLoader->getAircraftModelsCount();
|
||||
}
|
||||
|
||||
CStatusMessage CDbOwnModelsComponent::updateViewAndCache(const CAircraftModelList &models)
|
||||
{
|
||||
const CStatusMessage m = this->m_modelLoader->setCachedModels(models, this->getOwnModelsSimulator());
|
||||
if (m.isSuccess())
|
||||
{
|
||||
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(models);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
void CDbOwnModelsComponent::gracefulShutdown()
|
||||
{
|
||||
if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); }
|
||||
|
||||
@@ -46,18 +46,27 @@ namespace BlackGui
|
||||
//! Own models
|
||||
BlackMisc::Simulation::CAircraftModelList getOwnModels() const;
|
||||
|
||||
//! Own models selected in view
|
||||
BlackMisc::Simulation::CAircraftModelList getOwnSelectedModels() const;
|
||||
|
||||
//! Own models for simulator
|
||||
const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const;
|
||||
|
||||
//! Number of own models
|
||||
int getOwnModelsCount() const;
|
||||
|
||||
//! Update view and cache
|
||||
BlackMisc::CStatusMessage updateViewAndCache(const BlackMisc::Simulation::CAircraftModelList &models);
|
||||
|
||||
//! Models view
|
||||
BlackGui::Views::CAircraftModelView *view() const;
|
||||
|
||||
//! Access to aircraft model
|
||||
Models::CAircraftModelListModel *model() const;
|
||||
|
||||
//! Access to model loader
|
||||
BlackMisc::Simulation::IAircraftModelLoader *modelLoader() const;
|
||||
|
||||
//! Graceful shutdown
|
||||
void gracefulShutdown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user