mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<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::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)
|
||||
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::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::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)
|
||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
Reference in New Issue
Block a user