swift
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"
19 #include "misc/propertyindexref.h"
20 #include "misc/statusmessage.h"
21 #include "misc/swiftmiscexport.h"
22 #include "misc/valueobject.h"
23 
24 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::Simulation, CSimulatorInfo)
25 
26 namespace swift::misc::simulation
27 {
40  class SWIFT_MISC_EXPORT CSimulatorInfo : public CValueObject<CSimulatorInfo>
41  {
42  public:
45  {
46  None = 0,
47  FSX = 1 << 0,
48  FS9 = 1 << 1,
49  XPLANE = 1 << 2,
50  P3D = 1 << 3,
51  FG = 1 << 4,
52  MSFS = 1 << 5,
53  MSFS2024 = 1 << 6,
54  FSX_P3D = FSX | P3D,
55  AllFsFamily = FSX | FS9 | P3D | MSFS | MSFS2024,
56  All = FSX | FS9 | XPLANE | P3D | FG | MSFS | MSFS2024
57  };
58  Q_DECLARE_FLAGS(Simulator, SimulatorFlag)
59 
60 
61  static constexpr int NumberOfSimulators = 7;
62 
65 
67  CSimulatorInfo(const QString &identifierString);
68 
70  CSimulatorInfo(const QStringList &simulators);
71 
73  CSimulatorInfo(Simulator s);
74 
76  CSimulatorInfo(int flagsAsInt);
77 
79  CSimulatorInfo(bool isFSX, bool isFS9, bool xp, bool isP3D, bool fg, bool msfs, bool msfs2024);
80 
82  bool isUnspecified() const;
83 
85  bool isFSX() const;
86 
88  bool isFS9() const;
89 
91  bool isXPlane() const;
92 
94  bool isP3D() const;
95 
97  bool isFG() const;
98 
100  bool isMSFS() const;
101 
103  bool isMSFS2024() const;
104 
106  bool isAnySimulator() const;
107 
109  bool isSingleSimulator() const;
110 
112  bool isNoSimulator() const;
113 
115  bool isMultipleSimulators() const;
116 
118  bool isAllSimulators() const;
119 
121  bool isMicrosoftSimulator() const;
122 
124  bool isMicrosoftOrPrepare3DSimulator() const;
125 
127  bool isFsxP3DFamily() const;
128 
130  int numberSimulators() const;
131 
133  bool matchesAll(const CSimulatorInfo &otherInfo) const;
134 
136  bool matchesAny(const CSimulatorInfo &otherInfo) const;
137 
140  bool matchesAnyOrNone(const CSimulatorInfo &otherInfo) const;
141 
143  Simulator getSimulator() const { return static_cast<Simulator>(m_simulator); }
144 
146  void setSimulator(Simulator s) { m_simulator = static_cast<int>(s); }
147 
149  void addSimulator(Simulator s) { m_simulator |= static_cast<int>(s); }
150 
152  void addSimulator(const CSimulatorInfo &simulatorInfo) { this->addSimulator(simulatorInfo.getSimulator()); }
153 
155  void setAllSimulators() { setSimulator(All); }
156 
158  int comparePropertyByIndex(CPropertyIndexRef index, const CSimulatorInfo &compareValue) const;
159 
161  QString convertToQString(bool i18n = false) const;
162 
164  CIcons::IconIndex toIcon() const;
165 
167  CSimulatorInfo add(const CSimulatorInfo &other);
168 
170  QSet<CSimulatorInfo> asSingleSimulatorSet() const;
171 
173  void invertSimulators();
174 
176  CStatusMessage validateSimulatorsForModel() const;
177 
179  static Simulator boolToFlag(bool isFSX, bool isFS9, bool xp, bool isP3D, bool fg, bool msfs, bool msfs2024);
180 
182  static Simulator identifierToSimulator(const QString &identifier);
183 
185  static const CSimulatorInfo &allSimulators();
186 
188  static const QStringList &allSimulatorStrings();
189 
191  static const QSet<CSimulatorInfo> &allSimulatorsSet();
192 
194  static const CSimulatorInfo &allFsFamilySimulators();
195 
197  static CSimulatorInfo getLocallyInstalledSimulators();
198 
200  static const CSimulatorInfo &guessDefaultSimulator();
201 
203  static CSimulatorInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix);
204 
207  static const CSimulatorInfo &fg()
208  {
209  static const CSimulatorInfo s(FG);
210  return s;
211  }
212  static const CSimulatorInfo &fsx()
213  {
214  static const CSimulatorInfo s(FSX);
215  return s;
216  }
217  static const CSimulatorInfo &p3d()
218  {
219  static const CSimulatorInfo s(P3D);
220  return s;
221  }
222  static const CSimulatorInfo &fs9()
223  {
224  static const CSimulatorInfo s(FS9);
225  return s;
226  }
227  static const CSimulatorInfo &xplane()
228  {
229  static const CSimulatorInfo s(XPLANE);
230  return s;
231  }
232  static const CSimulatorInfo &msfs()
233  {
234  static const CSimulatorInfo s(MSFS);
235  return s;
236  }
237  static const CSimulatorInfo &msfs2024()
238  {
239  static const CSimulatorInfo s(MSFS2024);
240  return s;
241  }
243 
244  private:
245  int m_simulator = static_cast<int>(None);
246 
249  SWIFT_METAMEMBER(simulator));
250  };
251 
254  {
255  public:
258 
260  int getCount(const CSimulatorInfo &simulator) const;
261 
263  int getCountForUnknownSimulators() const;
264 
266  int getCountForFsFamilySimulators() const;
267 
269  int getCountForFsxFamilySimulators() const;
270 
272  void setCount(int count, const CSimulatorInfo &simulator);
273 
275  void increaseSimulatorCounts(const CSimulatorInfo &simulator);
276 
278  int getMaximum() const;
279 
281  int getMinimum() const;
282 
284  int simulatorsRepresented() const;
285 
287  QMultiMap<int, CSimulatorInfo> countPerSimulator() const;
288 
290  QString toQString() const;
291 
292  private:
293  QList<int> m_counts;
294  static int internalIndex(const CSimulatorInfo &simulator);
295  static CSimulatorInfo simulator(int internalIndex);
296  };
297 } // namespace swift::misc::simulation
298 
299 Q_DECLARE_METATYPE(swift::misc::simulation::CSimulatorInfo)
301 Q_DECLARE_OPERATORS_FOR_FLAGS(swift::misc::simulation::CSimulatorInfo::Simulator)
302 
303 #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.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Count per simulator, small utility class allows to retrieve values as per simulator.
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
void addSimulator(Simulator s)
Add simulator flags.
void addSimulator(const CSimulatorInfo &simulatorInfo)
Add simulator.
Simulator getSimulator() const
Simulator.
static const CSimulatorInfo & msfs()
Const simulator info objects.
static const CSimulatorInfo & fs9()
Const simulator info objects.
static const CSimulatorInfo & fsx()
Const simulator info objects.
static const CSimulatorInfo & p3d()
Const simulator info objects.
static const CSimulatorInfo & xplane()
Const simulator info objects.
static const CSimulatorInfo & msfs2024()
Const simulator info objects.
void setSimulator(Simulator s)
Simulator.
static const CSimulatorInfo & fg()
Const simulator info objects.
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
Utility classes for FSX, OS and driver independent code.
#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