Ref T529, model loader improvements

* XP loader improved progress messages
* added LoadingFailed
* use "Qt::QueuedConnection" for CMultiAircraftModelLoaderProvider

In some cases the loading progress signal was not send properly changing to Qt::QueuedConnection has solved the issue
This commit is contained in:
Klaus Basan
2019-02-07 03:12:16 +01:00
committed by Mat Sutcliffe
parent 91050e198c
commit 02f638501e
3 changed files with 30 additions and 14 deletions

View File

@@ -41,12 +41,14 @@ namespace BlackMisc
static const QString loaded("cache loaded"); static const QString loaded("cache loaded");
static const QString skipped("loading skipped"); static const QString skipped("loading skipped");
static const QString parsed("parsed data"); static const QString parsed("parsed data");
static const QString failed("failed");
switch (info) switch (info)
{ {
case CacheLoaded: return loaded; case CacheLoaded: return loaded;
case LoadingSkipped: return skipped;
case ParsedData: return parsed; case ParsedData: return parsed;
case LoadingSkipped: return skipped;
case LoadingFailed: return failed;
default: break; default: break;
} }
@@ -275,11 +277,17 @@ namespace BlackMisc
IAircraftModelLoader *CMultiAircraftModelLoaderProvider::initLoader(const CSimulatorInfo &simulator) IAircraftModelLoader *CMultiAircraftModelLoaderProvider::initLoader(const CSimulatorInfo &simulator)
{ {
// in some cases the loading progress signal was not send properly
// changing to Qt::QueuedConnection has solved the issues (Ref T529)
IAircraftModelLoader *loader = IAircraftModelLoader::createModelLoader(simulator, this); IAircraftModelLoader *loader = IAircraftModelLoader::createModelLoader(simulator, this);
connect(loader, &IAircraftModelLoader::loadingFinished, this, &CMultiAircraftModelLoaderProvider::loadingFinished); bool c = connect(loader, &IAircraftModelLoader::loadingFinished, this, &CMultiAircraftModelLoaderProvider::loadingFinished, Qt::QueuedConnection);
connect(loader, &IAircraftModelLoader::diskLoadingStarted, this, &CMultiAircraftModelLoaderProvider::diskLoadingStarted); Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
connect(loader, &IAircraftModelLoader::cacheChanged, this, &CMultiAircraftModelLoaderProvider::cacheChanged); c = connect(loader, &IAircraftModelLoader::diskLoadingStarted, this, &CMultiAircraftModelLoaderProvider::diskLoadingStarted, Qt::QueuedConnection);
connect(loader, &IAircraftModelLoader::loadingProgress, this, &CMultiAircraftModelLoaderProvider::loadingProgress); Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
c = connect(loader, &IAircraftModelLoader::cacheChanged, this, &CMultiAircraftModelLoaderProvider::cacheChanged, Qt::QueuedConnection);
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
c = connect(loader, &IAircraftModelLoader::loadingProgress, this, &CMultiAircraftModelLoaderProvider::loadingProgress, Qt::QueuedConnection);
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
return loader; return loader;
} }

View File

@@ -73,9 +73,16 @@ namespace BlackMisc
{ {
CacheLoaded, //!< cache was loaded CacheLoaded, //!< cache was loaded
ParsedData, //!< parsed data ParsedData, //!< parsed data
LoadingSkipped //!< Loading skipped (empty directory) LoadingSkipped, //!< loading skipped (empty directory)
LoadingFailed //!< loading failed
}; };
//! Loaded info
static bool isLoadedInfo(LoadFinishedInfo info)
{
return info == CacheLoaded || info == ParsedData;
}
//! Enum as string //! Enum as string
static const QString &enumToString(LoadFinishedInfo info); static const QString &enumToString(LoadFinishedInfo info);

View File

@@ -117,6 +117,7 @@ namespace BlackMisc
{ {
if (m_parserWorker && !m_parserWorker->isFinished()) { return; } if (m_parserWorker && !m_parserWorker->isFinished()) { return; }
emit this->diskLoadingStarted(simulator, mode); emit this->diskLoadingStarted(simulator, mode);
m_parserWorker = CWorker::fromTask(this, "CAircraftModelLoaderXPlane::performParsing", m_parserWorker = CWorker::fromTask(this, "CAircraftModelLoaderXPlane::performParsing",
[this, modelDirs, excludedDirectoryPatterns, modelConsolidation]() [this, modelDirs, excludedDirectoryPatterns, modelConsolidation]()
{ {
@@ -147,7 +148,8 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models) void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{ {
this->setModelsForSimulator(models, CSimulatorInfo::xplane()); this->setModelsForSimulator(models, CSimulatorInfo::xplane());
emit this->loadingFinished(CStatusMessage(this, CStatusMessage::SeverityInfo, u"XPlane updated '%1' models") << models.size(), CSimulatorInfo::xplane(), ParsedData); const CStatusMessage m = CStatusMessage(this, CStatusMessage::SeverityInfo, u"XPlane updated '%1' models") << models.size();
m_loadingMessages.push_back(m);
} }
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const
@@ -216,6 +218,7 @@ namespace BlackMisc
const QString baseModelString = model.getModelString(); const QString baseModelString = model.getModelString();
QDirIterator liveryIt(aircraftIt.fileInfo().canonicalPath() + "/liveries", QDir::Dirs | QDir::NoDotAndDotDot); QDirIterator liveryIt(aircraftIt.fileInfo().canonicalPath() + "/liveries", QDir::Dirs | QDir::NoDotAndDotDot);
emit loadingProgress(this->getSimulator(), QStringLiteral("Parsing flyable liveries in '%1'").arg(aircraftIt.fileInfo().canonicalPath()), -1);
while (liveryIt.hasNext()) while (liveryIt.hasNext())
{ {
liveryIt.next(); liveryIt.next();
@@ -258,10 +261,8 @@ namespace BlackMisc
// Now we do a full run // Now we do a full run
for (auto &package : m_cslPackages) for (auto &package : m_cslPackages)
{ {
QString packageFile(package.path); const QString packageFile = CFileUtils::appendFilePaths(package.path, "/xsb_aircraft.txt");
packageFile += "/xsb_aircraft.txt"; emit this->loadingProgress(this->getSimulator(), QStringLiteral("Parsing CSL '%1'").arg(packageFile), -1);
emit loadingProgress(this->getSimulator(), QStringLiteral("Parsing '%1'").arg(packageFile), -1);
QFile file(packageFile); QFile file(packageFile);
file.open(QIODevice::ReadOnly); file.open(QIODevice::ReadOnly);