1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include <QtCore/qglobal.h> |
5 | #include <QtCore/qcompare.h> |
6 | #include <QtCore/qversionnumber.h> |
7 | |
8 | #ifndef QOPERATINGSYSTEMVERSION_H |
9 | #define QOPERATINGSYSTEMVERSION_H |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | #if 0 |
14 | # pragma qt_class(QOperatingSystemVersionBase) |
15 | # pragma qt_class(QOperatingSystemVersion) |
16 | # pragma qt_sync_stop_processing // we have some ifdef'ery fooling syncqt |
17 | #endif |
18 | |
19 | class QString; |
20 | |
21 | class QOperatingSystemVersionBase |
22 | { |
23 | public: |
24 | // ### Qt 7: Keep synchronized with the copy in QOperatingSystemVersion until Qt7, |
25 | // then remove this comment :) |
26 | enum OSType { |
27 | Unknown = 0, |
28 | Windows, |
29 | MacOS, |
30 | IOS, |
31 | TvOS, |
32 | WatchOS, |
33 | Android, |
34 | VisionOS, |
35 | }; |
36 | |
37 | constexpr QOperatingSystemVersionBase(OSType osType, |
38 | int vmajor, int vminor = -1, int vmicro = -1) |
39 | : m_os(osType), |
40 | m_major(vmajor), |
41 | m_minor(vminor), |
42 | m_micro(vmicro) |
43 | { } |
44 | |
45 | static Q_CORE_EXPORT QOperatingSystemVersionBase current(); |
46 | static Q_CORE_EXPORT QString name(QOperatingSystemVersionBase osversion); |
47 | static Q_CORE_EXPORT bool isAnyOfType(std::initializer_list<OSType> types, OSType type); |
48 | |
49 | static constexpr OSType currentType() |
50 | { |
51 | #if defined(Q_OS_WIN) |
52 | return Windows; |
53 | #elif defined(Q_OS_MACOS) |
54 | return MacOS; |
55 | #elif defined(Q_OS_IOS) |
56 | return IOS; |
57 | #elif defined(Q_OS_TVOS) |
58 | return TvOS; |
59 | #elif defined(Q_OS_WATCHOS) |
60 | return WatchOS; |
61 | #elif defined(Q_OS_VISIONOS) |
62 | return VisionOS; |
63 | #elif defined(Q_OS_ANDROID) |
64 | return Android; |
65 | #else |
66 | return Unknown; |
67 | #endif |
68 | } |
69 | |
70 | inline QVersionNumber version() const { return QVersionNumber(m_major, m_minor, m_micro); } |
71 | |
72 | constexpr int majorVersion() const { return m_major; } |
73 | constexpr int minorVersion() const { return m_minor; } |
74 | constexpr int microVersion() const { return m_micro; } |
75 | |
76 | constexpr int segmentCount() const |
77 | { return m_micro >= 0 ? 3 : m_minor >= 0 ? 2 : m_major >= 0 ? 1 : 0; } |
78 | |
79 | inline bool isAnyOfType(std::initializer_list<OSType> types) const |
80 | { |
81 | return QOperatingSystemVersionBase::isAnyOfType(types, type: type()); |
82 | } |
83 | constexpr OSType type() const { return m_os; } |
84 | inline QString name() const { return name(osversion: *this); } |
85 | |
86 | protected: |
87 | static Q_CORE_EXPORT int compare(QOperatingSystemVersionBase v1, |
88 | QOperatingSystemVersionBase v2) noexcept; |
89 | |
90 | friend Qt::partial_ordering compareThreeWay(const QOperatingSystemVersionBase &lhs, |
91 | const QOperatingSystemVersionBase &rhs) noexcept |
92 | { |
93 | if (lhs.type() != rhs.type()) |
94 | return Qt::partial_ordering::unordered; |
95 | const int res = QOperatingSystemVersionBase::compare(v1: lhs, v2: rhs); |
96 | return Qt::compareThreeWay(lhs: res, rhs: 0); |
97 | } |
98 | #ifdef __cpp_lib_three_way_comparison |
99 | friend std::partial_ordering |
100 | operator<=>(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept |
101 | { return compareThreeWay(lhs, rhs); } |
102 | #else |
103 | friend bool |
104 | operator>(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept |
105 | { return is_gt(o: compareThreeWay(lhs, rhs)); } |
106 | |
107 | friend bool |
108 | operator>=(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept |
109 | { return is_gteq(o: compareThreeWay(lhs, rhs)); } |
110 | |
111 | friend bool |
112 | operator<(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept |
113 | { return is_lt(o: compareThreeWay(lhs, rhs)); } |
114 | |
115 | friend bool |
116 | operator<=(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept |
117 | { return is_lteq(o: compareThreeWay(lhs, rhs)); } |
118 | #endif |
119 | |
120 | QOperatingSystemVersionBase() = default; |
121 | private: |
122 | static QOperatingSystemVersionBase current_impl(); |
123 | |
124 | OSType m_os; |
125 | int m_major; |
126 | int m_minor; |
127 | int m_micro; |
128 | }; |
129 | |
130 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) && !defined(Q_QDOC) |
131 | class QOperatingSystemVersionUnexported : public QOperatingSystemVersionBase |
132 | { |
133 | public: |
134 | using QOperatingSystemVersionBase::QOperatingSystemVersionBase; |
135 | constexpr QOperatingSystemVersionUnexported(QOperatingSystemVersionBase other) noexcept |
136 | : QOperatingSystemVersionBase(other) {} |
137 | #else |
138 | class QOperatingSystemVersion : public QOperatingSystemVersionBase |
139 | { |
140 | using QOperatingSystemVersionUnexported = QOperatingSystemVersionBase; |
141 | public: |
142 | #endif |
143 | |
144 | // ### Qt7: Regroup with the rest below |
145 | static constexpr QOperatingSystemVersionBase MacOSSonoma { QOperatingSystemVersionBase::MacOS, 14, 0 }; |
146 | static constexpr QOperatingSystemVersionBase MacOSSequoia { QOperatingSystemVersionBase::MacOS, 15, 0 }; |
147 | static constexpr QOperatingSystemVersionBase Android14 { QOperatingSystemVersionBase::Android, 14, 0 }; |
148 | static constexpr QOperatingSystemVersionBase Windows11_23H2 { QOperatingSystemVersionBase::Windows, 10, 0, 22631 }; |
149 | static constexpr QOperatingSystemVersionBase Windows11_24H2 { QOperatingSystemVersionBase::Windows, 10, 0, 26100 }; |
150 | |
151 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) && !defined(Q_QDOC) |
152 | }; |
153 | |
154 | class Q_CORE_EXPORT QOperatingSystemVersion : public QOperatingSystemVersionUnexported |
155 | { |
156 | #endif |
157 | public: |
158 | // ### Qt7: Remove. Keep synchronized with QOperatingSystemVersionBase::OSType until then! |
159 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) |
160 | enum OSType { |
161 | Unknown = 0, |
162 | Windows, |
163 | MacOS, |
164 | IOS, |
165 | TvOS, |
166 | WatchOS, |
167 | Android, |
168 | VisionOS, |
169 | }; |
170 | #endif |
171 | |
172 | // ### Qt7: remove the branch with static const variables. Then group and |
173 | // sort the inline ones. Until then, new entries should be added to |
174 | // QOperatingSystemVersionUnexported. |
175 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) |
176 | static const QOperatingSystemVersion Windows7; |
177 | static const QOperatingSystemVersion Windows8; |
178 | static const QOperatingSystemVersion Windows8_1; |
179 | static const QOperatingSystemVersion Windows10; |
180 | |
181 | static const QOperatingSystemVersion OSXMavericks; |
182 | static const QOperatingSystemVersion OSXYosemite; |
183 | static const QOperatingSystemVersion OSXElCapitan; |
184 | static const QOperatingSystemVersion MacOSSierra; |
185 | static const QOperatingSystemVersion MacOSHighSierra; |
186 | static const QOperatingSystemVersion MacOSMojave; |
187 | static const QOperatingSystemVersion MacOSCatalina; |
188 | static const QOperatingSystemVersion MacOSBigSur; |
189 | static const QOperatingSystemVersion MacOSMonterey; |
190 | |
191 | static const QOperatingSystemVersion AndroidJellyBean; |
192 | static const QOperatingSystemVersion AndroidJellyBean_MR1; |
193 | static const QOperatingSystemVersion AndroidJellyBean_MR2; |
194 | static const QOperatingSystemVersion AndroidKitKat; |
195 | static const QOperatingSystemVersion AndroidLollipop; |
196 | static const QOperatingSystemVersion AndroidLollipop_MR1; |
197 | static const QOperatingSystemVersion AndroidMarshmallow; |
198 | static const QOperatingSystemVersion AndroidNougat; |
199 | static const QOperatingSystemVersion AndroidNougat_MR1; |
200 | static const QOperatingSystemVersion AndroidOreo; |
201 | static const QOperatingSystemVersion AndroidOreo_MR1; |
202 | static const QOperatingSystemVersion AndroidPie; |
203 | static const QOperatingSystemVersion Android10; |
204 | static const QOperatingSystemVersion Android11; |
205 | #else |
206 | static constexpr QOperatingSystemVersionBase Windows7 { QOperatingSystemVersionBase::Windows, 6, 1 }; |
207 | static constexpr QOperatingSystemVersionBase Windows8 { QOperatingSystemVersionBase::Windows, 6, 2 }; |
208 | static constexpr QOperatingSystemVersionBase Windows8_1 { QOperatingSystemVersionBase::Windows, 6, 3 }; |
209 | static constexpr QOperatingSystemVersionBase Windows10 { QOperatingSystemVersionBase::Windows, 10 }; |
210 | |
211 | static constexpr QOperatingSystemVersionBase OSXMavericks { QOperatingSystemVersionBase::MacOS, 10, 9 }; |
212 | static constexpr QOperatingSystemVersionBase OSXYosemite { QOperatingSystemVersionBase::MacOS, 10, 10 }; |
213 | static constexpr QOperatingSystemVersionBase OSXElCapitan { QOperatingSystemVersionBase::MacOS, 10, 11 }; |
214 | static constexpr QOperatingSystemVersionBase MacOSSierra { QOperatingSystemVersionBase::MacOS, 10, 12 }; |
215 | static constexpr QOperatingSystemVersionBase MacOSHighSierra { QOperatingSystemVersionBase::MacOS, 10, 13 }; |
216 | static constexpr QOperatingSystemVersionBase MacOSMojave { QOperatingSystemVersionBase::MacOS, 10, 14 }; |
217 | static constexpr QOperatingSystemVersionBase MacOSCatalina { QOperatingSystemVersionBase::MacOS, 10, 15 }; |
218 | static constexpr QOperatingSystemVersionBase MacOSBigSur = { QOperatingSystemVersionBase::MacOS, 11, 0 }; |
219 | static constexpr QOperatingSystemVersionBase MacOSMonterey = { QOperatingSystemVersionBase::MacOS, 12, 0 }; |
220 | |
221 | static constexpr QOperatingSystemVersionBase AndroidJellyBean { QOperatingSystemVersionBase::Android, 4, 1 }; |
222 | static constexpr QOperatingSystemVersionBase AndroidJellyBean_MR1 { QOperatingSystemVersionBase::Android, 4, 2 }; |
223 | static constexpr QOperatingSystemVersionBase AndroidJellyBean_MR2 { QOperatingSystemVersionBase::Android, 4, 3 }; |
224 | static constexpr QOperatingSystemVersionBase AndroidKitKat { QOperatingSystemVersionBase::Android, 4, 4 }; |
225 | static constexpr QOperatingSystemVersionBase AndroidLollipop { QOperatingSystemVersionBase::Android, 5, 0 }; |
226 | static constexpr QOperatingSystemVersionBase AndroidLollipop_MR1 { QOperatingSystemVersionBase::Android, 5, 1 }; |
227 | static constexpr QOperatingSystemVersionBase AndroidMarshmallow { QOperatingSystemVersionBase::Android, 6, 0 }; |
228 | static constexpr QOperatingSystemVersionBase AndroidNougat { QOperatingSystemVersionBase::Android, 7, 0 }; |
229 | static constexpr QOperatingSystemVersionBase AndroidNougat_MR1 { QOperatingSystemVersionBase::Android, 7, 1 }; |
230 | static constexpr QOperatingSystemVersionBase AndroidOreo { QOperatingSystemVersionBase::Android, 8, 0 }; |
231 | static constexpr QOperatingSystemVersionBase AndroidOreo_MR1 { QOperatingSystemVersionBase::Android, 8, 1 }; |
232 | static constexpr QOperatingSystemVersionBase AndroidPie { QOperatingSystemVersionBase::Android, 9, 0 }; |
233 | static constexpr QOperatingSystemVersionBase Android10 { QOperatingSystemVersionBase::Android, 10, 0 }; |
234 | static constexpr QOperatingSystemVersionBase Android11 { QOperatingSystemVersionBase::Android, 11, 0 }; |
235 | #endif |
236 | |
237 | static constexpr QOperatingSystemVersionBase Windows10_1809 { QOperatingSystemVersionBase::Windows, 10, 0, 17763 }; // RS5 |
238 | static constexpr QOperatingSystemVersionBase Windows10_1903 { QOperatingSystemVersionBase::Windows, 10, 0, 18362 }; // 19H1 |
239 | static constexpr QOperatingSystemVersionBase Windows10_1909 { QOperatingSystemVersionBase::Windows, 10, 0, 18363 }; // 19H2 |
240 | static constexpr QOperatingSystemVersionBase Windows10_2004 { QOperatingSystemVersionBase::Windows, 10, 0, 19041 }; // 20H1 |
241 | static constexpr QOperatingSystemVersionBase Windows10_20H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19042 }; |
242 | static constexpr QOperatingSystemVersionBase Windows10_21H1 { QOperatingSystemVersionBase::Windows, 10, 0, 19043 }; |
243 | static constexpr QOperatingSystemVersionBase Windows10_21H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19044 }; |
244 | static constexpr QOperatingSystemVersionBase Windows10_22H2 { QOperatingSystemVersionBase::Windows, 10, 0, 19045 }; |
245 | static constexpr QOperatingSystemVersionBase Windows11 { QOperatingSystemVersionBase::Windows, 10, 0, 22000 }; |
246 | static constexpr QOperatingSystemVersionBase Windows11_21H2 = Windows11; |
247 | static constexpr QOperatingSystemVersionBase Windows11_22H2 { QOperatingSystemVersionBase::Windows, 10, 0, 22621 }; |
248 | |
249 | static constexpr QOperatingSystemVersionBase Android12 { QOperatingSystemVersionBase::Android, 12, 0 }; |
250 | static constexpr QOperatingSystemVersionBase Android12L { QOperatingSystemVersionBase::Android, 12, 0 }; |
251 | static constexpr QOperatingSystemVersionBase Android13 { QOperatingSystemVersionBase::Android, 13, 0 }; |
252 | |
253 | static constexpr QOperatingSystemVersionBase MacOSVentura { QOperatingSystemVersionBase::MacOS, 13, 0 }; |
254 | |
255 | constexpr QOperatingSystemVersion(const QOperatingSystemVersionBase &osversion) |
256 | : QOperatingSystemVersionUnexported(osversion) {} |
257 | |
258 | constexpr QOperatingSystemVersion(OSType osType, int vmajor, int vminor = -1, int vmicro = -1) |
259 | : QOperatingSystemVersionUnexported(QOperatingSystemVersionBase::OSType(osType), vmajor, vminor, |
260 | vmicro) |
261 | { |
262 | } |
263 | |
264 | #if QT_CORE_REMOVED_SINCE(6, 3) || defined(Q_QDOC) |
265 | static QOperatingSystemVersion current(); |
266 | #endif |
267 | |
268 | static constexpr OSType currentType() |
269 | { |
270 | return OSType(QOperatingSystemVersionBase::currentType()); |
271 | } |
272 | |
273 | #if QT_CORE_REMOVED_SINCE(6, 3) || defined(Q_QDOC) |
274 | QVersionNumber version() const { return QOperatingSystemVersionBase::version(); } |
275 | |
276 | constexpr int majorVersion() const { return QOperatingSystemVersionBase::majorVersion(); } |
277 | constexpr int minorVersion() const { return QOperatingSystemVersionBase::minorVersion(); } |
278 | constexpr int microVersion() const { return QOperatingSystemVersionBase::microVersion(); } |
279 | |
280 | constexpr int segmentCount() const |
281 | { return QOperatingSystemVersionBase::segmentCount(); } |
282 | #endif // QT_CORE_REMOVED_SINCE(6, 3) |
283 | |
284 | constexpr OSType type() const { return OSType(QOperatingSystemVersionBase::type()); } |
285 | QT7_ONLY(Q_CORE_EXPORT) bool isAnyOfType(std::initializer_list<OSType> types) const; |
286 | #if QT_CORE_REMOVED_SINCE(6, 3) || defined(Q_QDOC) |
287 | QString name() const; |
288 | #endif |
289 | |
290 | private: |
291 | QOperatingSystemVersion() = default; |
292 | |
293 | #if QT_CORE_REMOVED_SINCE(6, 3) |
294 | // ### Qt 7: Remove. It's only here for backwards compat with previous inline calls. |
295 | [[maybe_unused]] static int compare(const QOperatingSystemVersion &v1, |
296 | const QOperatingSystemVersion &v2); |
297 | #endif |
298 | }; |
299 | Q_DECLARE_TYPEINFO(QOperatingSystemVersion, Q_PRIMITIVE_TYPE); |
300 | |
301 | #ifndef QT_NO_DEBUG_STREAM |
302 | class QDebug; |
303 | Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QOperatingSystemVersion &ov); |
304 | #endif |
305 | |
306 | QT_END_NAMESPACE |
307 | |
308 | #endif // QOPERATINGSYSTEMVERSION_H |
309 |
Definitions
- QOperatingSystemVersionBase
- OSType
- QOperatingSystemVersionBase
- currentType
- version
- majorVersion
- minorVersion
- microVersion
- segmentCount
- isAnyOfType
- type
- name
- compareThreeWay
- operator>
- operator>=
- operator<
- operator<=
- QOperatingSystemVersionBase
- QOperatingSystemVersionUnexported
- QOperatingSystemVersionUnexported
- MacOSSonoma
- MacOSSequoia
- Android14
- Windows11_23H2
- Windows11_24H2
- QOperatingSystemVersion
- OSType
- Windows10_1809
- Windows10_1903
- Windows10_1909
- Windows10_2004
- Windows10_20H2
- Windows10_21H1
- Windows10_21H2
- Windows10_22H2
- Windows11
- Windows11_21H2
- Windows11_22H2
- Android12
- Android12L
- Android13
- MacOSVentura
- QOperatingSystemVersion
- QOperatingSystemVersion
- currentType
- type
Learn Advanced QML with KDAB
Find out more