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_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 
117  bool isMicrosoftOrPrepare3DSimulator() const;
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 
148  void setAllSimulators() { setSimulator(All); }
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  }
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 
246  int getCountForUnknownSimulators() const;
247 
249  int getCountForFsFamilySimulators() const;
250 
252  int getCountForFsxFamilySimulators() const;
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 
270  QMultiMap<int, CSimulatorInfo> countPerSimulator() const;
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 
282 Q_DECLARE_METATYPE(swift::misc::simulation::CSimulatorInfo)
284 Q_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.
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 & 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: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