1 /*! 2 * \copyright Copyright (c) 2019-2021 Governikus GmbH & Co. KG, Germany 3 */ 4 5 #include "PlatformHelper.h" 6 7 #include <QFileSelector> 8 #include <QQmlContext> 9 #include <QQmlEngine> 10 #include <QQmlFileSelector> 11 12 namespace governikus 13 { 14 isPlatform(const QObject & object,const Platform selector)15bool isPlatform(const QObject& object, const Platform selector) 16 { 17 if (const QQmlContext* const context = QQmlEngine::contextForObject(&object)) 18 { 19 // The UI could have been changed using OVERRIDE_PLATFORM_SELECTOR 20 if (QQmlEngine* const engine = context->engine()) 21 { 22 const QStringList selectors = QQmlFileSelector::get(engine)->selector()->extraSelectors(); 23 switch (selector) 24 { 25 case Platform::ANDROID: 26 return selectors.contains(QLatin1String("android")); 27 28 case Platform::IOS: 29 return selectors.contains(QLatin1String("ios")); 30 31 case Platform::MOBILE: 32 return selectors.contains(QLatin1String("mobile")); 33 34 case Platform::DESKTOP: 35 return selectors.contains(QLatin1String("desktop")); 36 } 37 } 38 } 39 #ifdef Q_OS_IOS 40 if (selector == Platform::MOBILE || selector == Platform::IOS) 41 { 42 return true; 43 } 44 #endif 45 #ifdef Q_OS_ANDROID 46 if (selector == Platform::MOBILE || selector == Platform::ANDROID) 47 { 48 return true; 49 } 50 #endif 51 #if ((!defined(Q_OS_ANDROID) && defined(Q_OS_LINUX)) || defined(Q_OS_WIN) || defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD)) 52 if (selector == Platform::DESKTOP) 53 { 54 return true; 55 } 56 #endif 57 return false; 58 } 59 60 61 } // namespace governikus 62