#447, consider cache changed signal in order to avoid issue mentioned here

https://dev.vatsim-germany.org/issues/447#note-11
This commit is contained in:
Klaus Basan
2016-11-30 18:30:20 +01:00
parent 6befaa32d5
commit ed7963e551
4 changed files with 16 additions and 16 deletions

View File

@@ -30,7 +30,10 @@ namespace BlackMisc
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->m_caches.setCurrentSimulator(simulator);
// first connect is an internal connection to log info about load status
connect(this, &IAircraftModelLoader::loadingFinished, this, &IAircraftModelLoader::ps_loadFinished);
connect(&this->m_caches, &IMultiSimulatorModelCaches::cacheChanged, this, &IAircraftModelLoader::ps_cacheChanged);
}
IAircraftModelLoader::~IAircraftModelLoader()
@@ -49,7 +52,7 @@ namespace BlackMisc
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator(); // support default values
CAircraftModelList allModels(this->m_caches.getSynchronizedCachedModels(sim));
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
const int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
if (c > 0)
{
return this->setCachedModels(allModels, sim);
@@ -73,6 +76,11 @@ namespace BlackMisc
}
}
void IAircraftModelLoader::ps_cacheChanged(const CSimulatorInfo &simInfo)
{
emit this->loadingFinished(true, simInfo);
}
QStringList IAircraftModelLoader::getModelDirectoriesOrDefault() const
{
const QStringList mdirs = this->m_settings.getModelDirectoriesOrDefault(this->getSimulator());
@@ -136,8 +144,9 @@ namespace BlackMisc
}
if (mode.testFlag(CacheOnly))
{
// only cache, but we did not find any data
emit loadingFinished(false, this->getSimulator());
// only cache, but we did not find any data yet (still in progress?)
// here we rely on the cache load slot, no need to emit here
// an alternative was to sync cache here
return;
}
this->startLoadingFromDisk(mode, modelConsolidation, directory);

View File

@@ -147,7 +147,7 @@ namespace BlackMisc
BlackMisc::CStatusMessage replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator = CSimulatorInfo());
signals:
//! Parsing is finished
//! Parsing is finished or cache has been loaded
void loadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simulator);
protected:
@@ -175,6 +175,9 @@ namespace BlackMisc
protected slots:
//! Loading finished, also logs messages
void ps_loadFinished(bool success);
//! A cache has been changed
void ps_cacheChanged(const CSimulatorInfo &simInfo);
};
} // ns
} // ns

View File

@@ -125,14 +125,6 @@ namespace BlackMisc
}
}
void CAircraftCfgParser::ps_cacheChanged()
{
if (this->hasCachedData())
{
emit this->loadingFinished(true, this->getSimulator());
}
}
bool CAircraftCfgParser::isLoadingFinished() const
{
return !m_parserWorker || m_parserWorker->isFinished();

View File

@@ -64,10 +64,6 @@ namespace BlackMisc
virtual void startLoadingFromDisk(LoadMode mode, const ModelConsolidation &modelConsolidation, const QString &directory) override;
//! @}
private slots:
//! Cache changed
void ps_cacheChanged();
private:
//! Section within file
enum FileSection