swift
Loading...
Searching...
No Matches
simulatorinfo.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_SIMULATION_SIMULATORINFO_H
7#define SWIFT_MISC_SIMULATION_SIMULATORINFO_H
8
9#include <QFlag>
10#include <QFlags>
11#include <QJsonObject>
12#include <QList>
13#include <QMetaType>
14#include <QMultiMap>
15#include <QSet>
16#include <QStringList>
17
18#include "misc/metaclass.h"
20#include "misc/statusmessage.h"
22#include "misc/valueobject.h"
23
24SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::Simulation, CSimulatorInfo)
25
26namespace swift::misc::simulation
27{
40 class SWIFT_MISC_EXPORT CSimulatorInfo : public CValueObject<CSimulatorInfo>
41 {
42 public:
45 {
46 None = 0,
47 FSX_DEPRECATED = 1 << 0, // kept for backwards compatibility
48 FS9_DEPRECATED = 1 << 1, // kepts for backwards compatibility
49 XPLANE = 1 << 2,
50 P3D = 1 << 3,
51 FG = 1 << 4,
52 MSFS = 1 << 5,
53 MSFS2024 = 1 << 6,
54 AllFsFamily = P3D | MSFS | MSFS2024,
55 All = XPLANE | P3D | FG | MSFS | MSFS2024
56 };
57 Q_DECLARE_FLAGS(Simulator, SimulatorFlag)
58
59
60 static constexpr int NumberOfSimulators = 7;
61
63 CSimulatorInfo() = default;
64
66 CSimulatorInfo(const QString &identifierString);
67
69 CSimulatorInfo(const QStringList &simulators);
70
72 CSimulatorInfo(Simulator s);
73
75 CSimulatorInfo(int flagsAsInt);
76
78 CSimulatorInfo(bool xp, bool isP3D, bool fg, bool msfs, bool msfs2024);
79
81 bool isUnspecified() const;
82
84 bool isXPlane() const;
85
87 bool isP3D() const;
88
90 bool isFG() const;
91
93 bool isMSFS() const;
94
96 bool isMSFS2024() const;
97
99 bool isAnySimulator() const;
100
102 bool isSingleSimulator() const;
103
105 bool isNoSimulator() const;
106
108 bool isMultipleSimulators() const;
109
111 bool isAllSimulators() const;
112
114 bool isMicrosoftSimulator() const;
115
118
120 bool isFsxP3DFamily() const;
121
123 int numberSimulators() const;
124
126 bool matchesAll(const CSimulatorInfo &otherInfo) const;
127
129 bool matchesAny(const CSimulatorInfo &otherInfo) const;
130
133 bool matchesAnyOrNone(const CSimulatorInfo &otherInfo) const;
134
136 Simulator getSimulator() const { return static_cast<Simulator>(m_simulator); }
137
139 void setSimulator(Simulator s) { m_simulator = static_cast<int>(s); }
140
142 void addSimulator(Simulator s) { m_simulator |= static_cast<int>(s); }
143
145 void addSimulator(const CSimulatorInfo &simulatorInfo) { this->addSimulator(simulatorInfo.getSimulator()); }
146
149
151 int comparePropertyByIndex(CPropertyIndexRef index, const CSimulatorInfo &compareValue) const;
152
154 QString convertToQString(bool i18n = false) const;
155
157 CIcons::IconIndex toIcon() const;
158
160 CSimulatorInfo add(const CSimulatorInfo &other);
161
163 QSet<CSimulatorInfo> asSingleSimulatorSet() const;
164
166 void invertSimulators();
167
169 CStatusMessage validateSimulatorsForModel() const;
170
172 static Simulator boolToFlag(bool xp, bool isP3D, bool fg, bool msfs, bool msfs2024);
173
175 static Simulator identifierToSimulator(const QString &identifier);
176
178 static const CSimulatorInfo &allSimulators();
179
181 static const QStringList &allSimulatorStrings();
182
184 static const QSet<CSimulatorInfo> &allSimulatorsSet();
185
187 static const CSimulatorInfo &allFsFamilySimulators();
188
190 static CSimulatorInfo getLocallyInstalledSimulators();
191
193 static const CSimulatorInfo &guessDefaultSimulator();
194
196 static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix);
197
200 static const CSimulatorInfo &fg()
201 {
202 static const CSimulatorInfo s(FG);
203 return s;
204 }
205 static const CSimulatorInfo &p3d()
206 {
207 static const CSimulatorInfo s(P3D);
208 return s;
209 }
210 static const CSimulatorInfo &xplane()
211 {
212 static const CSimulatorInfo s(XPLANE);
213 return s;
214 }
215 static const CSimulatorInfo &msfs()
216 {
217 static const CSimulatorInfo s(MSFS);
218 return s;
219 }
220 static const CSimulatorInfo &msfs2024()
221 {
222 static const CSimulatorInfo s(MSFS2024);
223 return s;
224 }
225
226
227 private:
228 int m_simulator = static_cast<int>(None);
229
232 SWIFT_METAMEMBER(simulator));
233 };
234
237 {
238 public:
241
243 int getCount(const CSimulatorInfo &simulator) const;
244
247
250
253
255 void setCount(int count, const CSimulatorInfo &simulator);
256
258 void increaseSimulatorCounts(const CSimulatorInfo &simulator);
259
261 int getMaximum() const;
262
264 int getMinimum() const;
265
267 int simulatorsRepresented() const;
268
271
273 QString toQString() const;
274
275 private:
276 QList<int> m_counts;
277 static int internalIndex(const CSimulatorInfo &simulator);
278 static CSimulatorInfo simulator(int internalIndex);
279 };
280} // namespace swift::misc::simulation
281
284Q_DECLARE_OPERATORS_FOR_FLAGS(swift::misc::simulation::CSimulatorInfo::Simulator)
285
286#endif // SWIFT_MISC_SIMULATION_SIMULATORINFO_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Streamable status message, e.g.
void setCount(int count, const CSimulatorInfo &simulator)
Set count.
int getCountForFsxFamilySimulators() const
P3D, MSFS or FSX.
void increaseSimulatorCounts(const CSimulatorInfo &simulator)
Increase all simulators given here.
int simulatorsRepresented() const
Number of simulators with count > 0.
int getCount(const CSimulatorInfo &simulator) const
Object count for given simulator.
int getCountForUnknownSimulators() const
Unknown count.
QMultiMap< int, CSimulatorInfo > countPerSimulator() const
Sorted (ascending) per simulator.
int getCountForFsFamilySimulators() const
P3D, FSX, MSFS or FS9.
Simple hardcoded info about the corresponding simulator.
bool isAllSimulators() const
Is all simulators?
void addSimulator(Simulator s)
Add simulator flags.
static const CSimulatorInfo & msfs()
Const simulator info objects.
static const CSimulatorInfo & xplane()
Const simulator info objects.
static const CSimulatorInfo & p3d()
Const simulator info objects.
void addSimulator(const CSimulatorInfo &simulatorInfo)
Add simulator.
static const CSimulatorInfo & fg()
Const simulator info objects.
bool matchesAll(const CSimulatorInfo &otherInfo) const
Matches all simulators.
bool isSingleSimulator() const
Single simulator selected.
bool isNoSimulator() const
No simulator?
bool isMultipleSimulators() const
Represents > 1 simulator.
CSimulatorInfo()=default
Default constructor.
static const CSimulatorInfo & msfs2024()
Const simulator info objects.
bool matchesAny(const CSimulatorInfo &otherInfo) const
Matches any simulator.
bool isUnspecified() const
Unspecified simulator.
Simulator getSimulator() const
Simulator.
bool isMicrosoftSimulator() const
Microsoft Simulator?
bool isFsxP3DFamily() const
FSX family, i.e. FSX or P3D?
void setSimulator(Simulator s)
Simulator.
bool isAnySimulator() const
Any simulator?
int numberSimulators() const
Number simulators selected.
static constexpr int NumberOfSimulators
Number of known individual simulators.
bool isMicrosoftOrPrepare3DSimulator() const
Microsoft Simulator or P3D?
bool matchesAnyOrNone(const CSimulatorInfo &otherInfo) const
Matches any simulator or None (NULL).
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition valueobject.h:65