mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
Issue #77 Move CMultiAircraftModelLoaderProvider into a new module
This breaks the cyclic dependencies between IAircraftModelLoader and its subclasses.
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include "blackgui/guiapplication.h"
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackcore/db/databaseutils.h"
|
#include "blackcore/db/databaseutils.h"
|
||||||
|
#include "blackmisc/simulation/aircraftmodelloaderprovider.h"
|
||||||
#include "blackmisc/icons.h"
|
#include "blackmisc/icons.h"
|
||||||
#include "blackmisc/swiftdirectories.h"
|
#include "blackmisc/swiftdirectories.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackmisc/simulation/aircraftmodelloader.h"
|
#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/simulation/xplane/xplaneutil.h"
|
||||||
#include "blackmisc/directoryutils.h"
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/mixin/mixincompare.h"
|
#include "blackmisc/mixin/mixincompare.h"
|
||||||
@@ -23,9 +20,6 @@
|
|||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Simulation::Data;
|
using namespace BlackMisc::Simulation::Data;
|
||||||
using namespace BlackMisc::Simulation::Settings;
|
using namespace BlackMisc::Simulation::Settings;
|
||||||
using namespace BlackMisc::Simulation::FsCommon;
|
|
||||||
using namespace BlackMisc::Simulation::Flightgear;
|
|
||||||
using namespace BlackMisc::Simulation::XPlane;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -172,14 +166,6 @@ namespace BlackMisc
|
|||||||
return this->updateModelsForSimulator(models, m_simulator);
|
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 IAircraftModelLoader::getInitializedModelDirectories(const QStringList &modelDirectories, const CSimulatorInfo &simulator) const
|
||||||
{
|
{
|
||||||
QStringList modelDirs = modelDirectories.isEmpty() ? m_settings.getModelDirectoriesOrDefault(simulator) : modelDirectories;
|
QStringList modelDirs = modelDirectories.isEmpty() ? m_settings.getModelDirectoriesOrDefault(simulator) : modelDirectories;
|
||||||
@@ -228,65 +214,6 @@ namespace BlackMisc
|
|||||||
emit this->cacheChanged(simulator);
|
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)
|
CDummyModelLoader::CDummyModelLoader(const CSimulatorInfo &simulator, QObject *parent) : IAircraftModelLoader(simulator, parent)
|
||||||
{
|
{
|
||||||
// void
|
// void
|
||||||
|
|||||||
@@ -133,9 +133,6 @@ namespace BlackMisc
|
|||||||
virtual int updateModels(const CAircraftModelList &models) override;
|
virtual int updateModels(const CAircraftModelList &models) override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Create a loader and synchronize caches
|
|
||||||
static IAircraftModelLoader *createModelLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Disk loading started
|
//! Disk loading started
|
||||||
//! \remark will only indicate loading from disk, not cache loading
|
//! \remark will only indicate loading from disk, not cache loading
|
||||||
@@ -207,53 +204,6 @@ namespace BlackMisc
|
|||||||
private:
|
private:
|
||||||
qint64 m_loadingStartedTs = -1;
|
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
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
101
src/blackmisc/simulation/aircraftmodelloaderprovider.cpp
Normal file
101
src/blackmisc/simulation/aircraftmodelloaderprovider.cpp
Normal file
@@ -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 <QDir>
|
||||||
|
#include <Qt>
|
||||||
|
#include <QtGlobal>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
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
|
||||||
72
src/blackmisc/simulation/aircraftmodelloaderprovider.h
Normal file
72
src/blackmisc/simulation/aircraftmodelloaderprovider.h
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user