From b0561e6382ccc880d9e3dab78d967478eca611bb Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 22 Sep 2017 00:33:17 -0700 Subject: [PATCH] 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 --- .../global/qoperatingsystemversion.cpp | 10 ++++++++++ src/corelib/global/qoperatingsystemversion.h | 19 +++++++++++++++++++ .../global/qoperatingsystemversion_p.h | 19 ------------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/corelib/global/qoperatingsystemversion.cpp b/src/corelib/global/qoperatingsystemversion.cpp index a77727320b..682c9bab61 100644 --- a/src/corelib/global/qoperatingsystemversion.cpp +++ b/src/corelib/global/qoperatingsystemversion.cpp @@ -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 diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h index 55030c2200..5f27deab9e 100644 --- a/src/corelib/global/qoperatingsystemversion.h +++ b/src/corelib/global/qoperatingsystemversion.h @@ -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; } diff --git a/src/corelib/global/qoperatingsystemversion_p.h b/src/corelib/global/qoperatingsystemversion_p.h index 78d0daf0c6..6922f4ad54 100644 --- a/src/corelib/global/qoperatingsystemversion_p.h +++ b/src/corelib/global/qoperatingsystemversion_p.h @@ -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