Add currentType function to QOperatingSystemVersion

This allows us to retrieve the current OS type without constructing an
instance of the class, and it's also constexpr.

Change-Id: I8b32a1aebeb8139fe3fcf146e5de558fa1060bb8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Jake Petroules 2017-09-22 00:33:17 -07:00
parent 0d0ad598c5
commit b0561e6382
3 changed files with 29 additions and 19 deletions

View File

@ -155,6 +155,8 @@ QT_BEGIN_NAMESPACE
\fn QOperatingSystemVersion QOperatingSystemVersion::current()
Returns a QOperatingSystemVersion indicating the current OS and its version number.
\sa currentType()
*/
#if !defined(Q_OS_DARWIN) && !defined(Q_OS_WIN)
QOperatingSystemVersion QOperatingSystemVersion::current()
@ -300,6 +302,14 @@ int QOperatingSystemVersion::compare(const QOperatingSystemVersion &v1,
\sa name()
*/
/*!
\fn QOperatingSystemVersion::OSType QOperatingSystemVersion::currentType()
Returns the current OS type without constructing a QOperatingSystemVersion instance.
\sa current()
*/
/*!
\fn QString QOperatingSystemVersion::name() const

View File

@ -92,6 +92,25 @@ public:
static QOperatingSystemVersion current();
static Q_DECL_CONSTEXPR OSType currentType()
{
#if defined(Q_OS_WIN)
return Windows;
#elif defined(Q_OS_MACOS)
return MacOS;
#elif defined(Q_OS_IOS)
return IOS;
#elif defined(Q_OS_TVOS)
return TvOS;
#elif defined(Q_OS_WATCHOS)
return WatchOS;
#elif defined(Q_OS_ANDROID)
return Android;
#else
return Unknown;
#endif
}
Q_DECL_CONSTEXPR int majorVersion() const { return m_major; }
Q_DECL_CONSTEXPR int minorVersion() const { return m_minor; }
Q_DECL_CONSTEXPR int microVersion() const { return m_micro; }

View File

@ -63,25 +63,6 @@ QT_BEGIN_NAMESPACE
OSVERSIONINFOEX qWindowsVersionInfo();
#endif
static inline QOperatingSystemVersion::OSType currentType()
{
#if defined(Q_OS_WIN)
return QOperatingSystemVersion::Windows;
#elif defined(Q_OS_MACOS)
return QOperatingSystemVersion::MacOS;
#elif defined(Q_OS_IOS)
return QOperatingSystemVersion::IOS;
#elif defined(Q_OS_TVOS)
return QOperatingSystemVersion::TvOS;
#elif defined(Q_OS_WATCHOS)
return QOperatingSystemVersion::WatchOS;
#elif defined(Q_OS_ANDROID)
return QOperatingSystemVersion::Android;
#else
return QOperatingSystemVersion::Unknown;
#endif
}
QT_END_NAMESPACE
#endif // QOPERATINGSYSTEMVERSION_P_H