summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-11-06 11:41:54 +0100
committerhjk <hjk121@nokiamail.com>2014-11-19 11:05:29 +0100
commit72155f4eb4a4c14464c44d8e848b912eeae8580a (patch)
tree47a233041374da0e2bbe1d606f4716af12880e60
parentf5f8a8c346b7566b544d500254c6f9f4eb109c79 (diff)
Make QSysInfo enum types available cross-platform
This makes the WinVersion and MacVersion enums accessible in platform indepedent code to avoid the need to use #ifdef Q_OS_* chains in user code, leading to fewer platform-dependent code paths and better maintainability. To indicate "this is not a Windows based OS" a enum value QSysInfo::WV_None (with value 0x0000) in QSysInfo::WinVersion is introduced. This keeps the WV_*_based masks usable. To indicate "this is not a Darwin based OS" a enum values QSysInfo::MV_None (with value 0xffff) in QSysInfo::MacVersion is introduced. 0x0000 might have been preferable for (not so important "consitency" with QSysInfo::WV_None), but is already taken by QSysInfo::MV_Unknown with a different meaning. Change-Id: Ib395e0efba58558f31f4e0806f7333165aa90aa5 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/global/qglobal.cpp19
-rw-r--r--src/corelib/global/qsysinfo.h19
2 files changed, 27 insertions, 11 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index d56854064d..2d4edb48d1 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -985,9 +985,9 @@ bool qSharedBuild() Q_DECL_NOTHROW
\li \l ByteOrder specifies whether the platform is big-endian or
little-endian.
\li \l WindowsVersion specifies the version of the Windows operating
- system on which the application is run (Windows only)
+ system on which the application is run.
\li \l MacintoshVersion specifies the version of the Macintosh
- operating system on which the application is run (Mac only).
+ operating system on which the application is run.
\endlist
Some constants are defined only on certain platforms. You can use
@@ -1010,7 +1010,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
/*!
\variable QSysInfo::WindowsVersion
\brief the version of the Windows operating system on which the
- application is run (Windows only)
+ application is run.
*/
/*!
@@ -1018,19 +1018,22 @@ bool qSharedBuild() Q_DECL_NOTHROW
\since 4.4
Returns the version of the Windows operating system on which the
- application is run (Windows only).
+ application is run, or WV_None if the operating system is not
+ Windows.
*/
/*!
\variable QSysInfo::MacintoshVersion
\brief the version of the Macintosh operating system on which
- the application is run (Mac only).
+ the application is run.
*/
/*!
\fn QSysInfo::MacVersion QSysInfo::macVersion()
- Returns the version of Darwin (OS X or iOS) on which the application is run.
+ Returns the version of Darwin (OS X or iOS) on which the
+ application is run, or MV_None if the operating system
+ is not a version of Darwin.
*/
/*!
@@ -1093,6 +1096,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value WV_NT_based NT-based version of Windows
\value WV_CE_based CE-based version of Windows
+ \value WV_None Operating system other than Windows.
+
\sa MacVersion
*/
@@ -1140,6 +1145,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value MV_IOS_7_1 iOS 7.1
\value MV_IOS_8_0 iOS 8.0
+ \value MV_None Not a Darwin operating system
+
\sa WinVersion
*/
diff --git a/src/corelib/global/qsysinfo.h b/src/corelib/global/qsysinfo.h
index 2ac18f2ed8..35672479e0 100644
--- a/src/corelib/global/qsysinfo.h
+++ b/src/corelib/global/qsysinfo.h
@@ -72,8 +72,9 @@ public:
# endif
};
#endif
-#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
enum WinVersion {
+ WV_None = 0x0000,
+
WV_32s = 0x0001,
WV_95 = 0x0002,
WV_98 = 0x0003,
@@ -107,14 +108,18 @@ public:
WV_CE_6 = 0x0400,
WV_CE_based = 0x0f00
};
+#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
static const WinVersion WindowsVersion;
static WinVersion windowsVersion();
-
+#else
+ static const WinVersion WindowsVersion = WV_None;
+ static WinVersion windowsVersion() { return WV_None; }
#endif
-#ifdef Q_OS_MAC
-# define Q_MV_OSX(major, minor) (major == 10 ? minor + 2 : (major == 9 ? 1 : 0))
-# define Q_MV_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor)
+
+#define Q_MV_OSX(major, minor) (major == 10 ? minor + 2 : (major == 9 ? 1 : 0))
+#define Q_MV_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor)
enum MacVersion {
+ MV_None = 0xffff,
MV_Unknown = 0x0000,
/* version */
@@ -155,8 +160,12 @@ public:
MV_IOS_7_1 = Q_MV_IOS(7, 1),
MV_IOS_8_0 = Q_MV_IOS(8, 0)
};
+#if defined(Q_OS_MAC)
static const MacVersion MacintoshVersion;
static MacVersion macVersion();
+#else
+ static const MacVersion MacintoshVersion = MV_None;
+ static MacVersion macVersion() { return MV_None; }
#endif
static QString buildCpuArchitecture();