diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 8860b6eb2..30f0b5bb8 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -286,7 +286,7 @@ namespace BlackCore // use simulator info from ISimulator as it can access the emulated driver settings const CSimulatorInfo simInfo = simulator->getSimulatorInfo(); 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.setDefaultModel(simulator->getDefaultModel()); diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index e2b19461a..8fcf12e00 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -859,12 +859,12 @@ namespace BlackGui void CDbMappingComponent::setOwnModelSetSimulator(const CSimulatorInfo &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 { - return ui->comp_OwnModelSet->getModelSet(); + return ui->comp_OwnModelSet->getModelSetFromView(); } CStatusMessage CDbMappingComponent::stashModel(const CAircraftModel &model, bool replace) diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index 7933f551e..668cee5b5 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -94,7 +94,7 @@ namespace BlackGui void CModelMatcherComponent::onSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &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); this->redisplay(); } diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.cpp b/src/blackmisc/simulation/aircraftmodelsetloader.cpp index 36b86a4cd..f49d998b4 100644 --- a/src/blackmisc/simulation/aircraftmodelsetloader.cpp +++ b/src/blackmisc/simulation/aircraftmodelsetloader.cpp @@ -20,7 +20,7 @@ namespace BlackMisc { CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) : QObject(parent) { - connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged); + connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::onModelsCacheChanged); } CAircraftModelSetLoader::~CAircraftModelSetLoader() @@ -56,11 +56,9 @@ namespace BlackMisc 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.synchronizeCurrentCache(); - emit simulatorChanged(simulator); + emit this->simulatorChanged(simulator); } CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const @@ -115,6 +113,12 @@ namespace BlackMisc return this->setCachedModels(CAircraftModelList()); } + void CAircraftModelSetLoader::onModelsCacheChanged(const CSimulatorInfo &simulator) + { + this->changeSimulator(simulator); + emit this->cacheChanged(simulator); + } + CSimulatorInfo CAircraftModelSetLoader::getSimulator() const { return m_caches.getCurrentSimulator(); @@ -125,6 +129,13 @@ namespace BlackMisc 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) { return this->getSimulator().matchesAny(info); diff --git a/src/blackmisc/simulation/aircraftmodelsetloader.h b/src/blackmisc/simulation/aircraftmodelsetloader.h index 4cd5cc50d..e39afff6e 100644 --- a/src/blackmisc/simulation/aircraftmodelsetloader.h +++ b/src/blackmisc/simulation/aircraftmodelsetloader.h @@ -78,12 +78,16 @@ namespace BlackMisc //! \threadsafe BlackMisc::Simulation::CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; - //! Which simulator is supported by that very loader + //! Current simulator CSimulatorInfo getSimulator() const; //! Supported simulators as string 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? 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); } //! @} - 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. //! But it allows to modify data elsewhere and update the cache with manipulated data. 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. BlackMisc::CStatusMessage replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo()); - //! Change the simulator - void changeSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator); + signals: + //! Simulator has been changed + void simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! Cache changed + void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); protected: - //! Cache timestamp - QDateTime getCacheTimestamp() const; + BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches + + 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? bool hasCachedData() const; + //! Cache timestamp + QDateTime getCacheTimestamp() const; + //! Clear cache BlackMisc::CStatusMessage clearCache(); - - BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches }; } // namespace } // namespace diff --git a/src/blackmisc/simulation/data/modelcaches.cpp b/src/blackmisc/simulation/data/modelcaches.cpp index 3e7f5b06c..d17492a8c 100644 --- a/src/blackmisc/simulation/data/modelcaches.cpp +++ b/src/blackmisc/simulation/data/modelcaches.cpp @@ -37,6 +37,12 @@ namespace BlackMisc 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) { emit this->cacheChanged(simulator); diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index f4be6e084..6c0d5a316 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -157,6 +157,13 @@ namespace BlackMisc //! \threadsafe 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 int getCachedModelsCount(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; @@ -169,13 +176,6 @@ namespace BlackMisc //! Simulator which uses cache with filename BlackMisc::Simulation::CSimulatorInfo getSimulatorForFilename(const QString &filename) const; - //! Models - CAircraftModelList getSynchronizedCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator); - - //! Models - //! \threadsafe - CAircraftModelList getCurrentCachedModels() const; - //! Cache timestamp //! \threadsafe 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 version of synchronizeCurrentCache + void onLastSelectionChanged(); + private: //! Emit cacheChanged() utility function (allows breakpoint) void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -289,7 +292,7 @@ namespace BlackMisc BlackMisc::CData m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache BlackMisc::CData m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache BlackMisc::CData m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache - BlackMisc::CData m_currentSimulator { this }; //!< current simulator + BlackMisc::CData m_currentSimulator { this, &CModelCaches::onLastSelectionChanged }; //!< current simulator //! Non virtual version (can be used in ctor) void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -332,7 +335,7 @@ namespace BlackMisc BlackMisc::CData m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache BlackMisc::CData m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache BlackMisc::CData m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache - BlackMisc::CData m_currentSimulator { this }; //!< current simulator + BlackMisc::CData m_currentSimulator { this, &CModelSetCaches::onLastSelectionChanged }; //!< current simulator //! Non virtual version (can be used in ctor) void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);