refs #649, with #659 deferred caches available

* adjustments to use deferred caches
* removed simulator from CAircraftModelSetLoader`s signature as it was not used
* only change current simulator when explicitly set (avoid unintended setting)
* added function to obtain number of elements from model caches
This commit is contained in:
Klaus Basan
2016-05-29 12:37:03 +02:00
parent 771c531125
commit 875b311ede
19 changed files with 123 additions and 66 deletions

View File

@@ -51,7 +51,6 @@ namespace BlackCore
CEntityFlags::Entity allEntities = entities;
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored
const bool hasInfoObjects = this->hasInfoObjects();
const bool changedUrl = this->hasChangedUrl(currentEntity);
while (currentEntity)
{
const CDatabaseReaderConfig config(this->getConfigForEntity(currentEntity));
@@ -59,6 +58,7 @@ namespace BlackCore
{
if (hasInfoObjects)
{
const bool changedUrl = this->hasChangedUrl(currentEntity);
const QDateTime cacheTs(this->getCacheTimestamp(currentEntity));
const QDateTime latestEntityTs(this->getLatestEntityTimestamp(currentEntity));
const qint64 cacheTimestamp = cacheTs.isValid() ? cacheTs.toMSecsSinceEpoch() : -1;
@@ -76,7 +76,8 @@ namespace BlackCore
{
if (changedUrl)
{
CLogMessage(this).info("Data location changed, will override cache");
CLogMessage(this).info("Data location changed, will override cache for %1")
<< CEntityFlags::flagToString(currentEntity);
}
else
{
@@ -90,7 +91,11 @@ namespace BlackCore
{
// no info objects, server down
this->syncronizeCaches(currentEntity);
CLogMessage(this).info("No info object for %1, using cache") << CEntityFlags::flagToString(currentEntity);
const int c = this->getCacheCount(currentEntity);
CLogMessage(this).info("No info object for %1, using cache with %2 objects")
<< CEntityFlags::flagToString(currentEntity)
<< c;
entities &= ~currentEntity; // do not load from web
}
}
currentEntity = CEntityFlags::iterateDbEntities(allEntities);

View File

@@ -149,7 +149,10 @@ namespace BlackCore
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
//! Cache`s timestamp for given entity
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const = 0;
//! Cache`s number of entities
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const = 0;
//! Invalidate the caches for given entities
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;

View File

@@ -399,7 +399,7 @@ namespace BlackCore
if (entities.testFlag(CEntityFlags::CountryEntity)) {CDataCache::instance()->clearAllValues(this->m_countryCache.getKey()); }
}
QDateTime CIcaoDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
QDateTime CIcaoDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
{
switch (entity)
{
@@ -410,6 +410,17 @@ namespace BlackCore
}
}
int CIcaoDataReader::getCacheCount(CEntityFlags::Entity entity) const
{
switch (entity)
{
case CEntityFlags::AircraftIcaoEntity: return this->m_aircraftIcaoCache.getCopy().size();
case CEntityFlags::AirlineIcaoEntity: return this->m_airlineIcaoCache.getCopy().size();
case CEntityFlags::CountryEntity: return this->m_countryCache.getCopy().size();
default: return 0;
}
}
bool CIcaoDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
{
Q_UNUSED(entity);

View File

@@ -123,7 +123,8 @@ namespace BlackCore
//! @{
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
//! @}

View File

@@ -62,13 +62,20 @@ namespace BlackCore
Q_UNUSED(entities);
}
QDateTime CInfoDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
QDateTime CInfoDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
{
// no caching used here
Q_UNUSED(entity);
return QDateTime();
}
int CInfoDataReader::getCacheCount(CEntityFlags::Entity entity) const
{
// no caching used here
Q_UNUSED(entity);
return 0;
}
bool CInfoDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
{
// not implemented

View File

@@ -61,7 +61,8 @@ namespace BlackCore
//! @{
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
//! @}

View File

@@ -437,12 +437,18 @@ namespace BlackCore
Q_UNUSED(entities);
}
QDateTime CModelDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
QDateTime CModelDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
{
Q_UNUSED(entity);
return QDateTime();
}
int CModelDataReader::getCacheCount(CEntityFlags::Entity entity) const
{
Q_UNUSED(entity);
return 0;
}
bool CModelDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
{
Q_UNUSED(entity);

View File

@@ -128,7 +128,8 @@ namespace BlackCore
//! @{
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
//! @}

View File

@@ -133,7 +133,7 @@ namespace BlackCore
//! \todo unclear if this is valid for all simulators or for MS/P3D simulators only
BlackCore::CAircraftMatcher m_modelMatcher; //!< Model matcher
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this }; //!< load model set from caches
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches
private:
bool m_debugMessages = false; //!< Display debug messages

View File

