mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user