mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Ref T430, added FG pugin and simulator info
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
|
||||
@@ -46,8 +47,8 @@ namespace BlackMisc
|
||||
CSimulatorInfo::CSimulatorInfo(Simulator simulator) : m_simulator(static_cast<int>(simulator))
|
||||
{ }
|
||||
|
||||
CSimulatorInfo::CSimulatorInfo(bool fsx, bool fs9, bool xp, bool p3d) :
|
||||
m_simulator(boolToFlag(fsx, fs9, xp, p3d))
|
||||
CSimulatorInfo::CSimulatorInfo(bool fsx, bool fs9, bool xp, bool p3d, bool fg) :
|
||||
m_simulator(boolToFlag(fsx, fs9, xp, p3d, fg))
|
||||
{ }
|
||||
|
||||
CSimulatorInfo::CSimulatorInfo(int flagsAsInt) :
|
||||
@@ -79,9 +80,14 @@ namespace BlackMisc
|
||||
return getSimulator().testFlag(P3D);
|
||||
}
|
||||
|
||||
bool CSimulatorInfo::isFG() const
|
||||
{
|
||||
return getSimulator().testFlag(FG);
|
||||
}
|
||||
|
||||
bool CSimulatorInfo::isAnySimulator() const
|
||||
{
|
||||
return isFSX() || isFS9() || isXPlane() || isP3D();
|
||||
return isFSX() || isFS9() || isXPlane() || isP3D() || isFG();
|
||||
}
|
||||
|
||||
bool CSimulatorInfo::isSingleSimulator() const
|
||||
@@ -101,7 +107,7 @@ namespace BlackMisc
|
||||
|
||||
bool CSimulatorInfo::isAllSimulators() const
|
||||
{
|
||||
return isFSX() && isFS9() && isXPlane() && isP3D();
|
||||
return isFSX() && isFS9() && isXPlane() && isP3D() && isFG();
|
||||
}
|
||||
|
||||
bool CSimulatorInfo::isMicrosoftSimulator() const
|
||||
@@ -125,6 +131,7 @@ namespace BlackMisc
|
||||
if (isFSX()) { c++; }
|
||||
if (isXPlane()) { c++; }
|
||||
if (isP3D()) { c++; }
|
||||
if (isFG()) { c++; }
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -149,10 +156,11 @@ namespace BlackMisc
|
||||
Q_UNUSED(i18n);
|
||||
const Simulator s = getSimulator();
|
||||
const QString str =
|
||||
(s.testFlag(FSX) ? QStringLiteral("FSX ") : QStringLiteral("")) %
|
||||
(s.testFlag(FS9) ? QStringLiteral("FS9 ") : QStringLiteral("")) %
|
||||
(s.testFlag(P3D) ? QStringLiteral("P3D ") : QStringLiteral("")) %
|
||||
(s.testFlag(XPLANE) ? QStringLiteral("XPlane ") : QStringLiteral(""));
|
||||
(s.testFlag(FSX) ? QStringLiteral("FSX ") : QStringLiteral("")) %
|
||||
(s.testFlag(FS9) ? QStringLiteral("FS9 ") : QStringLiteral("")) %
|
||||
(s.testFlag(P3D) ? QStringLiteral("P3D ") : QStringLiteral("")) %
|
||||
(s.testFlag(XPLANE) ? QStringLiteral("XPlane ") : QStringLiteral("")) %
|
||||
(s.testFlag(FG) ? QStringLiteral("FG ") : QStringLiteral(""));
|
||||
return str.trimmed();
|
||||
}
|
||||
|
||||
@@ -166,6 +174,7 @@ namespace BlackMisc
|
||||
case FS9: return CIconList::allIcons().findByIndex(CIcons::SimulatorFS916);
|
||||
case P3D: return CIconList::allIcons().findByIndex(CIcons::SimulatorP3D16);
|
||||
case XPLANE: return CIconList::allIcons().findByIndex(CIcons::SimulatorXPlane16);
|
||||
case FG: return CIconList::allIcons().findByIndex(CIcons::SimulatorXPlane16);
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -184,6 +193,7 @@ namespace BlackMisc
|
||||
if (m_simulator & FSX) { set.insert(CSimulatorInfo(FSX)); }
|
||||
if (m_simulator & FS9) { set.insert(CSimulatorInfo(FS9)); }
|
||||
if (m_simulator & P3D) { set.insert(CSimulatorInfo(P3D)); }
|
||||
if (m_simulator & FG) { set.insert(CSimulatorInfo(FG)); }
|
||||
if (m_simulator & XPLANE) { set.insert(CSimulatorInfo(XPLANE)); }
|
||||
return set;
|
||||
}
|
||||
@@ -198,19 +208,21 @@ namespace BlackMisc
|
||||
static const QString e;
|
||||
if (!this->isSingleSimulator()) { return e; }
|
||||
const Simulator s = getSimulator();
|
||||
if (s.testFlag(FSX)) { return CSimulatorPluginInfo::fsxPluginIdentifier(); }
|
||||
if (s.testFlag(FS9)) { return CSimulatorPluginInfo::fs9PluginIdentifier(); }
|
||||
if (s.testFlag(P3D)) { return CSimulatorPluginInfo::p3dPluginIdentifier(); }
|
||||
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(); }
|
||||
if (s.testFlag(FG)) { return CSimulatorPluginInfo::fgPluginIdentifier(); }
|
||||
return e;
|
||||
}
|
||||
|
||||
CSimulatorInfo::Simulator CSimulatorInfo::boolToFlag(bool fsx, bool fs9, bool xp, bool p3d)
|
||||
CSimulatorInfo::Simulator CSimulatorInfo::boolToFlag(bool fsx, bool fs9, bool xp, bool p3d, bool fg)
|
||||
{
|
||||
Simulator s = fsx ? FSX : None;
|
||||
if (fs9) { s |= FS9; }
|
||||
if (xp) { s |= XPLANE; }
|
||||
if (p3d) { s |= P3D; }
|
||||
if (fg) { s |= FG; }
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -220,10 +232,11 @@ namespace BlackMisc
|
||||
if (i.isEmpty()) { return None; }
|
||||
|
||||
Simulator s = None;
|
||||
if (i.contains("fsx") || i.contains("fs10")) { s |= FSX; }
|
||||
if (i.contains("fs9") || i.contains("2004")) { s |= FS9; }
|
||||
if (i.contains("plane") || i.contains("xp")) { s |= XPLANE; }
|
||||
if (i.contains("3d") || i.contains("prepar") || i.contains("martin") || i.contains("lm") || i.contains("lock"))
|
||||
if (i.contains("fsx") || i.contains("fs10")) { s |= FSX; }
|
||||
if (i.contains("fs9") || i.contains("2004")) { s |= FS9; }
|
||||
if (i.contains("plane") || i.contains("xp")) { s |= XPLANE; }
|
||||
if (i.contains("gear") || stringCompare(QStringLiteral("fg"), identifier, Qt::CaseInsensitive)) { s |= FG; }
|
||||
if (i.contains("3d") || i.contains("prepar") || i.contains("martin") || i.contains("lm") || i.contains("lock"))
|
||||
{
|
||||
s |= P3D;
|
||||
}
|
||||
@@ -236,6 +249,21 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
const QStringList &CSimulatorInfo::allSimulatorStrings()
|
||||
{
|
||||
static const QStringList sims = []
|
||||
{
|
||||
QStringList s;
|
||||
for (const CSimulatorInfo &i : CSimulatorInfo::allSimulatorsSet())
|
||||
{
|
||||
s.push_back(i.toQString(false));
|
||||
}
|
||||
s.sort(Qt::CaseInsensitive);
|
||||
return s;
|
||||
}();
|
||||
return sims;
|
||||
}
|
||||
|
||||
const QSet<CSimulatorInfo> &CSimulatorInfo::allSimulatorsSet()
|
||||
{
|
||||
static const QSet<CSimulatorInfo> all(allSimulators().asSingleSimulatorSet());
|
||||
@@ -254,6 +282,7 @@ namespace BlackMisc
|
||||
bool fs9 = false;
|
||||
bool fsx = false;
|
||||
bool p3d = false;
|
||||
bool fg = false;
|
||||
|
||||
if (CBuildConfig::isRunningOnWindowsNtPlatform())
|
||||
{
|
||||
@@ -270,7 +299,7 @@ namespace BlackMisc
|
||||
|
||||
const bool xp = !CXPlaneUtil::xplaneRootDir().isEmpty();
|
||||
|
||||
sim.setSimulator(CSimulatorInfo::boolToFlag(fsx, fs9, xp, p3d));
|
||||
sim.setSimulator(CSimulatorInfo::boolToFlag(fsx, fs9, xp, p3d, fg));
|
||||
return sim;
|
||||
}
|
||||
|
||||
@@ -303,14 +332,16 @@ namespace BlackMisc
|
||||
const QJsonValue jfs9 = json.value(prefix % QStringLiteral("simfs9"));
|
||||
const QJsonValue jxp = json.value(prefix % QStringLiteral("simxplane"));
|
||||
const QJsonValue jp3d = json.value(prefix % QStringLiteral("simp3d"));
|
||||
const QJsonValue jfg = json.value(prefix % QStringLiteral("simfg"));
|
||||
|
||||
// we handle bool JSON values and bool as string
|
||||
const bool fsx = jfsx.isBool() ? jfsx.toBool() : CDatastoreUtility::dbBoolStringToBool(jfsx.toString());
|
||||
const bool fs9 = jfs9.isBool() ? jfs9.toBool() : CDatastoreUtility::dbBoolStringToBool(jfs9.toString());
|
||||
const bool xp = jxp.isBool() ? jxp.toBool() : CDatastoreUtility::dbBoolStringToBool(jxp.toString());
|
||||
const bool p3d = jp3d.isBool() ? jp3d.toBool() : CDatastoreUtility::dbBoolStringToBool(jp3d.toString());
|
||||
const bool fg = jfg.isBool() ? jfg.toBool() : CDatastoreUtility::dbBoolStringToBool(jfg.toString());
|
||||
|
||||
const CSimulatorInfo simInfo(fsx, fs9, xp, p3d);
|
||||
const CSimulatorInfo simInfo(fsx, fs9, xp, p3d, fg);
|
||||
return simInfo;
|
||||
}
|
||||
|
||||
@@ -368,7 +399,8 @@ namespace BlackMisc
|
||||
return QStringLiteral("FSX: ") % QString::number(m_counts[0]) %
|
||||
QStringLiteral(" P3D: ") % QString::number(m_counts[1]) %
|
||||
QStringLiteral(" FS9: ") % QString::number(m_counts[2]) %
|
||||
QStringLiteral(" XPlane: ") % QString::number(m_counts[3]);
|
||||
QStringLiteral(" XPlane: ") % QString::number(m_counts[3]) %
|
||||
QStringLiteral(" FG: ") % QString::number(m_counts[4]);
|
||||
}
|
||||
|
||||
void CCountPerSimulator::setCount(int count, const CSimulatorInfo &simulator)
|
||||
@@ -381,13 +413,14 @@ namespace BlackMisc
|
||||
if (simulator.isNoSimulator() || simulator.isUnspecified())
|
||||
{
|
||||
// unknown count
|
||||
m_counts[4] = m_counts[4] + 1;
|
||||
m_counts[5] = m_counts[5] + 1;
|
||||
return;
|
||||
}
|
||||
if (simulator.isFSX()) { m_counts[0]++; }
|
||||
if (simulator.isP3D()) { m_counts[1]++; }
|
||||
if (simulator.isFS9()) { m_counts[2]++; }
|
||||
if (simulator.isXPlane()) { m_counts[3]++; }
|
||||
if (simulator.isXPlane()) { m_counts[3]++; }
|
||||
if (simulator.isFG()) { m_counts[4]++; }
|
||||
}
|
||||
|
||||
int CCountPerSimulator::internalIndex(const CSimulatorInfo &simulator)
|
||||
@@ -395,10 +428,11 @@ namespace BlackMisc
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FSX: return 0;
|
||||
case CSimulatorInfo::P3D: return 1;
|
||||
case CSimulatorInfo::FS9: return 2;
|
||||
case CSimulatorInfo::FSX: return 0;
|
||||
case CSimulatorInfo::P3D: return 1;
|
||||
case CSimulatorInfo::FS9: return 2;
|
||||
case CSimulatorInfo::XPLANE: return 3;
|
||||
case CSimulatorInfo::FG: return 4;
|
||||
default: return CSimulatorInfo::NumberOfSimulators; // unknown
|
||||
}
|
||||
}
|
||||
@@ -411,6 +445,7 @@ namespace BlackMisc
|
||||
case 1: return CSimulatorInfo(CSimulatorInfo::P3D);
|
||||
case 2: return CSimulatorInfo(CSimulatorInfo::FS9);
|
||||
case 3: return CSimulatorInfo(CSimulatorInfo::XPLANE);
|
||||
case 4: return CSimulatorInfo(CSimulatorInfo::FG);
|
||||
default: return CSimulatorInfo(CSimulatorInfo::None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <QSet>
|
||||
#include <QMetaType>
|
||||
#include <QMultiMap>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -53,14 +53,15 @@ namespace BlackMisc
|
||||
FS9 = 1 << 1,
|
||||
XPLANE = 1 << 2,
|
||||
P3D = 1 << 3,
|
||||
FG = 1 << 4,
|
||||
FSX_P3D = FSX | P3D,
|
||||
AllFsFamily = FSX | FS9 | P3D,
|
||||
All = FSX | FS9 | XPLANE | P3D
|
||||
All = FSX | FS9 | XPLANE | P3D | FG
|
||||
};
|
||||
Q_DECLARE_FLAGS(Simulator, SimulatorFlag)
|
||||
|
||||
//! Number of known individual simulators
|
||||
static constexpr int NumberOfSimulators = 4;
|
||||
static constexpr int NumberOfSimulators = 5;
|
||||
|
||||
//! Default constructor
|
||||
CSimulatorInfo();
|
||||
@@ -78,7 +79,7 @@ namespace BlackMisc
|
||||
CSimulatorInfo(int flagsAsInt);
|
||||
|
||||
//! Constructor
|
||||
CSimulatorInfo(bool isFSX, bool isFS9, bool xp, bool isP3D);
|
||||
CSimulatorInfo(bool isFSX, bool isFS9, bool xp, bool isP3D, bool fg);
|
||||
|
||||
//! Unspecified simulator
|
||||
bool isUnspecified() const;
|
||||
@@ -95,6 +96,9 @@ namespace BlackMisc
|
||||
//! P3D?
|
||||
bool isP3D() const;
|
||||
|
||||
//! FG?
|
||||
bool isFG() const;
|
||||
|
||||
//! Any simulator?
|
||||
bool isAnySimulator() const;
|
||||
|
||||
@@ -143,7 +147,7 @@ namespace BlackMisc
|
||||
//! All simulators
|
||||
void setAllSimulators() { setSimulator(All); }
|
||||
|
||||
//! Compare for index
|
||||
//! \copydoc Mixin::String::toQString
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const CSimulatorInfo &compareValue) const;
|
||||
|
||||
//! \copydoc Mixin::String::toQString
|
||||
@@ -165,7 +169,7 @@ namespace BlackMisc
|
||||
const QString &toPluginIdentifier() const;
|
||||
|
||||
//! Bool flags to enum
|
||||
static Simulator boolToFlag(bool isFSX, bool isFS9, bool xp, bool isP3D);
|
||||
static Simulator boolToFlag(bool isFSX, bool isFS9, bool xp, bool isP3D, bool fg);
|
||||
|
||||
//! Identifer, as provided by plugin
|
||||
static Simulator identifierToSimulator(const QString &identifier);
|
||||
@@ -173,6 +177,9 @@ namespace BlackMisc
|
||||
//! All simulators
|
||||
static const CSimulatorInfo &allSimulators();
|
||||
|
||||
//! All simulator strings
|
||||
static const QStringList &allSimulatorStrings();
|
||||
|
||||
//! All simulators as set
|
||||
static const QSet<CSimulatorInfo> &allSimulatorsSet();
|
||||
|
||||
@@ -189,6 +196,7 @@ namespace BlackMisc
|
||||
static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix);
|
||||
|
||||
//! Const simulator info objects @{
|
||||
static const CSimulatorInfo &fg() { static const CSimulatorInfo s(FG); return s; }
|
||||
static const CSimulatorInfo &fsx() { static const CSimulatorInfo s(FSX); return s; }
|
||||
static const CSimulatorInfo &p3d() { static const CSimulatorInfo s(P3D); return s; }
|
||||
static const CSimulatorInfo &fs9() { static const CSimulatorInfo s(FS9); return s; }
|
||||
|
||||
@@ -88,6 +88,12 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::fgPluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.flightgear");
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CSimulatorPluginInfo::emulatedPluginIdentifier()
|
||||
{
|
||||
static const QString s("org.swift-project.plugins.simulator.emulated");
|
||||
|
||||
@@ -83,6 +83,9 @@ namespace BlackMisc
|
||||
//! Plugin identifier (XPlane)
|
||||
static const QString &xplanePluginIdentifier();
|
||||
|
||||
//! Plugin identifier (FlightGear)
|
||||
static const QString &fgPluginIdentifier();
|
||||
|
||||
//! Plugin identifier (emulated simulator plugin)
|
||||
static const QString &emulatedPluginIdentifier();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user