@@ -70,17 +70,15 @@ namespace BlackGui
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_modelChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_viewModelChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded);
const CSimulatorInfo sim = this->m_modelSetLoader.getSimulator();
if (sim.isSingleSimulator())
const CSimulatorInfo simulator = this->m_modelSetLoader.getSimulator();
if (simulator.isSingleSimulator())
{
// update display when all is set up
this->m_modelSetLoader.syncronizeCache(); // make sure data are loaded
QTimer::singleShot(500, [this, sim]()
QTimer::singleShot(500, [this]()
{
this->ps_changeSimulator(sim);
this->updateViewToCurrentModels();
});
}
}
@@ -162,7 +160,7 @@ namespace BlackGui
"Cannot add data for " + simulator.toQString(true) + " to " + this->getModelSetSimulator().toQString(true), true);
}
CAircraftModelList updateModels(this->getModelSet());
int d = updateModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
const int d = updateModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
if (d > 0)
{
this->ui->tvp_OwnModelSet->updateContainerMaybeAsync(updateModels);
@@ -195,7 +193,8 @@ namespace BlackGui
{
// make sure both tabs display the same simulator
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "Missing mapping component");
this->getMappingComponent()->setOwnModelsSimulator(this->getModelSetSimulator());
const CSimulatorInfo sim(this->getModelSetSimulator());
this->getMappingComponent()->setOwnModelsSimulator(sim);
if (!this->m_modelSetDialog)
{
this->m_modelSetDialog.reset(new CDbOwnModelSetDialog(this));
@@ -214,7 +213,7 @@ namespace BlackGui
}
else
{
static const CStatusMessage m = CStatusMessage(this).error("No model data for %1") << this->m_modelSetDialog->getSimulatorInfo().toQString(true);
static const CStatusMessage m = CStatusMessage(this).error("No model data for %1") << sim.toQString(true);
this->getMappingComponent()->showOverlayMessage(m);
}
}
@@ -239,8 +238,7 @@ namespace BlackGui
if (this->getModelSetSimulator() == simulator) { return; } // avoid endless loops
this->setModelSetSimulator(simulator);
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
this->updateViewToCurrentModels();
}
void CDbOwnModelSetComponent::ps_onSimulatorChanged(const CSimulatorInfo &simulator)
@@ -276,7 +274,7 @@ namespace BlackGui
}
}
void CDbOwnModelSetComponent::ps_preferencesChanged()
void CDbOwnModelSetComponent::ps_distributorPreferencesChanged()
{
const CDistributorListPreferences preferences = this->m_distributorPreferences.get();
const CSimulatorInfo simuulator = preferences.getLastUpdatedSimulator();
@@ -286,7 +284,7 @@ namespace BlackGui
}
}
void CDbOwnModelSetComponent::ps_modelChanged()
void CDbOwnModelSetComponent::ps_viewModelChanged()
{
ui->pb_SaveAsSetForSimulator->setEnabled(true);
}
@@ -298,6 +296,12 @@ namespace BlackGui
this->ui->tvp_OwnModelSet->setSaveFileName(name);
}
void CDbOwnModelSetComponent::updateViewToCurrentModels()
{
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
}
void CDbOwnModelSetComponent::setModelSetSimulator(const CSimulatorInfo &simulator)
{
if (this->m_modelSetLoader.getSimulator() == simulator) { return; } // avoid unnecessary signals

View File

@@ -123,22 +123,27 @@ namespace BlackGui
void ps_onJsonDataLoaded(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Preferences changed
void ps_preferencesChanged();
void ps_distributorPreferencesChanged();
//! Model has been changed
void ps_modelChanged();
//! Model (of view) has been changed
void ps_viewModelChanged();
private:
//! Default file name
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
//! Update view to current models
void updateViewToCurrentModels();
//! Update distributor order
void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator);
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_preferencesChanged };
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_distributorPreferencesChanged };
// -------------------------- custom menus -----------------------------------
//! The menu for loading and handling own models for mapping tasks
//! \note This is specific for that very component

View File

@@ -63,7 +63,9 @@ namespace BlackGui
int CDbOwnModelSetDialog::exec()
{
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
this->setSimulator(this->getMappingComponent()->getOwnModelsSimulator());
const CSimulatorInfo sim(this->getMappingComponent()->getOwnModelsSimulator());
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
this->setSimulator(sim);
this->checkData();
return QDialog::exec();
}

View File

@@ -71,7 +71,7 @@ namespace BlackGui
private:
BlackGui::COverlayMessagesFrame *m_overlayMessageFrame = nullptr;
QScopedPointer<Ui::CDistributorPreferencesComponent> ui;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
void updateContainerMaybeAsync(const BlackMisc::Simulation::CDistributorList &models, bool sortByOrder = true);

View File

@@ -77,7 +77,7 @@ namespace BlackGui
BlackMisc::Simulation::CAircraftModel defaultModel() const;
QScopedPointer<Ui::CModelMatcherComponent> ui;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
BlackCore::CAircraftMatcher m_matcher { BlackCore::CAircraftMatcher::All, this };
};
} // ns

View File

@@ -18,11 +18,9 @@ namespace BlackMisc
{
namespace Simulation
{
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent) :
CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) :
QObject(parent)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->syncronizeCache();
connect(&this->m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged);
}

View File

