mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #614, renamed to CAircraftModelSetLoader and detect changes in cache
This commit is contained in:
@@ -9,40 +9,43 @@
|
||||
|
||||
#include "aircraftmodelsetloader.h"
|
||||
|
||||
using namespace BlackMisc::Simulation::Data;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CModelSetLoader::CModelSetLoader(const CSimulatorInfo &info, QObject *parent) :
|
||||
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_simulatorInfo(info)
|
||||
{
|
||||
Q_ASSERT_X(info.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
connect(&this->m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged);
|
||||
}
|
||||
|
||||
CModelSetLoader::~CModelSetLoader()
|
||||
CAircraftModelSetLoader::~CAircraftModelSetLoader()
|
||||
{
|
||||
this->gracefulShutdown();
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetLoader::setModelsInCache(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simulator"); }
|
||||
const CStatusMessage m(this->m_caches.setModels(models, sim));
|
||||
const CStatusMessage m(this->m_caches.setCachedModels(models, sim));
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetLoader::replaceOrAddModelsInCache(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
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 : this->m_simulatorInfo;
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
|
||||
CAircraftModelList allModels(this->m_caches.getModels(sim));
|
||||
CAircraftModelList allModels(this->m_caches.getCachedModels(sim));
|
||||
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
if (c > 0)
|
||||
{
|
||||
return this->setModelsInCache(models, sim);
|
||||
return this->setCachedModels(models, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -50,7 +53,7 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
|
||||
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
this->m_caches.syncronize(simulator);
|
||||
@@ -58,47 +61,47 @@ namespace BlackMisc
|
||||
emit simulatorChanged(simulator);
|
||||
}
|
||||
|
||||
CAircraftModelList CModelSetLoader::getAircraftModels() const
|
||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
|
||||
{
|
||||
return this->m_caches.getModels(this->m_simulatorInfo);
|
||||
}
|
||||
|
||||
QDateTime CModelSetLoader::getCacheTimestamp() const
|
||||
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
|
||||
{
|
||||
return this->m_caches.getCacheTimestamp(this->m_simulatorInfo);
|
||||
}
|
||||
|
||||
void CModelSetLoader::syncronizeCache()
|
||||
void CAircraftModelSetLoader::syncronizeCache()
|
||||
{
|
||||
return this->m_caches.syncronize(this->m_simulatorInfo);
|
||||
}
|
||||
|
||||
bool CModelSetLoader::hasCachedData() const
|
||||
bool CAircraftModelSetLoader::hasCachedData() const
|
||||
{
|
||||
return !this->m_caches.getModels(this->m_simulatorInfo).isEmpty();
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetLoader::clearCache()
|
||||
CStatusMessage CAircraftModelSetLoader::clearCache()
|
||||
{
|
||||
return this->setModelsInCache(CAircraftModelList());
|
||||
}
|
||||
|
||||
const CSimulatorInfo &CModelSetLoader::getSimulator() const
|
||||
const CSimulatorInfo &CAircraftModelSetLoader::getSimulator() const
|
||||
{
|
||||
return m_simulatorInfo;
|
||||
}
|
||||
|
||||
QString CModelSetLoader::getSimulatorAsString() const
|
||||
QString CAircraftModelSetLoader::getSimulatorAsString() const
|
||||
{
|
||||
return m_simulatorInfo.toQString();
|
||||
}
|
||||
|
||||
bool CModelSetLoader::supportsSimulator(const CSimulatorInfo &info)
|
||||
bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info)
|
||||
{
|
||||
return getSimulator().matchesAny(info);
|
||||
}
|
||||
|
||||
void CModelSetLoader::gracefulShutdown()
|
||||
void CAircraftModelSetLoader::gracefulShutdown()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
@@ -26,16 +26,25 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Handling of current set for simulator
|
||||
*/
|
||||
class BLACKMISC_EXPORT CModelSetLoader : public QObject
|
||||
class BLACKMISC_EXPORT CAircraftModelSetLoader :
|
||||
public QObject,
|
||||
public BlackMisc::Simulation::IModelsSetable,
|
||||
public BlackMisc::Simulation::IModelsUpdatable,
|
||||
public BlackMisc::Simulation::IModelsPerSimulatorSetable,
|
||||
public BlackMisc::Simulation::IModelsPerSimulatorUpdatable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorSetable)
|
||||
Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorUpdatable)
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CModelSetLoader(const CSimulatorInfo &info, QObject *parent = nullptr);
|
||||
CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CModelSetLoader();
|
||||
virtual ~CAircraftModelSetLoader();
|
||||
|
||||
//! The loaded models
|
||||
//! \threadsafe
|
||||
@@ -60,6 +69,9 @@ namespace BlackMisc
|
||||
//! 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.
|
||||
@@ -85,7 +97,7 @@ namespace BlackMisc
|
||||
//! Clear cache
|
||||
BlackMisc::CStatusMessage clearCache();
|
||||
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
|
||||
BlackMisc::Simulation::Data::CModelSetCaches m_caches { this }; //!< caches
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -161,11 +161,21 @@ namespace BlackMisc
|
||||
//! Syncronize
|
||||
void syncronize(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
signals:
|
||||
//! Cache has been changed
|
||||
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
private slots:
|
||||
void ps_changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
|
||||
void ps_changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); }
|
||||
void ps_changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); }
|
||||
void ps_changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); }
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFsx> m_modelCacheFsx {this }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFs9> m_modelCacheFs9 {this }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> m_modelCacheXP {this }; //!< XP cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFsx> m_modelCacheFsx {this, &CModelSetCaches::ps_changedFsx }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::ps_changedFs9}; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::ps_changedP3D }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::ps_changedXP }; //!< XP cache
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user