refs #619, adjusted model loader / implementing classes

* init data based on last setup
* init changed some signatures
This commit is contained in:
Klaus Basan
2016-03-12 05:30:47 +01:00
parent 7714f5db9f
commit 83d7b7ceef
6 changed files with 30 additions and 27 deletions

View File

@@ -96,12 +96,12 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex()
int comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const;
//! Can be initialized from FSD //! Can be initialized from FSD
bool canInitializeFromFsd() const; bool canInitializeFromFsd() const;
//! Compare for index
int comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const;
//! Corresponding callsign if applicable //! Corresponding callsign if applicable
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_callsign; } const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_callsign; }

View File

@@ -58,23 +58,23 @@ namespace BlackMisc
if (this->m_loadingInProgress) { return; } if (this->m_loadingInProgress) { return; }
this->m_loadingInProgress = true; this->m_loadingInProgress = true;
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData(); const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
if (useCachedData && mode.testFlag(CacheFirst)) if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
{ {
emit loadingFinished(true); emit loadingFinished(true, this->m_simulatorInfo);
return; return;
} }
else if (useCachedData && mode.testFlag(CacheUntilNewer)) else if (useCachedData && mode.testFlag(CacheUntilNewer))
{ {
if (!this->areModelFilesUpdated()) if (!this->areModelFilesUpdated())
{ {
emit loadingFinished(true); emit loadingFinished(true, this->m_simulatorInfo);
return; return;
} }
} }
if (mode.testFlag(CacheOnly)) if (mode.testFlag(CacheOnly))
{ {
// only cache, but we did not find any data // only cache, but we did not find any data
emit loadingFinished(false); emit loadingFinished(false, this->m_simulatorInfo);
return; return;
} }
this->startLoadingFromDisk(mode); this->startLoadingFromDisk(mode);

View File

@@ -42,7 +42,7 @@ namespace BlackMisc
CacheUntilNewer = 1 << 2, //!< use cache until newer data re available CacheUntilNewer = 1 << 2, //!< use cache until newer data re available
CacheFirst = 1 << 3, //!< always use cache (if it has data) CacheFirst = 1 << 3, //!< always use cache (if it has data)
CacheSkipped = 1 << 4, //!< ignore cache CacheSkipped = 1 << 4, //!< ignore cache
CacheOnly = 1 << 5, //!< force ignoring the cache CacheOnly = 1 << 5, //!< only read cache, never load from disk
Default = LoadInBackground | CacheFirst //!< default mode Default = LoadInBackground | CacheFirst //!< default mode
}; };
Q_DECLARE_FLAGS(LoadMode, LoadModeFlag) Q_DECLARE_FLAGS(LoadMode, LoadModeFlag)
@@ -97,7 +97,7 @@ namespace BlackMisc
signals: signals:
//! Parsing is finished //! Parsing is finished
void loadingFinished(bool success); void loadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simulator);
protected: protected:
//! Constructor //! Constructor

View File

@@ -107,8 +107,9 @@ namespace BlackMisc
{ {
if (pair.second) if (pair.second)
{ {
this->updateCfgEntriesList(pair.first); this->m_parsedCfgEntriesList = pair.first;
this->setModelsInCache(pair.first.toAircraftModelList()); this->setModelsInCache(pair.first.toAircraftModelList());
emit loadingFinished(true, this->m_simulatorInfo);
} }
}); });
} }
@@ -117,7 +118,15 @@ namespace BlackMisc
bool ok; bool ok;
this->m_parsedCfgEntriesList = performParsing(m_rootDirectory, m_excludedDirectories, &ok); this->m_parsedCfgEntriesList = performParsing(m_rootDirectory, m_excludedDirectories, &ok);
this->setModelsInCache(this->m_parsedCfgEntriesList.toAircraftModelList()); this->setModelsInCache(this->m_parsedCfgEntriesList.toAircraftModelList());
emit loadingFinished(ok); emit loadingFinished(ok, this->m_simulatorInfo);
}
}
void CAircraftCfgParser::ps_cacheChanged()
{
if (this->hasCachedData())
{
emit this->loadingFinished(true, this->m_simulatorInfo);
} }
} }
@@ -188,12 +197,6 @@ namespace BlackMisc
return empty; return empty;
} }
void CAircraftCfgParser::updateCfgEntriesList(const CAircraftCfgEntriesList &cfgEntriesList)
{
m_parsedCfgEntriesList = cfgEntriesList;
emit loadingFinished(true);
}
CStatusMessage CAircraftCfgParser::setModelsInCache(const CAircraftModelList &models) CStatusMessage CAircraftCfgParser::setModelsInCache(const CAircraftModelList &models)
{ {
if (this->m_simulatorInfo.fsx()) if (this->m_simulatorInfo.fsx())

View File

@@ -56,10 +56,6 @@ namespace BlackMisc
//! Create an parser object for given simulator //! Create an parser object for given simulator
static std::unique_ptr<CAircraftCfgParser> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo); static std::unique_ptr<CAircraftCfgParser> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
public slots:
//! Parsed or injected entires
void updateCfgEntriesList(const BlackMisc::Simulation::FsCommon::CAircraftCfgEntriesList &cfgEntriesList);
protected: protected:
//! Set cached values //! Set cached values
BlackMisc::CStatusMessage setModelsInCache(const BlackMisc::Simulation::CAircraftModelList &models); BlackMisc::CStatusMessage setModelsInCache(const BlackMisc::Simulation::CAircraftModelList &models);
@@ -69,6 +65,10 @@ namespace BlackMisc
virtual void startLoadingFromDisk(LoadMode mode) override; virtual void startLoadingFromDisk(LoadMode mode) override;
//! @} //! @}
private slots:
//! Cache changed
void ps_cacheChanged();
private: private:
//! Section within file //! Section within file
enum FileSection enum FileSection
@@ -95,9 +95,9 @@ namespace BlackMisc
QPointer<BlackMisc::CWorker> m_parserWorker; //!< worker will destroy itself, so weak pointer QPointer<BlackMisc::CWorker> m_parserWorker; //!< worker will destroy itself, so weak pointer
//! \todo KB/MS Is there nothing better than having 3 cache members? //! \todo KB/MS Is there nothing better than having 3 cache members?
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this}; //!< FSX cache BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this, &CAircraftCfgParser::ps_cacheChanged}; //!< FSX cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this}; //!< Fs9 cache BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CAircraftCfgParser::ps_cacheChanged}; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this}; //!< P3D cache BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CAircraftCfgParser::ps_cacheChanged}; //!< P3D cache
static const QString &fileFilter(); static const QString &fileFilter();
}; };

View File

@@ -67,7 +67,7 @@ namespace BlackMisc
m_installedModels.clear(); m_installedModels.clear();
if (m_rootDirectory.isEmpty()) if (m_rootDirectory.isEmpty())
{ {
emit loadingFinished(false); emit loadingFinished(false, this->m_simulatorInfo);
return; return;
} }
@@ -90,7 +90,7 @@ namespace BlackMisc
else if (mode.testFlag(LoadDirectly)) else if (mode.testFlag(LoadDirectly))
{ {
m_installedModels = performParsing(m_rootDirectory, m_excludedDirectories); m_installedModels = performParsing(m_rootDirectory, m_excludedDirectories);
emit loadingFinished(true); emit loadingFinished(true, this->m_simulatorInfo);
} }
} }
@@ -126,7 +126,7 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models) void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{ {
m_installedModels = models; m_installedModels = models;
emit loadingFinished(true); emit loadingFinished(true, this->m_simulatorInfo);
} }
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const