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>
This commit is contained in:
hjk 2014-11-06 11:41:54 +01:00
parent f5f8a8c346
commit 72155f4eb4
2 changed files with 27 additions and 11 deletions

View File

@ -985,9 +985,9 @@ bool qSharedBuild() Q_DECL_NOTHROW
\li \l ByteOrder specifies whether the platform is big-endian or \li \l ByteOrder specifies whether the platform is big-endian or
little-endian. little-endian.
\li \l WindowsVersion specifies the version of the Windows operating \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 \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 \endlist
Some constants are defined only on certain platforms. You can use Some constants are defined only on certain platforms. You can use
@ -1010,7 +1010,7 @@ bool qSharedBuild() Q_DECL_NOTHROW
/*! /*!
\variable QSysInfo::WindowsVersion \variable QSysInfo::WindowsVersion
\brief the version of the Windows operating system on which the \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 \since 4.4
Returns the version of the Windows operating system on which the 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 \variable QSysInfo::MacintoshVersion
\brief the version of the Macintosh operating system on which \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() \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_NT_based NT-based version of Windows
\value WV_CE_based CE-based version of Windows \value WV_CE_based CE-based version of Windows
\value WV_None Operating system other than Windows.
\sa MacVersion \sa MacVersion
*/ */
@ -1140,6 +1145,8 @@ bool qSharedBuild() Q_DECL_NOTHROW
\value MV_IOS_7_1 iOS 7.1 \value MV_IOS_7_1 iOS 7.1
\value MV_IOS_8_0 iOS 8.0 \value MV_IOS_8_0 iOS 8.0
\value MV_None Not a Darwin operating system
\sa WinVersion \sa WinVersion
*/ */

View File

@ -72,8 +72,9 @@ public:
# endif # endif
}; };
#endif #endif
#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
enum WinVersion { enum WinVersion {
WV_None = 0x0000,
WV_32s = 0x0001, WV_32s = 0x0001,
WV_95 = 0x0002, WV_95 = 0x0002,
WV_98 = 0x0003, WV_98 = 0x0003,
@ -107,14 +108,18 @@ public:
WV_CE_6 = 0x0400, WV_CE_6 = 0x0400,
WV_CE_based = 0x0f00 WV_CE_based = 0x0f00
}; };
#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
static const WinVersion WindowsVersion; static const WinVersion WindowsVersion;
static WinVersion windowsVersion(); static WinVersion windowsVersion();
#else
static const WinVersion WindowsVersion = WV_None;
static WinVersion windowsVersion() { return WV_None; }
#endif #endif
#ifdef Q_OS_MAC
# define Q_MV_OSX(major, minor) (major == 10 ? minor + 2 : (major == 9 ? 1 : 0)) #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_IOS(major, minor) (QSysInfo::MV_IOS | major << 4 | minor)
enum MacVersion { enum MacVersion {
MV_None = 0xffff,
MV_Unknown = 0x0000, MV_Unknown = 0x0000,
/* version */ /* version */
@ -155,8 +160,12 @@ public:
MV_IOS_7_1 = Q_MV_IOS(7, 1), MV_IOS_7_1 = Q_MV_IOS(7, 1),
MV_IOS_8_0 = Q_MV_IOS(8, 0) MV_IOS_8_0 = Q_MV_IOS(8, 0)
}; };
#if defined(Q_OS_MAC)
static const MacVersion MacintoshVersion; static const MacVersion MacintoshVersion;
static MacVersion macVersion(); static MacVersion macVersion();
#else
static const MacVersion MacintoshVersion = MV_None;
static MacVersion macVersion() { return MV_None; }
#endif #endif
static QString buildCpuArchitecture(); static QString buildCpuArchitecture();