From a22591c8c07d5c7d4326ce2e699809eb4fa700ac Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Wed, 11 Nov 2020 00:14:17 +0000 Subject: [PATCH] Issue #77 Move CMultiAircraftModelLoaderProvider into a new module This breaks the cyclic dependencies between IAircraftModelLoader and its subclasses. --- .../components/dbownmodelscomponent.cpp | 1 + .../simulation/aircraftmodelloader.cpp | 73 ------------- .../simulation/aircraftmodelloader.h | 50 --------- .../aircraftmodelloaderprovider.cpp | 101 ++++++++++++++++++ .../simulation/aircraftmodelloaderprovider.h | 72 +++++++++++++ 5 files changed, 174 insertions(+), 123 deletions(-) create mode 100644 src/blackmisc/simulation/aircraftmodelloaderprovider.cpp create mode 100644 src/blackmisc/simulation/aircraftmodelloaderprovider.h diff --git a/src/blackgui/components/dbownmodelscomponent.cpp b/src/blackgui/components/dbownmodelscomponent.cpp index fbfe3b68e..9b4b9a43c 100644 --- a/src/blackgui/components/dbownmodelscomponent.cpp +++ b/src/blackgui/components/dbownmodelscomponent.cpp @@ -15,6 +15,7 @@ #include "blackgui/guiapplication.h" #include "blackcore/webdataservices.h" #include "blackcore/db/databaseutils.h" +#include "blackmisc/simulation/aircraftmodelloaderprovider.h" #include "blackmisc/icons.h" #include "blackmisc/swiftdirectories.h" #include "blackmisc/logmessage.h" diff --git a/src/blackmisc/simulation/aircraftmodelloader.cpp b/src/blackmisc/simulation/aircraftmodelloader.cpp index 90908f01e..82b906f71 100644 --- a/src/blackmisc/simulation/aircraftmodelloader.cpp +++ b/src/blackmisc/simulation/aircraftmodelloader.cpp @@ -7,9 +7,6 @@ */ #include "blackmisc/simulation/aircraftmodelloader.h" -#include "blackmisc/simulation/fscommon/aircraftcfgparser.h" -#include "blackmisc/simulation/xplane/aircraftmodelloaderxplane.h" -#include "blackmisc/simulation/flightgear/aircraftmodelloaderflightgear.h" #include "blackmisc/simulation/xplane/xplaneutil.h" #include "blackmisc/directoryutils.h" #include "blackmisc/mixin/mixincompare.h" @@ -23,9 +20,6 @@ using namespace BlackMisc; using namespace BlackMisc::Simulation::Data; using namespace BlackMisc::Simulation::Settings; -using namespace BlackMisc::Simulation::FsCommon; -using namespace BlackMisc::Simulation::Flightgear; -using namespace BlackMisc::Simulation::XPlane; namespace BlackMisc { @@ -172,14 +166,6 @@ namespace BlackMisc return this->updateModelsForSimulator(models, m_simulator); } - IAircraftModelLoader *IAircraftModelLoader::createModelLoader(const CSimulatorInfo &simulator, QObject *parent) - { - Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Single simulator"); - if (simulator.isXPlane()) { return new CAircraftModelLoaderXPlane(parent); } - if (simulator.isFG()) { return new CAircraftModelLoaderFlightgear(parent); } - return CAircraftCfgParser::createModelLoader(simulator, parent); - } - QStringList IAircraftModelLoader::getInitializedModelDirectories(const QStringList &modelDirectories, const CSimulatorInfo &simulator) const { QStringList modelDirs = modelDirectories.isEmpty() ? m_settings.getModelDirectoriesOrDefault(simulator) : modelDirectories; @@ -228,65 +214,6 @@ namespace BlackMisc emit this->cacheChanged(simulator); } - IAircraftModelLoader *CMultiAircraftModelLoaderProvider::loaderInstance(const CSimulatorInfo &simulator) - { - Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); - switch (simulator.getSimulator()) - { - case CSimulatorInfo::FSX: - { - if (!m_loaderFsx) { m_loaderFsx = this->initLoader(CSimulatorInfo::fsx()); } - return m_loaderFsx; - } - case CSimulatorInfo::P3D: - { - if (!m_loaderP3D) { m_loaderP3D = this->initLoader(CSimulatorInfo::p3d()); } - return m_loaderP3D; - } - case CSimulatorInfo::XPLANE: - { - if (!m_loaderXP) { m_loaderXP = this->initLoader(CSimulatorInfo::xplane()); } - return m_loaderXP; - } - case CSimulatorInfo::FS9: - { - if (!m_loaderFS9) { m_loaderFS9 = this->initLoader(CSimulatorInfo::fs9()); } - return m_loaderFS9; - } - case CSimulatorInfo::FG: - { - if (!m_loaderFG) { m_loaderFG = this->initLoader(CSimulatorInfo::fg()); } - return m_loaderFG; - } - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); - break; - } - return nullptr; - } - - CMultiAircraftModelLoaderProvider &CMultiAircraftModelLoaderProvider::multiModelLoaderInstance() - { - static CMultiAircraftModelLoaderProvider loader; - return loader; - } - - 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); - 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; - } - CDummyModelLoader::CDummyModelLoader(const CSimulatorInfo &simulator, QObject *parent) : IAircraftModelLoader(simulator, parent) { // void diff --git a/src/blackmisc/simulation/aircraftmodelloader.h b/src/blackmisc/simulation/aircraftmodelloader.h index 358fb10ce..681f8d834 100644 --- a/src/blackmisc/simulation/aircraftmodelloader.h +++ b/src/blackmisc/simulation/aircraftmodelloader.h @@ -133,9 +133,6 @@ namespace BlackMisc virtual int updateModels(const CAircraftModelList &models) override; //! @} - //! Create a loader and synchronize caches - static IAircraftModelLoader *createModelLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr); - signals: //! Disk loading started //! \remark will only indicate loading from disk, not cache loading @@ -207,53 +204,6 @@ namespace BlackMisc private: qint64 m_loadingStartedTs = -1; }; - - /*! - * Single instances of all model loaders (lazy init) - */ - class BLACKMISC_EXPORT CMultiAircraftModelLoaderProvider : public QObject - { - Q_OBJECT - - public: - //! Loader instance - IAircraftModelLoader *loaderInstance(const CSimulatorInfo &simulator); - - //! Singleton - static CMultiAircraftModelLoaderProvider &multiModelLoaderInstance(); - - //! Simulator specific loaders - //! @{ - IAircraftModelLoader *modelLoaderFsx() const { return m_loaderFsx; } - IAircraftModelLoader *modelLoaderP3D() const { return m_loaderP3D; } - IAircraftModelLoader *modelLoaderXP() const { return m_loaderXP; } - IAircraftModelLoader *modelLoaderFS9() const { return m_loaderFS9; } - IAircraftModelLoader *modelLoaderFG() const { return m_loaderFG; } - //! @} - - signals: - //! \copydoc IAircraftModelLoader::loadingFinished - void loadingFinished(const BlackMisc::CStatusMessageList &status, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info); - - //! \copydoc IAircraftModelLoader::diskLoadingStarted - void diskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode); - - //! \copydoc IAircraftModelLoader::loadingProgress - void loadingProgress(const CSimulatorInfo &simulator, const QString &message, int progressPercentage); - - //! \copydoc IAircraftModelLoader::cacheChanged - void cacheChanged(const CSimulatorInfo &simulator); - - private: - IAircraftModelLoader *m_loaderFsx = nullptr; - IAircraftModelLoader *m_loaderP3D = nullptr; - IAircraftModelLoader *m_loaderXP = nullptr; - IAircraftModelLoader *m_loaderFS9 = nullptr; - IAircraftModelLoader *m_loaderFG = nullptr; - - //! Init the loader - IAircraftModelLoader *initLoader(const CSimulatorInfo &simulator); - }; } // ns } // ns diff --git a/src/blackmisc/simulation/aircraftmodelloaderprovider.cpp b/src/blackmisc/simulation/aircraftmodelloaderprovider.cpp new file mode 100644 index 000000000..ae57e5eae --- /dev/null +++ b/src/blackmisc/simulation/aircraftmodelloaderprovider.cpp @@ -0,0 +1,101 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "blackmisc/simulation/aircraftmodelloaderprovider.h" +#include "blackmisc/simulation/fscommon/aircraftcfgparser.h" +#include "blackmisc/simulation/xplane/aircraftmodelloaderxplane.h" +#include "blackmisc/simulation/flightgear/aircraftmodelloaderflightgear.h" +#include "blackmisc/simulation/xplane/xplaneutil.h" +#include "blackmisc/directoryutils.h" +#include "blackmisc/mixin/mixincompare.h" +#include "blackmisc/logmessage.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Simulation::Data; +using namespace BlackMisc::Simulation::Settings; +using namespace BlackMisc::Simulation::FsCommon; +using namespace BlackMisc::Simulation::Flightgear; +using namespace BlackMisc::Simulation::XPlane; + +namespace BlackMisc +{ + namespace Simulation + { + IAircraftModelLoader *CMultiAircraftModelLoaderProvider::createModelLoader(const CSimulatorInfo &simulator, QObject *parent) + { + Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Single simulator"); + if (simulator.isXPlane()) { return new CAircraftModelLoaderXPlane(parent); } + if (simulator.isFG()) { return new CAircraftModelLoaderFlightgear(parent); } + return CAircraftCfgParser::createModelLoader(simulator, parent); + } + + IAircraftModelLoader *CMultiAircraftModelLoaderProvider::loaderInstance(const CSimulatorInfo &simulator) + { + Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator"); + switch (simulator.getSimulator()) + { + case CSimulatorInfo::FSX: + { + if (!m_loaderFsx) { m_loaderFsx = this->initLoader(CSimulatorInfo::fsx()); } + return m_loaderFsx; + } + case CSimulatorInfo::P3D: + { + if (!m_loaderP3D) { m_loaderP3D = this->initLoader(CSimulatorInfo::p3d()); } + return m_loaderP3D; + } + case CSimulatorInfo::XPLANE: + { + if (!m_loaderXP) { m_loaderXP = this->initLoader(CSimulatorInfo::xplane()); } + return m_loaderXP; + } + case CSimulatorInfo::FS9: + { + if (!m_loaderFS9) { m_loaderFS9 = this->initLoader(CSimulatorInfo::fs9()); } + return m_loaderFS9; + } + case CSimulatorInfo::FG: + { + if (!m_loaderFG) { m_loaderFG = this->initLoader(CSimulatorInfo::fg()); } + return m_loaderFG; + } + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); + break; + } + return nullptr; + } + + CMultiAircraftModelLoaderProvider &CMultiAircraftModelLoaderProvider::multiModelLoaderInstance() + { + static CMultiAircraftModelLoaderProvider loader; + return loader; + } + + 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 = createModelLoader(simulator, this); + 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; + } + } // ns +} // ns diff --git a/src/blackmisc/simulation/aircraftmodelloaderprovider.h b/src/blackmisc/simulation/aircraftmodelloaderprovider.h new file mode 100644 index 000000000..e9a467dce --- /dev/null +++ b/src/blackmisc/simulation/aircraftmodelloaderprovider.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_IAIRCRAFTMODELLOADERPROVIDER_H +#define BLACKMISC_SIMULATION_IAIRCRAFTMODELLOADERPROVIDER_H + +#include "blackmisc/simulation/aircraftmodelloader.h" + +namespace BlackMisc +{ + namespace Simulation + { + /*! + * Single instances of all model loaders (lazy init) + */ + class BLACKMISC_EXPORT CMultiAircraftModelLoaderProvider : public QObject + { + Q_OBJECT + + public: + //! Create a loader and synchronize caches + static IAircraftModelLoader *createModelLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr); + + //! Loader instance + IAircraftModelLoader *loaderInstance(const CSimulatorInfo &simulator); + + //! Singleton + static CMultiAircraftModelLoaderProvider &multiModelLoaderInstance(); + + //! Simulator specific loaders + //! @{ + IAircraftModelLoader *modelLoaderFsx() const { return m_loaderFsx; } + IAircraftModelLoader *modelLoaderP3D() const { return m_loaderP3D; } + IAircraftModelLoader *modelLoaderXP() const { return m_loaderXP; } + IAircraftModelLoader *modelLoaderFS9() const { return m_loaderFS9; } + IAircraftModelLoader *modelLoaderFG() const { return m_loaderFG; } + //! @} + + signals: + //! \copydoc IAircraftModelLoader::loadingFinished + void loadingFinished(const BlackMisc::CStatusMessageList &status, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info); + + //! \copydoc IAircraftModelLoader::diskLoadingStarted + void diskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode); + + //! \copydoc IAircraftModelLoader::loadingProgress + void loadingProgress(const CSimulatorInfo &simulator, const QString &message, int progressPercentage); + + //! \copydoc IAircraftModelLoader::cacheChanged + void cacheChanged(const CSimulatorInfo &simulator); + + private: + IAircraftModelLoader *m_loaderFsx = nullptr; + IAircraftModelLoader *m_loaderP3D = nullptr; + IAircraftModelLoader *m_loaderXP = nullptr; + IAircraftModelLoader *m_loaderFS9 = nullptr; + IAircraftModelLoader *m_loaderFG = nullptr; + + //! Init the loader + IAircraftModelLoader *initLoader(const CSimulatorInfo &simulator); + }; + } // ns +} // ns + +#endif // guard