@@ -46,7 +46,7 @@ namespace BlackMisc
public:
//! Constructor
CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr);
CAircraftModelSetLoader(QObject *parent = nullptr);
//! Destructor
virtual ~CAircraftModelSetLoader();

View File

@@ -8,6 +8,7 @@
*/
#include "blackmisc/logmessage.h"
#include "blackmisc/verify.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include <QtGlobal>
@@ -28,6 +29,7 @@ namespace BlackMisc
CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const
{
const CSimulatorInfo sim(this->getCurrentSimulator());
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
if (!sim.isSingleSimulator()) { return CAircraftModelList(); }
return this->getCachedModels(sim);
}
@@ -35,6 +37,7 @@ namespace BlackMisc
bool IMultiSimulatorModelCaches::syncronizeCurrentCache()
{
const CSimulatorInfo sim(this->getCurrentSimulator());
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
if (!sim.isSingleSimulator()) { return false; }
this->syncronizeCache(sim);
return true;
@@ -43,7 +46,10 @@ namespace BlackMisc
CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
{
this->m_currentSimulator.synchronize();
this->syncronizeCache(this->m_currentSimulator.getCopy());
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
this->syncronizeCache(sim);
const QString simStr(sim.toQString(true));
CLogMessage(this).info("Initialized model caches to %1") << simStr;
}
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
@@ -56,7 +62,7 @@ namespace BlackMisc
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getCopy();
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getCopy();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
return CAircraftModelList();
}
}
@@ -64,8 +70,6 @@ namespace BlackMisc
CStatusMessage CModelCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { return m; }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
@@ -73,7 +77,7 @@ namespace BlackMisc
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(models);
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(models);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
return CStatusMessage();
}
}
@@ -81,6 +85,7 @@ namespace BlackMisc
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
{
const CSimulatorInfo sim(this->getCurrentSimulator());
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
if (!sim.isSingleSimulator()) { return QDateTime(); }
return this->getCacheTimestamp(sim);
}
@@ -95,7 +100,7 @@ namespace BlackMisc
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getTimestamp();
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getTimestamp();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
return QDateTime();
}
}
@@ -103,28 +108,35 @@ namespace BlackMisc
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { CLogMessage::preformatted(m); }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.synchronize(); break;
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.synchronize(); break;
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.synchronize(); break;
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
case CSimulatorInfo::FSX: this->m_modelCacheFsx.synchronize(); break;
case CSimulatorInfo::P3D: this->m_modelCacheP3D.synchronize(); break;
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.synchronize(); break;
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
break;
}
}
void CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
{
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
if (s == simulator) { return sameSimMsg; }
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
this->syncronizeCache(simulator);
return m;
}
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
{
this->m_currentSimulator.synchronize();
this->syncronizeCache(this->m_currentSimulator.getCopy());
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
this->syncronizeCache(sim);
const QString simStr(sim.toQString(true));
CLogMessage(this).info("Initialized model set caches to %1") << simStr;
}
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
@@ -137,7 +149,7 @@ namespace BlackMisc
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getCopy();
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getCopy();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
return CAircraftModelList();
}
}
@@ -145,8 +157,6 @@ namespace BlackMisc
CStatusMessage CModelSetCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { return m; }
CAircraftModelList orderedModels(models);
if (orderedModels.needsOrder())
{
@@ -164,7 +174,7 @@ namespace BlackMisc
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(orderedModels);
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(orderedModels);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
return CStatusMessage();
}
}
@@ -187,8 +197,6 @@ namespace BlackMisc
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { CLogMessage::preformatted(m); }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
@@ -200,11 +208,15 @@ namespace BlackMisc
}
}
void CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
{
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
if (s == simulator) { return sameSimMsg; }
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
this->syncronizeCache(simulator);
return m;
}
} // ns
} // ns
} // ns

View File

@@ -187,7 +187,7 @@ namespace BlackMisc
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
//!Selected simulator
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
//! \copydoc IModelsPerSimulatorSetable::setModels
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
@@ -207,6 +207,7 @@ namespace BlackMisc
};
//! Bundle of caches for all simulators
//! \remark remembers its last simulator selection
class CModelCaches : public IMultiSimulatorModelCaches
{
Q_OBJECT
@@ -222,7 +223,7 @@ namespace BlackMisc
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
//! @}
private:
@@ -234,7 +235,7 @@ namespace BlackMisc
};
//! Bundle of caches for model sets of all simulators
//! \remark Temp. workaround
//! \remark remembers its last simulator selection
class CModelSetCaches : public IMultiSimulatorModelCaches
{
Q_OBJECT
@@ -250,7 +251,7 @@ namespace BlackMisc
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
//! @}
private:

View File

@@ -146,7 +146,7 @@ namespace BlackMisc
QString CFsCommonUtil::fs9AircraftDir()
{
QString dir(fs9AircraftDirFromRegistry());
const QString dir(fs9AircraftDirFromRegistry());
if (!dir.isEmpty()) { return dir; }
//! \todo hardcoded sim parts should come from settings
return "C:/Flight Simulator 9/Aircraft";