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 skipped("loading skipped");
static const QString parsed("parsed data");
static const QString failed("failed");
switch (info)
{
case CacheLoaded: return loaded;
case CacheLoaded: return loaded;
case ParsedData: return parsed;
case LoadingSkipped: return skipped;
case ParsedData: return parsed;
case LoadingFailed: return failed;
default: break;
}
@@ -275,11 +277,17 @@ namespace BlackMisc
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);
connect(loader, &IAircraftModelLoader::loadingFinished, this, &CMultiAircraftModelLoaderProvider::loadingFinished);
connect(loader, &IAircraftModelLoader::diskLoadingStarted, this, &CMultiAircraftModelLoaderProvider::diskLoadingStarted);
connect(loader, &IAircraftModelLoader::cacheChanged, this, &CMultiAircraftModelLoaderProvider::cacheChanged);
connect(loader, &IAircraftModelLoader::loadingProgress, this, &CMultiAircraftModelLoaderProvider::loadingProgress);
bool c = connect(loader, &IAircraftModelLoader::loadingFinished, this, &CMultiAircraftModelLoaderProvider::loadingFinished, Qt::QueuedConnection);
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
c = connect(loader, &IAircraftModelLoader::diskLoadingStarted, this, &CMultiAircraftModelLoaderProvider::diskLoadingStarted, Qt::QueuedConnection);
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;
}

View File

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

View File

@@ -117,6 +117,7 @@ namespace BlackMisc
{
if (m_parserWorker && !m_parserWorker->isFinished()) { return; }
emit this->diskLoadingStarted(simulator, mode);
m_parserWorker = CWorker::fromTask(this, "CAircraftModelLoaderXPlane::performParsing",
[this, modelDirs, excludedDirectoryPatterns, modelConsolidation]()
{
@@ -147,7 +148,8 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{
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
@@ -216,6 +218,7 @@ namespace BlackMisc
const QString baseModelString = model.getModelString();
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())
{
liveryIt.next();
@@ -258,10 +261,8 @@ namespace BlackMisc
// Now we do a full run
for (auto &package : m_cslPackages)
{
QString packageFile(package.path);
packageFile += "/xsb_aircraft.txt";
emit loadingProgress(this->getSimulator(), QStringLiteral("Parsing '%1'").arg(packageFile), -1);
const QString packageFile = CFileUtils::appendFilePaths(package.path, "/xsb_aircraft.txt");
emit this->loadingProgress(this->getSimulator(), QStringLiteral("Parsing CSL '%1'").arg(packageFile), -1);
QFile file(packageFile);
file.open(QIODevice::ReadOnly);