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