mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
Ref T197, simulator info
* CSimulatorInfo only initialized once and not over and over again in plugin info * getSimulatorInfo() no longer virtual, as we can access the member CSimulatorInfo directly * display exact simualtor in FSX/P3D driver * renamed to identifierToSimulator and fixed typo "Identifier"
This commit is contained in:
@@ -33,13 +33,13 @@ namespace BlackMisc
|
||||
CSimulatorInfo::CSimulatorInfo()
|
||||
{ }
|
||||
|
||||
CSimulatorInfo::CSimulatorInfo(const QString &identifierString) : m_simulator(identifierToFlag(identifierString))
|
||||
CSimulatorInfo::CSimulatorInfo(const QString &identifierString) : m_simulator(identifierToSimulator(identifierString))
|
||||
{ }
|
||||
|
||||
CSimulatorInfo::CSimulatorInfo(const QStringList &simulators)
|
||||
{
|
||||
const QString identifier = simulators.join(' ');
|
||||
m_simulator = identifierToFlag(identifier);
|
||||
m_simulator = identifierToSimulator(identifier);
|
||||
}
|
||||
|
||||
CSimulatorInfo::CSimulatorInfo(Simulator simulator) : m_simulator(static_cast<int>(simulator))
|
||||
@@ -181,10 +181,10 @@ namespace BlackMisc
|
||||
static const QString e;
|
||||
if (!this->isSingleSimulator()) { return e; }
|
||||
const Simulator s = getSimulator();
|
||||
if (s.testFlag(FSX)) { return CSimulatorPluginInfo::fsxPluginIndentifier(); }
|
||||
if (s.testFlag(FS9)) { return CSimulatorPluginInfo::fs9PluginIndentifier(); }
|
||||
if (s.testFlag(P3D)) { return CSimulatorPluginInfo::p3dPluginIndentifier(); }
|
||||
if (s.testFlag(XPLANE)) { return CSimulatorPluginInfo::xplanePluginIndentifier(); }
|
||||
if (s.testFlag(FSX)) { return CSimulatorPluginInfo::fsxPluginIdentifier(); }
|
||||
if (s.testFlag(FS9)) { return CSimulatorPluginInfo::fs9PluginIdentifier(); }
|
||||
if (s.testFlag(P3D)) { return CSimulatorPluginInfo::p3dPluginIdentifier(); }
|
||||
if (s.testFlag(XPLANE)) { return CSimulatorPluginInfo::xplanePluginIdentifier(); }
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -197,9 +197,9 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
CSimulatorInfo::Simulator CSimulatorInfo::identifierToFlag(const QString &identifier)
|
||||
CSimulatorInfo::Simulator CSimulatorInfo::identifierToSimulator(const QString &identifier)
|
||||
{
|
||||
QString i(identifier.toLower().trimmed().remove(' ').remove('-'));
|
||||
const QString i(identifier.toLower().trimmed().remove(' ').remove('-'));
|
||||
if (i.isEmpty()) { return None; }
|
||||
|
||||
Simulator s = None;
|
||||
|
||||
@@ -31,14 +31,16 @@ namespace BlackMisc
|
||||
namespace Simulation
|
||||
{
|
||||
//! Simple hardcoded info about the corresponding simulator.
|
||||
//!
|
||||
//! * in an ideal world this class would not exist, all would depend on flexible plugins \sa CSimulatorPluginInfo
|
||||
//! * in a real world the info is needed in a couple of places to specify the simulator
|
||||
//! ** when data from the swift datastore are read, the corresponding simulator is specified
|
||||
//! ** when model metadata are written to the swift datastore the DB simulator info needs to be provided
|
||||
//! ** when models are indexed from disk it does not know the corresponding driver
|
||||
//! ** also there is no strict dependency of some functions to the driver. I might not have the XP plugin installed,
|
||||
//! but need to handle XP data from the swift data store
|
||||
//! If someone manages to remove this hardocded simulator information and makes it entirely flexible
|
||||
//! but need to handle XP data from the swift datastore.
|
||||
//!
|
||||
//! If someone manages to remove this hardcoded simulator information and makes it entirely flexible
|
||||
//! based upon the plugin metadata feel free.
|
||||
class BLACKMISC_EXPORT CSimulatorInfo : public CValueObject<CSimulatorInfo>
|
||||
{
|
||||
@@ -163,7 +165,7 @@ namespace BlackMisc
|
||||
static Simulator boolToFlag(bool fsx, bool fs9, bool xp, bool p3d);
|
||||
|
||||
//! Identifer, as provided by plugin
|
||||
static Simulator identifierToFlag(const QString &identifier);
|
||||
static Simulator identifierToSimulator(const QString &identifier);
|
||||
|
||||
//! All simulators
|
||||
static const CSimulatorInfo &allSimulators();
|
||||
|
||||
@@ -19,8 +19,10 @@ namespace BlackMisc
|
||||
namespace Simulation
|
||||
{
|
||||
CSimulatorPluginInfo::CSimulatorPluginInfo(const QString &identifier, const QString &name, const QString &simulator, const QString &description, bool valid) :
|
||||
m_identifier(identifier), m_name(name), m_simulator(simulator), m_description(description), m_valid(valid)
|
||||
{ }
|
||||
m_identifier(identifier), m_name(name), m_simulator(simulator), m_description(description), m_info(simulator), m_valid(valid)
|
||||
{
|
||||
Q_ASSERT_X(m_info.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
}
|
||||
|
||||
void CSimulatorPluginInfo::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
@@ -38,6 +40,12 @@ namespace BlackMisc
|
||||
{
|
||||
CValueObject::convertFromJson(json);
|
||||
}
|
||||
|
||||
// set info if it wasn't set already
|
||||
if (m_info.isNoSimulator() && !m_simulator.isEmpty())
|
||||
{
|
||||
m_info = CSimulatorInfo(m_simulator);
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorPluginInfo::isUnspecified() const
|
||||
@@ -45,14 +53,9 @@ namespace BlackMisc
|
||||
return m_identifier.isEmpty();
|
||||
}
|
||||
|
||||
CSimulatorInfo CSimulatorPluginInfo::getSimulatorInfo() const
|
||||
{
|
||||
return CSimulatorInfo(getSimulator());
|
||||
}
|
||||
|
||||
bool CSimulatorPluginInfo::isEmulatedPlugin() const
|
||||
{
|
||||
return this->getIdentifier() == emulatedPluginIndentifier();
|
||||
return this->getIdentifier() == emulatedPluginIdentifier();
|
||||
}
|
||||
|
||||
QString CSimulatorPluginInfo::convertToQString(bool i18n) const
|
||||
@@ -61,31 +64,31 @@ namespace BlackMisc
|
||||
return QString("%1 (%2)").arg(m_name, m_identifier);
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::fsxPluginIndentifier()
|
||||
const QString &CSimulatorPluginInfo::fsxPluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.fsx");
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::p3dPluginIndentifier()
|
||||
const QString &CSimulatorPluginInfo::p3dPluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.p3d");
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::fs9PluginIndentifier()
|
||||
const QString &CSimulatorPluginInfo::fs9PluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.fs9");
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::xplanePluginIndentifier()
|
||||
const QString &CSimulatorPluginInfo::xplanePluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.xplane");
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::emulatedPluginIndentifier()
|
||||
const QString &CSimulatorPluginInfo::emulatedPluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.emulated");
|
||||
return s;
|
||||
@@ -95,11 +98,11 @@ namespace BlackMisc
|
||||
{
|
||||
static const QStringList identifiers(
|
||||
{
|
||||
fsxPluginIndentifier(),
|
||||
p3dPluginIndentifier(),
|
||||
xplanePluginIndentifier(),
|
||||
fs9PluginIndentifier(),
|
||||
emulatedPluginIndentifier()
|
||||
fsxPluginIdentifier(),
|
||||
p3dPluginIdentifier(),
|
||||
xplanePluginIdentifier(),
|
||||
fs9PluginIdentifier(),
|
||||
emulatedPluginIdentifier()
|
||||
});
|
||||
return identifiers;
|
||||
}
|
||||
@@ -109,14 +112,14 @@ namespace BlackMisc
|
||||
if (BlackConfig::CBuildConfig::isRunningOnUnixPlatform())
|
||||
{
|
||||
// On UNIX we likely run XP
|
||||
return QStringList { xplanePluginIndentifier() };
|
||||
return QStringList { xplanePluginIdentifier() };
|
||||
}
|
||||
|
||||
return QStringList
|
||||
{
|
||||
fsxPluginIndentifier(),
|
||||
p3dPluginIndentifier(),
|
||||
xplanePluginIndentifier()
|
||||
fsxPluginIdentifier(),
|
||||
p3dPluginIdentifier(),
|
||||
xplanePluginIdentifier()
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace BlackMisc
|
||||
namespace Simulation
|
||||
{
|
||||
//! Describing a simulator plugin
|
||||
class BLACKMISC_EXPORT CSimulatorPluginInfo : public BlackMisc::CValueObject<CSimulatorPluginInfo>
|
||||
class BLACKMISC_EXPORT CSimulatorPluginInfo : public CValueObject<CSimulatorPluginInfo>
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
@@ -60,7 +60,7 @@ namespace BlackMisc
|
||||
const QString &getSimulator() const { return m_simulator; }
|
||||
|
||||
//! Simulator info object
|
||||
BlackMisc::Simulation::CSimulatorInfo getSimulatorInfo() const;
|
||||
const CSimulatorInfo &getSimulatorInfo() const { return m_info; }
|
||||
|
||||
//! Is this the emulated driver?
|
||||
bool isEmulatedPlugin() const;
|
||||
@@ -72,19 +72,19 @@ namespace BlackMisc
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Plugin identifier (FSX)
|
||||
static const QString &fsxPluginIndentifier();
|
||||
static const QString &fsxPluginIdentifier();
|
||||
|
||||
//! Plugin identifier (P3D)
|
||||
static const QString &p3dPluginIndentifier();
|
||||
static const QString &p3dPluginIdentifier();
|
||||
|
||||
//! Plugin identifier (FS9)
|
||||
static const QString &fs9PluginIndentifier();
|
||||
static const QString &fs9PluginIdentifier();
|
||||
|
||||
//! Plugin identifier (XPlane)
|
||||
static const QString &xplanePluginIndentifier();
|
||||
static const QString &xplanePluginIdentifier();
|
||||
|
||||
//! Plugin identifier (emulated simulator plugin)
|
||||
static const QString &emulatedPluginIndentifier();
|
||||
static const QString &emulatedPluginIdentifier();
|
||||
|
||||
//! All valid identifiers
|
||||
static const QStringList &allIdentifiers();
|
||||
@@ -97,6 +97,7 @@ namespace BlackMisc
|
||||
QString m_name;
|
||||
QString m_simulator;
|
||||
QString m_description;
|
||||
CSimulatorInfo m_info;
|
||||
bool m_valid { false };
|
||||
|
||||
BLACK_METACLASS(
|
||||
@@ -105,6 +106,7 @@ namespace BlackMisc
|
||||
BLACK_METAMEMBER(name, 0, DisabledForComparison | DisabledForHashing),
|
||||
BLACK_METAMEMBER(simulator, 0, DisabledForComparison | DisabledForHashing),
|
||||
BLACK_METAMEMBER(description, 0, DisabledForComparison | DisabledForHashing),
|
||||
BLACK_METAMEMBER(info, 0, DisabledForComparison | DisabledForHashing),
|
||||
BLACK_METAMEMBER(valid, 0, DisabledForComparison | DisabledForHashing)
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user