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
qqmldommock.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
5
#
include
"qqmldommock_p.h"
6
#
include
"qqmldomitem_p.h"
7
#
include
"qqmldomcomments_p.h"
8
9
#
include
<
QtCore
/
QBasicMutex
>
10
#
include
<
QtCore
/
QMutexLocker
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
QQmlJS
{
15
namespace
Dom
{
16
17
MockObject MockObject::
copy
()
const
18
{
19
QMap<QString, MockObject> newObjs;
20
auto
objs = subObjects;
21
auto
itO = objs.cbegin();
22
auto
endO = objs.cend();
23
while
(itO != endO) {
24
newObjs.insert(itO.key(), itO->copy());
25
++itO;
26
}
27
return
MockObject(pathFromOwner(), newObjs, subValues);
28
}
29
30
std
::
pair
<
QString
,
MockObject
> MockObject::
asStringPair
()
const
31
{
32
return
std::make_pair(pathFromOwner().last().headName(), *
this
);
33
}
34
35
bool
MockObject::
iterateDirectSubpaths
(
const
DomItem
&self, DirectVisitor visitor)
const
36
{
37
static
QHash<QString, QString> knownFields;
38
static
QBasicMutex m;
39
auto
toField = [](
const
QString &f) -> QStringView {
40
QMutexLocker l(&m);
41
if
(!knownFields.contains(f))
42
knownFields[f] = f;
43
return
knownFields[f];
44
};
45
bool
cont = CommentableDomElement::iterateDirectSubpaths(self, visitor);
46
auto
itV = subValues.begin();
47
auto
endV = subValues.end();
48
while
(itV != endV) {
49
cont = cont && self.invokeVisitorOnValue(visitor,
PathEls
::Field(toField(itV.key())), *itV);
50
++itV;
51
}
52
auto
itO = subObjects.begin();
53
auto
endO = subObjects.end();
54
while
(itO != endO) {
55
cont = cont && visitor(
PathEls
::Field(toField(itO.key())), [&self, &itO]() {
56
return
self.copy(&(*itO));
57
});
58
++itO;
59
}
60
return
cont;
61
}
62
63
std
::shared_ptr<
OwningItem
>
MockOwner
::
doCopy
(
const
DomItem
&)
const
64
{
65
return
std
::make_shared<
MockOwner
>(*
this
);
66
}
67
68
MockOwner
::
MockOwner
(
const
MockOwner
&o)
69
:
OwningItem
(o),
pathFromTop
(
o
.
pathFromTop
),
subValues
(
o
.
subValues
)
70
{
71
auto
objs = o.subObjects;
72
auto
itO = objs.cbegin();
73
auto
endO = objs.cend();
74
while
(itO != endO) {
75
subObjects.insert(itO.key(), itO->copy());
76
++itO;
77
}
78
}
79
80
std
::shared_ptr<
MockOwner
>
MockOwner
::
makeCopy
(
const
DomItem
&self)
const
81
{
82
return
std
::static_pointer_cast<
MockOwner
>(doCopy(self));
83
}
84
85
Path
MockOwner
::
canonicalPath
(
const
DomItem
&)
const
86
{
87
return
pathFromTop;
88
}
89
90
bool
MockOwner
::
iterateDirectSubpaths
(
const
DomItem
&self, DirectVisitor visitor)
const
91
{
92
static
QHash<QString, QString> knownFields;
93
static
QBasicMutex m;
94
auto
toField = [](
const
QString &f) -> QStringView {
95
QMutexLocker l(&m);
96
if
(!knownFields.contains(f))
97
knownFields[f] = f;
98
return
knownFields[f];
99
};
100
{
101
auto
itV = subValues.begin();
102
auto
endV = subValues.end();
103
while
(itV != endV) {
104
if
(!self.invokeVisitorOnValue(visitor,
PathEls
::Field(toField(itV.key())), *itV))
105
return
false
;
106
++itV;
107
}
108
}
109
{
110
auto
itO = subObjects.begin();
111
auto
endO = subObjects.end();
112
while
(itO != endO) {
113
if
(!visitor(
PathEls
::Field(toField(itO.key())),
114
[&self, &itO]() {
return
self.copy(&(*itO)); })) {
115
return
false
;
116
}
117
++itO;
118
}
119
}
120
{
121
auto
it = subMaps.begin();
122
auto
end = subMaps.end();
123
while
(it != end) {
124
if
(!self.invokeVisitorOnField(visitor, toField(it.key()), it.value()))
125
return
false
;
126
++it;
127
}
128
}
129
{
130
auto
it = subMultiMaps.begin();
131
auto
end = subMultiMaps.end();
132
while
(it != end) {
133
if
(!self.invokeVisitorOnField(visitor, toField(it.key()), it.value()))
134
return
false
;
135
++it;
136
}
137
}
138
{
139
auto
it = subLists.begin();
140
auto
end = subLists.end();
141
while
(it != end) {
142
if
(!self.invokeVisitorOnField(visitor, toField(it.key()), it.value()))
143
return
false
;
144
++it;
145
}
146
}
147
return
true
;
148
}
149
150
}
// end namespace Dom
151
}
// end namespace QQmlJS
152
QT_END_NAMESPACE
QQmlJS::Dom::DomItem
A value type that references any element of the Dom.
Definition
qqmldomitem_p.h:851
QQmlJS::Dom::MockObject::iterateDirectSubpaths
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Definition
qqmldommock.cpp:35
QQmlJS::Dom::MockObject::copy
MockObject copy() const
Definition
qqmldommock.cpp:17
QQmlJS::Dom::MockObject::asStringPair
std::pair< QString, MockObject > asStringPair() const
Definition
qqmldommock.cpp:30
QQmlJS::Dom::MockOwner::iterateDirectSubpaths
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const override
Definition
qqmldommock.cpp:90
QQmlJS::Dom::MockOwner::doCopy
std::shared_ptr< OwningItem > doCopy(const DomItem &self) const override
Definition
qqmldommock.cpp:63
QQmlJS::Dom::MockOwner::makeCopy
std::shared_ptr< MockOwner > makeCopy(const DomItem &self) const
Definition
qqmldommock.cpp:80
QQmlJS::Dom::MockOwner::MockOwner
MockOwner(const MockOwner &o)
Definition
qqmldommock.cpp:68
QQmlJS::Dom::MockOwner::canonicalPath
Path canonicalPath(const DomItem &self) const override
Definition
qqmldommock.cpp:85
QQmlJS::Dom::MockOwner::subMaps
QMap< QString, QMap< QString, MockObject > > subMaps
Definition
qqmldommock_p.h:105
QQmlJS::Dom::OwningItem
A DomItem that owns other DomItems and is managed through a shared pointer.
Definition
qqmldomitem_p.h:1401
QQmlJS::Dom::Path
Definition
qqmldompath_p.h:582
QQmlJS::Dom::PathEls
Definition
qqmldompath_p.h:47
QQmlJS::Dom
Definition
qqmljsimportvisitor_p.h:38
QQmlJS
Definition
qv4bytecodegenerator_p.h:27
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtdeclarative
src
qmldom
qqmldommock.cpp
Generated on
for Qt by
1.18.0