mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Ref T292, model set loader style and adjustments
This commit is contained in:
@@ -30,40 +30,22 @@ namespace BlackMisc
|
||||
|
||||
CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : m_caches.getCurrentSimulator();
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simulator"); }
|
||||
const CStatusMessage m(m_caches.setCachedModels(models, sim));
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
const CStatusMessage m(m_caches.setCachedModels(models, simulator));
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelSetLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : m_caches.getCurrentSimulator();
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
|
||||
m_caches.synchronizeCache(sim);
|
||||
CAircraftModelList allModels(m_caches.getSynchronizedCachedModels(sim));
|
||||
const int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
if (c > 0)
|
||||
{
|
||||
return this->setCachedModels(models, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data changed");
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
m_caches.setCurrentSimulator(simulator);
|
||||
m_caches.synchronizeCurrentCache();
|
||||
if (m_currentSimulator == simulator) { return; }
|
||||
m_currentSimulator = simulator;
|
||||
m_caches.synchronizeCache(simulator);
|
||||
emit this->simulatorChanged(simulator);
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
|
||||
{
|
||||
return m_caches.getCurrentCachedModels();
|
||||
return m_caches.getCachedModels(m_currentSimulator);
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator)
|
||||
@@ -90,27 +72,27 @@ namespace BlackMisc
|
||||
|
||||
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
|
||||
{
|
||||
return m_caches.getCurrentCacheTimestamp();
|
||||
return m_caches.getCacheTimestamp(m_currentSimulator);
|
||||
}
|
||||
|
||||
bool CAircraftModelSetLoader::synchronizeCache()
|
||||
void CAircraftModelSetLoader::synchronizeCache()
|
||||
{
|
||||
return m_caches.synchronizeCurrentCache();
|
||||
m_caches.synchronizeCache(m_currentSimulator);
|
||||
}
|
||||
|
||||
bool CAircraftModelSetLoader::admitCache()
|
||||
void CAircraftModelSetLoader::admitCache()
|
||||
{
|
||||
return m_caches.admitCurrentCache();
|
||||
m_caches.admitCache(m_currentSimulator);
|
||||
}
|
||||
|
||||
bool CAircraftModelSetLoader::hasCachedData() const
|
||||
{
|
||||
return !m_caches.getCurrentCachedModels().isEmpty();
|
||||
return !m_caches.getCachedModels(m_currentSimulator).isEmpty();
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelSetLoader::clearCache()
|
||||
{
|
||||
return this->setCachedModels(CAircraftModelList());
|
||||
return m_caches.clearCachedModels(this->getSimulator());
|
||||
}
|
||||
|
||||
void CAircraftModelSetLoader::onModelsCacheChanged(const CSimulatorInfo &simulator)
|
||||
@@ -119,11 +101,6 @@ namespace BlackMisc
|
||||
emit this->cacheChanged(simulator);
|
||||
}
|
||||
|
||||
CSimulatorInfo CAircraftModelSetLoader::getSimulator() const
|
||||
{
|
||||
return m_caches.getCurrentSimulator();
|
||||
}
|
||||
|
||||
QString CAircraftModelSetLoader::getSimulatorAsString() const
|
||||
{
|
||||
return this->getSimulator().toQString();
|
||||
|
||||
@@ -33,16 +33,16 @@ namespace BlackMisc
|
||||
*/
|
||||
class BLACKMISC_EXPORT CAircraftModelSetLoader :
|
||||
public QObject,
|
||||
public BlackMisc::Simulation::IModelsSetable,
|
||||
public BlackMisc::Simulation::IModelsUpdatable,
|
||||
public BlackMisc::Simulation::IModelsPerSimulatorSetable,
|
||||
public BlackMisc::Simulation::IModelsPerSimulatorUpdatable
|
||||
public IModelsSetable,
|
||||
public IModelsUpdatable,
|
||||
public IModelsForSimulatorSetable,
|
||||
public IModelsForSimulatorUpdatable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorUpdatable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable)
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
@@ -52,19 +52,19 @@ namespace BlackMisc
|
||||
virtual ~CAircraftModelSetLoader();
|
||||
|
||||
//! Make sure cache is synchronized
|
||||
bool synchronizeCache();
|
||||
void synchronizeCache();
|
||||
|
||||
//! Admit current cache
|
||||
bool admitCache();
|
||||
void admitCache();
|
||||
|
||||
//! The loaded models
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAircraftModelList getAircraftModels() const;
|
||||
CAircraftModelList getAircraftModels() const;
|
||||
|
||||
//! The loaded models for given simulator
|
||||
//! \threadsafe
|
||||
//! \remark non-const because it synchronizes cache
|
||||
BlackMisc::Simulation::CAircraftModelList getAircraftModels(const CSimulatorInfo &simulator);
|
||||
CAircraftModelList getAircraftModels(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Count of loaded models
|
||||
//! \threadsafe
|
||||
@@ -72,25 +72,25 @@ namespace BlackMisc
|
||||
|
||||
//! Model for given model string
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAircraftModel getModelForModelString(const QString &modelString) const;
|
||||
CAircraftModel getModelForModelString(const QString &modelString) const;
|
||||
|
||||
//! Models from cache
|
||||
//! \threadsafe
|
||||
BlackMisc::Simulation::CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Current simulator
|
||||
//! \threadsafe
|
||||
CSimulatorInfo getSimulator() const;
|
||||
CSimulatorInfo getSimulator() const { return m_currentSimulator; }
|
||||
|
||||
//! 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);
|
||||
void setSimulator(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Is the given simulator supported?
|
||||
bool supportsSimulator(const BlackMisc::Simulation::CSimulatorInfo &info);
|
||||
bool supportsSimulator(const CSimulatorInfo &info);
|
||||
|
||||
//! Simulators with initialized caches
|
||||
CSimulatorInfo simulatorsWithInitializedModelSet() const;
|
||||
@@ -98,51 +98,47 @@ namespace BlackMisc
|
||||
//! Shutdown
|
||||
void gracefulShutdown();
|
||||
|
||||
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoString
|
||||
//! \copydoc Data::CModelCaches::getInfoString
|
||||
QString getInfoString() const;
|
||||
|
||||
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoStringFsFamily
|
||||
//! \copydoc Data::CModelCaches::getInfoStringFsFamily
|
||||
QString getInfoStringFsFamily() const;
|
||||
|
||||
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getCacheCountAndTimestamp
|
||||
//! \copydoc Data::CModelCaches::getCacheCountAndTimestamp
|
||||
QString getModelCacheCountAndTimestamp() const;
|
||||
|
||||
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getCacheCountAndTimestamp
|
||||
//! \copydoc Data::CModelCaches::getCacheCountAndTimestamp
|
||||
QString getModelCacheCountAndTimestamp(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! \name Implementations of the models interfaces
|
||||
//! @{
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
|
||||
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->getSimulator()); }
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
|
||||
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
|
||||
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
|
||||
virtual int updateModels(const CAircraftModelList &models) override { return m_caches.updateModelsForSimulator(models, this->getSimulator()); }
|
||||
virtual void setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
|
||||
virtual int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { return m_caches.updateModelsForSimulator(models, simulator); }
|
||||
//! @}
|
||||
|
||||
//! 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());
|
||||
|
||||
//! 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 replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
|
||||
//! Set cached models
|
||||
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator);
|
||||
|
||||
signals:
|
||||
//! Simulator has been changed
|
||||
void simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void simulatorChanged(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Cache changed
|
||||
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void cacheChanged(const CSimulatorInfo &simulator);
|
||||
|
||||
protected:
|
||||
BlackMisc::Simulation::Data::CModelSetCaches m_caches { true, this }; //!< caches
|
||||
Data::CModelSetCaches m_caches { true, this }; //!< caches
|
||||
CSimulatorInfo m_currentSimulator = CSimulatorInfo::guessDefaultSimulator();
|
||||
|
||||
private:
|
||||
//! Change the simulator
|
||||
//! \remark unckecked, does not check if simulator is the same
|
||||
void changeSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void changeSimulator(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Model cache has changed
|
||||
void onModelsCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void onModelsCacheChanged(const CSimulatorInfo &simulator);
|
||||
|
||||
//! Any cached data?
|
||||
bool hasCachedData() const;
|
||||
|
||||
Reference in New Issue
Block a user