refs #614, use interfaces from last step to reuse mergeWithDb data in multiple components

* adjusted menus
* adjusted loaders and components
This commit is contained in:
Klaus Basan
2016-04-08 14:11:40 +02:00
parent 43c69d2ed0
commit abca1fde52
12 changed files with 115 additions and 47 deletions

View File

@@ -80,7 +80,7 @@ namespace BlackMisc
CAircraftModelList IAircraftModelLoader::getAircraftModels() const
{
return this->m_caches.getModels(this->m_simulatorInfo);
return this->m_caches.getCachedModels(this->m_simulatorInfo);
}
QDateTime IAircraftModelLoader::getCacheTimestamp() const
@@ -90,17 +90,17 @@ namespace BlackMisc
void IAircraftModelLoader::syncronizeCache()
{
return this->m_caches.syncronize(this->m_simulatorInfo);
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
}
bool IAircraftModelLoader::hasCachedData() const
{
return !this->m_caches.getModels(this->m_simulatorInfo).isEmpty();
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
}
CStatusMessage IAircraftModelLoader::clearCache()
{
return this->setModelsInCache(CAircraftModelList());
return this->setCachedModels(CAircraftModelList());
}
void IAircraftModelLoader::startLoading(LoadMode mode, const CAircraftModelList &dbModels)

View File

@@ -13,7 +13,7 @@
#define BLACKMISC_SIMULATION_IAIRCRAFTMODELLOADER_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/pixmap.h"
@@ -28,9 +28,18 @@ namespace BlackMisc
/*!
* Load the aircraft for a simulator
*/
class BLACKMISC_EXPORT IAircraftModelLoader : public QObject
class BLACKMISC_EXPORT IAircraftModelLoader :
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:
//! Parser mode

View File

@@ -56,14 +56,14 @@ namespace BlackMisc
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->m_caches.syncronize(simulator);
this->m_simulatorInfo = simulator;
this->m_caches.syncronizeCache(simulator);
emit simulatorChanged(simulator);
}
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
{
return this->m_caches.getModels(this->m_simulatorInfo);
return this->m_caches.getCachedModels(this->m_simulatorInfo);
}
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
@@ -73,17 +73,17 @@ namespace BlackMisc
void CAircraftModelSetLoader::syncronizeCache()
{
return this->m_caches.syncronize(this->m_simulatorInfo);
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
}
bool CAircraftModelSetLoader::hasCachedData() const
{
return !this->m_caches.getModels(this->m_simulatorInfo).isEmpty();
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
}
CStatusMessage CAircraftModelSetLoader::clearCache()
{
return this->setModelsInCache(CAircraftModelList());
return this->setCachedModels(CAircraftModelList());
}
const CSimulatorInfo &CAircraftModelSetLoader::getSimulator() const

View File

@@ -13,8 +13,7 @@
#define BLACKMISC_SIMULATION_AIRCRAFTMODELSETLOADER_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/pixmap.h"
#include <QObject>
@@ -65,6 +64,14 @@ namespace BlackMisc
//! Shutdown
void gracefulShutdown();
//! \name Implementations of the models interfaces
//! @{
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->m_simulatorInfo); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->m_simulatorInfo); }
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); }
//! @}
signals:
//! Simulator has been changed
void simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
@@ -75,11 +82,11 @@ namespace BlackMisc
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 setModelsInCache(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
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 replaceOrAddModelsInCache(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
BlackMisc::CStatusMessage replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
//! Change the simulator
void changeSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);

View File

@@ -9,6 +9,7 @@
#include "aircraftcfgparser.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include "blackmisc/simulation/aircraftmodelutils.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/predicates.h"
#include "blackmisc/logmessage.h"
@@ -110,7 +111,7 @@ namespace BlackMisc
if (ok)
{
models = (aircraftCfgEntriesList.toAircraftModelList(this->getSimulator()));
this->mergeWithDbData(models, dbModels);
CAircraftModelUtilities::mergeWithDbData(models, dbModels);
}
return std::make_tuple(aircraftCfgEntriesList, models, ok);
});
@@ -124,7 +125,7 @@ namespace BlackMisc
const bool hasData = !models.isEmpty();
if (hasData)
{
this->setModelsInCache(models); // not thread safe
this->setCachedModels(models); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, this->m_simulatorInfo);
@@ -140,11 +141,11 @@ namespace BlackMisc
bool ok;
this->m_parsedCfgEntriesList = performParsing(m_rootDirectory, m_excludedDirectories, &ok);
CAircraftModelList models(this->m_parsedCfgEntriesList.toAircraftModelList(this->getSimulator()));
this->mergeWithDbData(models, dbModels);
CAircraftModelUtilities::mergeWithDbData(models, dbModels);
const bool hasData = !models.isEmpty();
if (hasData)
{
this->setModelsInCache(models); // not thread safe
this->setCachedModels(models); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, this->m_simulatorInfo);

View File

@@ -9,6 +9,7 @@
#include "aircraftmodelloaderxplane.h"
#include "xplaneutil.h"
#include "blackmisc/simulation/aircraftmodelutils.h"
#include "blackmisc/predicates.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/fileutils.h"
@@ -80,7 +81,7 @@ namespace BlackMisc
[this, rootDirectory, excludedDirectories, dbModels]()
{
auto models = performParsing(rootDirectory, excludedDirectories);
mergeWithDbData(models, dbModels);
CAircraftModelUtilities::mergeWithDbData(models, dbModels);
return models;
});
m_parserWorker->thenWithResult<CAircraftModelList>(this, [this](const auto & models)
@@ -91,7 +92,7 @@ namespace BlackMisc
else if (mode.testFlag(LoadDirectly))
{
CAircraftModelList models(performParsing(m_rootDirectory, m_excludedDirectories));
mergeWithDbData(models, dbModels);
CAircraftModelUtilities::mergeWithDbData(models, dbModels);
updateInstalledModels(models);
}
}
@@ -111,7 +112,7 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{
this->setModelsInCache(models);
this->setCachedModels(models);
emit loadingFinished(true, this->m_simulatorInfo);
}