refs #834, improved default value for last set/models simulator

Remark: The bug itself was slightly related to the default value, as only the default loader suffered from a not reset flag
This commit is contained in:
Klaus Basan
2016-12-15 02:48:30 +01:00
parent 5107d55115
commit 73ba4e5ff2
6 changed files with 33 additions and 28 deletions

View File

@@ -50,11 +50,11 @@ namespace BlackGui
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::ps_requestOwnModelsUpdate); connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::ps_requestOwnModelsUpdate);
// should be single simulator or no simulator (default) // Last selection isPinned -> no sync needed
this->m_simulatorSelection.synchronize();
const CSimulatorInfo simulator(this->m_simulatorSelection.get()); const CSimulatorInfo simulator(this->m_simulatorSelection.get());
const bool succes = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator); Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
if (succes) const bool success = this->initModelLoader(simulator);
if (success)
{ {
this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly); this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly);
} }
@@ -427,7 +427,7 @@ namespace BlackGui
return; return;
} }
if (!this->m_modelLoader->isLoadingFinished()) if (this->m_modelLoader->isLoadingInProgress())
{ {
CLogMessage(this).info("Loading for %1 already in progress") << simulator.toQString(); CLogMessage(this).info("Loading for %1 already in progress") << simulator.toQString();
return; return;

View File

@@ -62,7 +62,7 @@ namespace BlackGui
explicit CDbOwnModelsComponent(QWidget *parent = nullptr); explicit CDbOwnModelsComponent(QWidget *parent = nullptr);
//! Destructor //! Destructor
~CDbOwnModelsComponent(); virtual ~CDbOwnModelsComponent();
//! Own (installed) model for given model string //! Own (installed) model for given model string
BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const; BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const;
@@ -132,8 +132,8 @@ namespace BlackGui
private: private:
QScopedPointer<Ui::CDbOwnModelsComponent> ui; QScopedPointer<Ui::CDbOwnModelsComponent> ui;
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
BlackMisc::CData<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 //! Init or change model loader
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator); bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);

View File

@@ -80,6 +80,10 @@ namespace BlackMisc
//! Loading finished? //! Loading finished?
virtual bool isLoadingFinished() const = 0; virtual bool isLoadingFinished() const = 0;
//! Loading in progress
//! \threadsafe
bool isLoadingInProgress() const { return m_loadingInProgress; }
//! Get the loaded models //! Get the loaded models
//! \threadsafe //! \threadsafe
BlackMisc::Simulation::CAircraftModelList getAircraftModels() const; BlackMisc::Simulation::CAircraftModelList getAircraftModels() const;
@@ -166,7 +170,7 @@ namespace BlackMisc
//! Start the loading process from disk //! Start the loading process from disk
virtual void startLoadingFromDisk(LoadMode mode, const ModelConsolidation &modelConsolidation, const QString &directory) = 0; virtual void startLoadingFromDisk(LoadMode mode, const ModelConsolidation &modelConsolidation, const QString &directory) = 0;
std::atomic<bool> m_cancelLoading { false }; //!< flag std::atomic<bool> m_cancelLoading { false }; //!< flag, requesting to cancel loading
std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress
BlackMisc::Simulation::Data::CModelCaches m_caches { false, this }; //!< caches BlackMisc::Simulation::Data::CModelCaches m_caches { false, this }; //!< caches
BlackMisc::Simulation::CMultiSimulatorSettings m_settings { this }; //!< settings BlackMisc::Simulation::CMultiSimulatorSettings m_settings { this }; //!< settings

View File

@@ -69,16 +69,12 @@ namespace BlackMisc
//! Last selection //! Last selection
struct TModelCacheLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo> struct TModelCacheLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{ {
//! Default value
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue()
{
static const BlackMisc::Simulation::CSimulatorInfo s(BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator());
return s;
}
//! First load is synchronous //! First load is synchronous
static constexpr bool isPinned() { return true; } static constexpr bool isPinned() { return true; }
//! Default simulator
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
//! Key //! Key
static const char *key() { return "modelcachelastselection"; } static const char *key() { return "modelcachelastselection"; }
}; };
@@ -118,16 +114,12 @@ namespace BlackMisc
//! Last selection //! Last selection
struct TModelSetLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo> struct TModelSetLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{ {
//! Default value
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue()
{
static const BlackMisc::Simulation::CSimulatorInfo s(BlackMisc::Simulation::CSimulatorInfo::guessDefaultSimulator());
return s;
}
//! First load is synchronous //! First load is synchronous
static constexpr bool isPinned() { return true; } static constexpr bool isPinned() { return true; }
//! Default simulator
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
//! Key //! Key
static const char *key() { return "modelsetlastselection"; } static const char *key() { return "modelsetlastselection"; }
}; };

View File

@@ -230,9 +230,10 @@ namespace BlackMisc
return sim; return sim;
} }
const CSimulatorInfo CSimulatorInfo::guessDefaultSimulator() //! \cond PRIVATE
CSimulatorInfo guessDefaultSimulatorImpl()
{ {
CSimulatorInfo locallyInstalled(getLocallyInstalledSimulators()); static const CSimulatorInfo locallyInstalled(CSimulatorInfo::getLocallyInstalledSimulators());
if (CBuildConfig::isRunningOnLinuxPlatform()) if (CBuildConfig::isRunningOnLinuxPlatform())
{ {
return CSimulatorInfo("XPLANE"); return CSimulatorInfo("XPLANE");
@@ -242,8 +243,16 @@ namespace BlackMisc
if (locallyInstalled.fs9()) { return CSimulatorInfo("FS9"); } if (locallyInstalled.fs9()) { return CSimulatorInfo("FS9"); }
// fallback // fallback
return CSimulatorInfo("FSX"); return CSimulatorInfo("P3D");
} }
//! \endcond
const CSimulatorInfo &CSimulatorInfo::guessDefaultSimulator()
{
static const CSimulatorInfo sim(guessDefaultSimulatorImpl());
return sim;
}
CSimulatorInfo CSimulatorInfo::fromDatabaseJson(const QJsonObject &json, const QString prefix) CSimulatorInfo CSimulatorInfo::fromDatabaseJson(const QJsonObject &json, const QString prefix)
{ {

View File

@@ -162,8 +162,8 @@ namespace BlackMisc
//! Locally installed simulators //! Locally installed simulators
static const CSimulatorInfo getLocallyInstalledSimulators(); static const CSimulatorInfo getLocallyInstalledSimulators();
//! Guess a default simulator //! Guess a default simulator based on installation
static const CSimulatorInfo guessDefaultSimulator(); static const CSimulatorInfo &guessDefaultSimulator();
//! From database JSON //! From database JSON
static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString prefix); static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString prefix);