mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T67, check models against simulator when loading them
* set simulator which the model view accepts for loading * removed old flags
This commit is contained in:
@@ -47,6 +47,7 @@ namespace BlackGui
|
||||
ui->tvp_OwnAircraftModels->addFilterDialog();
|
||||
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CLoadModelsMenu(this, true));
|
||||
ui->tvp_OwnAircraftModels->setSimulatorForLoading(ui->comp_SimulatorSelector->getValue());
|
||||
|
||||
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::ps_requestOwnModelsUpdate);
|
||||
|
||||
@@ -65,7 +66,7 @@ namespace BlackGui
|
||||
|
||||
ui->comp_SimulatorSelector->setValue(simulator);
|
||||
ui->le_Simulator->setText(simulator.toQString());
|
||||
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelsComponent::ps_requestSimulatorModelsWithCacheInBackground);
|
||||
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelsComponent::ps_onSimulatorChanged);
|
||||
|
||||
// menu
|
||||
ui->tvp_OwnAircraftModels->setCustomMenu(new CConsolidateWithDbDataMenu(ui->tvp_OwnAircraftModels, this, false));
|
||||
@@ -465,7 +466,7 @@ namespace BlackGui
|
||||
CLogMessage(this).error("Loading of models failed, simulator '%1', details: %2") << simulator.toQString() << status.getMessage();
|
||||
}
|
||||
|
||||
// cache loads may occur in background, do not adjust UI
|
||||
// cache loads may occur in background, do not adjust UI settings
|
||||
if (info == IAircraftModelLoader::CacheLoaded) { return; }
|
||||
|
||||
// parsed loads normally explicit
|
||||
@@ -482,5 +483,12 @@ namespace BlackGui
|
||||
{
|
||||
this->ps_requestSimulatorModels(simulator, IAircraftModelLoader::InBackgroundWithCache);
|
||||
}
|
||||
|
||||
void CDbOwnModelsComponent::ps_onSimulatorChanged()
|
||||
{
|
||||
const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue());
|
||||
ui->tvp_OwnAircraftModels->setSimulatorForLoading(sim);
|
||||
this->ps_requestSimulatorModelsWithCacheInBackground(sim);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -133,10 +133,13 @@ namespace BlackGui
|
||||
//! Request simulator models from cache
|
||||
void ps_requestSimulatorModelsWithCacheInBackground(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Own simulator changed
|
||||
void ps_onSimulatorChanged();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbOwnModelsComponent> ui;
|
||||
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
|
||||
BlackMisc::CDataReadOnly<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_simulatorSelection {this }; //!< last selection
|
||||
BlackMisc::CDataReadOnly<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_simulatorSelection { this }; //!< last selection
|
||||
|
||||
//! Init or change model loader
|
||||
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
@@ -60,13 +60,13 @@ namespace BlackGui
|
||||
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear);
|
||||
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuMaterializeFilter);
|
||||
ui->tvp_OwnModelSet->addFilterDialog();
|
||||
ui->tvp_OwnModelSet->setJsonLoad(CAircraftModelView::AllowOnlySingleSimulator | CAircraftModelView::ReduceToOneSimulator);
|
||||
ui->tvp_OwnModelSet->setCustomMenu(new CLoadModelsMenu(this));
|
||||
ui->tvp_OwnModelSet->setCustomMenu(new CConsolidateWithDbDataMenu(ui->tvp_OwnModelSet, this, true));
|
||||
ui->tvp_OwnModelSet->setCustomMenu(new CConsolidateWithSimulatorModels(ui->tvp_OwnModelSet, this, false));
|
||||
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuOrderable);
|
||||
ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
|
||||
ui->tvp_OwnModelSet->initAsOrderable();
|
||||
ui->tvp_OwnModelSet->setSimulatorForLoading(ui->comp_SimulatorSelector->getValue());
|
||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
||||
|
||||
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
|
||||
@@ -342,6 +342,7 @@ namespace BlackGui
|
||||
{
|
||||
if (this->m_modelSetLoader.getSimulator() == simulator) { return; } // avoid unnecessary signals
|
||||
this->m_modelSetLoader.changeSimulator(simulator);
|
||||
ui->tvp_OwnModelSet->setSimulatorForLoading(simulator);
|
||||
ui->le_Simulator->setText(simulator.toQString(true));
|
||||
ui->comp_SimulatorSelector->setValue(simulator);
|
||||
}
|
||||
|
||||
@@ -330,48 +330,22 @@ namespace BlackGui
|
||||
|
||||
CStatusMessage CAircraftModelView::modifyLoadedJsonData(CAircraftModelList &models) const
|
||||
{
|
||||
if (!this->m_jsonLoad.testFlag(ReduceToOneSimulator)) { return {}; }
|
||||
if (this->m_loadingRequiresSimulator.isNoSimulator()) { return {}; }
|
||||
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityDebug, "Empty models", true); }
|
||||
const CSimulatorInfo maxSims = models.simulatorsWithMaxEntries();
|
||||
if (maxSims.isNoSimulator())
|
||||
{
|
||||
return CStatusMessage(this, CStatusMessage::SeverityError, "No simulator with maximum, cannot reduce");
|
||||
}
|
||||
|
||||
if (maxSims.isSingleSimulator())
|
||||
{
|
||||
int rm = models.removeIfNotMatchingSimulator(maxSims);
|
||||
return rm < 1 ?
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Now only for " + maxSims.toQString(true), true) :
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Reduced by % 1 to only use %2", true) << rm << maxSims.toQString(true);
|
||||
}
|
||||
|
||||
// one simulator dominating
|
||||
if (maxSims.isSingleSimulator())
|
||||
{
|
||||
int rm = models.removeIfNotMatchingSimulator(maxSims);
|
||||
return rm < 1 ?
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Now only for " + maxSims.toQString(true), true) :
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Reduced by % 1 to only use %2", true) << rm << maxSims.toQString(true);
|
||||
}
|
||||
|
||||
// multiple sims with same count
|
||||
const CSimulatorInfo first = CSimulatorInfoList::splitIntoSingleSimulators(maxSims).front();
|
||||
int d = models.removeIfNotMatchingSimulator(first);
|
||||
return d < 1 ?
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Now only for " + maxSims.toQString(true), true) :
|
||||
CStatusMessage(this, CStatusMessage::SeverityInfo, "Reduced by % 1 to only use %2", true) << d << maxSims.toQString(true);
|
||||
const int removed = models.removeIfNotMatchingSimulator(this->m_loadingRequiresSimulator);
|
||||
if (removed < 1) { return {}; }
|
||||
return CStatusMessage(this, CStatusMessage::SeverityWarning, "Reduced by %1 model(s) to only use %2 models", true) << removed << this->m_loadingRequiresSimulator.toQString(true);
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelView::validateLoadedJsonData(const CAircraftModelList &models) const
|
||||
{
|
||||
static const CStatusMessage ok(this, CStatusMessage::SeverityInfo, "model validation passed", true);
|
||||
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "no data", true); }
|
||||
if (this->m_jsonLoad == AllowOnlySingleSimulator)
|
||||
if (models.isEmpty()) { return COrderableViewWithDbObjects::validateLoadedJsonData(models); }
|
||||
if (this->m_loadingRequiresSimulator.isNoSimulator()) { return COrderableViewWithDbObjects::validateLoadedJsonData(models); }
|
||||
if (models.containsNotMatchingSimulator(this->m_loadingRequiresSimulator))
|
||||
{
|
||||
const CSimulatorInfo sim = models.simulatorsSupported();
|
||||
if (sim.isSingleSimulator()) { return ok; }
|
||||
return CStatusMessage(this, CStatusMessage::SeverityError, "data need to be from one simulator");
|
||||
return CStatusMessage(this, CStatusMessage::SeverityError, "Found entry not matching %1 in model data", true) << this->m_loadingRequiresSimulator.toQString();
|
||||
}
|
||||
return COrderableViewWithDbObjects::validateLoadedJsonData(models);
|
||||
}
|
||||
|
||||
@@ -54,15 +54,6 @@ namespace BlackGui
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! How to validate loaded JSON data
|
||||
enum JsonLoadFlag
|
||||
{
|
||||
NotSet = 0,
|
||||
AllowOnlySingleSimulator = 1 << 0,
|
||||
ReduceToOneSimulator = 1 << 1
|
||||
};
|
||||
Q_DECLARE_FLAGS(JsonLoad, JsonLoadFlag)
|
||||
|
||||
//! Constructor
|
||||
explicit CAircraftModelView(QWidget *parent = nullptr);
|
||||
|
||||
@@ -114,8 +105,8 @@ namespace BlackGui
|
||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::highlightModelStrings
|
||||
bool highlightModelStrings() const;
|
||||
|
||||
//! Load validation
|
||||
void setJsonLoad(JsonLoad jsonLoad) { m_jsonLoad = jsonLoad; }
|
||||
//! Loading data will be restricted to simulator
|
||||
void setSimulatorForLoading(const BlackMisc::Simulation::CSimulatorInfo &sim) { m_loadingRequiresSimulator = sim; }
|
||||
|
||||
signals:
|
||||
//! Request to stash if applicable
|
||||
@@ -157,14 +148,10 @@ namespace BlackGui
|
||||
void ps_requestStash();
|
||||
|
||||
private:
|
||||
bool m_stashingClearsSelection = true; //!< stashing unselects
|
||||
JsonLoad m_jsonLoad = NotSet; //!< Loaded JSON validation
|
||||
bool m_stashingClearsSelection = true; //!< stashing unselects
|
||||
BlackMisc::Simulation::CSimulatorInfo m_loadingRequiresSimulator; //!< simulator required when loading
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Views::CAircraftModelView::JsonLoad)
|
||||
Q_DECLARE_METATYPE(BlackGui::Views::CAircraftModelView::JsonLoadFlag)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackGui::Views::CAircraftModelView::JsonLoad)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user