mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Ref T292, Ref T285 replaced model set loader in "own model set" UI component and used CCentralMultiSimulatorModelSetCachesAware instead
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <QWidget>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
#include <QPointer>
|
||||
#include <QDesktopServices>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -70,6 +71,8 @@ namespace BlackGui
|
||||
ui->tvp_OwnModelSet->initAsOrderable();
|
||||
ui->tvp_OwnModelSet->setSimulatorForLoading(ui->comp_SimulatorSelector->getValue());
|
||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
||||
ui->comp_SimulatorSelector->setRememberSelectionAndSetToLastSelection();
|
||||
const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
|
||||
|
||||
//! \fixme maybe it would be better to set those in stylesheet file
|
||||
ui->pb_SaveAsSetForSimulator->setStyleSheet("padding-left: 3px; padding-right: 3px;");
|
||||
@@ -81,17 +84,11 @@ namespace BlackGui
|
||||
connect(ui->pb_CopyFromAnotherSwift, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked);
|
||||
connect(ui->pb_FirstSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked);
|
||||
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelSetComponent::setSimulator, Qt::QueuedConnection);
|
||||
connect(&m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::setSimulator, Qt::QueuedConnection);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this, &CDbOwnModelSetComponent::onRowCountChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::viewModelChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::onJsonDataLoaded);
|
||||
|
||||
const CSimulatorInfo simulator = m_modelSetLoader.getSimulator();
|
||||
if (simulator.isSingleSimulator())
|
||||
{
|
||||
this->setSimulator(simulator);
|
||||
ui->comp_SimulatorSelector->setRememberSelection(true);
|
||||
}
|
||||
this->triggerSetSimulatorDeferred(simulator);
|
||||
}
|
||||
|
||||
CDbOwnModelSetComponent::~CDbOwnModelSetComponent()
|
||||
@@ -153,11 +150,6 @@ namespace BlackGui
|
||||
return ui->tvp_OwnModelSet->container().size();
|
||||
}
|
||||
|
||||
CSimulatorInfo CDbOwnModelSetComponent::getModelSetSimulator() const
|
||||
{
|
||||
return m_modelSetLoader.getSimulator();
|
||||
}
|
||||
|
||||
CStatusMessage CDbOwnModelSetComponent::addToModelSet(const CAircraftModel &model, const CSimulatorInfo &simulator)
|
||||
{
|
||||
return this->addToModelSet(CAircraftModelList({model}), simulator);
|
||||
@@ -231,10 +223,10 @@ namespace BlackGui
|
||||
|
||||
if (sender == ui->pb_SaveAsSetForSimulator)
|
||||
{
|
||||
const CAircraftModelList ml(ui->tvp_OwnModelSet->container());
|
||||
if (!ml.isEmpty())
|
||||
const CAircraftModelList ownModelSet(ui->tvp_OwnModelSet->container());
|
||||
if (!ownModelSet.isEmpty())
|
||||
{
|
||||
const CStatusMessage m = m_modelSetLoader.setCachedModels(ml, this->getSelectedSimulator());
|
||||
const CStatusMessage m = this->setCachedModels(ownModelSet, this->getSelectedSimulator());
|
||||
CLogMessage::preformatted(m);
|
||||
}
|
||||
return;
|
||||
@@ -310,7 +302,7 @@ namespace BlackGui
|
||||
|
||||
void CDbOwnModelSetComponent::updateViewToCurrentModels()
|
||||
{
|
||||
const CAircraftModelList models(m_modelSetLoader.getAircraftModels());
|
||||
const CAircraftModelList models(this->getModelSet());
|
||||
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
|
||||
}
|
||||
|
||||
@@ -370,13 +362,26 @@ namespace BlackGui
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
|
||||
m_simulator = simulator;
|
||||
m_modelSetLoader.setSimulator(simulator);
|
||||
ui->comp_SimulatorSelector->setValue(simulator);
|
||||
ui->tvp_OwnModelSet->setSimulatorForLoading(simulator);
|
||||
ui->le_Simulator->setText(simulator.toQString(true));
|
||||
ui->comp_SimulatorSelector->setValue(simulator);
|
||||
this->synchronizeCache(simulator);
|
||||
this->updateViewToCurrentModels();
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::triggerSetSimulatorDeferred(const CSimulatorInfo &simulator)
|
||||
{
|
||||
this->admitCache(simulator);
|
||||
|
||||
QPointer<CDbOwnModelSetComponent> myself(this);
|
||||
QTimer::singleShot(1000, this, [ = ]
|
||||
{
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
if (!myself) { return; }
|
||||
this->setSimulator(simulator);
|
||||
});
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::showAirlineAircraftMatrix() const
|
||||
{
|
||||
const CAircraftModelList set(this->getModelSetFromView());
|
||||
@@ -387,13 +392,13 @@ namespace BlackGui
|
||||
|
||||
void CDbOwnModelSetComponent::updateDistributorOrder(const CSimulatorInfo &simulator)
|
||||
{
|
||||
CAircraftModelList modelSet = m_modelSetLoader.getAircraftModels(simulator);
|
||||
CAircraftModelList modelSet = this->getCachedModels(simulator);
|
||||
if (modelSet.isEmpty()) { return; }
|
||||
const CDistributorListPreferences preferences = m_distributorPreferences.getThreadLocal();
|
||||
const CDistributorList distributors = preferences.getDistributors(simulator);
|
||||
if (distributors.isEmpty()) { return; }
|
||||
modelSet.updateDistributorOrder(distributors);
|
||||
m_modelSetLoader.setModelsForSimulator(modelSet, simulator);
|
||||
this->setCachedModels(modelSet, simulator);
|
||||
|
||||
// display?
|
||||
const CSimulatorInfo currentSimulator(this->getModelSetSimulator());
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
#include "blackgui/components/dbmappingcomponentaware.h"
|
||||
#include "blackgui/menus/menudelegate.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
#include "blackmisc/simulation/settings/modelsettings.h"
|
||||
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/aircraftmodelsetloader.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
|
||||
@@ -48,10 +48,9 @@ namespace BlackGui
|
||||
class CDbOwnModelSetComponent :
|
||||
public QFrame,
|
||||
public CDbMappingComponentAware,
|
||||
public BlackMisc::Simulation::Data::CCentralMultiSimulatorModelSetCachesAware,
|
||||
public BlackMisc::Simulation::IModelsSetable,
|
||||
public BlackMisc::Simulation::IModelsUpdatable,
|
||||
public BlackMisc::Simulation::IModelsForSimulatorSetable,
|
||||
public BlackMisc::Simulation::IModelsForSimulatorUpdatable,
|
||||
public BlackMisc::Simulation::ISimulatorSelectable
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -86,27 +85,31 @@ namespace BlackGui
|
||||
//! \remark this the set from the container, which can be different from cache while updating
|
||||
int getModelSetCountFromView() const;
|
||||
|
||||
//! \copydoc BlackMisc::Simulation::CAircraftModelSetLoader::getCachedModels
|
||||
BlackMisc::Simulation::CAircraftModelList getModelSetFromLoader() const { return m_modelSetLoader.getCachedModels(this->getModelSetSimulator()); }
|
||||
//! Cached models for current simulator
|
||||
BlackMisc::Simulation::CAircraftModelList getModelSet() const { return this->getCachedModels(m_simulator); }
|
||||
|
||||
//! Model set is for simulator
|
||||
BlackMisc::Simulation::CSimulatorInfo getModelSetSimulator() const;
|
||||
//! Cached models count for current simulator
|
||||
int getModelSetCount() const { return this->getCachedModelsCount(m_simulator); }
|
||||
|
||||
//! Count and cache timestamp
|
||||
QString getModelCacheCountAndTimestamp() const { return QString::number(getModelSetCount()); }
|
||||
|
||||
//! Simulator
|
||||
void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Used model set loader
|
||||
const BlackMisc::Simulation::CAircraftModelSetLoader &modelSetLoader() const { return m_modelSetLoader; }
|
||||
//! Deferred init of simulator
|
||||
void triggerSetSimulatorDeferred(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! \copydoc CDbMappingComponentAware::setMappingComponent
|
||||
virtual void setMappingComponent(CDbMappingComponent *component) override;
|
||||
|
||||
//! Model set is for simulator
|
||||
BlackMisc::Simulation::CSimulatorInfo getModelSetSimulator() const { return m_simulator; }
|
||||
|
||||
//! \name Implementations of the models interfaces
|
||||
//! @{
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setModelSet(models, this->getModelSetSimulator()); }
|
||||
virtual void setModelsForSimulator(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setModelSet(models, simulator); }
|
||||
virtual int updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { return this->replaceOrAddModelSet(models, this->getModelSetSimulator()); }
|
||||
virtual int updateModelsForSimulator(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { return this->replaceOrAddModelSet(models, simulator); }
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getSelectedSimulator() const override { return this->getModelSetSimulator(); }
|
||||
//! @}
|
||||
|
||||
@@ -160,11 +163,10 @@ namespace BlackGui
|
||||
void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
|
||||
QScopedPointer<CDbOwnModelSetFormDialog> m_modelSetFormDialog;
|
||||
QScopedPointer<CFirstModelSetDialog> m_firstModelSet;
|
||||
QScopedPointer<CDbOwnModelSetFormDialog> m_modelSetFormDialog;
|
||||
QScopedPointer<CFirstModelSetDialog> m_firstModelSet;
|
||||
QScopedPointer<CCopyModelsFromOtherSwiftVersionsDialog> m_copyFromAnotherSwift;
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< currently set simulator
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
|
||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TDistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::distributorPreferencesChanged }; //!< distributor preferences
|
||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TModel> m_modelSettings { this }; //!< settings for models
|
||||
|
||||
|
||||
Reference in New Issue
Block a user