Ref T246, unified signal handling in model caches and loader

* setSimulator as checked, simulatorChanged as unchecked version
* some renamings
* made some functions private, turned public slots -> public
This commit is contained in:
Klaus Basan
2018-02-10 01:31:24 +01:00
parent d64ddfa8af
commit ccd7c477e2
7 changed files with 60 additions and 32 deletions

View File

@@ -286,7 +286,7 @@ namespace BlackCore
// use simulator info from ISimulator as it can access the emulated driver settings // use simulator info from ISimulator as it can access the emulated driver settings
const CSimulatorInfo simInfo = simulator->getSimulatorInfo(); const CSimulatorInfo simInfo = simulator->getSimulatorInfo();
Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
m_modelSetLoader.changeSimulator(simInfo); m_modelSetLoader.setSimulator(simInfo);
m_aircraftMatcher.setModelSet(m_modelSetLoader.getAircraftModels(), simInfo); m_aircraftMatcher.setModelSet(m_modelSetLoader.getAircraftModels(), simInfo);
m_aircraftMatcher.setDefaultModel(simulator->getDefaultModel()); m_aircraftMatcher.setDefaultModel(simulator->getDefaultModel());

View File

@@ -859,12 +859,12 @@ namespace BlackGui
void CDbMappingComponent::setOwnModelSetSimulator(const CSimulatorInfo &simulator) void CDbMappingComponent::setOwnModelSetSimulator(const CSimulatorInfo &simulator)
{ {
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
ui->comp_OwnModelSet->setModelSetSimulator(simulator); ui->comp_OwnModelSet->setSimulator(simulator);
} }
CAircraftModelList CDbMappingComponent::getOwnModelSet() const CAircraftModelList CDbMappingComponent::getOwnModelSet() const
{ {
return ui->comp_OwnModelSet->getModelSet(); return ui->comp_OwnModelSet->getModelSetFromView();
} }
CStatusMessage CDbMappingComponent::stashModel(const CAircraftModel &model, bool replace) CStatusMessage CDbMappingComponent::stashModel(const CAircraftModel &model, bool replace)

View File

@@ -94,7 +94,7 @@ namespace BlackGui
void CModelMatcherComponent::onSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator) void CModelMatcherComponent::onSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator)
{ {
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
m_modelSetLoader.changeSimulator(simulator); m_modelSetLoader.setSimulator(simulator);
m_matcher.setModelSet(m_modelSetLoader.getAircraftModels(), simulator); m_matcher.setModelSet(m_modelSetLoader.getAircraftModels(), simulator);
this->redisplay(); this->redisplay();
} }

View File

