mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +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:
@@ -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