mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #619, allow to directly manipulate cache in loader
This commit is contained in:
@@ -39,12 +39,12 @@ namespace BlackMisc
|
||||
return dir.exists();
|
||||
}
|
||||
|
||||
bool IAircraftModelLoader::mergeWithDbData(CAircraftModelList &modelsFromSimulator, const CAircraftModelList &dbModels)
|
||||
bool IAircraftModelLoader::mergeWithDbData(CAircraftModelList &modelsFromSimulator, const CAircraftModelList &dbModels, bool force)
|
||||
{
|
||||
if (dbModels.isEmpty() || modelsFromSimulator.isEmpty()) { return false; }
|
||||
for (CAircraftModel &simModel : modelsFromSimulator)
|
||||
{
|
||||
if (simModel.hasValidDbKey()) { continue; } // already done
|
||||
if (!force && simModel.hasValidDbKey()) { continue; } // already done
|
||||
CAircraftModel dbModel(dbModels.findFirstByModelStringOrDefault(simModel.getModelString()));
|
||||
if (!dbModel.hasValidDbKey())
|
||||
{
|
||||
@@ -56,6 +56,36 @@ namespace BlackMisc
|
||||
return true;
|
||||
}
|
||||
|
||||
CStatusMessage IAircraftModelLoader::replaceCacheWithModelData(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
|
||||
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
|
||||
const CStatusMessage m(this->m_caches.setModels(models, sim));
|
||||
if (m.isSeverityInfoOrLess())
|
||||
{
|
||||
// set is asny
|
||||
// emit loadingFinished(true, sim);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage IAircraftModelLoader::replaceOrAddModelsInCache(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));
|
||||
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
if (c > 0)
|
||||
{
|
||||
return this->replaceCacheWithModelData(models, sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data changed");
|
||||
}
|
||||
}
|
||||
|
||||
void IAircraftModelLoader::ps_loadFinished(bool success)
|
||||
{
|
||||
Q_UNUSED(success);
|
||||
|
||||
@@ -91,11 +91,20 @@ namespace BlackMisc
|
||||
//! Shutdown
|
||||
void gracefulShutdown();
|
||||
|
||||
//! Create a loader
|
||||
//! Create a loader and syncronize caches
|
||||
static std::unique_ptr<IAircraftModelLoader> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
|
||||
|
||||
//! Merge with DB data if possible
|
||||
static bool mergeWithDbData(BlackMisc::Simulation::CAircraftModelList &modelsFromSimulator, const BlackMisc::Simulation::CAircraftModelList &dbModels);
|
||||
static bool mergeWithDbData(BlackMisc::Simulation::CAircraftModelList &modelsFromSimulator, const BlackMisc::Simulation::CAircraftModelList &dbModels, bool force = false);
|
||||
|
||||
public slots:
|
||||
//! Set cache from outside, this should only be used in special cases.
|
||||
//! But it allows to modify data elsewhere nd update the cache with manipulated data.
|
||||
BlackMisc::CStatusMessage replaceCacheWithModelData(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 nd update the cache with manipulated data.
|
||||
BlackMisc::CStatusMessage replaceOrAddModelsInCache(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
|
||||
|
||||
signals:
|
||||
//! Parsing is finished
|
||||
|
||||
Reference in New Issue
Block a user