Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosdeviceinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtCore/private/qohoslogger_p.h>
6
8
9namespace QOhosDeviceInfo {
10
11namespace {
12
13bool isSupportedDeviceType(RecognizedDeviceType recognizedDeviceType)
14{
15 switch (recognizedDeviceType) {
19 return true;
20 }
21 return false;
22}
23
24}
25
27
28void init(QMap<Type, QVariant> devinfo)
29{
30 s_deviceInfo = std::move(devinfo);
31}
32
34{
35 auto result = s_deviceInfo.value(prop);
36 if (!result.isValid()) {
37 qOhosWarning(QtForOhos)
38 << "QOhosDeviceInfo::getProperty cannot obtain value from DeviceInfo map";
39 }
40 return result;
41}
42
44{
45 static const QMap<QString, RecognizedDeviceType> deviceTypeNameMapping = {
46 {QStringLiteral("2in1"), RecognizedDeviceType::_2in1},
47 {QStringLiteral("tablet"), RecognizedDeviceType::tablet},
48 {QStringLiteral("phone"), RecognizedDeviceType::phone},
49 };
50
51 auto deviceTypeName = getProperty(Type::deviceType).toString();
52 auto deviceTypeIt = deviceTypeNameMapping.constFind(deviceTypeName);
53 auto deviceType = deviceTypeIt != deviceTypeNameMapping.constEnd()
54 ? makeQOhosOptional(deviceTypeIt.value())
56
57 return deviceType;
58}
59
61{
62 return tryGetRecognizedDeviceType() == QOhosDeviceInfo::RecognizedDeviceType::tablet;
63}
64
65bool is2in1()
66{
67 return tryGetRecognizedDeviceType() == QOhosDeviceInfo::RecognizedDeviceType::_2in1;
68}
69
70bool isPhone()
71{
72 return tryGetRecognizedDeviceType() == RecognizedDeviceType::phone;
73}
74
76{
77 return getProperty(Type::sdkApiVersion).toInt();
78}
79
81{
82 auto deviceType = tryGetRecognizedDeviceType();
83 return deviceType.has_value() && isSupportedDeviceType(deviceType.value());
84}
85
86}
87
88QT_END_NAMESPACE
bool isCurrentDeviceSupported()
QVariant getProperty(Type prop)
void init(QMap< Type, QVariant > devinfo)
QOhosOptional< RecognizedDeviceType > tryGetRecognizedDeviceType()
static QMap< Type, QVariant > s_deviceInfo
Combined button and popup list for selecting options.
std::nullopt_t makeEmptyQOhosOptional()