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
qxcomponentregistry.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
<
qarkui
/
qxcomponentregistry
.
h
>
5
6
#
include
<
QtCore
/
private
/
qohoslogger_p
.
h
>
7
#
include
<
qohosutils
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
namespace
QArkUi
{
12
13
std
::optional<
QXComponentNode
>
14
QXComponentRegistry
::
tryTakeNodeByXComponentId
(
const
QXComponentId
&id)
15
{
16
std
::optional<
QXComponentNode
> result;
17
auto
it = m_xComponents.find(id);
18
if
(it != m_xComponents.end()) {
19
result = it->second;
20
m_xComponents.erase(it);
21
}
22
return
result;
23
}
24
25
QXComponentRegistry
&
QXComponentRegistry
::
instance
()
26
{
27
static
QXComponentRegistry
registry;
28
return
registry;
29
}
30
31
bool
QXComponentRegistry
::Init(napi_env env, napi_value exports)
32
{
33
auto
exportsObj = QNapi::checkedCast<QNapi::Object>(QNapi::Value{env, exports});
34
auto
xComponentWrappedValue = QNapi::getOptionalPropOrEmpty<QNapi::Object>(
35
exportsObj,
36
OH_NATIVE_XCOMPONENT_OBJ);
37
if
(xComponentWrappedValue.IsEmpty())
38
return
false
;
39
40
::OH_NativeXComponent *xComponent =
nullptr
;
41
auto
status = ::napi_unwrap(
42
env,
43
xComponentWrappedValue,
44
reinterpret_cast
<
void
**>(&xComponent));
45
if
(status != ::napi_ok) {
46
qOhosPrintfError(
"Failed to unwrap xcomponent with napi_status: %d"
, status);
47
return
false
;
48
}
49
50
auto
optXComponentId = QXComponentId::tryCreateFromXComponent(xComponent);
51
if
(!optXComponentId.has_value()) {
52
qOhosPrintfError(
"Failed to retrieve id from xcomponent. Ignoring the component"
);
53
return
false
;
54
}
55
56
auto
xComponentId = optXComponentId.value();
57
58
auto
optXComponentIdType = xComponentId.recognizedType();
59
if
(!optXComponentIdType.has_value()) {
60
qOhosPrintfError(
61
"Ignoring xComponent due to unrecognized id value: %s"
,
62
xComponentId.stringId().c_str());
63
return
false
;
64
}
65
66
bool
canRegister =
false
;
67
switch
(optXComponentIdType.value()) {
68
case
QXComponentId
::
RecognizedType
::
RenderXComponent
:
69
canRegister =
false
;
70
break
;
71
case
QXComponentId
::
RecognizedType
::
NativeNodeFloatWindow
:
72
case
QXComponentId
::
RecognizedType
::
NativeNodeSubWindow
:
73
case
QXComponentId
::
RecognizedType
::
NativeNodeMainWindow
:
74
canRegister =
true
;
75
break
;
76
}
77
78
if
(!canRegister) {
79
qOhosPrintfDebug(
80
"Ignoring xComponent because its id type is not supported in registry. id: %s type: %d"
,
81
xComponentId.stringId().c_str(),
82
optXComponentIdType.value());
83
return
false
;
84
}
85
86
auto
®istry =
instance
(
)
;
87
88
bool
xComponentRegistered;
89
std
::tie(
std
::ignore, xComponentRegistered) =
90
registry.m_xComponents.emplace(xComponentId,
QXComponentNode
(xComponent));
91
92
if
(!xComponentRegistered) {
93
qOhosReportFatalErrorAndAbort(
94
"Error: Duplicate xComponent detected. Duplicate ID: %s"
,
95
xComponentId.stringId().c_str());
96
}
97
98
return
true
;
99
}
100
101
}
102
103
QT_END_NAMESPACE
QArkUi::QXComponentRegistry
Definition
qxcomponentregistry.h:19
QArkUi::QXComponentRegistry::tryTakeNodeByXComponentId
std::optional< QXComponentNode > tryTakeNodeByXComponentId(const QXComponentId &id)
Definition
qxcomponentregistry.cpp:14
QArkUi::QXComponentRegistry::instance
static QXComponentRegistry & instance()
Definition
qxcomponentregistry.cpp:25
QXComponentId
Definition
qxcomponent.h:47
QXComponentId::RecognizedType
RecognizedType
Definition
qxcomponent.h:50
QXComponentId::RecognizedType::NativeNodeFloatWindow
@ NativeNodeFloatWindow
Definition
qxcomponent.h:54
QXComponentId::RecognizedType::NativeNodeSubWindow
@ NativeNodeSubWindow
Definition
qxcomponent.h:52
QXComponentId::RecognizedType::RenderXComponent
@ RenderXComponent
Definition
qxcomponent.h:51
QXComponentId::RecognizedType::NativeNodeMainWindow
@ NativeNodeMainWindow
Definition
qxcomponent.h:53
QArkUi
Definition
displaymanager.cpp:17
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
QXComponentNode
QXComponent< QXComponentType::Node > QXComponentNode
Definition
qxcomponent.h:44
qtbase
src
plugins
platforms
ohos
qarkui
qxcomponentregistry.cpp
Generated on
for Qt by
1.18.0