@@ -20,7 +20,7 @@ namespace BlackMisc
{ {
CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) : QObject(parent) CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) : QObject(parent)
{ {
connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged); connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::onModelsCacheChanged);
} }
CAircraftModelSetLoader::~CAircraftModelSetLoader() CAircraftModelSetLoader::~CAircraftModelSetLoader()
@@ -56,11 +56,9 @@ namespace BlackMisc
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator) void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
{ {
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
if (this->getSimulator() == simulator) { return; }
m_caches.setCurrentSimulator(simulator); m_caches.setCurrentSimulator(simulator);
m_caches.synchronizeCurrentCache(); m_caches.synchronizeCurrentCache();
emit simulatorChanged(simulator); emit this->simulatorChanged(simulator);
} }
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
@@ -115,6 +113,12 @@ namespace BlackMisc
return this->setCachedModels(CAircraftModelList()); return this->setCachedModels(CAircraftModelList());
} }
void CAircraftModelSetLoader::onModelsCacheChanged(const CSimulatorInfo &simulator)
{
this->changeSimulator(simulator);
emit this->cacheChanged(simulator);
}
CSimulatorInfo CAircraftModelSetLoader::getSimulator() const CSimulatorInfo CAircraftModelSetLoader::getSimulator() const
{ {
return m_caches.getCurrentSimulator(); return m_caches.getCurrentSimulator();
@@ -125,6 +129,13 @@ namespace BlackMisc
return this->getSimulator().toQString(); return this->getSimulator().toQString();
} }
void CAircraftModelSetLoader::setSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
if (this->getSimulator() == simulator) { return; }
this->changeSimulator(simulator);
}
bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info) bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info)
{ {
return this->getSimulator().matchesAny(info); return this->getSimulator().matchesAny(info);

View File

@@ -78,12 +78,16 @@ namespace BlackMisc
//! \threadsafe //! \threadsafe
BlackMisc::Simulation::CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; BlackMisc::Simulation::CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Which simulator is supported by that very loader //! Current simulator
CSimulatorInfo getSimulator() const; CSimulatorInfo getSimulator() const;
//! Supported simulators as string //! Supported simulators as string
QString getSimulatorAsString() const; QString getSimulatorAsString() const;
//! Set simulator
//! \remark checked version, does nothing if simulator is alread set
void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Is the given simulator supported? //! Is the given simulator supported?
bool supportsSimulator(const BlackMisc::Simulation::CSimulatorInfo &info); bool supportsSimulator(const BlackMisc::Simulation::CSimulatorInfo &info);
@@ -107,14 +111,6 @@ namespace BlackMisc
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); } virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
//! @} //! @}
signals:
//! Simulator has been changed
void simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Cache changed
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
public slots:
//! Set cache from outside, this should only be used in special cases. //! Set cache from outside, this should only be used in special cases.
//! But it allows to modify data elsewhere and update the cache with manipulated data. //! But it allows to modify data elsewhere and update the cache with manipulated data.
BlackMisc::CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo()); BlackMisc::CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
@@ -123,20 +119,32 @@ namespace BlackMisc
//! But it allows to modify data elsewhere and update the cache with manipulated data. //! But it allows to modify data elsewhere and update the cache with manipulated data.
BlackMisc::CStatusMessage replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo()); BlackMisc::CStatusMessage replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
//! Change the simulator signals:
void changeSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator); //! Simulator has been changed
void simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Cache changed
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
protected: protected:
//! Cache timestamp BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches
QDateTime getCacheTimestamp() const;
private:
//! Change the simulator
//! \remark unckecked, does not check if simulator is the same
void changeSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Model cache has changed
void onModelsCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Any cached data? //! Any cached data?
bool hasCachedData() const; bool hasCachedData() const;
//! Cache timestamp
QDateTime getCacheTimestamp() const;
//! Clear cache //! Clear cache
BlackMisc::CStatusMessage clearCache(); BlackMisc::CStatusMessage clearCache();
BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches
}; };
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -37,6 +37,12 @@ namespace BlackMisc
return is.arg(this->getCachedModelsCount(CSimulatorInfo::FSX)).arg(this->getCachedModelsCount(CSimulatorInfo::P3D)).arg(this->getCachedModelsCount(CSimulatorInfo::FS9)); return is.arg(this->getCachedModelsCount(CSimulatorInfo::FSX)).arg(this->getCachedModelsCount(CSimulatorInfo::P3D)).arg(this->getCachedModelsCount(CSimulatorInfo::FS9));
} }
void IMultiSimulatorModelCaches::onLastSelectionChanged()
{
this->synchronizeCurrentCache();
this->emitCacheChanged(this->getCurrentSimulator());
}
void IMultiSimulatorModelCaches::emitCacheChanged(const CSimulatorInfo &simulator) void IMultiSimulatorModelCaches::emitCacheChanged(const CSimulatorInfo &simulator)
{ {
emit this->cacheChanged(simulator); emit this->cacheChanged(simulator);

View File

@@ -157,6 +157,13 @@ namespace BlackMisc
//! \threadsafe //! \threadsafe
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
//! Models
CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Models
//! \threadsafe
CAircraftModelList getCurrentCachedModels() const;
//! Count of models for simulator //! Count of models for simulator
int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
@@ -169,13 +176,6 @@ namespace BlackMisc
//! Simulator which uses cache with filename //! Simulator which uses cache with filename
BlackMisc::Simulation::CSimulatorInfo getSimulatorForFilename(const QString &filename) const; BlackMisc::Simulation::CSimulatorInfo getSimulatorForFilename(const QString &filename) const;
//! Models
CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Models
//! \threadsafe
CAircraftModelList getCurrentCachedModels() const;
//! Cache timestamp //! Cache timestamp
//! \threadsafe //! \threadsafe
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0; virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
@@ -251,6 +251,9 @@ namespace BlackMisc
void changedXP() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); } void changedXP() { emitCacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); }
//! @} //! @}
//! Void version of synchronizeCurrentCache
void onLastSelectionChanged();
private: private:
//! Emit cacheChanged() utility function (allows breakpoint) //! Emit cacheChanged() utility function (allows breakpoint)
void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
@@ -289,7 +292,7 @@ namespace BlackMisc
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this }; //!< current simulator BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this, &CModelCaches::onLastSelectionChanged }; //!< current simulator
//! Non virtual version (can be used in ctor) //! Non virtual version (can be used in ctor)
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator); void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
@@ -332,7 +335,7 @@ namespace BlackMisc
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this }; //!< current simulator BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_currentSimulator { this, &CModelSetCaches::onLastSelectionChanged }; //!< current simulator
//! Non virtual version (can be used in ctor) //! Non virtual version (can be used in ctor)
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator); void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);