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) {
18 return true;
20 return false;
21 }
22 return false;
23}
24
25}
26
28
29void init(QMap<Type, QVariant> devinfo)
30{
31 s_deviceInfo = std::move(devinfo);
32}
33
35{
36 auto result = s_deviceInfo.value(prop);
37 if (!result.isValid()) {
38 qOhosWarning(QtForOhos)
39 << "QOhosDeviceInfo::getProperty cannot obtain value from DeviceInfo map";
40 }
41 return result;
42}
43
45{
46 static const QMap<QString, RecognizedDeviceType> deviceTypeNameMapping = {
47 {QStringLiteral("2in1"), RecognizedDeviceType::_2in1},
48 {QStringLiteral("tablet"), RecognizedDeviceType::tablet},
49 {QStringLiteral("phone"), RecognizedDeviceType::phone},
50 };
51
52 auto deviceTypeName = getProperty(Type::deviceType).toString();
53 auto deviceTypeIt = deviceTypeNameMapping.constFind(deviceTypeName);
54 auto deviceType = deviceTypeIt != deviceTypeNameMapping.constEnd()
55 ? makeQOhosOptional(deviceTypeIt.value())
57
58 return deviceType;
59}
60
62{
63 return tryGetRecognizedDeviceType() == QOhosDeviceInfo::RecognizedDeviceType::tablet;
64}
65
66bool is2in1()
67{
68 return tryGetRecognizedDeviceType() == QOhosDeviceInfo::RecognizedDeviceType::_2in1;
69}
70
71bool isPhone()
72{
73 return tryGetRecognizedDeviceType() == RecognizedDeviceType::phone;
74}
75
77{
78 return getProperty(Type::sdkApiVersion).toInt();
79}
80
82{
83 auto deviceType = tryGetRecognizedDeviceType();
84 return deviceType.hasValue() && isSupportedDeviceType(deviceType.value());
85}
86
87}
88
89QT_END_NAMESPACE
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
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.
QOhosOptional< void > makeEmptyQOhosOptional()