Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qxcomponent.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
4
#
include
<
render
/
qxcomponent
.
h
>
5
6
#
include
<
array
>
7
#
include
<
cstdint
>
8
#
include
<
qohosutils
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
namespace
13
{
14
15
const
std
::string
xComponentPrefixForMainWindow
=
"__nnMainWindow_"
;
16
const
std
::string
xComponentPrefixForSubWindow
=
"__nnSubWindow_"
;
17
const
std
::string
xComponentPrefixForFloatWindow
=
"__nnFloatWindow_"
;
18
const
std
::string
xComponentPrefixForRenderXComponent
=
"RenderXComponent_"
;
19
20
bool
startsWith
(
const
std
::string &str,
const
std
::string &prefix)
21
{
22
return
str.compare(0, prefix.size(), prefix) == 0;
23
}
24
25
std
::optional<
QXComponentId
::
RecognizedType
>
tryMapXComponentIdValueToRecognizedType
(
const
std
::string &idValue)
26
{
27
static
const
std
::pair<
std
::string,
QXComponentId
::
RecognizedType
> prefixToTypeMapping[] = {
28
{xComponentPrefixForMainWindow, QXComponentId::RecognizedType::NativeNodeMainWindow},
29
{xComponentPrefixForSubWindow, QXComponentId::RecognizedType::NativeNodeSubWindow},
30
{xComponentPrefixForFloatWindow, QXComponentId::RecognizedType::NativeNodeFloatWindow},
31
{xComponentPrefixForRenderXComponent, QXComponentId::RecognizedType::RenderXComponent},
32
};
33
34
for
(
const
auto
&prefixTypePair: prefixToTypeMapping) {
35
if
(startsWith(idValue, prefixTypePair.first))
36
return
prefixTypePair.second;
37
}
38
39
return
std
::nullopt;
40
}
41
42
}
43
44
bool
QXComponentId
::
operator
==(
const
QXComponentId
&other)
const
45
{
46
return
m_id == other.m_id;
47
}
48
49
bool
QXComponentId
::
operator
!=(
const
QXComponentId
&other)
const
50
{
51
return
m_id != other.m_id;
52
}
53
54
bool
QXComponentId
::
operator
<(
const
QXComponentId
&other)
const
55
{
56
return
m_id < other.m_id;
57
}
58
59
QXComponentId
QXComponentId
::
createForNativeNodeMainWindow
(
const
std
::string &qAbilityInstanceId)
60
{
61
return
QXComponentId
(
xComponentPrefixForMainWindow
+ qAbilityInstanceId);
62
}
63
64
QXComponentId
QXComponentId
::createForNativeNodeSubWindow(
QtOhos
::
InternalWindowId
windowId)
65
{
66
return
QXComponentId(xComponentPrefixForSubWindow + windowId.toStdString());
67
}
68
69
QXComponentId
QXComponentId
::createForRenderXComponent(
QtOhos
::
InternalWindowId
windowId)
70
{
71
return
QXComponentId(xComponentPrefixForRenderXComponent + windowId.toStdString());
72
}
73
74
QXComponentId
QXComponentId
::createForNativeNodeFloatWindow(
QtOhos
::
InternalWindowId
windowId)
75
{
76
return
QXComponentId(xComponentPrefixForFloatWindow + windowId.toStdString());
77
}
78
79
QXComponentId
::QXComponentId(
std
::string id)
80
: m_id(
std
::move(id))
81
, m_optRecognizedType(tryMapXComponentIdValueToRecognizedType(m_id))
82
{
83
}
84
85
std
::string
QXComponentId
::
stringId
()
const
86
{
87
return
m_id;
88
}
89
90
std
::optional<
QXComponentId
>
QXComponentId
::tryCreateFromXComponent(::OH_NativeXComponent *xComponent)
91
{
92
constexpr
auto
requiredBufferSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
93
94
if
(xComponent ==
nullptr
)
95
qOhosReportFatalErrorAndAbort(
"OH_NativeXComponent was null"
);
96
97
std
::uint64_t xComponentIdLength = requiredBufferSize;
98
std
::array<
char
, requiredBufferSize> xComponentIdData = {};
99
auto
errorCode = ::OH_NativeXComponent_GetXComponentId(
100
xComponent,
101
xComponentIdData.data(),
102
&xComponentIdLength);
103
if
(errorCode != ::OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
104
qOhosReportFatalErrorAndAbort(
105
"OH_NativeXComponent_GetXComponentId failed with error: %d"
, errorCode);
106
}
107
108
return
QXComponentId
(
109
std
::string(
110
xComponentIdData.data(),
111
xComponentIdLength));
112
}
113
114
QNapi
::
Value
QXComponentId
::
toNapiValue
(napi_env env)
const
115
{
116
return
QNapi::String::New(env, m_id);
117
}
118
119
std
::optional<
QXComponentId
::
RecognizedType
>
QXComponentId
::
recognizedType
()
const
120
{
121
return
m_optRecognizedType;
122
}
123
124
QT_END_NAMESPACE
QXComponentId
Definition
qxcomponent.h:47
QXComponentId::createForNativeNodeMainWindow
static QXComponentId createForNativeNodeMainWindow(const std::string &qAbilityInstanceId)
Definition
qxcomponent.cpp:59
QXComponentId::stringId
std::string stringId() const
Definition
qxcomponent.cpp:85
QXComponentId::RecognizedType
RecognizedType
Definition
qxcomponent.h:50
QXComponentId::toNapiValue
QNapi::Value toNapiValue(napi_env env) const
Definition
qxcomponent.cpp:114
QXComponentId::operator!=
bool operator!=(const QXComponentId &other) const
Definition
qxcomponent.cpp:49
QXComponentId::operator==
bool operator==(const QXComponentId &other) const
Definition
qxcomponent.cpp:44
QXComponentId::operator<
bool operator<(const QXComponentId &other) const
Definition
qxcomponent.cpp:54
QXComponentId::recognizedType
std::optional< RecognizedType > recognizedType() const
Definition
qxcomponent.cpp:119
QtOhos::InternalWindowId
Definition
qohosinternalwindowid_p.h:29
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QT_BEGIN_NAMESPACE::xComponentPrefixForFloatWindow
const std::string xComponentPrefixForFloatWindow
Definition
qxcomponent.cpp:17
QT_BEGIN_NAMESPACE::startsWith
bool startsWith(const std::string &str, const std::string &prefix)
Definition
qxcomponent.cpp:20
QT_BEGIN_NAMESPACE::xComponentPrefixForMainWindow
const std::string xComponentPrefixForMainWindow
Definition
qxcomponent.cpp:15
QT_BEGIN_NAMESPACE::xComponentPrefixForRenderXComponent
const std::string xComponentPrefixForRenderXComponent
Definition
qxcomponent.cpp:18
QT_BEGIN_NAMESPACE::xComponentPrefixForSubWindow
const std::string xComponentPrefixForSubWindow
Definition
qxcomponent.cpp:16
QT_BEGIN_NAMESPACE::tryMapXComponentIdValueToRecognizedType
std::optional< QXComponentId::RecognizedType > tryMapXComponentIdValueToRecognizedType(const std::string &idValue)
Definition
qxcomponent.cpp:25
QtOhos
Definition
qcore_ohos.cpp:59
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtbase
src
plugins
platforms
ohos
render
qxcomponent.cpp
Generated on
for Qt by
1.18.0