Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/types/qqmllistmodel.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
24 | ** | - | ||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
35 | ** | - | ||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
37 | ** | - | ||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "qqmllistmodel_p_p.h" | - | ||||||||||||||||||
41 | #include "qqmllistmodelworkeragent_p.h" | - | ||||||||||||||||||
42 | #include <private/qqmlopenmetaobject_p.h> | - | ||||||||||||||||||
43 | #include <private/qqmljsast_p.h> | - | ||||||||||||||||||
44 | #include <private/qqmljsengine_p.h> | - | ||||||||||||||||||
45 | #include <private/qjsvalue_p.h> | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | #include <private/qqmlcustomparser_p.h> | - | ||||||||||||||||||
48 | #include <private/qqmlengine_p.h> | - | ||||||||||||||||||
49 | #include <private/qqmlnotifier_p.h> | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | #include <private/qv4object_p.h> | - | ||||||||||||||||||
52 | #include <private/qv4dateobject_p.h> | - | ||||||||||||||||||
53 | #include <private/qv4objectiterator_p.h> | - | ||||||||||||||||||
54 | #include <private/qv4alloca_p.h> | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | #include <qqmlcontext.h> | - | ||||||||||||||||||
57 | #include <qqmlinfo.h> | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||
60 | #include <QtCore/qstack.h> | - | ||||||||||||||||||
61 | #include <QXmlStreamReader> | - | ||||||||||||||||||
62 | #include <QtCore/qdatetime.h> | - | ||||||||||||||||||
63 | #include <QScopedValueRollback> | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | Q_DECLARE_METATYPE(const QV4::CompiledData::Binding*); | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | // Set to 1024 as a debugging aid - easier to distinguish uids from indices of elements/models. | - | ||||||||||||||||||
70 | enum { MIN_LISTMODEL_UID = 1024 }; | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | static QAtomicInt uidCounter(MIN_LISTMODEL_UID); | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | template <typename T> | - | ||||||||||||||||||
75 | static bool isMemoryUsed(const char *mem) | - | ||||||||||||||||||
76 | { | - | ||||||||||||||||||
77 | for (size_t i=0 ; i < sizeof(T) ; ++i) {
| 344-3012 | ||||||||||||||||||
78 | if (mem[i] != 0)
| 248-2764 | ||||||||||||||||||
79 | return true; executed 248 times by 2 tests: return true; Executed by:
| 248 | ||||||||||||||||||
80 | } executed 2764 times by 2 tests: end of block Executed by:
| 2764 | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | return false; executed 344 times by 2 tests: return false; Executed by:
| 344 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | static QString roleTypeName(ListLayout::Role::DataType t) | - | ||||||||||||||||||
86 | { | - | ||||||||||||||||||
87 | static const QString roleTypeNames[] = { | - | ||||||||||||||||||
88 | QStringLiteral("String"), QStringLiteral("Number"), QStringLiteral("Bool"), | - | ||||||||||||||||||
89 | QStringLiteral("List"), QStringLiteral("QObject"), QStringLiteral("VariantMap"), | - | ||||||||||||||||||
90 | QStringLiteral("DateTime"), QStringLiteral("Function") | - | ||||||||||||||||||
91 | }; | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | if (t > ListLayout::Role::Invalid && t < ListLayout::Role::MaxDataType)
| 0-36 | ||||||||||||||||||
94 | return roleTypeNames[t]; executed 36 times by 2 tests: return roleTypeNames[t]; Executed by:
| 36 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::DataType type) | - | ||||||||||||||||||
100 | { | - | ||||||||||||||||||
101 | QStringHash<Role *>::Node *node = roleHash.findNode(key); | - | ||||||||||||||||||
102 | if (node) {
| 910-3656 | ||||||||||||||||||
103 | const Role &r = *node->value; | - | ||||||||||||||||||
104 | if (type != r.type)
| 4-3652 | ||||||||||||||||||
105 | qmlWarning(nullptr) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); executed 4 times by 1 test: qmlWarning(nullptr) << ([]() noexcept -> QString { enum { Size = sizeof(u"" "Can't assign to existing role '%1' of different type [%2 -> %3]")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) ...ign to existing role '%1' of different type [%2 -> %3]" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()).arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); Executed by:
executed 4 times by 1 test: return qstring_literal_temp; Executed by:
| 4 | ||||||||||||||||||
106 | return r; executed 3656 times by 11 tests: return r; Executed by:
| 3656 | ||||||||||||||||||
107 | } | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | return createRole(key, type); executed 910 times by 13 tests: return createRole(key, type); Executed by:
| 910 | ||||||||||||||||||
110 | } | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | const ListLayout::Role &ListLayout::getRoleOrCreate(QV4::String *key, Role::DataType type) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | QStringHash<Role *>::Node *node = roleHash.findNode(key); | - | ||||||||||||||||||
115 | if (node) {
| 1208-2740 | ||||||||||||||||||
116 | const Role &r = *node->value; | - | ||||||||||||||||||
117 | if (type != r.type)
| 12-2728 | ||||||||||||||||||
118 | qmlWarning(nullptr) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); executed 12 times by 2 tests: qmlWarning(nullptr) << ([]() noexcept -> QString { enum { Size = sizeof(u"" "Can't assign to existing role '%1' of different type [%2 -> %3]")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) ...ign to existing role '%1' of different type [%2 -> %3]" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()).arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type)); Executed by:
executed 12 times by 2 tests: return qstring_literal_temp; Executed by:
| 12 | ||||||||||||||||||
119 | return r; executed 2740 times by 8 tests: return r; Executed by:
| 2740 | ||||||||||||||||||
120 | } | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | QString qkey = key->toQString(); | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | return createRole(qkey, type); executed 1208 times by 7 tests: return createRole(qkey, type); Executed by:
| 1208 | ||||||||||||||||||
125 | } | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | const ListLayout::Role &ListLayout::createRole(const QString &key, ListLayout::Role::DataType type) | - | ||||||||||||||||||
128 | { | - | ||||||||||||||||||
129 | const int dataSizes[] = { sizeof(StringOrTranslation), sizeof(double), sizeof(bool), sizeof(ListModel *), sizeof(QPointer<QObject>), sizeof(QVariantMap), sizeof(QDateTime), sizeof(QJSValue) }; | - | ||||||||||||||||||
130 | const int dataAlignments[] = { sizeof(StringOrTranslation), sizeof(double), sizeof(bool), sizeof(ListModel *), sizeof(QObject *), sizeof(QVariantMap), sizeof(QDateTime), sizeof(QJSValue) }; | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | Role *r = new Role; | - | ||||||||||||||||||
133 | r->name = key; | - | ||||||||||||||||||
134 | r->type = type; | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | if (type == Role::List) {
| 128-1990 | ||||||||||||||||||
137 | r->subLayout = new ListLayout; | - | ||||||||||||||||||
138 | } else { executed 128 times by 4 tests: end of block Executed by:
| 128 | ||||||||||||||||||
139 | r->subLayout = nullptr; | - | ||||||||||||||||||
140 | } executed 1990 times by 15 tests: end of block Executed by:
| 1990 | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | int dataSize = dataSizes[type]; | - | ||||||||||||||||||
143 | int dataAlignment = dataAlignments[type]; | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | int dataOffset = (currentBlockOffset + dataAlignment-1) & ~(dataAlignment-1); | - | ||||||||||||||||||
146 | if (dataOffset + dataSize > ListElement::BLOCK_SIZE) {
| 6-2112 | ||||||||||||||||||
147 | r->blockIndex = ++currentBlock; | - | ||||||||||||||||||
148 | r->blockOffset = 0; | - | ||||||||||||||||||
149 | currentBlockOffset = dataSize; | - | ||||||||||||||||||
150 | } else { executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
151 | r->blockIndex = currentBlock; | - | ||||||||||||||||||
152 | r->blockOffset = dataOffset; | - | ||||||||||||||||||
153 | currentBlockOffset = dataOffset + dataSize; | - | ||||||||||||||||||
154 | } executed 2112 times by 15 tests: end of block Executed by:
| 2112 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | int roleIndex = roles.count(); | - | ||||||||||||||||||
157 | r->index = roleIndex; | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | roles.append(r); | - | ||||||||||||||||||
160 | roleHash.insert(key, r); | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | return *r; executed 2118 times by 15 tests: return *r; Executed by:
| 2118 | ||||||||||||||||||
163 | } | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | ListLayout::ListLayout(const ListLayout *other) : currentBlock(0), currentBlockOffset(0) | - | ||||||||||||||||||
166 | { | - | ||||||||||||||||||
167 | const int otherRolesCount = other->roles.count(); | - | ||||||||||||||||||
168 | roles.reserve(otherRolesCount); | - | ||||||||||||||||||
169 | for (int i=0 ; i < otherRolesCount; ++i) {
| 90-942 | ||||||||||||||||||
170 | Role *role = new Role(other->roles[i]); | - | ||||||||||||||||||
171 | roles.append(role); | - | ||||||||||||||||||
172 | roleHash.insert(role->name, role); | - | ||||||||||||||||||
173 | } executed 90 times by 1 test: end of block Executed by:
| 90 | ||||||||||||||||||
174 | currentBlockOffset = other->currentBlockOffset; | - | ||||||||||||||||||
175 | currentBlock = other->currentBlock; | - | ||||||||||||||||||
176 | } executed 942 times by 2 tests: end of block Executed by:
| 942 | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | ListLayout::~ListLayout() | - | ||||||||||||||||||
179 | { | - | ||||||||||||||||||
180 | qDeleteAll(roles); | - | ||||||||||||||||||
181 | } executed 3516 times by 15 tests: end of block Executed by:
| 3516 | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | void ListLayout::sync(ListLayout *src, ListLayout *target) | - | ||||||||||||||||||
184 | { | - | ||||||||||||||||||
185 | int roleOffset = target->roles.count(); | - | ||||||||||||||||||
186 | int newRoleCount = src->roles.count() - roleOffset; | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | for (int i=0 ; i < newRoleCount ; ++i) {
| 476-926 | ||||||||||||||||||
189 | Role *role = new Role(src->roles[roleOffset + i]); | - | ||||||||||||||||||
190 | target->roles.append(role); | - | ||||||||||||||||||
191 | target->roleHash.insert(role->name, role); | - | ||||||||||||||||||
192 | } executed 476 times by 1 test: end of block Executed by:
| 476 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | target->currentBlockOffset = src->currentBlockOffset; | - | ||||||||||||||||||
195 | target->currentBlock = src->currentBlock; | - | ||||||||||||||||||
196 | } executed 926 times by 2 tests: end of block Executed by:
| 926 | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | ListLayout::Role::Role(const Role *other) | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | name = other->name; | - | ||||||||||||||||||
201 | type = other->type; | - | ||||||||||||||||||
202 | blockIndex = other->blockIndex; | - | ||||||||||||||||||
203 | blockOffset = other->blockOffset; | - | ||||||||||||||||||
204 | index = other->index; | - | ||||||||||||||||||
205 | if (other->subLayout)
| 38-528 | ||||||||||||||||||
206 | subLayout = new ListLayout(other->subLayout); executed 38 times by 1 test: subLayout = new ListLayout(other->subLayout); Executed by:
| 38 | ||||||||||||||||||
207 | else | - | ||||||||||||||||||
208 | subLayout = nullptr; executed 528 times by 1 test: subLayout = nullptr; Executed by:
| 528 | ||||||||||||||||||
209 | } | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | ListLayout::Role::~Role() | - | ||||||||||||||||||
212 | { | - | ||||||||||||||||||
213 | delete subLayout; | - | ||||||||||||||||||
214 | } executed 2672 times by 15 tests: end of block Executed by:
| 2672 | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | const ListLayout::Role *ListLayout::getRoleOrCreate(const QString &key, const QVariant &data) | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | Role::DataType type; | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | switch (data.type()) { | - | ||||||||||||||||||
221 | case QVariant::Double: type = Role::Number; break; executed 302 times by 4 tests: break; Executed by:
executed 302 times by 4 tests: case QVariant::Double: Executed by:
| 302 | ||||||||||||||||||
222 | case QVariant::Int: type = Role::Number; break; executed 144 times by 4 tests: break; Executed by:
executed 144 times by 4 tests: case QVariant::Int: Executed by:
| 144 | ||||||||||||||||||
223 | case QVariant::Bool: type = Role::Bool; break; executed 66 times by 3 tests: break; Executed by:
executed 66 times by 3 tests: case QVariant::Bool: Executed by:
| 66 | ||||||||||||||||||
224 | case QVariant::String: type = Role::String; break; executed 3944 times by 11 tests: break; Executed by:
executed 3944 times by 11 tests: case QVariant::String: Executed by:
| 3944 | ||||||||||||||||||
225 | case QVariant::Map: type = Role::VariantMap; break; never executed: break; never executed: case QVariant::Map: | 0 | ||||||||||||||||||
226 | case QVariant::DateTime: type = Role::DateTime; break; executed 2 times by 1 test: break; Executed by:
executed 2 times by 1 test: case QVariant::DateTime: Executed by:
| 2 | ||||||||||||||||||
227 | case QVariant::UserType: { executed 42 times by 4 tests: case QVariant::UserType: Executed by:
| 42 | ||||||||||||||||||
228 | if (data.userType() == qMetaTypeId<QJSValue>() &&
| 0-42 | ||||||||||||||||||
229 | data.value<QJSValue>().isCallable()) {
| 0 | ||||||||||||||||||
230 | type = Role::Function; | - | ||||||||||||||||||
231 | break; never executed: break; | 0 | ||||||||||||||||||
232 | } else if (data.userType() == qMetaTypeId<const QV4::CompiledData::Binding*>()
| 8-34 | ||||||||||||||||||
233 | && data.value<const QV4::CompiledData::Binding*>()->isTranslationBinding()) {
| 0-8 | ||||||||||||||||||
234 | type = Role::String; | - | ||||||||||||||||||
235 | break; executed 8 times by 3 tests: break; Executed by:
| 8 | ||||||||||||||||||
236 | } else { | - | ||||||||||||||||||
237 | type = Role::List; | - | ||||||||||||||||||
238 | break; executed 34 times by 2 tests: break; Executed by:
| 34 | ||||||||||||||||||
239 | } | - | ||||||||||||||||||
240 | } | - | ||||||||||||||||||
241 | default: type = Role::Invalid; break; executed 2 times by 1 test: break; Executed by:
executed 2 times by 1 test: default: Executed by:
| 2 | ||||||||||||||||||
242 | } | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | if (type == Role::Invalid) {
| 2-4500 | ||||||||||||||||||
245 | qmlWarning(nullptr) << "Can't create role for unsupported data type"; | - | ||||||||||||||||||
246 | return nullptr; executed 2 times by 1 test: return nullptr; Executed by:
| 2 | ||||||||||||||||||
247 | } | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | return &getRoleOrCreate(key, type); executed 4500 times by 14 tests: return &getRoleOrCreate(key, type); Executed by:
| 4500 | ||||||||||||||||||
250 | } | - | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | const ListLayout::Role *ListLayout::getExistingRole(const QString &key) const | - | ||||||||||||||||||
253 | { | - | ||||||||||||||||||
254 | Role *r = nullptr; | - | ||||||||||||||||||
255 | QStringHash<Role *>::Node *node = roleHash.findNode(key); | - | ||||||||||||||||||
256 | if (node)
| 0-58 | ||||||||||||||||||
257 | r = node->value; executed 58 times by 2 tests: r = node->value; Executed by:
| 58 | ||||||||||||||||||
258 | return r; executed 58 times by 2 tests: return r; Executed by:
| 58 | ||||||||||||||||||
259 | } | - | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key) const | - | ||||||||||||||||||
262 | { | - | ||||||||||||||||||
263 | Role *r = nullptr; | - | ||||||||||||||||||
264 | QStringHash<Role *>::Node *node = roleHash.findNode(key); | - | ||||||||||||||||||
265 | if (node)
| 8-862 | ||||||||||||||||||
266 | r = node->value; executed 862 times by 8 tests: r = node->value; Executed by:
| 862 | ||||||||||||||||||
267 | return r; executed 870 times by 8 tests: return r; Executed by:
| 870 | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | StringOrTranslation::StringOrTranslation(const QString &s) | - | ||||||||||||||||||
271 | { | - | ||||||||||||||||||
272 | d.setFlag(); | - | ||||||||||||||||||
273 | setString(s); | - | ||||||||||||||||||
274 | } executed 1170 times by 8 tests: end of block Executed by:
| 1170 | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | StringOrTranslation::StringOrTranslation(const QV4::CompiledData::Binding *binding) | - | ||||||||||||||||||
277 | { | - | ||||||||||||||||||
278 | d.setFlag(); | - | ||||||||||||||||||
279 | clear(); | - | ||||||||||||||||||
280 | d = binding; | - | ||||||||||||||||||
281 | } never executed: end of block | 0 | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | StringOrTranslation::~StringOrTranslation() | - | ||||||||||||||||||
284 | { | - | ||||||||||||||||||
285 | clear(); | - | ||||||||||||||||||
286 | } executed 5122 times by 14 tests: end of block Executed by:
| 5122 | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | void StringOrTranslation::setString(const QString &s) | - | ||||||||||||||||||
289 | { | - | ||||||||||||||||||
290 | d.setFlag(); | - | ||||||||||||||||||
291 | clear(); | - | ||||||||||||||||||
292 | QStringData *stringData = const_cast<QString &>(s).data_ptr(); | - | ||||||||||||||||||
293 | d = stringData; | - | ||||||||||||||||||
294 | if (stringData)
| 0-5126 | ||||||||||||||||||
295 | stringData->ref.ref(); executed 5126 times by 13 tests: stringData->ref.ref(); Executed by:
| 5126 | ||||||||||||||||||
296 | } executed 5126 times by 13 tests: end of block Executed by:
| 5126 | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | void StringOrTranslation::setTranslation(const QV4::CompiledData::Binding *binding) | - | ||||||||||||||||||
299 | { | - | ||||||||||||||||||
300 | d.setFlag(); | - | ||||||||||||||||||
301 | clear(); | - | ||||||||||||||||||
302 | d = binding; | - | ||||||||||||||||||
303 | } executed 8 times by 3 tests: end of block Executed by:
| 8 | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | QString StringOrTranslation::toString(const QQmlListModel *owner) const | - | ||||||||||||||||||
306 | { | - | ||||||||||||||||||
307 | if (d.isNull())
| 0-10271 | ||||||||||||||||||
308 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
309 | if (d.isT1()) {
| 10-10261 | ||||||||||||||||||
310 | QStringDataPtr holder = { d.asT1() }; | - | ||||||||||||||||||
311 | holder.ptr->ref.ref(); | - | ||||||||||||||||||
312 | return QString(holder); executed 10261 times by 11 tests: return QString(holder); Executed by:
| 10261 | ||||||||||||||||||
313 | } | - | ||||||||||||||||||
314 | if (!owner)
| 0-10 | ||||||||||||||||||
315 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
316 | return d.asT2()->valueAsString(owner->m_compilationUnit->data); executed 10 times by 3 tests: return d.asT2()->valueAsString(owner->m_compilationUnit->data); Executed by:
| 10 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | QString StringOrTranslation::asString() const | - | ||||||||||||||||||
320 | { | - | ||||||||||||||||||
321 | if (d.isNull())
| 0-6 | ||||||||||||||||||
322 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
323 | if (!d.isT1())
| 0-6 | ||||||||||||||||||
324 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
325 | QStringDataPtr holder = { d.asT1() }; | - | ||||||||||||||||||
326 | holder.ptr->ref.ref(); | - | ||||||||||||||||||
327 | return QString(holder); executed 6 times by 2 tests: return QString(holder); Executed by:
| 6 | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | void StringOrTranslation::clear() | - | ||||||||||||||||||
331 | { | - | ||||||||||||||||||
332 | if (QStringData *strData = d.isT1() ? d.asT1() : nullptr) {
| 8-10248 | ||||||||||||||||||
333 | if (!strData->ref.deref())
| 105-5015 | ||||||||||||||||||
334 | QStringData::deallocate(strData); executed 105 times by 7 tests: QStringData::deallocate(strData); Executed by:
| 105 | ||||||||||||||||||
335 | } executed 5120 times by 13 tests: end of block Executed by:
| 5120 | ||||||||||||||||||
336 | d = static_cast<QStringData *>(nullptr); | - | ||||||||||||||||||
337 | } executed 10256 times by 14 tests: end of block Executed by:
| 10256 | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | QObject *ListModel::getOrCreateModelObject(QQmlListModel *model, int elementIndex) | - | ||||||||||||||||||
340 | { | - | ||||||||||||||||||
341 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
342 | if (e->m_objectCache == nullptr) {
| 298-660 | ||||||||||||||||||
343 | void *memory = operator new(sizeof(QObject) + sizeof(QQmlData)); | - | ||||||||||||||||||
344 | void *ddataMemory = ((char *)memory) + sizeof(QObject); | - | ||||||||||||||||||
345 | e->m_objectCache = new (memory) QObject; | - | ||||||||||||||||||
346 | QQmlData *ddata = new (ddataMemory) QQmlData; | - | ||||||||||||||||||
347 | ddata->ownMemory = false; | - | ||||||||||||||||||
348 | QObjectPrivate::get(e->m_objectCache)->declarativeData = ddata; | - | ||||||||||||||||||
349 | (void)new ModelNodeMetaObject(e->m_objectCache, model, elementIndex); | - | ||||||||||||||||||
350 | } executed 660 times by 8 tests: end of block Executed by:
| 660 | ||||||||||||||||||
351 | return e->m_objectCache; executed 958 times by 8 tests: return e->m_objectCache; Executed by:
| 958 | ||||||||||||||||||
352 | } | - | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | bool ListModel::sync(ListModel *src, ListModel *target) | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | // Sanity check | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | bool hasChanges = false; | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | // Build hash of elements <-> uid for each of the lists | - | ||||||||||||||||||
361 | QHash<int, ElementSync> elementHash; | - | ||||||||||||||||||
362 | for (int i = 0; i < target->elements.count(); ++i) {
| 64-926 | ||||||||||||||||||
363 | ListElement *e = target->elements.at(i); | - | ||||||||||||||||||
364 | int uid = e->getUid(); | - | ||||||||||||||||||
365 | ElementSync sync; | - | ||||||||||||||||||
366 | sync.target = e; | - | ||||||||||||||||||
367 | sync.targetIndex = i; | - | ||||||||||||||||||
368 | elementHash.insert(uid, sync); | - | ||||||||||||||||||
369 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||
370 | for (int i = 0; i < src->elements.count(); ++i) {
| 694-926 | ||||||||||||||||||
371 | ListElement *e = src->elements.at(i); | - | ||||||||||||||||||
372 | int uid = e->getUid(); | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | QHash<int, ElementSync>::iterator it = elementHash.find(uid); | - | ||||||||||||||||||
375 | if (it == elementHash.end()) {
| 60-634 | ||||||||||||||||||
376 | ElementSync sync; | - | ||||||||||||||||||
377 | sync.src = e; | - | ||||||||||||||||||
378 | sync.srcIndex = i; | - | ||||||||||||||||||
379 | elementHash.insert(uid, sync); | - | ||||||||||||||||||
380 | } else { executed 634 times by 1 test: end of block Executed by:
| 634 | ||||||||||||||||||
381 | ElementSync &sync = it.value(); | - | ||||||||||||||||||
382 | sync.src = e; | - | ||||||||||||||||||
383 | sync.srcIndex = i; | - | ||||||||||||||||||
384 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
385 | } | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | QQmlListModel *targetModel = target->m_modelCache; | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | // Get list of elements that are in the target but no longer in the source. These get deleted first. | - | ||||||||||||||||||
390 | int rowsRemoved = 0; | - | ||||||||||||||||||
391 | for (int i = 0 ; i < target->elements.count() ; ++i) {
| 64-926 | ||||||||||||||||||
392 | ListElement *element = target->elements.at(i); | - | ||||||||||||||||||
393 | ElementSync &s = elementHash.find(element->getUid()).value(); | - | ||||||||||||||||||
394 | Q_ASSERT(s.targetIndex >= 0); | - | ||||||||||||||||||
395 | // need to update the targetIndex, to keep it correct after removals | - | ||||||||||||||||||
396 | s.targetIndex -= rowsRemoved; | - | ||||||||||||||||||
397 | if (s.src == nullptr) {
| 4-60 | ||||||||||||||||||
398 | Q_ASSERT(s.targetIndex == i); | - | ||||||||||||||||||
399 | hasChanges = true; | - | ||||||||||||||||||
400 | if (targetModel)
| 0-4 | ||||||||||||||||||
401 | targetModel->beginRemoveRows(QModelIndex(), i, i); executed 4 times by 1 test: targetModel->beginRemoveRows(QModelIndex(), i, i); Executed by:
| 4 | ||||||||||||||||||
402 | s.target->destroy(target->m_layout); | - | ||||||||||||||||||
403 | target->elements.removeOne(s.target); | - | ||||||||||||||||||
404 | delete s.target; | - | ||||||||||||||||||
405 | if (targetModel)
| 0-4 | ||||||||||||||||||
406 | targetModel->endRemoveRows(); executed 4 times by 1 test: targetModel->endRemoveRows(); Executed by:
| 4 | ||||||||||||||||||
407 | ++rowsRemoved; | - | ||||||||||||||||||
408 | --i; | - | ||||||||||||||||||
409 | continue; executed 4 times by 1 test: continue; Executed by:
| 4 | ||||||||||||||||||
410 | } | - | ||||||||||||||||||
411 | } executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | // Sync the layouts | - | ||||||||||||||||||
414 | ListLayout::sync(src->m_layout, target->m_layout); | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | // Clear the target list, and append in correct order from the source | - | ||||||||||||||||||
417 | target->elements.clear(); | - | ||||||||||||||||||
418 | for (int i = 0; i < src->elements.count(); ++i) {
| 694-926 | ||||||||||||||||||
419 | ListElement *srcElement = src->elements.at(i); | - | ||||||||||||||||||
420 | ElementSync &s = elementHash.find(srcElement->getUid()).value(); | - | ||||||||||||||||||
421 | Q_ASSERT(s.srcIndex >= 0); | - | ||||||||||||||||||
422 | ListElement *targetElement = s.target; | - | ||||||||||||||||||
423 | if (targetElement == nullptr) {
| 60-634 | ||||||||||||||||||
424 | targetElement = new ListElement(srcElement->getUid()); | - | ||||||||||||||||||
425 | } executed 634 times by 1 test: end of block Executed by:
| 634 | ||||||||||||||||||
426 | s.changedRoles = ListElement::sync(srcElement, src->m_layout, targetElement, target->m_layout); | - | ||||||||||||||||||
427 | target->elements.append(targetElement); | - | ||||||||||||||||||
428 | } executed 694 times by 1 test: end of block Executed by:
| 694 | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | target->updateCacheIndices(); | - | ||||||||||||||||||
431 | - | |||||||||||||||||||
432 | // Update values stored in target meta objects | - | ||||||||||||||||||
433 | for (int i=0 ; i < target->elements.count() ; ++i) {
| 694-926 | ||||||||||||||||||
434 | ListElement *e = target->elements[i]; | - | ||||||||||||||||||
435 | if (ModelNodeMetaObject *mo = e->objectCache())
| 0-694 | ||||||||||||||||||
436 | mo->updateValues(); never executed: mo->updateValues(); | 0 | ||||||||||||||||||
437 | } executed 694 times by 1 test: end of block Executed by:
| 694 | ||||||||||||||||||
438 | - | |||||||||||||||||||
439 | // now emit the change notifications required. This can be safely done, as we're only emitting changes, moves and inserts, | - | ||||||||||||||||||
440 | // so the model indices can't be out of bounds | - | ||||||||||||||||||
441 | // | - | ||||||||||||||||||
442 | // to ensure things are kept in the correct order, emit inserts and moves first. This shouls ensure all persistent | - | ||||||||||||||||||
443 | // model indices are updated correctly | - | ||||||||||||||||||
444 | int rowsInserted = 0; | - | ||||||||||||||||||
445 | for (int i = 0 ; i < target->elements.count() ; ++i) {
| 694-926 | ||||||||||||||||||
446 | ListElement *element = target->elements.at(i); | - | ||||||||||||||||||
447 | ElementSync &s = elementHash.find(element->getUid()).value(); | - | ||||||||||||||||||
448 | Q_ASSERT(s.srcIndex >= 0); | - | ||||||||||||||||||
449 | s.srcIndex += rowsInserted; | - | ||||||||||||||||||
450 | if (s.srcIndex != s.targetIndex) {
| 60-634 | ||||||||||||||||||
451 | if (targetModel) {
| 90-544 | ||||||||||||||||||
452 | if (s.targetIndex == -1) {
| 0-544 | ||||||||||||||||||
453 | targetModel->beginInsertRows(QModelIndex(), i, i); | - | ||||||||||||||||||
454 | targetModel->endInsertRows(); | - | ||||||||||||||||||
455 | } else { executed 544 times by 1 test: end of block Executed by:
| 544 | ||||||||||||||||||
456 | targetModel->beginMoveRows(QModelIndex(), i, i, QModelIndex(), s.srcIndex); | - | ||||||||||||||||||
457 | targetModel->endMoveRows(); | - | ||||||||||||||||||
458 | } never executed: end of block | 0 | ||||||||||||||||||
459 | } | - | ||||||||||||||||||
460 | hasChanges = true; | - | ||||||||||||||||||
461 | ++rowsInserted; | - | ||||||||||||||||||
462 | } executed 634 times by 1 test: end of block Executed by:
| 634 | ||||||||||||||||||
463 | if (s.targetIndex != -1 && !s.changedRoles.isEmpty()) {
| 10-634 | ||||||||||||||||||
464 | QModelIndex idx = targetModel->createIndex(i, 0); | - | ||||||||||||||||||
465 | if (targetModel)
| 0-10 | ||||||||||||||||||
466 | targetModel->dataChanged(idx, idx, s.changedRoles); executed 10 times by 1 test: targetModel->dataChanged(idx, idx, s.changedRoles); Executed by:
| 10 | ||||||||||||||||||
467 | hasChanges = true; | - | ||||||||||||||||||
468 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
469 | } executed 694 times by 1 test: end of block Executed by:
| 694 | ||||||||||||||||||
470 | return hasChanges; executed 926 times by 2 tests: return hasChanges; Executed by:
| 926 | ||||||||||||||||||
471 | } | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | ListModel::ListModel(ListLayout *layout, QQmlListModel *modelCache) : m_layout(layout), m_modelCache(modelCache) | - | ||||||||||||||||||
474 | { | - | ||||||||||||||||||
475 | } executed 3596 times by 15 tests: end of block Executed by:
| 3596 | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | void ListModel::destroy() | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | for (const auto &destroyer : remove(0, elements.count())) | - | ||||||||||||||||||
480 | destroyer(); executed 6288 times by 15 tests: destroyer(); Executed by:
| 6288 | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | m_layout = nullptr; | - | ||||||||||||||||||
483 | if (m_modelCache && m_modelCache->m_primary == false)
| 98-3490 | ||||||||||||||||||
484 | delete m_modelCache; executed 138 times by 4 tests: delete m_modelCache; Executed by:
| 138 | ||||||||||||||||||
485 | m_modelCache = nullptr; | - | ||||||||||||||||||
486 | } executed 3588 times by 15 tests: end of block Executed by:
| 3588 | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | int ListModel::appendElement() | - | ||||||||||||||||||
489 | { | - | ||||||||||||||||||
490 | int elementIndex = elements.count(); | - | ||||||||||||||||||
491 | newElement(elementIndex); | - | ||||||||||||||||||
492 | return elementIndex; executed 5560 times by 15 tests: return elementIndex; Executed by:
| 5560 | ||||||||||||||||||
493 | } | - | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | void ListModel::insertElement(int index) | - | ||||||||||||||||||
496 | { | - | ||||||||||||||||||
497 | newElement(index); | - | ||||||||||||||||||
498 | updateCacheIndices(index); | - | ||||||||||||||||||
499 | } executed 460 times by 5 tests: end of block Executed by:
| 460 | ||||||||||||||||||
500 | - | |||||||||||||||||||
501 | void ListModel::move(int from, int to, int n) | - | ||||||||||||||||||
502 | { | - | ||||||||||||||||||
503 | if (from > to) {
| 34-54 | ||||||||||||||||||
504 | // Only move forwards - flip if backwards moving | - | ||||||||||||||||||
505 | int tfrom = from; | - | ||||||||||||||||||
506 | int tto = to; | - | ||||||||||||||||||
507 | from = tto; | - | ||||||||||||||||||
508 | to = tto+n; | - | ||||||||||||||||||
509 | n = tfrom-tto; | - | ||||||||||||||||||
510 | } executed 34 times by 4 tests: end of block Executed by:
| 34 | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | QPODVector<ListElement *, 4> store; | - | ||||||||||||||||||
513 | for (int i=0 ; i < (to-from) ; ++i)
| 88-94 | ||||||||||||||||||
514 | store.append(elements[from+n+i]); executed 94 times by 5 tests: store.append(elements[from+n+i]); Executed by:
| 94 | ||||||||||||||||||
515 | for (int i=0 ; i < n ; ++i)
| 88-126 | ||||||||||||||||||
516 | store.append(elements[from+i]); executed 126 times by 5 tests: store.append(elements[from+i]); Executed by:
| 126 | ||||||||||||||||||
517 | for (int i=0 ; i < store.count() ; ++i)
| 88-220 | ||||||||||||||||||
518 | elements[from+i] = store[i]; executed 220 times by 5 tests: elements[from+i] = store[i]; Executed by:
| 220 | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | updateCacheIndices(from, to + n); | - | ||||||||||||||||||
521 | } executed 88 times by 5 tests: end of block Executed by:
| 88 | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | void ListModel::newElement(int index) | - | ||||||||||||||||||
524 | { | - | ||||||||||||||||||
525 | ListElement *e = new ListElement; | - | ||||||||||||||||||
526 | elements.insert(index, e); | - | ||||||||||||||||||
527 | } executed 6020 times by 15 tests: end of block Executed by:
| 6020 | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | void ListModel::updateCacheIndices(int start, int end) | - | ||||||||||||||||||
530 | { | - | ||||||||||||||||||
531 | int count = elements.count(); | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | if (end < 0 || end > count)
| 0-5250 | ||||||||||||||||||
534 | end = count; executed 5250 times by 15 tests: end = count; Executed by:
| 5250 | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | for (int i = start; i < end; ++i) {
| 3118-5338 | ||||||||||||||||||
537 | ListElement *e = elements.at(i); | - | ||||||||||||||||||
538 | if (ModelNodeMetaObject *mo = e->objectCache())
| 324-2794 | ||||||||||||||||||
539 | mo->m_elementIndex = i; executed 324 times by 3 tests: mo->m_elementIndex = i; Executed by:
| 324 | ||||||||||||||||||
540 | } executed 3118 times by 6 tests: end of block Executed by:
| 3118 | ||||||||||||||||||
541 | } executed 5338 times by 15 tests: end of block Executed by:
| 5338 | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | QVariant ListModel::getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng) | - | ||||||||||||||||||
544 | { | - | ||||||||||||||||||
545 | if (roleIndex >= m_layout->roleCount())
| 2-11583 | ||||||||||||||||||
546 | return QVariant(); executed 2 times by 1 test: return QVariant(); Executed by:
| 2 | ||||||||||||||||||
547 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
548 | const ListLayout::Role &r = m_layout->getExistingRole(roleIndex); | - | ||||||||||||||||||
549 | return e->getProperty(r, owner, eng); executed 11583 times by 13 tests: return e->getProperty(r, owner, eng); Executed by:
| 11583 | ||||||||||||||||||
550 | } | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | ListModel *ListModel::getListProperty(int elementIndex, const ListLayout::Role &role) | - | ||||||||||||||||||
553 | { | - | ||||||||||||||||||
554 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
555 | return e->getListProperty(role); executed 62 times by 2 tests: return e->getListProperty(role); Executed by:
| 62 | ||||||||||||||||||
556 | } | - | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles) | - | ||||||||||||||||||
559 | { | - | ||||||||||||||||||
560 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | QV4::ExecutionEngine *v4 = object->engine(); | - | ||||||||||||||||||
563 | QV4::Scope scope(v4); | - | ||||||||||||||||||
564 | QV4::ScopedObject o(scope); | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); | - | ||||||||||||||||||
567 | QV4::ScopedString propertyName(scope); | - | ||||||||||||||||||
568 | QV4::ScopedValue propertyValue(scope); | - | ||||||||||||||||||
569 | while (1) { | - | ||||||||||||||||||
570 | propertyName = it.nextPropertyNameAsString(propertyValue); | - | ||||||||||||||||||
571 | if (!propertyName)
| 122-134 | ||||||||||||||||||
572 | break; executed 122 times by 2 tests: break; Executed by:
| 122 | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | // Check if this key exists yet | - | ||||||||||||||||||
575 | int roleIndex = -1; | - | ||||||||||||||||||
576 | - | |||||||||||||||||||
577 | // Add the value now | - | ||||||||||||||||||
578 | if (const QV4::String *s = propertyValue->as<QV4::String>()) {
| 6-128 | ||||||||||||||||||
579 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); | - | ||||||||||||||||||
580 | roleIndex = e->setStringProperty(r, s->toQString()); | - | ||||||||||||||||||
581 | } else if (propertyValue->isNumber()) { executed 6 times by 2 tests: end of block Executed by:
| 6-68 | ||||||||||||||||||
582 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); | - | ||||||||||||||||||
583 | roleIndex = e->setDoubleProperty(r, propertyValue->asDouble()); | - | ||||||||||||||||||
584 | } else if (QV4::ArrayObject *a = propertyValue->as<QV4::ArrayObject>()) { executed 68 times by 2 tests: end of block Executed by:
| 22-68 | ||||||||||||||||||
585 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List); | - | ||||||||||||||||||
586 | ListModel *subModel = new ListModel(r.subLayout, nullptr); | - | ||||||||||||||||||
587 | - | |||||||||||||||||||
588 | int arrayLength = a->getLength(); | - | ||||||||||||||||||
589 | for (int j=0 ; j < arrayLength ; ++j) {
| 22-32 | ||||||||||||||||||
590 | o = a->get(j); | - | ||||||||||||||||||
591 | subModel->append(o); | - | ||||||||||||||||||
592 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | roleIndex = e->setListProperty(r, subModel); | - | ||||||||||||||||||
595 | } else if (propertyValue->isBoolean()) { executed 22 times by 2 tests: end of block Executed by:
| 4-34 | ||||||||||||||||||
596 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Bool); | - | ||||||||||||||||||
597 | roleIndex = e->setBoolProperty(r, propertyValue->booleanValue()); | - | ||||||||||||||||||
598 | } else if (QV4::DateObject *dd = propertyValue->as<QV4::DateObject>()) { executed 4 times by 1 test: end of block Executed by:
| 2-32 | ||||||||||||||||||
599 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::DateTime); | - | ||||||||||||||||||
600 | QDateTime dt = dd->toQDateTime(); | - | ||||||||||||||||||
601 | roleIndex = e->setDateTimeProperty(r, dt); | - | ||||||||||||||||||
602 | } else if (QV4::FunctionObject *f = propertyValue->as<QV4::FunctionObject>()) { executed 2 times by 1 test: end of block Executed by:
| 0-32 | ||||||||||||||||||
603 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Function); | - | ||||||||||||||||||
604 | QV4::ScopedFunctionObject func(scope, f); | - | ||||||||||||||||||
605 | QJSValue jsv; | - | ||||||||||||||||||
606 | QJSValuePrivate::setValue(&jsv, v4, func); | - | ||||||||||||||||||
607 | roleIndex = e->setFunctionProperty(r, jsv); | - | ||||||||||||||||||
608 | } else if (QV4::Object *o = propertyValue->as<QV4::Object>()) { never executed: end of block
| 0-20 | ||||||||||||||||||
609 | if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
| 2-18 | ||||||||||||||||||
610 | QObject *o = wrapper->object(); | - | ||||||||||||||||||
611 | const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject); | - | ||||||||||||||||||
612 | if (role.type == ListLayout::Role::QObject)
| 0-2 | ||||||||||||||||||
613 | roleIndex = e->setQObjectProperty(role, o); executed 2 times by 1 test: roleIndex = e->setQObjectProperty(role, o); Executed by:
| 2 | ||||||||||||||||||
614 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
615 | const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap); | - | ||||||||||||||||||
616 | if (role.type == ListLayout::Role::VariantMap) {
| 0-18 | ||||||||||||||||||
617 | QV4::ScopedObject obj(scope, o); | - | ||||||||||||||||||
618 | roleIndex = e->setVariantMapProperty(role, obj); | - | ||||||||||||||||||
619 | } executed 18 times by 2 tests: end of block Executed by:
| 18 | ||||||||||||||||||
620 | } executed 18 times by 2 tests: end of block Executed by:
| 18 | ||||||||||||||||||
621 | } else if (propertyValue->isNullOrUndefined()) {
| 0-12 | ||||||||||||||||||
622 | const ListLayout::Role *r = m_layout->getExistingRole(propertyName); | - | ||||||||||||||||||
623 | if (r)
| 0-12 | ||||||||||||||||||
624 | e->clearProperty(*r); executed 12 times by 2 tests: e->clearProperty(*r); Executed by:
| 12 | ||||||||||||||||||
625 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | if (roleIndex != -1)
| 20-114 | ||||||||||||||||||
628 | roles->append(roleIndex); executed 114 times by 2 tests: roles->append(roleIndex); Executed by:
| 114 | ||||||||||||||||||
629 | } executed 134 times by 2 tests: end of block Executed by:
| 134 | ||||||||||||||||||
630 | - | |||||||||||||||||||
631 | if (ModelNodeMetaObject *mo = e->objectCache())
| 26-96 | ||||||||||||||||||
632 | mo->updateValues(*roles); executed 26 times by 1 test: mo->updateValues(*roles); Executed by:
| 26 | ||||||||||||||||||
633 | } executed 122 times by 2 tests: end of block Executed by:
| 122 | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | void ListModel::set(int elementIndex, QV4::Object *object) | - | ||||||||||||||||||
636 | { | - | ||||||||||||||||||
637 | if (!object)
| 6-2736 | ||||||||||||||||||
638 | return; executed 6 times by 1 test: return; Executed by:
| 6 | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | QV4::ExecutionEngine *v4 = object->engine(); | - | ||||||||||||||||||
643 | QV4::Scope scope(v4); | - | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); | - | ||||||||||||||||||
646 | QV4::ScopedString propertyName(scope); | - | ||||||||||||||||||
647 | QV4::ScopedValue propertyValue(scope); | - | ||||||||||||||||||
648 | QV4::ScopedObject o(scope); | - | ||||||||||||||||||
649 | while (1) { | - | ||||||||||||||||||
650 | propertyName = it.nextPropertyNameAsString(propertyValue); | - | ||||||||||||||||||
651 | if (!propertyName)
| 2736-3832 | ||||||||||||||||||
652 | break; executed 2736 times by 9 tests: break; Executed by:
| 2736 | ||||||||||||||||||
653 | - | |||||||||||||||||||
654 | // Add the value now | - | ||||||||||||||||||
655 | if (QV4::String *s = propertyValue->stringValue()) {
| 1176-2656 | ||||||||||||||||||
656 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); | - | ||||||||||||||||||
657 | if (r.type == ListLayout::Role::String)
| 6-1170 | ||||||||||||||||||
658 | e->setStringPropertyFast(r, s->toQString()); executed 1170 times by 8 tests: e->setStringPropertyFast(r, s->toQString()); Executed by:
| 1170 | ||||||||||||||||||
659 | } else if (propertyValue->isNumber()) { executed 1176 times by 8 tests: end of block Executed by:
| 322-2334 | ||||||||||||||||||
660 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); | - | ||||||||||||||||||
661 | if (r.type == ListLayout::Role::Number) {
| 0-2334 | ||||||||||||||||||
662 | e->setDoublePropertyFast(r, propertyValue->asDouble()); | - | ||||||||||||||||||
663 | } executed 2334 times by 5 tests: end of block Executed by:
| 2334 | ||||||||||||||||||
664 | } else if (QV4::ArrayObject *a = propertyValue->as<QV4::ArrayObject>()) { executed 2334 times by 5 tests: end of block Executed by:
| 126-2334 | ||||||||||||||||||
665 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List); | - | ||||||||||||||||||
666 | if (r.type == ListLayout::Role::List) {
| 0-126 | ||||||||||||||||||
667 | ListModel *subModel = new ListModel(r.subLayout, nullptr); | - | ||||||||||||||||||
668 | - | |||||||||||||||||||
669 | int arrayLength = a->getLength(); | - | ||||||||||||||||||
670 | for (int j=0 ; j < arrayLength ; ++j) {
| 126-344 | ||||||||||||||||||
671 | o = a->get(j); | - | ||||||||||||||||||
672 | subModel->append(o); | - | ||||||||||||||||||
673 | } executed 344 times by 3 tests: end of block Executed by:
| 344 | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | e->setListPropertyFast(r, subModel); | - | ||||||||||||||||||
676 | } executed 126 times by 3 tests: end of block Executed by:
| 126 | ||||||||||||||||||
677 | } else if (propertyValue->isBoolean()) { executed 126 times by 3 tests: end of block Executed by:
| 88-126 | ||||||||||||||||||
678 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Bool); | - | ||||||||||||||||||
679 | if (r.type == ListLayout::Role::Bool) {
| 0-88 | ||||||||||||||||||
680 | e->setBoolPropertyFast(r, propertyValue->booleanValue()); | - | ||||||||||||||||||
681 | } executed 88 times by 2 tests: end of block Executed by:
| 88 | ||||||||||||||||||
682 | } else if (QV4::DateObject *date = propertyValue->as<QV4::DateObject>()) { executed 88 times by 2 tests: end of block Executed by:
| 10-98 | ||||||||||||||||||
683 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::DateTime); | - | ||||||||||||||||||
684 | if (r.type == ListLayout::Role::DateTime) {
| 0-10 | ||||||||||||||||||
685 | QDateTime dt = date->toQDateTime();; | - | ||||||||||||||||||
686 | e->setDateTimePropertyFast(r, dt); | - | ||||||||||||||||||
687 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
688 | } else if (QV4::Object *o = propertyValue->as<QV4::Object>()) { executed 10 times by 1 test: end of block Executed by:
| 6-92 | ||||||||||||||||||
689 | if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
| 8-84 | ||||||||||||||||||
690 | QObject *o = wrapper->object(); | - | ||||||||||||||||||
691 | const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject); | - | ||||||||||||||||||
692 | if (r.type == ListLayout::Role::QObject)
| 0-8 | ||||||||||||||||||
693 | e->setQObjectPropertyFast(r, o); executed 8 times by 1 test: e->setQObjectPropertyFast(r, o); Executed by:
| 8 | ||||||||||||||||||
694 | } else { executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
695 | const ListLayout::Role &role = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::VariantMap); | - | ||||||||||||||||||
696 | if (role.type == ListLayout::Role::VariantMap)
| 0-84 | ||||||||||||||||||
697 | e->setVariantMapFast(role, o); executed 84 times by 2 tests: e->setVariantMapFast(role, o); Executed by:
| 84 | ||||||||||||||||||
698 | } executed 84 times by 2 tests: end of block Executed by:
| 84 | ||||||||||||||||||
699 | } else if (propertyValue->isNullOrUndefined()) {
| 0-6 | ||||||||||||||||||
700 | const ListLayout::Role *r = m_layout->getExistingRole(propertyName); | - | ||||||||||||||||||
701 | if (r)
| 0-6 | ||||||||||||||||||
702 | e->clearProperty(*r); never executed: e->clearProperty(*r); | 0 | ||||||||||||||||||
703 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
704 | } executed 3832 times by 9 tests: end of block Executed by:
| 3832 | ||||||||||||||||||
705 | } executed 2736 times by 9 tests: end of block Executed by:
| 2736 | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | QVector<std::function<void()>> ListModel::remove(int index, int count) | - | ||||||||||||||||||
708 | { | - | ||||||||||||||||||
709 | QVector<std::function<void()>> toDestroy; | - | ||||||||||||||||||
710 | auto layout = m_layout; | - | ||||||||||||||||||
711 | for (int i=0 ; i < count ; ++i) {
| 3864-6636 | ||||||||||||||||||
712 | auto element = elements[index+i]; | - | ||||||||||||||||||
713 | toDestroy.append([element, layout](){ | - | ||||||||||||||||||
714 | element->destroy(layout); | - | ||||||||||||||||||
715 | delete element; | - | ||||||||||||||||||
716 | }); executed 6636 times by 15 tests: end of block Executed by:
| 6636 | ||||||||||||||||||
717 | } executed 6636 times by 15 tests: end of block Executed by:
| 6636 | ||||||||||||||||||
718 | elements.remove(index, count); | - | ||||||||||||||||||
719 | updateCacheIndices(index); | - | ||||||||||||||||||
720 | return toDestroy; executed 3864 times by 15 tests: return toDestroy; Executed by:
| 3864 | ||||||||||||||||||
721 | } | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | void ListModel::insert(int elementIndex, QV4::Object *object) | - | ||||||||||||||||||
724 | { | - | ||||||||||||||||||
725 | insertElement(elementIndex); | - | ||||||||||||||||||
726 | set(elementIndex, object); | - | ||||||||||||||||||
727 | } executed 460 times by 5 tests: end of block Executed by:
| 460 | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | int ListModel::append(QV4::Object *object) | - | ||||||||||||||||||
730 | { | - | ||||||||||||||||||
731 | int elementIndex = appendElement(); | - | ||||||||||||||||||
732 | set(elementIndex, object); | - | ||||||||||||||||||
733 | return elementIndex; executed 2282 times by 8 tests: return elementIndex; Executed by:
| 2282 | ||||||||||||||||||
734 | } | - | ||||||||||||||||||
735 | - | |||||||||||||||||||
736 | int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data) | - | ||||||||||||||||||
737 | { | - | ||||||||||||||||||
738 | int roleIndex = -1; | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | if (elementIndex >= 0 && elementIndex < elements.count()) {
| 0-4502 | ||||||||||||||||||
741 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | const ListLayout::Role *r = m_layout->getRoleOrCreate(key, data); | - | ||||||||||||||||||
744 | if (r) {
| 2-4500 | ||||||||||||||||||
745 | roleIndex = e->setVariantProperty(*r, data); | - | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | ModelNodeMetaObject *cache = e->objectCache(); | - | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | if (roleIndex != -1 && cache)
| 18-4448 | ||||||||||||||||||
750 | cache->updateValues(QVector<int>(1, roleIndex)); executed 18 times by 3 tests: cache->updateValues(QVector<int>(1, roleIndex)); Executed by:
| 18 | ||||||||||||||||||
751 | } executed 4500 times by 14 tests: end of block Executed by:
| 4500 | ||||||||||||||||||
752 | } executed 4502 times by 14 tests: end of block Executed by:
| 4502 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | return roleIndex; executed 4504 times by 14 tests: return roleIndex; Executed by:
| 4504 | ||||||||||||||||||
755 | } | - | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | int ListModel::setExistingProperty(int elementIndex, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng) | - | ||||||||||||||||||
758 | { | - | ||||||||||||||||||
759 | int roleIndex = -1; | - | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | if (elementIndex >= 0 && elementIndex < elements.count()) {
| 0-58 | ||||||||||||||||||
762 | ListElement *e = elements[elementIndex]; | - | ||||||||||||||||||
763 | const ListLayout::Role *r = m_layout->getExistingRole(key); | - | ||||||||||||||||||
764 | if (r)
| 0-58 | ||||||||||||||||||
765 | roleIndex = e->setJsProperty(*r, data, eng); executed 58 times by 2 tests: roleIndex = e->setJsProperty(*r, data, eng); Executed by:
| 58 | ||||||||||||||||||
766 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | return roleIndex; executed 58 times by 2 tests: return roleIndex; Executed by:
| 58 | ||||||||||||||||||
769 | } | - | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | inline char *ListElement::getPropertyMemory(const ListLayout::Role &role) | - | ||||||||||||||||||
772 | { | - | ||||||||||||||||||
773 | ListElement *e = this; | - | ||||||||||||||||||
774 | int blockIndex = 0; | - | ||||||||||||||||||
775 | while (blockIndex < role.blockIndex) {
| 48-28247 | ||||||||||||||||||
776 | if (e->next == nullptr) {
| 10-38 | ||||||||||||||||||
777 | e->next = new ListElement; | - | ||||||||||||||||||
778 | e->next->uid = uid; | - | ||||||||||||||||||
779 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||||||||
780 | e = e->next; | - | ||||||||||||||||||
781 | ++blockIndex; | - | ||||||||||||||||||
782 | } executed 48 times by 2 tests: end of block Executed by:
| 48 | ||||||||||||||||||
783 | - | |||||||||||||||||||
784 | char *mem = &e->data[role.blockOffset]; | - | ||||||||||||||||||
785 | return mem; executed 28247 times by 15 tests: return mem; Executed by:
| 28247 | ||||||||||||||||||
786 | } | - | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | ModelNodeMetaObject *ListElement::objectCache() | - | ||||||||||||||||||
789 | { | - | ||||||||||||||||||
790 | if (!m_objectCache)
| 370-8064 | ||||||||||||||||||
791 | return nullptr; executed 8064 times by 14 tests: return nullptr; Executed by:
| 8064 | ||||||||||||||||||
792 | return ModelNodeMetaObject::get(m_objectCache); executed 370 times by 4 tests: return ModelNodeMetaObject::get(m_objectCache); Executed by:
| 370 | ||||||||||||||||||
793 | } | - | ||||||||||||||||||
794 | - | |||||||||||||||||||
795 | StringOrTranslation *ListElement::getStringProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
796 | { | - | ||||||||||||||||||
797 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
798 | StringOrTranslation *s = reinterpret_cast<StringOrTranslation *>(mem); | - | ||||||||||||||||||
799 | return s; executed 5122 times by 14 tests: return s; Executed by:
| 5122 | ||||||||||||||||||
800 | } | - | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | QObject *ListElement::getQObjectProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
803 | { | - | ||||||||||||||||||
804 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
805 | QPointer<QObject> *o = reinterpret_cast<QPointer<QObject> *>(mem); | - | ||||||||||||||||||
806 | return o->data(); never executed: return o->data(); | 0 | ||||||||||||||||||
807 | } | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | QVariantMap *ListElement::getVariantMapProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
810 | { | - | ||||||||||||||||||
811 | QVariantMap *map = nullptr; | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
814 | if (isMemoryUsed<QVariantMap>(mem))
| 172-244 | ||||||||||||||||||
815 | map = reinterpret_cast<QVariantMap *>(mem); executed 172 times by 2 tests: map = reinterpret_cast<QVariantMap *>(mem); Executed by:
| 172 | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | return map; executed 416 times by 2 tests: return map; Executed by:
| 416 | ||||||||||||||||||
818 | } | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | QDateTime *ListElement::getDateTimeProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
821 | { | - | ||||||||||||||||||
822 | QDateTime *dt = nullptr; | - | ||||||||||||||||||
823 | - | |||||||||||||||||||
824 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
825 | if (isMemoryUsed<QDateTime>(mem))
| 0-10 | ||||||||||||||||||
826 | dt = reinterpret_cast<QDateTime *>(mem); executed 10 times by 1 test: dt = reinterpret_cast<QDateTime *>(mem); Executed by:
| 10 | ||||||||||||||||||
827 | - | |||||||||||||||||||
828 | return dt; executed 10 times by 1 test: return dt; Executed by:
| 10 | ||||||||||||||||||
829 | } | - | ||||||||||||||||||
830 | - | |||||||||||||||||||
831 | QJSValue *ListElement::getFunctionProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
832 | { | - | ||||||||||||||||||
833 | QJSValue *f = nullptr; | - | ||||||||||||||||||
834 | - | |||||||||||||||||||
835 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
836 | if (isMemoryUsed<QJSValue>(mem))
| 0 | ||||||||||||||||||
837 | f = reinterpret_cast<QJSValue *>(mem); never executed: f = reinterpret_cast<QJSValue *>(mem); | 0 | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | return f; never executed: return f; | 0 | ||||||||||||||||||
840 | } | - | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | QPointer<QObject> *ListElement::getGuardProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
843 | { | - | ||||||||||||||||||
844 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
845 | - | |||||||||||||||||||
846 | bool existingGuard = false; | - | ||||||||||||||||||
847 | for (size_t i=0 ; i < sizeof(QPointer<QObject>) ; ++i) {
| 2-40 | ||||||||||||||||||
848 | if (mem[i] != 0) {
| 8-32 | ||||||||||||||||||
849 | existingGuard = true; | - | ||||||||||||||||||
850 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||
851 | } | - | ||||||||||||||||||
852 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | QPointer<QObject> *o = nullptr; | - | ||||||||||||||||||
855 | - | |||||||||||||||||||
856 | if (existingGuard)
| 2-8 | ||||||||||||||||||
857 | o = reinterpret_cast<QPointer<QObject> *>(mem); executed 8 times by 1 test: o = reinterpret_cast<QPointer<QObject> *>(mem); Executed by:
| 8 | ||||||||||||||||||
858 | - | |||||||||||||||||||
859 | return o; executed 10 times by 1 test: return o; Executed by:
| 10 | ||||||||||||||||||
860 | } | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | ListModel *ListElement::getListProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
863 | { | - | ||||||||||||||||||
864 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
865 | ListModel **value = reinterpret_cast<ListModel **>(mem); | - | ||||||||||||||||||
866 | return *value; executed 664 times by 4 tests: return *value; Executed by:
| 664 | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
868 | - | |||||||||||||||||||
869 | QVariant ListElement::getProperty(const ListLayout::Role &role, const QQmlListModel *owner, QV4::ExecutionEngine *eng) | - | ||||||||||||||||||
870 | { | - | ||||||||||||||||||
871 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | QVariant data; | - | ||||||||||||||||||
874 | - | |||||||||||||||||||
875 | switch (role.type) { | - | ||||||||||||||||||
876 | case ListLayout::Role::Number: executed 1848 times by 4 tests: case ListLayout::Role::Number: Executed by:
| 1848 | ||||||||||||||||||
877 | { | - | ||||||||||||||||||
878 | double *value = reinterpret_cast<double *>(mem); | - | ||||||||||||||||||
879 | data = *value; | - | ||||||||||||||||||
880 | } | - | ||||||||||||||||||
881 | break; executed 1848 times by 4 tests: break; Executed by:
| 1848 | ||||||||||||||||||
882 | case ListLayout::Role::String: executed 10271 times by 12 tests: case ListLayout::Role::String: Executed by:
| 10271 | ||||||||||||||||||
883 | { | - | ||||||||||||||||||
884 | StringOrTranslation *value = reinterpret_cast<StringOrTranslation *>(mem); | - | ||||||||||||||||||
885 | if (value->isSet())
| 0-10271 | ||||||||||||||||||
886 | data = value->toString(owner); executed 10271 times by 12 tests: data = value->toString(owner); Executed by:
| 10271 | ||||||||||||||||||
887 | } | - | ||||||||||||||||||
888 | break; executed 10271 times by 12 tests: break; Executed by:
| 10271 | ||||||||||||||||||
889 | case ListLayout::Role::Bool: executed 122 times by 2 tests: case ListLayout::Role::Bool: Executed by:
| 122 | ||||||||||||||||||
890 | { | - | ||||||||||||||||||
891 | bool *value = reinterpret_cast<bool *>(mem); | - | ||||||||||||||||||
892 | data = *value; | - | ||||||||||||||||||
893 | } | - | ||||||||||||||||||
894 | break; executed 122 times by 2 tests: break; Executed by:
| 122 | ||||||||||||||||||
895 | case ListLayout::Role::List: executed 202 times by 4 tests: case ListLayout::Role::List: Executed by:
| 202 | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | ListModel **value = reinterpret_cast<ListModel **>(mem); | - | ||||||||||||||||||
898 | ListModel *model = *value; | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | if (model) {
| 0-202 | ||||||||||||||||||
901 | if (model->m_modelCache == nullptr) {
| 64-138 | ||||||||||||||||||
902 | model->m_modelCache = new QQmlListModel(owner, model, eng); | - | ||||||||||||||||||
903 | QQmlEngine::setContextForObject(model->m_modelCache, QQmlEngine::contextForObject(owner)); | - | ||||||||||||||||||
904 | } executed 138 times by 4 tests: end of block Executed by:
| 138 | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | QObject *object = model->m_modelCache; | - | ||||||||||||||||||
907 | data = QVariant::fromValue(object); | - | ||||||||||||||||||
908 | } executed 202 times by 4 tests: end of block Executed by:
| 202 | ||||||||||||||||||
909 | } | - | ||||||||||||||||||
910 | break; executed 202 times by 4 tests: break; Executed by:
| 202 | ||||||||||||||||||
911 | case ListLayout::Role::QObject: executed 4 times by 1 test: case ListLayout::Role::QObject: Executed by:
| 4 | ||||||||||||||||||
912 | { | - | ||||||||||||||||||
913 | QPointer<QObject> *guard = reinterpret_cast<QPointer<QObject> *>(mem); | - | ||||||||||||||||||
914 | QObject *object = guard->data(); | - | ||||||||||||||||||
915 | if (object)
| 0-4 | ||||||||||||||||||
916 | data = QVariant::fromValue(object); executed 4 times by 1 test: data = QVariant::fromValue(object); Executed by:
| 4 | ||||||||||||||||||
917 | } | - | ||||||||||||||||||
918 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
919 | case ListLayout::Role::VariantMap: executed 24 times by 2 tests: case ListLayout::Role::VariantMap: Executed by:
| 24 | ||||||||||||||||||
920 | { | - | ||||||||||||||||||
921 | if (isMemoryUsed<QVariantMap>(mem)) {
| 0-24 | ||||||||||||||||||
922 | QVariantMap *map = reinterpret_cast<QVariantMap *>(mem); | - | ||||||||||||||||||
923 | data = *map; | - | ||||||||||||||||||
924 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
925 | } | - | ||||||||||||||||||
926 | break; executed 24 times by 2 tests: break; Executed by:
| 24 | ||||||||||||||||||
927 | case ListLayout::Role::DateTime: executed 10 times by 1 test: case ListLayout::Role::DateTime: Executed by:
| 10 | ||||||||||||||||||
928 | { | - | ||||||||||||||||||
929 | if (isMemoryUsed<QDateTime>(mem)) {
| 0-10 | ||||||||||||||||||
930 | QDateTime *dt = reinterpret_cast<QDateTime *>(mem); | - | ||||||||||||||||||
931 | data = *dt; | - | ||||||||||||||||||
932 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
933 | } | - | ||||||||||||||||||
934 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||||||||
935 | case ListLayout::Role::Function: never executed: case ListLayout::Role::Function: | 0 | ||||||||||||||||||
936 | { | - | ||||||||||||||||||
937 | if (isMemoryUsed<QJSValue>(mem)) {
| 0 | ||||||||||||||||||
938 | QJSValue *func = reinterpret_cast<QJSValue *>(mem); | - | ||||||||||||||||||
939 | data = QVariant::fromValue(*func); | - | ||||||||||||||||||
940 | } never executed: end of block | 0 | ||||||||||||||||||
941 | } | - | ||||||||||||||||||
942 | break; never executed: break; | 0 | ||||||||||||||||||
943 | default: never executed: default: | 0 | ||||||||||||||||||
944 | break; never executed: break; | 0 | ||||||||||||||||||
945 | } | - | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | return data; executed 12481 times by 13 tests: return data; Executed by:
| 12481 | ||||||||||||||||||
948 | } | - | ||||||||||||||||||
949 | - | |||||||||||||||||||
950 | int ListElement::setStringProperty(const ListLayout::Role &role, const QString &s) | - | ||||||||||||||||||
951 | { | - | ||||||||||||||||||
952 | int roleIndex = -1; | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | if (role.type == ListLayout::Role::String) {
| 0-3956 | ||||||||||||||||||
955 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
956 | StringOrTranslation *c = reinterpret_cast<StringOrTranslation *>(mem); | - | ||||||||||||||||||
957 | bool changed; | - | ||||||||||||||||||
958 | if (!c->isSet() || c->isTranslation())
| 0-3950 | ||||||||||||||||||
959 | changed = true; executed 3950 times by 12 tests: changed = true; Executed by:
| 3950 | ||||||||||||||||||
960 | else | - | ||||||||||||||||||
961 | changed = c->asString().compare(s) != 0; executed 6 times by 2 tests: changed = c->asString().compare(s) != 0; Executed by:
| 6 | ||||||||||||||||||
962 | c->setString(s); | - | ||||||||||||||||||
963 | if (changed)
| 0-3956 | ||||||||||||||||||
964 | roleIndex = role.index; executed 3956 times by 12 tests: roleIndex = role.index; Executed by:
| 3956 | ||||||||||||||||||
965 | } executed 3956 times by 12 tests: end of block Executed by:
| 3956 | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | return roleIndex; executed 3956 times by 12 tests: return roleIndex; Executed by:
| 3956 | ||||||||||||||||||
968 | } | - | ||||||||||||||||||
969 | - | |||||||||||||||||||
970 | int ListElement::setDoubleProperty(const ListLayout::Role &role, double d) | - | ||||||||||||||||||
971 | { | - | ||||||||||||||||||
972 | int roleIndex = -1; | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | if (role.type == ListLayout::Role::Number) {
| 6-1446 | ||||||||||||||||||
975 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
976 | double *value = reinterpret_cast<double *>(mem); | - | ||||||||||||||||||
977 | bool changed = *value != d; | - | ||||||||||||||||||
978 | *value = d; | - | ||||||||||||||||||
979 | if (changed)
| 236-1210 | ||||||||||||||||||
980 | roleIndex = role.index; executed 1210 times by 5 tests: roleIndex = role.index; Executed by:
| 1210 | ||||||||||||||||||
981 | } executed 1446 times by 5 tests: end of block Executed by:
| 1446 | ||||||||||||||||||
982 | - | |||||||||||||||||||
983 | return roleIndex; executed 1452 times by 5 tests: return roleIndex; Executed by:
| 1452 | ||||||||||||||||||
984 | } | - | ||||||||||||||||||
985 | - | |||||||||||||||||||
986 | int ListElement::setBoolProperty(const ListLayout::Role &role, bool b) | - | ||||||||||||||||||
987 | { | - | ||||||||||||||||||
988 | int roleIndex = -1; | - | ||||||||||||||||||
989 | - | |||||||||||||||||||
990 | if (role.type == ListLayout::Role::Bool) {
| 0-70 | ||||||||||||||||||
991 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
992 | bool *value = reinterpret_cast<bool *>(mem); | - | ||||||||||||||||||
993 | bool changed = *value != b; | - | ||||||||||||||||||
994 | *value = b; | - | ||||||||||||||||||
995 | if (changed)
| 30-40 | ||||||||||||||||||
996 | roleIndex = role.index; executed 40 times by 3 tests: roleIndex = role.index; Executed by:
| 40 | ||||||||||||||||||
997 | } executed 70 times by 3 tests: end of block Executed by:
| 70 | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | return roleIndex; executed 70 times by 3 tests: return roleIndex; Executed by:
| 70 | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | int ListElement::setListProperty(const ListLayout::Role &role, ListModel *m) | - | ||||||||||||||||||
1003 | { | - | ||||||||||||||||||
1004 | int roleIndex = -1; | - | ||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | if (role.type == ListLayout::Role::List) {
| 0-68 | ||||||||||||||||||
1007 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1008 | ListModel **value = reinterpret_cast<ListModel **>(mem); | - | ||||||||||||||||||
1009 | if (*value && *value != m) {
| 0-46 | ||||||||||||||||||
1010 | (*value)->destroy(); | - | ||||||||||||||||||
1011 | delete *value; | - | ||||||||||||||||||
1012 | } executed 22 times by 2 tests: end of block Executed by:
| 22 | ||||||||||||||||||
1013 | *value = m; | - | ||||||||||||||||||
1014 | roleIndex = role.index; | - | ||||||||||||||||||
1015 | } executed 68 times by 3 tests: end of block Executed by:
| 68 | ||||||||||||||||||
1016 | - | |||||||||||||||||||
1017 | return roleIndex; executed 68 times by 3 tests: return roleIndex; Executed by:
| 68 | ||||||||||||||||||
1018 | } | - | ||||||||||||||||||
1019 | - | |||||||||||||||||||
1020 | int ListElement::setQObjectProperty(const ListLayout::Role &role, QObject *o) | - | ||||||||||||||||||
1021 | { | - | ||||||||||||||||||
1022 | int roleIndex = -1; | - | ||||||||||||||||||
1023 | - | |||||||||||||||||||
1024 | if (role.type == ListLayout::Role::QObject) {
| 0-2 | ||||||||||||||||||
1025 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1026 | QPointer<QObject> *g = reinterpret_cast<QPointer<QObject> *>(mem); | - | ||||||||||||||||||
1027 | bool existingGuard = false; | - | ||||||||||||||||||
1028 | for (size_t i=0 ; i < sizeof(QPointer<QObject>) ; ++i) {
| 0-2 | ||||||||||||||||||
1029 | if (mem[i] != 0) {
| 0-2 | ||||||||||||||||||
1030 | existingGuard = true; | - | ||||||||||||||||||
1031 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
1032 | } | - | ||||||||||||||||||
1033 | } never executed: end of block | 0 | ||||||||||||||||||
1034 | bool changed; | - | ||||||||||||||||||
1035 | if (existingGuard) {
| 0-2 | ||||||||||||||||||
1036 | changed = g->data() != o; | - | ||||||||||||||||||
1037 | g->~QPointer(); | - | ||||||||||||||||||
1038 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1039 | changed = true; | - | ||||||||||||||||||
1040 | } never executed: end of block | 0 | ||||||||||||||||||
1041 | new (mem) QPointer<QObject>(o); | - | ||||||||||||||||||
1042 | if (changed)
| 0-2 | ||||||||||||||||||
1043 | roleIndex = role.index; executed 2 times by 1 test: roleIndex = role.index; Executed by:
| 2 | ||||||||||||||||||
1044 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | return roleIndex; executed 2 times by 1 test: return roleIndex; Executed by:
| 2 | ||||||||||||||||||
1047 | } | - | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | int ListElement::setVariantMapProperty(const ListLayout::Role &role, QV4::Object *o) | - | ||||||||||||||||||
1050 | { | - | ||||||||||||||||||
1051 | int roleIndex = -1; | - | ||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | if (role.type == ListLayout::Role::VariantMap) {
| 0-18 | ||||||||||||||||||
1054 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1055 | if (isMemoryUsed<QVariantMap>(mem)) {
| 6-12 | ||||||||||||||||||
1056 | QVariantMap *map = reinterpret_cast<QVariantMap *>(mem); | - | ||||||||||||||||||
1057 | map->~QMap(); | - | ||||||||||||||||||
1058 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1059 | new (mem) QVariantMap(o->engine()->variantMapFromJS(o)); | - | ||||||||||||||||||
1060 | roleIndex = role.index; | - | ||||||||||||||||||
1061 | } executed 18 times by 2 tests: end of block Executed by:
| 18 | ||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | return roleIndex; executed 18 times by 2 tests: return roleIndex; Executed by:
| 18 | ||||||||||||||||||
1064 | } | - | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | int ListElement::setVariantMapProperty(const ListLayout::Role &role, QVariantMap *m) | - | ||||||||||||||||||
1067 | { | - | ||||||||||||||||||
1068 | int roleIndex = -1; | - | ||||||||||||||||||
1069 | - | |||||||||||||||||||
1070 | if (role.type == ListLayout::Role::VariantMap) {
| 0-106 | ||||||||||||||||||
1071 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1072 | if (isMemoryUsed<QVariantMap>(mem)) {
| 12-94 | ||||||||||||||||||
1073 | QVariantMap *map = reinterpret_cast<QVariantMap *>(mem); | - | ||||||||||||||||||
1074 | if (m && map->isSharedWith(*m))
| 0-6 | ||||||||||||||||||
1075 | return roleIndex; executed 6 times by 1 test: return roleIndex; Executed by:
| 6 | ||||||||||||||||||
1076 | map->~QMap(); | - | ||||||||||||||||||
1077 | } else if (!m) { executed 6 times by 2 tests: end of block Executed by:
| 6-56 | ||||||||||||||||||
1078 | return roleIndex; executed 56 times by 1 test: return roleIndex; Executed by:
| 56 | ||||||||||||||||||
1079 | } | - | ||||||||||||||||||
1080 | if (m)
| 6-38 | ||||||||||||||||||
1081 | new (mem) QVariantMap(*m); executed 38 times by 1 test: new (mem) QVariantMap(*m); Executed by:
| 38 | ||||||||||||||||||
1082 | else | - | ||||||||||||||||||
1083 | new (mem) QVariantMap; executed 6 times by 2 tests: new (mem) QVariantMap; Executed by:
| 6 | ||||||||||||||||||
1084 | roleIndex = role.index; | - | ||||||||||||||||||
1085 | } executed 44 times by 2 tests: end of block Executed by:
| 44 | ||||||||||||||||||
1086 | - | |||||||||||||||||||
1087 | return roleIndex; executed 44 times by 2 tests: return roleIndex; Executed by:
| 44 | ||||||||||||||||||
1088 | } | - | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | int ListElement::setDateTimeProperty(const ListLayout::Role &role, const QDateTime &dt) | - | ||||||||||||||||||
1091 | { | - | ||||||||||||||||||
1092 | int roleIndex = -1; | - | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | if (role.type == ListLayout::Role::DateTime) {
| 0-8 | ||||||||||||||||||
1095 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1096 | if (isMemoryUsed<QDateTime>(mem)) {
| 0-8 | ||||||||||||||||||
1097 | QDateTime *dt = reinterpret_cast<QDateTime *>(mem); | - | ||||||||||||||||||
1098 | dt->~QDateTime(); | - | ||||||||||||||||||
1099 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1100 | new (mem) QDateTime(dt); | - | ||||||||||||||||||
1101 | roleIndex = role.index; | - | ||||||||||||||||||
1102 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | return roleIndex; executed 8 times by 1 test: return roleIndex; Executed by:
| 8 | ||||||||||||||||||
1105 | } | - | ||||||||||||||||||
1106 | - | |||||||||||||||||||
1107 | int ListElement::setFunctionProperty(const ListLayout::Role &role, const QJSValue &f) | - | ||||||||||||||||||
1108 | { | - | ||||||||||||||||||
1109 | int roleIndex = -1; | - | ||||||||||||||||||
1110 | - | |||||||||||||||||||
1111 | if (role.type == ListLayout::Role::Function) {
| 0 | ||||||||||||||||||
1112 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1113 | if (isMemoryUsed<QJSValue>(mem)) {
| 0 | ||||||||||||||||||
1114 | QJSValue *f = reinterpret_cast<QJSValue *>(mem); | - | ||||||||||||||||||
1115 | f->~QJSValue(); | - | ||||||||||||||||||
1116 | } never executed: end of block | 0 | ||||||||||||||||||
1117 | new (mem) QJSValue(f); | - | ||||||||||||||||||
1118 | roleIndex = role.index; | - | ||||||||||||||||||
1119 | } never executed: end of block | 0 | ||||||||||||||||||
1120 | - | |||||||||||||||||||
1121 | return roleIndex; never executed: return roleIndex; | 0 | ||||||||||||||||||
1122 | } | - | ||||||||||||||||||
1123 | - | |||||||||||||||||||
1124 | int ListElement::setTranslationProperty(const ListLayout::Role &role, const QV4::CompiledData::Binding *b) | - | ||||||||||||||||||
1125 | { | - | ||||||||||||||||||
1126 | int roleIndex = -1; | - | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | if (role.type == ListLayout::Role::String) {
| 0-8 | ||||||||||||||||||
1129 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1130 | StringOrTranslation *s = reinterpret_cast<StringOrTranslation *>(mem); | - | ||||||||||||||||||
1131 | s->setTranslation(b); | - | ||||||||||||||||||
1132 | roleIndex = role.index; | - | ||||||||||||||||||
1133 | } executed 8 times by 3 tests: end of block Executed by:
| 8 | ||||||||||||||||||
1134 | - | |||||||||||||||||||
1135 | return roleIndex; executed 8 times by 3 tests: return roleIndex; Executed by:
| 8 | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | void ListElement::setStringPropertyFast(const ListLayout::Role &role, const QString &s) | - | ||||||||||||||||||
1140 | { | - | ||||||||||||||||||
1141 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1142 | new (mem) StringOrTranslation(s); | - | ||||||||||||||||||
1143 | } executed 1170 times by 8 tests: end of block Executed by:
| 1170 | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | void ListElement::setDoublePropertyFast(const ListLayout::Role &role, double d) | - | ||||||||||||||||||
1146 | { | - | ||||||||||||||||||
1147 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1148 | double *value = new (mem) double; | - | ||||||||||||||||||
1149 | *value = d; | - | ||||||||||||||||||
1150 | } executed 2334 times by 5 tests: end of block Executed by:
| 2334 | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | void ListElement::setBoolPropertyFast(const ListLayout::Role &role, bool b) | - | ||||||||||||||||||
1153 | { | - | ||||||||||||||||||
1154 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1155 | bool *value = new (mem) bool; | - | ||||||||||||||||||
1156 | *value = b; | - | ||||||||||||||||||
1157 | } executed 88 times by 2 tests: end of block Executed by:
| 88 | ||||||||||||||||||
1158 | - | |||||||||||||||||||
1159 | void ListElement::setQObjectPropertyFast(const ListLayout::Role &role, QObject *o) | - | ||||||||||||||||||
1160 | { | - | ||||||||||||||||||
1161 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1162 | new (mem) QPointer<QObject>(o); | - | ||||||||||||||||||
1163 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | void ListElement::setListPropertyFast(const ListLayout::Role &role, ListModel *m) | - | ||||||||||||||||||
1166 | { | - | ||||||||||||||||||
1167 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1168 | ListModel **value = new (mem) ListModel *; | - | ||||||||||||||||||
1169 | *value = m; | - | ||||||||||||||||||
1170 | } executed 168 times by 3 tests: end of block Executed by:
| 168 | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | void ListElement::setVariantMapFast(const ListLayout::Role &role, QV4::Object *o) | - | ||||||||||||||||||
1173 | { | - | ||||||||||||||||||
1174 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1175 | QVariantMap *map = new (mem) QVariantMap; | - | ||||||||||||||||||
1176 | *map = o->engine()->variantMapFromJS(o); | - | ||||||||||||||||||
1177 | } executed 84 times by 2 tests: end of block Executed by:
| 84 | ||||||||||||||||||
1178 | - | |||||||||||||||||||
1179 | void ListElement::setDateTimePropertyFast(const ListLayout::Role &role, const QDateTime &dt) | - | ||||||||||||||||||
1180 | { | - | ||||||||||||||||||
1181 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1182 | new (mem) QDateTime(dt); | - | ||||||||||||||||||
1183 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
1184 | - | |||||||||||||||||||
1185 | void ListElement::setFunctionPropertyFast(const ListLayout::Role &role, const QJSValue &f) | - | ||||||||||||||||||
1186 | { | - | ||||||||||||||||||
1187 | char *mem = getPropertyMemory(role); | - | ||||||||||||||||||
1188 | new (mem) QJSValue(f); | - | ||||||||||||||||||
1189 | } never executed: end of block | 0 | ||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | void ListElement::clearProperty(const ListLayout::Role &role) | - | ||||||||||||||||||
1192 | { | - | ||||||||||||||||||
1193 | switch (role.type) { | - | ||||||||||||||||||
1194 | case ListLayout::Role::String: never executed: case ListLayout::Role::String: | 0 | ||||||||||||||||||
1195 | setStringProperty(role, QString()); | - | ||||||||||||||||||
1196 | break; never executed: break; | 0 | ||||||||||||||||||
1197 | case ListLayout::Role::Number: executed 6 times by 2 tests: case ListLayout::Role::Number: Executed by:
| 6 | ||||||||||||||||||
1198 | setDoubleProperty(role, 0.0); | - | ||||||||||||||||||
1199 | break; executed 6 times by 2 tests: break; Executed by:
| 6 | ||||||||||||||||||
1200 | case ListLayout::Role::Bool: never executed: case ListLayout::Role::Bool: | 0 | ||||||||||||||||||
1201 | setBoolProperty(role, false); | - | ||||||||||||||||||
1202 | break; never executed: break; | 0 | ||||||||||||||||||
1203 | case ListLayout::Role::List: never executed: case ListLayout::Role::List: | 0 | ||||||||||||||||||
1204 | setListProperty(role, nullptr); | - | ||||||||||||||||||
1205 | break; never executed: break; | 0 | ||||||||||||||||||
1206 | case ListLayout::Role::QObject: never executed: case ListLayout::Role::QObject: | 0 | ||||||||||||||||||
1207 | setQObjectProperty(role, nullptr); | - | ||||||||||||||||||
1208 | break; never executed: break; | 0 | ||||||||||||||||||
1209 | case ListLayout::Role::DateTime: executed 2 times by 1 test: case ListLayout::Role::DateTime: Executed by:
| 2 | ||||||||||||||||||
1210 | setDateTimeProperty(role, QDateTime()); | - | ||||||||||||||||||
1211 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
1212 | case ListLayout::Role::VariantMap: executed 6 times by 2 tests: case ListLayout::Role::VariantMap: Executed by:
| 6 | ||||||||||||||||||
1213 | setVariantMapProperty(role, (QVariantMap *)nullptr); | - | ||||||||||||||||||
1214 | break; executed 6 times by 2 tests: break; Executed by:
| 6 | ||||||||||||||||||
1215 | case ListLayout::Role::Function: never executed: case ListLayout::Role::Function: | 0 | ||||||||||||||||||
1216 | setFunctionProperty(role, QJSValue()); | - | ||||||||||||||||||
1217 | break; never executed: break; | 0 | ||||||||||||||||||
1218 | default: never executed: default: | 0 | ||||||||||||||||||
1219 | break; never executed: break; | 0 | ||||||||||||||||||
1220 | } | - | ||||||||||||||||||
1221 | } | - | ||||||||||||||||||
1222 | - | |||||||||||||||||||
1223 | ListElement::ListElement() | - | ||||||||||||||||||
1224 | { | - | ||||||||||||||||||
1225 | m_objectCache = nullptr; | - | ||||||||||||||||||
1226 | uid = uidCounter.fetchAndAddOrdered(1); | - | ||||||||||||||||||
1227 | next = nullptr; | - | ||||||||||||||||||
1228 | memset(data, 0, sizeof(data)); | - | ||||||||||||||||||
1229 | } executed 6030 times by 15 tests: end of block Executed by:
| 6030 | ||||||||||||||||||
1230 | - | |||||||||||||||||||
1231 | ListElement::ListElement(int existingUid) | - | ||||||||||||||||||
1232 | { | - | ||||||||||||||||||
1233 | m_objectCache = nullptr; | - | ||||||||||||||||||
1234 | uid = existingUid; | - | ||||||||||||||||||
1235 | next = nullptr; | - | ||||||||||||||||||
1236 | memset(data, 0, sizeof(data)); | - | ||||||||||||||||||
1237 | } executed 634 times by 1 test: end of block Executed by:
| 634 | ||||||||||||||||||
1238 | - | |||||||||||||||||||
1239 | ListElement::~ListElement() | - | ||||||||||||||||||
1240 | { | - | ||||||||||||||||||
1241 | delete next; | - | ||||||||||||||||||
1242 | } executed 6650 times by 15 tests: end of block Executed by:
| 6650 | ||||||||||||||||||
1243 | - | |||||||||||||||||||
1244 | QVector<int> ListElement::sync(ListElement *src, ListLayout *srcLayout, ListElement *target, ListLayout *targetLayout) | - | ||||||||||||||||||
1245 | { | - | ||||||||||||||||||
1246 | QVector<int> changedRoles; | - | ||||||||||||||||||
1247 | for (int i=0 ; i < srcLayout->roleCount() ; ++i) {
| 694-1104 | ||||||||||||||||||
1248 | const ListLayout::Role &srcRole = srcLayout->getExistingRole(i); | - | ||||||||||||||||||
1249 | const ListLayout::Role &targetRole = targetLayout->getExistingRole(i); | - | ||||||||||||||||||
1250 | - | |||||||||||||||||||
1251 | int roleIndex = -1; | - | ||||||||||||||||||
1252 | switch (srcRole.type) { | - | ||||||||||||||||||
1253 | case ListLayout::Role::List: executed 106 times by 1 test: case ListLayout::Role::List: Executed by:
| 106 | ||||||||||||||||||
1254 | { | - | ||||||||||||||||||
1255 | ListModel *srcSubModel = src->getListProperty(srcRole); | - | ||||||||||||||||||
1256 | ListModel *targetSubModel = target->getListProperty(targetRole); | - | ||||||||||||||||||
1257 | - | |||||||||||||||||||
1258 | if (srcSubModel) {
| 50-56 | ||||||||||||||||||
1259 | if (targetSubModel == nullptr) {
| 14-42 | ||||||||||||||||||
1260 | targetSubModel = new ListModel(targetRole.subLayout, nullptr); | - | ||||||||||||||||||
1261 | target->setListPropertyFast(targetRole, targetSubModel); | - | ||||||||||||||||||
1262 | } executed 42 times by 1 test: end of block Executed by:
| 42 | ||||||||||||||||||
1263 | if (ListModel::sync(srcSubModel, targetSubModel))
| 14-42 | ||||||||||||||||||
1264 | roleIndex = targetRole.index; executed 42 times by 1 test: roleIndex = targetRole.index; Executed by:
| 42 | ||||||||||||||||||
1265 | } executed 56 times by 1 test: end of block Executed by:
| 56 | ||||||||||||||||||
1266 | } | - | ||||||||||||||||||
1267 | break; executed 106 times by 1 test: break; Executed by:
| 106 | ||||||||||||||||||
1268 | case ListLayout::Role::QObject: never executed: case ListLayout::Role::QObject: | 0 | ||||||||||||||||||
1269 | { | - | ||||||||||||||||||
1270 | QObject *object = src->getQObjectProperty(srcRole); | - | ||||||||||||||||||
1271 | roleIndex = target->setQObjectProperty(targetRole, object); | - | ||||||||||||||||||
1272 | } | - | ||||||||||||||||||
1273 | break; never executed: break; | 0 | ||||||||||||||||||
1274 | case ListLayout::Role::String: executed 8 times by 1 test: case ListLayout::Role::String: Executed by:
| 8 | ||||||||||||||||||
1275 | case ListLayout::Role::Number: executed 890 times by 1 test: case ListLayout::Role::Number: Executed by:
| 890 | ||||||||||||||||||
1276 | case ListLayout::Role::Bool: never executed: case ListLayout::Role::Bool: | 0 | ||||||||||||||||||
1277 | case ListLayout::Role::DateTime: never executed: case ListLayout::Role::DateTime: | 0 | ||||||||||||||||||
1278 | case ListLayout::Role::Function: never executed: case ListLayout::Role::Function: | 0 | ||||||||||||||||||
1279 | { | - | ||||||||||||||||||
1280 | QVariant v = src->getProperty(srcRole, nullptr, nullptr); | - | ||||||||||||||||||
1281 | roleIndex = target->setVariantProperty(targetRole, v); | - | ||||||||||||||||||
1282 | } | - | ||||||||||||||||||
1283 | break; executed 898 times by 1 test: break; Executed by:
| 898 | ||||||||||||||||||
1284 | case ListLayout::Role::VariantMap: executed 100 times by 1 test: case ListLayout::Role::VariantMap: Executed by:
| 100 | ||||||||||||||||||
1285 | { | - | ||||||||||||||||||
1286 | QVariantMap *map = src->getVariantMapProperty(srcRole); | - | ||||||||||||||||||
1287 | roleIndex = target->setVariantMapProperty(targetRole, map); | - | ||||||||||||||||||
1288 | } | - | ||||||||||||||||||
1289 | break; executed 100 times by 1 test: break; Executed by:
| 100 | ||||||||||||||||||
1290 | default: never executed: default: | 0 | ||||||||||||||||||
1291 | break; never executed: break; | 0 | ||||||||||||||||||
1292 | } | - | ||||||||||||||||||
1293 | if (roleIndex >= 0)
| 338-766 | ||||||||||||||||||
1294 | changedRoles << roleIndex; executed 766 times by 1 test: changedRoles << roleIndex; Executed by:
| 766 | ||||||||||||||||||
1295 | } executed 1104 times by 1 test: end of block Executed by:
| 1104 | ||||||||||||||||||
1296 | - | |||||||||||||||||||
1297 | return changedRoles; executed 694 times by 1 test: return changedRoles; Executed by:
| 694 | ||||||||||||||||||
1298 | } | - | ||||||||||||||||||
1299 | - | |||||||||||||||||||
1300 | void ListElement::destroy(ListLayout *layout) | - | ||||||||||||||||||
1301 | { | - | ||||||||||||||||||
1302 | if (layout) {
| 10-6640 | ||||||||||||||||||
1303 | for (int i=0 ; i < layout->roleCount() ; ++i) {
| 6640-9940 | ||||||||||||||||||
1304 | const ListLayout::Role &r = layout->getExistingRole(i); | - | ||||||||||||||||||
1305 | - | |||||||||||||||||||
1306 | switch (r.type) { | - | ||||||||||||||||||
1307 | case ListLayout::Role::String: executed 5122 times by 14 tests: case ListLayout::Role::String: Executed by:
| 5122 | ||||||||||||||||||
1308 | { | - | ||||||||||||||||||
1309 | StringOrTranslation *string = getStringProperty(r); | - | ||||||||||||||||||
1310 | if (string)
| 0-5122 | ||||||||||||||||||
1311 | string->~StringOrTranslation(); executed 5122 times by 14 tests: string->~StringOrTranslation(); Executed by:
| 5122 | ||||||||||||||||||
1312 | } | - | ||||||||||||||||||
1313 | break; executed 5122 times by 14 tests: break; Executed by:
| 5122 | ||||||||||||||||||
1314 | case ListLayout::Role::List: executed 390 times by 4 tests: case ListLayout::Role::List: Executed by:
| 390 | ||||||||||||||||||
1315 | { | - | ||||||||||||||||||
1316 | ListModel *model = getListProperty(r); | - | ||||||||||||||||||
1317 | if (model) {
| 176-214 | ||||||||||||||||||
1318 | model->destroy(); | - | ||||||||||||||||||
1319 | delete model; | - | ||||||||||||||||||
1320 | } executed 214 times by 4 tests: end of block Executed by:
| 214 | ||||||||||||||||||
1321 | } | - | ||||||||||||||||||
1322 | break; executed 390 times by 4 tests: break; Executed by:
| 390 | ||||||||||||||||||
1323 | case ListLayout::Role::QObject: executed 10 times by 1 test: case ListLayout::Role::QObject: Executed by:
| 10 | ||||||||||||||||||
1324 | { | - | ||||||||||||||||||
1325 | QPointer<QObject> *guard = getGuardProperty(r); | - | ||||||||||||||||||
1326 | if (guard)
| 2-8 | ||||||||||||||||||
1327 | guard->~QPointer(); executed 8 times by 1 test: guard->~QPointer(); Executed by:
| 8 | ||||||||||||||||||
1328 | } | - | ||||||||||||||||||
1329 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||||||||
1330 | case ListLayout::Role::VariantMap: executed 316 times by 2 tests: case ListLayout::Role::VariantMap: Executed by:
| 316 | ||||||||||||||||||
1331 | { | - | ||||||||||||||||||
1332 | QVariantMap *map = getVariantMapProperty(r); | - | ||||||||||||||||||
1333 | if (map)
| 128-188 | ||||||||||||||||||
1334 | map->~QMap(); executed 128 times by 2 tests: map->~QMap(); Executed by:
| 128 | ||||||||||||||||||
1335 | } | - | ||||||||||||||||||
1336 | break; executed 316 times by 2 tests: break; Executed by:
| 316 | ||||||||||||||||||
1337 | case ListLayout::Role::DateTime: executed 10 times by 1 test: case ListLayout::Role::DateTime: Executed by:
| 10 | ||||||||||||||||||
1338 | { | - | ||||||||||||||||||
1339 | QDateTime *dt = getDateTimeProperty(r); | - | ||||||||||||||||||
1340 | if (dt)
| 0-10 | ||||||||||||||||||
1341 | dt->~QDateTime(); executed 10 times by 1 test: dt->~QDateTime(); Executed by:
| 10 | ||||||||||||||||||
1342 | } | - | ||||||||||||||||||
1343 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||||||||
1344 | case ListLayout::Role::Function: never executed: case ListLayout::Role::Function: | 0 | ||||||||||||||||||
1345 | { | - | ||||||||||||||||||
1346 | QJSValue *f = getFunctionProperty(r); | - | ||||||||||||||||||
1347 | if (f)
| 0 | ||||||||||||||||||
1348 | f->~QJSValue(); never executed: f->~QJSValue(); | 0 | ||||||||||||||||||
1349 | } | - | ||||||||||||||||||
1350 | break; never executed: break; | 0 | ||||||||||||||||||
1351 | default: executed 4092 times by 6 tests: default: Executed by:
| 4092 | ||||||||||||||||||
1352 | // other types don't need explicit cleanup. | - | ||||||||||||||||||
1353 | break; executed 4092 times by 6 tests: break; Executed by:
| 4092 | ||||||||||||||||||
1354 | } | - | ||||||||||||||||||
1355 | } | - | ||||||||||||||||||
1356 | - | |||||||||||||||||||
1357 | delete m_objectCache; | - | ||||||||||||||||||
1358 | } executed 6640 times by 15 tests: end of block Executed by:
| 6640 | ||||||||||||||||||
1359 | - | |||||||||||||||||||
1360 | if (next)
| 10-6640 | ||||||||||||||||||
1361 | next->destroy(nullptr); executed 10 times by 2 tests: next->destroy(nullptr); Executed by:
| 10 | ||||||||||||||||||
1362 | uid = -1; | - | ||||||||||||||||||
1363 | } executed 6650 times by 15 tests: end of block Executed by:
| 6650 | ||||||||||||||||||
1364 | - | |||||||||||||||||||
1365 | int ListElement::setVariantProperty(const ListLayout::Role &role, const QVariant &d) | - | ||||||||||||||||||
1366 | { | - | ||||||||||||||||||
1367 | int roleIndex = -1; | - | ||||||||||||||||||
1368 | - | |||||||||||||||||||
1369 | switch (role.type) { | - | ||||||||||||||||||
1370 | case ListLayout::Role::Number: executed 1338 times by 5 tests: case ListLayout::Role::Number: Executed by:
| 1338 | ||||||||||||||||||
1371 | roleIndex = setDoubleProperty(role, d.toDouble()); | - | ||||||||||||||||||
1372 | break; executed 1338 times by 5 tests: break; Executed by:
| 1338 | ||||||||||||||||||
1373 | case ListLayout::Role::String: executed 3958 times by 13 tests: case ListLayout::Role::String: Executed by:
| 3958 | ||||||||||||||||||
1374 | if (d.userType() == qMetaTypeId<const QV4::CompiledData::Binding *>())
| 8-3950 | ||||||||||||||||||
1375 | roleIndex = setTranslationProperty(role, d.value<const QV4::CompiledData::Binding*>()); executed 8 times by 3 tests: roleIndex = setTranslationProperty(role, d.value<const QV4::CompiledData::Binding*>()); Executed by:
| 8 | ||||||||||||||||||
1376 | else | - | ||||||||||||||||||
1377 | roleIndex = setStringProperty(role, d.toString()); executed 3950 times by 12 tests: roleIndex = setStringProperty(role, d.toString()); Executed by:
| 3950 | ||||||||||||||||||
1378 | break; executed 3958 times by 13 tests: break; Executed by:
| 3958 | ||||||||||||||||||
1379 | case ListLayout::Role::Bool: executed 66 times by 3 tests: case ListLayout::Role::Bool: Executed by:
| 66 | ||||||||||||||||||
1380 | roleIndex = setBoolProperty(role, d.toBool()); | - | ||||||||||||||||||
1381 | break; executed 66 times by 3 tests: break; Executed by:
| 66 | ||||||||||||||||||
1382 | case ListLayout::Role::List: executed 34 times by 2 tests: case ListLayout::Role::List: Executed by:
| 34 | ||||||||||||||||||
1383 | roleIndex = setListProperty(role, d.value<ListModel *>()); | - | ||||||||||||||||||
1384 | break; executed 34 times by 2 tests: break; Executed by:
| 34 | ||||||||||||||||||
1385 | case ListLayout::Role::VariantMap: { never executed: case ListLayout::Role::VariantMap: | 0 | ||||||||||||||||||
1386 | QVariantMap map = d.toMap(); | - | ||||||||||||||||||
1387 | roleIndex = setVariantMapProperty(role, &map); | - | ||||||||||||||||||
1388 | } | - | ||||||||||||||||||
1389 | break; never executed: break; | 0 | ||||||||||||||||||
1390 | case ListLayout::Role::DateTime: executed 2 times by 1 test: case ListLayout::Role::DateTime: Executed by:
| 2 | ||||||||||||||||||
1391 | roleIndex = setDateTimeProperty(role, d.toDateTime()); | - | ||||||||||||||||||
1392 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
1393 | case ListLayout::Role::Function: never executed: case ListLayout::Role::Function: | 0 | ||||||||||||||||||
1394 | roleIndex = setFunctionProperty(role, d.value<QJSValue>()); | - | ||||||||||||||||||
1395 | break; never executed: break; | 0 | ||||||||||||||||||
1396 | default: never executed: default: | 0 | ||||||||||||||||||
1397 | break; never executed: break; | 0 | ||||||||||||||||||
1398 | } | - | ||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | return roleIndex; executed 5398 times by 14 tests: return roleIndex; Executed by:
| 5398 | ||||||||||||||||||
1401 | } | - | ||||||||||||||||||
1402 | - | |||||||||||||||||||
1403 | int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d, QV4::ExecutionEngine *eng) | - | ||||||||||||||||||
1404 | { | - | ||||||||||||||||||
1405 | // Check if this key exists yet | - | ||||||||||||||||||
1406 | int roleIndex = -1; | - | ||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | QV4::Scope scope(eng); | - | ||||||||||||||||||
1409 | - | |||||||||||||||||||
1410 | // Add the value now | - | ||||||||||||||||||
1411 | if (d.isString()) {
| 0-58 | ||||||||||||||||||
1412 | QString qstr = d.toQString(); | - | ||||||||||||||||||
1413 | roleIndex = setStringProperty(role, qstr); | - | ||||||||||||||||||
1414 | } else if (d.isNumber()) { never executed: end of block
| 0-40 | ||||||||||||||||||
1415 | roleIndex = setDoubleProperty(role, d.asDouble()); | - | ||||||||||||||||||
1416 | } else if (d.as<QV4::ArrayObject>()) { executed 40 times by 2 tests: end of block Executed by:
| 4-40 | ||||||||||||||||||
1417 | QV4::ScopedArrayObject a(scope, d); | - | ||||||||||||||||||
1418 | if (role.type == ListLayout::Role::List) {
| 2-12 | ||||||||||||||||||
1419 | QV4::Scope scope(a->engine()); | - | ||||||||||||||||||
1420 | QV4::ScopedObject o(scope); | - | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | ListModel *subModel = new ListModel(role.subLayout, nullptr); | - | ||||||||||||||||||
1423 | int arrayLength = a->getLength(); | - | ||||||||||||||||||
1424 | for (int j=0 ; j < arrayLength ; ++j) {
| 12-24 | ||||||||||||||||||
1425 | o = a->get(j); | - | ||||||||||||||||||
1426 | subModel->append(o); | - | ||||||||||||||||||
1427 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
1428 | roleIndex = setListProperty(role, subModel); | - | ||||||||||||||||||
1429 | } else { executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1430 | qmlWarning(nullptr) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List)); executed 2 times by 1 test: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||
1431 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1432 | } else if (d.isBoolean()) {
| 0-4 | ||||||||||||||||||
1433 | roleIndex = setBoolProperty(role, d.booleanValue()); | - | ||||||||||||||||||
1434 | } else if (d.as<QV4::DateObject>()) { never executed: end of block
| 0-2 | ||||||||||||||||||
1435 | QV4::Scoped<QV4::DateObject> dd(scope, d); | - | ||||||||||||||||||
1436 | QDateTime dt = dd->toQDateTime(); | - | ||||||||||||||||||
1437 | roleIndex = setDateTimeProperty(role, dt); | - | ||||||||||||||||||
1438 | } else if (d.as<QV4::FunctionObject>()) { executed 2 times by 1 test: end of block Executed by:
| 0-2 | ||||||||||||||||||
1439 | QV4::ScopedFunctionObject f(scope, d); | - | ||||||||||||||||||
1440 | QJSValue jsv; | - | ||||||||||||||||||
1441 | QJSValuePrivate::setValue(&jsv, eng, f); | - | ||||||||||||||||||
1442 | roleIndex = setFunctionProperty(role, jsv); | - | ||||||||||||||||||
1443 | } else if (d.isObject()) { never executed: end of block
| 0-2 | ||||||||||||||||||
1444 | QV4::ScopedObject o(scope, d); | - | ||||||||||||||||||
1445 | QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>(); | - | ||||||||||||||||||
1446 | if (role.type == ListLayout::Role::QObject && wrapper) {
| 0 | ||||||||||||||||||
1447 | QObject *o = wrapper->object(); | - | ||||||||||||||||||
1448 | roleIndex = setQObjectProperty(role, o); | - | ||||||||||||||||||
1449 | } else if (role.type == ListLayout::Role::VariantMap) { never executed: end of block
| 0 | ||||||||||||||||||
1450 | roleIndex = setVariantMapProperty(role, o); | - | ||||||||||||||||||
1451 | } never executed: end of block | 0 | ||||||||||||||||||
1452 | } else if (d.isNullOrUndefined()) { never executed: end of block
| 0-2 | ||||||||||||||||||
1453 | clearProperty(role); | - | ||||||||||||||||||
1454 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | return roleIndex; executed 58 times by 2 tests: return roleIndex; Executed by:
| 58 | ||||||||||||||||||
1457 | } | - | ||||||||||||||||||
1458 | - | |||||||||||||||||||
1459 | ModelNodeMetaObject::ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex) | - | ||||||||||||||||||
1460 | : QQmlOpenMetaObject(object), m_enabled(false), m_model(model), m_elementIndex(elementIndex), m_initialized(false) | - | ||||||||||||||||||
1461 | {} executed 660 times by 8 tests: end of block Executed by:
| 660 | ||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | void ModelNodeMetaObject::initialize() | - | ||||||||||||||||||
1464 | { | - | ||||||||||||||||||
1465 | const int roleCount = m_model->m_listModel->roleCount(); | - | ||||||||||||||||||
1466 | QVector<QByteArray> properties; | - | ||||||||||||||||||
1467 | properties.reserve(roleCount); | - | ||||||||||||||||||
1468 | for (int i = 0 ; i < roleCount ; ++i) {
| 36-104 | ||||||||||||||||||
1469 | const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i); | - | ||||||||||||||||||
1470 | QByteArray name = role.name.toUtf8(); | - | ||||||||||||||||||
1471 | properties << name; | - | ||||||||||||||||||
1472 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||
1473 | type()->createProperties(properties); | - | ||||||||||||||||||
1474 | updateValues(); | - | ||||||||||||||||||
1475 | m_enabled = true; | - | ||||||||||||||||||
1476 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | ModelNodeMetaObject::~ModelNodeMetaObject() | - | ||||||||||||||||||
1479 | { | - | ||||||||||||||||||
1480 | } | - | ||||||||||||||||||
1481 | - | |||||||||||||||||||
1482 | QAbstractDynamicMetaObject *ModelNodeMetaObject::toDynamicMetaObject(QObject *object) | - | ||||||||||||||||||
1483 | { | - | ||||||||||||||||||
1484 | if (!m_initialized) {
| 36-412 | ||||||||||||||||||
1485 | m_initialized = true; | - | ||||||||||||||||||
1486 | initialize(); | - | ||||||||||||||||||
1487 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1488 | return QQmlOpenMetaObject::toDynamicMetaObject(object); executed 448 times by 1 test: return QQmlOpenMetaObject::toDynamicMetaObject(object); Executed by:
| 448 | ||||||||||||||||||
1489 | } | - | ||||||||||||||||||
1490 | - | |||||||||||||||||||
1491 | ModelNodeMetaObject *ModelNodeMetaObject::get(QObject *obj) | - | ||||||||||||||||||
1492 | { | - | ||||||||||||||||||
1493 | QObjectPrivate *op = QObjectPrivate::get(obj); | - | ||||||||||||||||||
1494 | return static_cast<ModelNodeMetaObject*>(op->metaObject); executed 428 times by 4 tests: return static_cast<ModelNodeMetaObject*>(op->metaObject); Executed by:
| 428 | ||||||||||||||||||
1495 | } | - | ||||||||||||||||||
1496 | - | |||||||||||||||||||
1497 | void ModelNodeMetaObject::updateValues() | - | ||||||||||||||||||
1498 | { | - | ||||||||||||||||||
1499 | const int roleCount = m_model->m_listModel->roleCount(); | - | ||||||||||||||||||
1500 | if (!m_initialized) {
| 0-36 | ||||||||||||||||||
1501 | if (roleCount) {
| 0 | ||||||||||||||||||
1502 | Q_ALLOCA_VAR(int, changedRoles, roleCount * sizeof(int)); | - | ||||||||||||||||||
1503 | for (int i = 0; i < roleCount; ++i)
| 0 | ||||||||||||||||||
1504 | changedRoles[i] = i; never executed: changedRoles[i] = i; | 0 | ||||||||||||||||||
1505 | emitDirectNotifies(changedRoles, roleCount); | - | ||||||||||||||||||
1506 | } never executed: end of block | 0 | ||||||||||||||||||
1507 | return; never executed: return; | 0 | ||||||||||||||||||
1508 | } | - | ||||||||||||||||||
1509 | for (int i=0 ; i < roleCount ; ++i) {
| 36-104 | ||||||||||||||||||
1510 | const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i); | - | ||||||||||||||||||
1511 | QByteArray name = role.name.toUtf8(); | - | ||||||||||||||||||
1512 | const QVariant &data = m_model->data(m_elementIndex, i); | - | ||||||||||||||||||
1513 | setValue(name, data, role.type == ListLayout::Role::List); | - | ||||||||||||||||||
1514 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||||||||
1515 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1516 | - | |||||||||||||||||||
1517 | void ModelNodeMetaObject::updateValues(const QVector<int> &roles) | - | ||||||||||||||||||
1518 | { | - | ||||||||||||||||||
1519 | if (!m_initialized) {
| 18-26 | ||||||||||||||||||
1520 | emitDirectNotifies(roles.constData(), roles.count()); | - | ||||||||||||||||||
1521 | return; executed 18 times by 3 tests: return; Executed by:
| 18 | ||||||||||||||||||
1522 | } | - | ||||||||||||||||||
1523 | int roleCount = roles.count(); | - | ||||||||||||||||||
1524 | for (int i=0 ; i < roleCount ; ++i) {
| 24-26 | ||||||||||||||||||
1525 | int roleIndex = roles.at(i); | - | ||||||||||||||||||
1526 | const ListLayout::Role &role = m_model->m_listModel->getExistingRole(roleIndex); | - | ||||||||||||||||||
1527 | QByteArray name = role.name.toUtf8(); | - | ||||||||||||||||||
1528 | const QVariant &data = m_model->data(m_elementIndex, roleIndex); | - | ||||||||||||||||||
1529 | setValue(name, data, role.type == ListLayout::Role::List); | - | ||||||||||||||||||
1530 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
1531 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
1532 | - | |||||||||||||||||||
1533 | void ModelNodeMetaObject::propertyWritten(int index) | - | ||||||||||||||||||
1534 | { | - | ||||||||||||||||||
1535 | if (!m_enabled)
| 0 | ||||||||||||||||||
1536 | return; never executed: return; | 0 | ||||||||||||||||||
1537 | - | |||||||||||||||||||
1538 | QString propName = QString::fromUtf8(name(index)); | - | ||||||||||||||||||
1539 | const QVariant value = this->value(index); | - | ||||||||||||||||||
1540 | - | |||||||||||||||||||
1541 | QV4::Scope scope(m_model->engine()); | - | ||||||||||||||||||
1542 | QV4::ScopedValue v(scope, scope.engine->fromVariant(value)); | - | ||||||||||||||||||
1543 | - | |||||||||||||||||||
1544 | int roleIndex = m_model->m_listModel->setExistingProperty(m_elementIndex, propName, v, scope.engine); | - | ||||||||||||||||||
1545 | if (roleIndex != -1)
| 0 | ||||||||||||||||||
1546 | m_model->emitItemsChanged(m_elementIndex, 1, QVector<int>(1, roleIndex)); never executed: m_model->emitItemsChanged(m_elementIndex, 1, QVector<int>(1, roleIndex)); | 0 | ||||||||||||||||||
1547 | } never executed: end of block | 0 | ||||||||||||||||||
1548 | - | |||||||||||||||||||
1549 | // Does the emission of the notifiers when we haven't created the meta-object yet | - | ||||||||||||||||||
1550 | void ModelNodeMetaObject::emitDirectNotifies(const int *changedRoles, int roleCount) | - | ||||||||||||||||||
1551 | { | - | ||||||||||||||||||
1552 | Q_ASSERT(!m_initialized); | - | ||||||||||||||||||
1553 | QQmlData *ddata = QQmlData::get(object(), /*create*/false); | - | ||||||||||||||||||
1554 | if (!ddata)
| 0-18 | ||||||||||||||||||
1555 | return; never executed: return; | 0 | ||||||||||||||||||
1556 | // There's nothing to emit if we're a list model in a worker thread. | - | ||||||||||||||||||
1557 | if (!qmlEngine(m_model))
| 4-14 | ||||||||||||||||||
1558 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
1559 | for (int i = 0; i < roleCount; ++i) {
| 14 | ||||||||||||||||||
1560 | const int changedRole = changedRoles[i]; | - | ||||||||||||||||||
1561 | QQmlNotifier::notify(ddata, changedRole); | - | ||||||||||||||||||
1562 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||
1563 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||
1564 | - | |||||||||||||||||||
1565 | namespace QV4 { | - | ||||||||||||||||||
1566 | - | |||||||||||||||||||
1567 | bool ModelObject::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) | - | ||||||||||||||||||
1568 | { | - | ||||||||||||||||||
1569 | if (!id.isString())
| 0-58 | ||||||||||||||||||
1570 | return Object::virtualPut(m, id, value, receiver); never executed: return Object::virtualPut(m, id, value, receiver); | 0 | ||||||||||||||||||
1571 | QString propName = id.toQString(); | - | ||||||||||||||||||
1572 | - | |||||||||||||||||||
1573 | ModelObject *that = static_cast<ModelObject*>(m); | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | ExecutionEngine *eng = that->engine(); | - | ||||||||||||||||||
1576 | const int elementIndex = that->d()->elementIndex(); | - | ||||||||||||||||||
1577 | int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng); | - | ||||||||||||||||||
1578 | if (roleIndex != -1)
| 4-54 | ||||||||||||||||||
1579 | that->d()->m_model->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); executed 54 times by 2 tests: that->d()->m_model->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); Executed by:
| 54 | ||||||||||||||||||
1580 | - | |||||||||||||||||||
1581 | ModelNodeMetaObject *mo = ModelNodeMetaObject::get(that->object()); | - | ||||||||||||||||||
1582 | if (mo->initialized())
| 4-54 | ||||||||||||||||||
1583 | mo->emitPropertyNotification(propName.toUtf8()); executed 4 times by 1 test: mo->emitPropertyNotification(propName.toUtf8()); Executed by:
| 4 | ||||||||||||||||||
1584 | return true; executed 58 times by 2 tests: return true; Executed by:
| 58 | ||||||||||||||||||
1585 | } | - | ||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | ReturnedValue ModelObject::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) | - | ||||||||||||||||||
1588 | { | - | ||||||||||||||||||
1589 | if (!id.isString())
| 0-852 | ||||||||||||||||||
1590 | return QObjectWrapper::virtualGet(m, id, receiver, hasProperty); never executed: return QObjectWrapper::virtualGet(m, id, receiver, hasProperty); | 0 | ||||||||||||||||||
1591 | - | |||||||||||||||||||
1592 | const ModelObject *that = static_cast<const ModelObject*>(m); | - | ||||||||||||||||||
1593 | Scope scope(that); | - | ||||||||||||||||||
1594 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||||||||
1595 | const ListLayout::Role *role = that->d()->m_model->m_listModel->getExistingRole(name); | - | ||||||||||||||||||
1596 | if (!role)
| 2-850 | ||||||||||||||||||
1597 | return QObjectWrapper::virtualGet(m, id, receiver, hasProperty); executed 2 times by 1 test: return QObjectWrapper::virtualGet(m, id, receiver, hasProperty); Executed by:
| 2 | ||||||||||||||||||
1598 | if (hasProperty)
| 0-850 | ||||||||||||||||||
1599 | *hasProperty = true; never executed: *hasProperty = true; | 0 | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | if (QQmlEngine *qmlEngine = that->engine()->qmlEngine()) {
| 114-736 | ||||||||||||||||||
1602 | QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlEngine); | - | ||||||||||||||||||
1603 | if (ep && ep->propertyCapture)
| 0-736 | ||||||||||||||||||
1604 | ep->propertyCapture->captureProperty(that->object(), -1, role->index, executed 58 times by 3 tests: ep->propertyCapture->captureProperty(that->object(), -1, role->index, QQmlPropertyCapture::OnlyOnce, false); Executed by:
| 58 | ||||||||||||||||||
1605 | QQmlPropertyCapture::OnlyOnce, false); executed 58 times by 3 tests: ep->propertyCapture->captureProperty(that->object(), -1, role->index, QQmlPropertyCapture::OnlyOnce, false); Executed by:
| 58 | ||||||||||||||||||
1606 | } executed 736 times by 8 tests: end of block Executed by:
| 736 | ||||||||||||||||||
1607 | - | |||||||||||||||||||
1608 | const int elementIndex = that->d()->elementIndex(); | - | ||||||||||||||||||
1609 | QVariant value = that->d()->m_model->data(elementIndex, role->index); | - | ||||||||||||||||||
1610 | return that->engine()->fromVariant(value); executed 850 times by 8 tests: return that->engine()->fromVariant(value); Executed by:
| 850 | ||||||||||||||||||
1611 | } | - | ||||||||||||||||||
1612 | - | |||||||||||||||||||
1613 | void ModelObject::virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes) | - | ||||||||||||||||||
1614 | { | - | ||||||||||||||||||
1615 | ModelObject *that = static_cast<ModelObject*>(m); | - | ||||||||||||||||||
1616 | ExecutionEngine *v4 = that->engine(); | - | ||||||||||||||||||
1617 | name->setM(nullptr); | - | ||||||||||||||||||
1618 | *index = UINT_MAX; | - | ||||||||||||||||||
1619 | if (it->arrayIndex < uint(that->d()->m_model->m_listModel->roleCount())) {
| 4-14 | ||||||||||||||||||
1620 | Scope scope(that->engine()); | - | ||||||||||||||||||
1621 | const ListLayout::Role &role = that->d()->m_model->m_listModel->getExistingRole(it->arrayIndex); | - | ||||||||||||||||||
1622 | ++it->arrayIndex; | - | ||||||||||||||||||
1623 | ScopedString roleName(scope, v4->newString(role.name)); | - | ||||||||||||||||||
1624 | name->setM(roleName->d()); | - | ||||||||||||||||||
1625 | *attributes = QV4::Attr_Data; | - | ||||||||||||||||||
1626 | QVariant value = that->d()->m_model->data(that->d()->elementIndex(), role.index); | - | ||||||||||||||||||
1627 | p->value = v4->fromVariant(value); | - | ||||||||||||||||||
1628 | return; executed 14 times by 1 test: return; Executed by:
| 14 | ||||||||||||||||||
1629 | } | - | ||||||||||||||||||
1630 | // Fall back to QV4::Object as opposed to QV4::QObjectWrapper otherwise it will add | - | ||||||||||||||||||
1631 | // unnecessary entries that relate to the roles used. These just create extra work | - | ||||||||||||||||||
1632 | // later on as they will just be ignored. | - | ||||||||||||||||||
1633 | QV4::Object::virtualAdvanceIterator(m, it, name, index, p, attributes); | - | ||||||||||||||||||
1634 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1635 | - | |||||||||||||||||||
1636 | DEFINE_OBJECT_VTABLE(ModelObject); | - | ||||||||||||||||||
1637 | - | |||||||||||||||||||
1638 | } // namespace QV4 | - | ||||||||||||||||||
1639 | - | |||||||||||||||||||
1640 | DynamicRoleModelNode::DynamicRoleModelNode(QQmlListModel *owner, int uid) : m_owner(owner), m_uid(uid), m_meta(new DynamicRoleModelNodeMetaObject(this)) | - | ||||||||||||||||||
1641 | { | - | ||||||||||||||||||
1642 | setNodeUpdatesEnabled(true); | - | ||||||||||||||||||
1643 | } executed 2238 times by 2 tests: end of block Executed by:
| 2238 | ||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | DynamicRoleModelNode *DynamicRoleModelNode::create(const QVariantMap &obj, QQmlListModel *owner) | - | ||||||||||||||||||
1646 | { | - | ||||||||||||||||||
1647 | DynamicRoleModelNode *object = new DynamicRoleModelNode(owner, uidCounter.fetchAndAddOrdered(1)); | - | ||||||||||||||||||
1648 | QVector<int> roles; | - | ||||||||||||||||||
1649 | object->updateValues(obj, roles); | - | ||||||||||||||||||
1650 | return object; executed 1514 times by 2 tests: return object; Executed by:
| 1514 | ||||||||||||||||||
1651 | } | - | ||||||||||||||||||
1652 | - | |||||||||||||||||||
1653 | QVector<int> DynamicRoleModelNode::sync(DynamicRoleModelNode *src, DynamicRoleModelNode *target) | - | ||||||||||||||||||
1654 | { | - | ||||||||||||||||||
1655 | QVector<int> changedRoles; | - | ||||||||||||||||||
1656 | for (int i = 0; i < src->m_meta->count(); ++i) {
| 824-1116 | ||||||||||||||||||
1657 | const QByteArray &name = src->m_meta->name(i); | - | ||||||||||||||||||
1658 | QVariant value = src->m_meta->value(i); | - | ||||||||||||||||||
1659 | - | |||||||||||||||||||
1660 | QQmlListModel *srcModel = qobject_cast<QQmlListModel *>(value.value<QObject *>()); | - | ||||||||||||||||||
1661 | QQmlListModel *targetModel = qobject_cast<QQmlListModel *>(target->m_meta->value(i).value<QObject *>()); | - | ||||||||||||||||||
1662 | - | |||||||||||||||||||
1663 | bool modelHasChanges = false; | - | ||||||||||||||||||
1664 | if (srcModel) {
| 82-1034 | ||||||||||||||||||
1665 | if (targetModel == nullptr)
| 26-56 | ||||||||||||||||||
1666 | targetModel = QQmlListModel::createWithOwner(target->m_owner); executed 56 times by 1 test: targetModel = QQmlListModel::createWithOwner(target->m_owner); Executed by:
| 56 | ||||||||||||||||||
1667 | - | |||||||||||||||||||
1668 | modelHasChanges = QQmlListModel::sync(srcModel, targetModel); | - | ||||||||||||||||||
1669 | - | |||||||||||||||||||
1670 | QObject *targetModelObject = targetModel; | - | ||||||||||||||||||
1671 | value = QVariant::fromValue(targetModelObject); | - | ||||||||||||||||||
1672 | } else if (targetModel) { executed 82 times by 1 test: end of block Executed by:
| 2-1032 | ||||||||||||||||||
1673 | delete targetModel; | - | ||||||||||||||||||
1674 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | if (target->setValue(name, value) || modelHasChanges)
| 14-944 | ||||||||||||||||||
1677 | changedRoles << target->m_owner->m_roles.indexOf(QString::fromUtf8(name)); executed 958 times by 1 test: changedRoles << target->m_owner->m_roles.indexOf(QString::fromUtf8(name)); Executed by:
| 958 | ||||||||||||||||||
1678 | } executed 1116 times by 1 test: end of block Executed by:
| 1116 | ||||||||||||||||||
1679 | return changedRoles; executed 824 times by 1 test: return changedRoles; Executed by:
| 824 | ||||||||||||||||||
1680 | } | - | ||||||||||||||||||
1681 | - | |||||||||||||||||||
1682 | void DynamicRoleModelNode::updateValues(const QVariantMap &object, QVector<int> &roles) | - | ||||||||||||||||||
1683 | { | - | ||||||||||||||||||
1684 | for (auto it = object.cbegin(), end = object.cend(); it != end; ++it) {
| 1652-2284 | ||||||||||||||||||
1685 | const QString &key = it.key(); | - | ||||||||||||||||||
1686 | - | |||||||||||||||||||
1687 | int roleIndex = m_owner->m_roles.indexOf(key); | - | ||||||||||||||||||
1688 | if (roleIndex == -1) {
| 766-1518 | ||||||||||||||||||
1689 | roleIndex = m_owner->m_roles.count(); | - | ||||||||||||||||||
1690 | m_owner->m_roles.append(key); | - | ||||||||||||||||||
1691 | } executed 1518 times by 2 tests: end of block Executed by:
| 1518 | ||||||||||||||||||
1692 | - | |||||||||||||||||||
1693 | QVariant value = it.value(); | - | ||||||||||||||||||
1694 | - | |||||||||||||||||||
1695 | // A JS array/object is translated into a (hierarchical) QQmlListModel, | - | ||||||||||||||||||
1696 | // so translate to a variant map/list first with toVariant(). | - | ||||||||||||||||||
1697 | if (value.userType() == qMetaTypeId<QJSValue>())
| 0-2284 | ||||||||||||||||||
1698 | value = value.value<QJSValue>().toVariant(); never executed: value = value.value<QJSValue>().toVariant(); | 0 | ||||||||||||||||||
1699 | - | |||||||||||||||||||
1700 | if (value.type() == QVariant::List) {
| 164-2120 | ||||||||||||||||||
1701 | QQmlListModel *subModel = QQmlListModel::createWithOwner(m_owner); | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | QVariantList subArray = value.toList(); | - | ||||||||||||||||||
1704 | QVariantList::const_iterator subIt = subArray.cbegin(); | - | ||||||||||||||||||
1705 | QVariantList::const_iterator subEnd = subArray.cend(); | - | ||||||||||||||||||
1706 | while (subIt != subEnd) {
| 164-414 | ||||||||||||||||||
1707 | const QVariantMap &subObject = subIt->toMap(); | - | ||||||||||||||||||
1708 | subModel->m_modelObjects.append(DynamicRoleModelNode::create(subObject, subModel)); | - | ||||||||||||||||||
1709 | ++subIt; | - | ||||||||||||||||||
1710 | } executed 414 times by 2 tests: end of block Executed by:
| 414 | ||||||||||||||||||
1711 | - | |||||||||||||||||||
1712 | QObject *subModelObject = subModel; | - | ||||||||||||||||||
1713 | value = QVariant::fromValue(subModelObject); | - | ||||||||||||||||||
1714 | } executed 164 times by 2 tests: end of block Executed by:
| 164 | ||||||||||||||||||
1715 | - | |||||||||||||||||||
1716 | const QByteArray &keyUtf8 = key.toUtf8(); | - | ||||||||||||||||||
1717 | - | |||||||||||||||||||
1718 | QQmlListModel *existingModel = qobject_cast<QQmlListModel *>(m_meta->value(keyUtf8).value<QObject *>()); | - | ||||||||||||||||||
1719 | delete existingModel; | - | ||||||||||||||||||
1720 | - | |||||||||||||||||||
1721 | if (m_meta->setValue(keyUtf8, value))
| 94-2190 | ||||||||||||||||||
1722 | roles << roleIndex; executed 2190 times by 2 tests: roles << roleIndex; Executed by:
| 2190 | ||||||||||||||||||
1723 | } executed 2284 times by 2 tests: end of block Executed by:
| 2284 | ||||||||||||||||||
1724 | } executed 1652 times by 2 tests: end of block Executed by:
| 1652 | ||||||||||||||||||
1725 | - | |||||||||||||||||||
1726 | DynamicRoleModelNodeMetaObject::DynamicRoleModelNodeMetaObject(DynamicRoleModelNode *object) | - | ||||||||||||||||||
1727 | : QQmlOpenMetaObject(object), m_enabled(false), m_owner(object) | - | ||||||||||||||||||
1728 | { | - | ||||||||||||||||||
1729 | } executed 2238 times by 2 tests: end of block Executed by:
| 2238 | ||||||||||||||||||
1730 | - | |||||||||||||||||||
1731 | DynamicRoleModelNodeMetaObject::~DynamicRoleModelNodeMetaObject() | - | ||||||||||||||||||
1732 | { | - | ||||||||||||||||||
1733 | for (int i=0 ; i < count() ; ++i) {
| 2238-3096 | ||||||||||||||||||
1734 | QQmlListModel *subModel = qobject_cast<QQmlListModel *>(value(i).value<QObject *>()); | - | ||||||||||||||||||
1735 | delete subModel; | - | ||||||||||||||||||
1736 | } executed 3096 times by 2 tests: end of block Executed by:
| 3096 | ||||||||||||||||||
1737 | } executed 2238 times by 2 tests: end of block Executed by:
| 2238 | ||||||||||||||||||
1738 | - | |||||||||||||||||||
1739 | void DynamicRoleModelNodeMetaObject::propertyWrite(int index) | - | ||||||||||||||||||
1740 | { | - | ||||||||||||||||||
1741 | if (!m_enabled)
| 0-58 | ||||||||||||||||||
1742 | return; never executed: return; | 0 | ||||||||||||||||||
1743 | - | |||||||||||||||||||
1744 | QVariant v = value(index); | - | ||||||||||||||||||
1745 | QQmlListModel *model = qobject_cast<QQmlListModel *>(v.value<QObject *>()); | - | ||||||||||||||||||
1746 | delete model; | - | ||||||||||||||||||
1747 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
1748 | - | |||||||||||||||||||
1749 | void DynamicRoleModelNodeMetaObject::propertyWritten(int index) | - | ||||||||||||||||||
1750 | { | - | ||||||||||||||||||
1751 | if (!m_enabled)
| 0-58 | ||||||||||||||||||
1752 | return; never executed: return; | 0 | ||||||||||||||||||
1753 | - | |||||||||||||||||||
1754 | QQmlListModel *parentModel = m_owner->m_owner; | - | ||||||||||||||||||
1755 | - | |||||||||||||||||||
1756 | QVariant v = value(index); | - | ||||||||||||||||||
1757 | - | |||||||||||||||||||
1758 | // A JS array/object is translated into a (hierarchical) QQmlListModel, | - | ||||||||||||||||||
1759 | // so translate to a variant map/list first with toVariant(). | - | ||||||||||||||||||
1760 | if (v.userType() == qMetaTypeId<QJSValue>())
| 12-46 | ||||||||||||||||||
1761 | v= v.value<QJSValue>().toVariant(); executed 12 times by 2 tests: v= v.value<QJSValue>().toVariant(); Executed by:
| 12 | ||||||||||||||||||
1762 | - | |||||||||||||||||||
1763 | if (v.type() == QVariant::List) {
| 12-46 | ||||||||||||||||||
1764 | QQmlListModel *subModel = QQmlListModel::createWithOwner(parentModel); | - | ||||||||||||||||||
1765 | - | |||||||||||||||||||
1766 | QVariantList subArray = v.toList(); | - | ||||||||||||||||||
1767 | QVariantList::const_iterator subIt = subArray.cbegin(); | - | ||||||||||||||||||
1768 | QVariantList::const_iterator subEnd = subArray.cend(); | - | ||||||||||||||||||
1769 | while (subIt != subEnd) {
| 12-24 | ||||||||||||||||||
1770 | const QVariantMap &subObject = subIt->toMap(); | - | ||||||||||||||||||
1771 | subModel->m_modelObjects.append(DynamicRoleModelNode::create(subObject, subModel)); | - | ||||||||||||||||||
1772 | ++subIt; | - | ||||||||||||||||||
1773 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
1774 | - | |||||||||||||||||||
1775 | QObject *subModelObject = subModel; | - | ||||||||||||||||||
1776 | v = QVariant::fromValue(subModelObject); | - | ||||||||||||||||||
1777 | - | |||||||||||||||||||
1778 | setValue(index, v); | - | ||||||||||||||||||
1779 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
1780 | - | |||||||||||||||||||
1781 | int elementIndex = parentModel->m_modelObjects.indexOf(m_owner); | - | ||||||||||||||||||
1782 | if (elementIndex != -1) {
| 0-58 | ||||||||||||||||||
1783 | int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData())); | - | ||||||||||||||||||
1784 | if (roleIndex != -1)
| 0-58 | ||||||||||||||||||
1785 | parentModel->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); executed 58 times by 2 tests: parentModel->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex)); Executed by:
| 58 | ||||||||||||||||||
1786 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
1787 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
1788 | - | |||||||||||||||||||
1789 | /*! | - | ||||||||||||||||||
1790 | \qmltype ListModel | - | ||||||||||||||||||
1791 | \instantiates QQmlListModel | - | ||||||||||||||||||
1792 | \inqmlmodule QtQml.Models | - | ||||||||||||||||||
1793 | \ingroup qtquick-models | - | ||||||||||||||||||
1794 | \brief Defines a free-form list data source. | - | ||||||||||||||||||
1795 | - | |||||||||||||||||||
1796 | The ListModel is a simple container of ListElement definitions, each | - | ||||||||||||||||||
1797 | containing data roles. The contents can be defined dynamically, or | - | ||||||||||||||||||
1798 | explicitly in QML. | - | ||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | The number of elements in the model can be obtained from its \l count property. | - | ||||||||||||||||||
1801 | A number of familiar methods are also provided to manipulate the contents of the | - | ||||||||||||||||||
1802 | model, including append(), insert(), move(), remove() and set(). These methods | - | ||||||||||||||||||
1803 | accept dictionaries as their arguments; these are translated to ListElement objects | - | ||||||||||||||||||
1804 | by the model. | - | ||||||||||||||||||
1805 | - | |||||||||||||||||||
1806 | Elements can be manipulated via the model using the setProperty() method, which | - | ||||||||||||||||||
1807 | allows the roles of the specified element to be set and changed. | - | ||||||||||||||||||
1808 | - | |||||||||||||||||||
1809 | \section1 Example Usage | - | ||||||||||||||||||
1810 | - | |||||||||||||||||||
1811 | The following example shows a ListModel containing three elements, with the roles | - | ||||||||||||||||||
1812 | "name" and "cost". | - | ||||||||||||||||||
1813 | - | |||||||||||||||||||
1814 | \div {class="float-right"} | - | ||||||||||||||||||
1815 | \inlineimage listmodel.png | - | ||||||||||||||||||
1816 | \enddiv | - | ||||||||||||||||||
1817 | - | |||||||||||||||||||
1818 | \snippet qml/listmodel/listmodel.qml 0 | - | ||||||||||||||||||
1819 | - | |||||||||||||||||||
1820 | Roles (properties) in each element must begin with a lower-case letter and | - | ||||||||||||||||||
1821 | should be common to all elements in a model. The ListElement documentation | - | ||||||||||||||||||
1822 | provides more guidelines for how elements should be defined. | - | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | Since the example model contains an \c id property, it can be referenced | - | ||||||||||||||||||
1825 | by views, such as the ListView in this example: | - | ||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | \snippet qml/listmodel/listmodel-simple.qml 0 | - | ||||||||||||||||||
1828 | \dots 8 | - | ||||||||||||||||||
1829 | \snippet qml/listmodel/listmodel-simple.qml 1 | - | ||||||||||||||||||
1830 | - | |||||||||||||||||||
1831 | It is possible for roles to contain list data. In the following example we | - | ||||||||||||||||||
1832 | create a list of fruit attributes: | - | ||||||||||||||||||
1833 | - | |||||||||||||||||||
1834 | \snippet qml/listmodel/listmodel-nested.qml model | - | ||||||||||||||||||
1835 | - | |||||||||||||||||||
1836 | The delegate displays all the fruit attributes: | - | ||||||||||||||||||
1837 | - | |||||||||||||||||||
1838 | \div {class="float-right"} | - | ||||||||||||||||||
1839 | \inlineimage listmodel-nested.png | - | ||||||||||||||||||
1840 | \enddiv | - | ||||||||||||||||||
1841 | - | |||||||||||||||||||
1842 | \snippet qml/listmodel/listmodel-nested.qml delegate | - | ||||||||||||||||||
1843 | - | |||||||||||||||||||
1844 | \section1 Modifying List Models | - | ||||||||||||||||||
1845 | - | |||||||||||||||||||
1846 | The content of a ListModel may be created and modified using the clear(), | - | ||||||||||||||||||
1847 | append(), set(), insert() and setProperty() methods. For example: | - | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | \snippet qml/listmodel/listmodel-modify.qml delegate | - | ||||||||||||||||||
1850 | - | |||||||||||||||||||
1851 | Note that when creating content dynamically the set of available properties | - | ||||||||||||||||||
1852 | cannot be changed once set. Whatever properties are first added to the model | - | ||||||||||||||||||
1853 | are the only permitted properties in the model. | - | ||||||||||||||||||
1854 | - | |||||||||||||||||||
1855 | \section1 Using Threaded List Models with WorkerScript | - | ||||||||||||||||||
1856 | - | |||||||||||||||||||
1857 | ListModel can be used together with WorkerScript access a list model | - | ||||||||||||||||||
1858 | from multiple threads. This is useful if list modifications are | - | ||||||||||||||||||
1859 | synchronous and take some time: the list operations can be moved to a | - | ||||||||||||||||||
1860 | different thread to avoid blocking of the main GUI thread. | - | ||||||||||||||||||
1861 | - | |||||||||||||||||||
1862 | Here is an example that uses WorkerScript to periodically append the | - | ||||||||||||||||||
1863 | current time to a list model: | - | ||||||||||||||||||
1864 | - | |||||||||||||||||||
1865 | \snippet ../quick/threading/threadedlistmodel/timedisplay.qml 0 | - | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | The included file, \tt dataloader.js, looks like this: | - | ||||||||||||||||||
1868 | - | |||||||||||||||||||
1869 | \snippet ../quick/threading/threadedlistmodel/dataloader.js 0 | - | ||||||||||||||||||
1870 | - | |||||||||||||||||||
1871 | The timer in the main example sends messages to the worker script by calling | - | ||||||||||||||||||
1872 | \l WorkerScript::sendMessage(). When this message is received, | - | ||||||||||||||||||
1873 | \c WorkerScript.onMessage() is invoked in \c dataloader.js, | - | ||||||||||||||||||
1874 | which appends the current time to the list model. | - | ||||||||||||||||||
1875 | - | |||||||||||||||||||
1876 | Note the call to sync() from the external thread. | - | ||||||||||||||||||
1877 | You must call sync() or else the changes made to the list from that | - | ||||||||||||||||||
1878 | thread will not be reflected in the list model in the main thread. | - | ||||||||||||||||||
1879 | - | |||||||||||||||||||
1880 | \sa {qml-data-models}{Data Models}, {Qt Quick Examples - Threading}, {Qt QML} | - | ||||||||||||||||||
1881 | */ | - | ||||||||||||||||||
1882 | - | |||||||||||||||||||
1883 | QQmlListModel::QQmlListModel(QObject *parent) | - | ||||||||||||||||||
1884 | : QAbstractListModel(parent) | - | ||||||||||||||||||
1885 | { | - | ||||||||||||||||||
1886 | m_mainThread = true; | - | ||||||||||||||||||
1887 | m_primary = true; | - | ||||||||||||||||||
1888 | m_agent = nullptr; | - | ||||||||||||||||||
1889 | m_dynamicRoles = false; | - | ||||||||||||||||||
1890 | - | |||||||||||||||||||
1891 | m_layout = new ListLayout; | - | ||||||||||||||||||
1892 | m_listModel = new ListModel(m_layout, this); | - | ||||||||||||||||||
1893 | - | |||||||||||||||||||
1894 | m_engine = nullptr; | - | ||||||||||||||||||
1895 | } executed 2456 times by 15 tests: end of block Executed by:
| 2456 | ||||||||||||||||||
1896 | - | |||||||||||||||||||
1897 | QQmlListModel::QQmlListModel(const QQmlListModel *owner, ListModel *data, QV4::ExecutionEngine *engine, QObject *parent) | - | ||||||||||||||||||
1898 | : QAbstractListModel(parent) | - | ||||||||||||||||||
1899 | { | - | ||||||||||||||||||
1900 | m_mainThread = owner->m_mainThread; | - | ||||||||||||||||||
1901 | m_primary = false; | - | ||||||||||||||||||
1902 | m_agent = owner->m_agent; | - | ||||||||||||||||||
1903 | - | |||||||||||||||||||
1904 | Q_ASSERT(owner->m_dynamicRoles == false); | - | ||||||||||||||||||
1905 | m_dynamicRoles = false; | - | ||||||||||||||||||
1906 | m_layout = nullptr; | - | ||||||||||||||||||
1907 | m_listModel = data; | - | ||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | m_engine = engine; | - | ||||||||||||||||||
1910 | m_compilationUnit = owner->m_compilationUnit; | - | ||||||||||||||||||
1911 | } executed 138 times by 4 tests: end of block Executed by:
| 138 | ||||||||||||||||||
1912 | - | |||||||||||||||||||
1913 | QQmlListModel::QQmlListModel(QQmlListModel *orig, QQmlListModelWorkerAgent *agent) | - | ||||||||||||||||||
1914 | : QAbstractListModel(agent) | - | ||||||||||||||||||
1915 | { | - | ||||||||||||||||||
1916 | m_mainThread = false; | - | ||||||||||||||||||
1917 | m_primary = true; | - | ||||||||||||||||||
1918 | m_agent = agent; | - | ||||||||||||||||||
1919 | m_dynamicRoles = orig->m_dynamicRoles; | - | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | m_layout = new ListLayout(orig->m_layout); | - | ||||||||||||||||||
1922 | m_listModel = new ListModel(m_layout, this); | - | ||||||||||||||||||
1923 | - | |||||||||||||||||||
1924 | if (m_dynamicRoles)
| 436-468 | ||||||||||||||||||
1925 | sync(orig, this); executed 468 times by 1 test: sync(orig, this); Executed by:
| 468 | ||||||||||||||||||
1926 | else | - | ||||||||||||||||||
1927 | ListModel::sync(orig->m_listModel, m_listModel); executed 436 times by 2 tests: ListModel::sync(orig->m_listModel, m_listModel); Executed by:
| 436 | ||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | m_engine = nullptr; | - | ||||||||||||||||||
1930 | m_compilationUnit = orig->m_compilationUnit; | - | ||||||||||||||||||
1931 | } executed 904 times by 2 tests: end of block Executed by:
| 904 | ||||||||||||||||||
1932 | - | |||||||||||||||||||
1933 | QQmlListModel::~QQmlListModel() | - | ||||||||||||||||||
1934 | { | - | ||||||||||||||||||
1935 | qDeleteAll(m_modelObjects); | - | ||||||||||||||||||
1936 | - | |||||||||||||||||||
1937 | if (m_primary) {
| 138-3352 | ||||||||||||||||||
1938 | m_listModel->destroy(); | - | ||||||||||||||||||
1939 | delete m_listModel; | - | ||||||||||||||||||
1940 | - | |||||||||||||||||||
1941 | if (m_mainThread && m_agent) {
| 934-2378 | ||||||||||||||||||
1942 | m_agent->modelDestroyed(); | - | ||||||||||||||||||
1943 | m_agent->release(); | - | ||||||||||||||||||
1944 | } executed 934 times by 2 tests: end of block Executed by:
| 934 | ||||||||||||||||||
1945 | } executed 3352 times by 15 tests: end of block Executed by:
| 3352 | ||||||||||||||||||
1946 | - | |||||||||||||||||||
1947 | m_listModel = nullptr; | - | ||||||||||||||||||
1948 | - | |||||||||||||||||||
1949 | delete m_layout; | - | ||||||||||||||||||
1950 | m_layout = nullptr; | - | ||||||||||||||||||
1951 | } executed 3490 times by 15 tests: end of block Executed by:
| 3490 | ||||||||||||||||||
1952 | - | |||||||||||||||||||
1953 | QQmlListModel *QQmlListModel::createWithOwner(QQmlListModel *newOwner) | - | ||||||||||||||||||
1954 | { | - | ||||||||||||||||||
1955 | QQmlListModel *model = new QQmlListModel; | - | ||||||||||||||||||
1956 | - | |||||||||||||||||||
1957 | model->m_mainThread = newOwner->m_mainThread; | - | ||||||||||||||||||
1958 | model->m_engine = newOwner->m_engine; | - | ||||||||||||||||||
1959 | model->m_agent = newOwner->m_agent; | - | ||||||||||||||||||
1960 | model->m_dynamicRoles = newOwner->m_dynamicRoles; | - | ||||||||||||||||||
1961 | - | |||||||||||||||||||
1962 | if (model->m_mainThread && model->m_agent)
| 30-160 | ||||||||||||||||||
1963 | model->m_agent->addref(); executed 30 times by 1 test: model->m_agent->addref(); Executed by:
| 30 | ||||||||||||||||||
1964 | - | |||||||||||||||||||
1965 | QQmlEngine::setContextForObject(model, QQmlEngine::contextForObject(newOwner)); | - | ||||||||||||||||||
1966 | - | |||||||||||||||||||
1967 | return model; executed 232 times by 2 tests: return model; Executed by:
| 232 | ||||||||||||||||||
1968 | } | - | ||||||||||||||||||
1969 | - | |||||||||||||||||||
1970 | QV4::ExecutionEngine *QQmlListModel::engine() const | - | ||||||||||||||||||
1971 | { | - | ||||||||||||||||||
1972 | if (m_engine == nullptr) {
| 640-12779 | ||||||||||||||||||
1973 | m_engine = qmlEngine(this)->handle(); | - | ||||||||||||||||||
1974 | } executed 640 times by 7 tests: end of block Executed by:
| 640 | ||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | return m_engine; executed 13419 times by 13 tests: return m_engine; Executed by:
| 13419 | ||||||||||||||||||
1977 | } | - | ||||||||||||||||||
1978 | - | |||||||||||||||||||
1979 | bool QQmlListModel::sync(QQmlListModel *src, QQmlListModel *target) | - | ||||||||||||||||||
1980 | { | - | ||||||||||||||||||
1981 | Q_ASSERT(src->m_dynamicRoles && target->m_dynamicRoles); | - | ||||||||||||||||||
1982 | - | |||||||||||||||||||
1983 | bool hasChanges = false; | - | ||||||||||||||||||
1984 | - | |||||||||||||||||||
1985 | target->m_roles = src->m_roles; | - | ||||||||||||||||||
1986 | - | |||||||||||||||||||
1987 | // Build hash of elements <-> uid for each of the lists | - | ||||||||||||||||||
1988 | QHash<int, ElementSync> elementHash; | - | ||||||||||||||||||
1989 | for (int i = 0 ; i < target->m_modelObjects.count(); ++i) {
| 128-1018 | ||||||||||||||||||
1990 | DynamicRoleModelNode *e = target->m_modelObjects.at(i); | - | ||||||||||||||||||
1991 | int uid = e->getUid(); | - | ||||||||||||||||||
1992 | ElementSync sync; | - | ||||||||||||||||||
1993 | sync.target = e; | - | ||||||||||||||||||
1994 | sync.targetIndex = i; | - | ||||||||||||||||||
1995 | elementHash.insert(uid, sync); | - | ||||||||||||||||||
1996 | } executed 128 times by 1 test: end of block Executed by:
| 128 | ||||||||||||||||||
1997 | for (int i = 0 ; i < src->m_modelObjects.count(); ++i) {
| 824-1018 | ||||||||||||||||||
1998 | DynamicRoleModelNode *e = src->m_modelObjects.at(i); | - | ||||||||||||||||||
1999 | int uid = e->getUid(); | - | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | QHash<int, ElementSync>::iterator it = elementHash.find(uid); | - | ||||||||||||||||||
2002 | if (it == elementHash.end()) {
| 100-724 | ||||||||||||||||||
2003 | ElementSync sync; | - | ||||||||||||||||||
2004 | sync.src = e; | - | ||||||||||||||||||
2005 | sync.srcIndex = i; | - | ||||||||||||||||||
2006 | elementHash.insert(uid, sync); | - | ||||||||||||||||||
2007 | } else { executed 724 times by 1 test: end of block Executed by:
| 724 | ||||||||||||||||||
2008 | ElementSync &sync = it.value(); | - | ||||||||||||||||||
2009 | sync.src = e; | - | ||||||||||||||||||
2010 | sync.srcIndex = i; | - | ||||||||||||||||||
2011 | } executed 100 times by 1 test: end of block Executed by:
| 100 | ||||||||||||||||||
2012 | } | - | ||||||||||||||||||
2013 | - | |||||||||||||||||||
2014 | // Get list of elements that are in the target but no longer in the source. These get deleted first. | - | ||||||||||||||||||
2015 | int rowsRemoved = 0; | - | ||||||||||||||||||
2016 | for (int i = 0 ; i < target->m_modelObjects.count() ; ++i) {
| 128-1018 | ||||||||||||||||||
2017 | DynamicRoleModelNode *element = target->m_modelObjects.at(i); | - | ||||||||||||||||||
2018 | ElementSync &s = elementHash.find(element->getUid()).value(); | - | ||||||||||||||||||
2019 | Q_ASSERT(s.targetIndex >= 0); | - | ||||||||||||||||||
2020 | // need to update the targetIndex, to keep it correct after removals | - | ||||||||||||||||||
2021 | s.targetIndex -= rowsRemoved; | - | ||||||||||||||||||
2022 | if (s.src == nullptr) {
| 28-100 | ||||||||||||||||||
2023 | Q_ASSERT(s.targetIndex == i); | - | ||||||||||||||||||
2024 | hasChanges = true; | - | ||||||||||||||||||
2025 | target->beginRemoveRows(QModelIndex(), i, i); | - | ||||||||||||||||||
2026 | target->m_modelObjects.remove(i, 1); | - | ||||||||||||||||||
2027 | target->endRemoveRows(); | - | ||||||||||||||||||
2028 | delete s.target; | - | ||||||||||||||||||
2029 | ++rowsRemoved; | - | ||||||||||||||||||
2030 | --i; | - | ||||||||||||||||||
2031 | continue; executed 28 times by 1 test: continue; Executed by:
| 28 | ||||||||||||||||||
2032 | } | - | ||||||||||||||||||
2033 | } executed 100 times by 1 test: end of block Executed by:
| 100 | ||||||||||||||||||
2034 | - | |||||||||||||||||||
2035 | // Clear the target list, and append in correct order from the source | - | ||||||||||||||||||
2036 | target->m_modelObjects.clear(); | - | ||||||||||||||||||
2037 | for (int i = 0 ; i < src->m_modelObjects.count() ; ++i) {
| 824-1018 | ||||||||||||||||||
2038 | DynamicRoleModelNode *element = src->m_modelObjects.at(i); | - | ||||||||||||||||||
2039 | ElementSync &s = elementHash.find(element->getUid()).value(); | - | ||||||||||||||||||
2040 | Q_ASSERT(s.srcIndex >= 0); | - | ||||||||||||||||||
2041 | DynamicRoleModelNode *targetElement = s.target; | - | ||||||||||||||||||
2042 | if (targetElement == nullptr) {
| 100-724 | ||||||||||||||||||
2043 | targetElement = new DynamicRoleModelNode(target, element->getUid()); | - | ||||||||||||||||||
2044 | } executed 724 times by 1 test: end of block Executed by:
| 724 | ||||||||||||||||||
2045 | s.changedRoles = DynamicRoleModelNode::sync(element, targetElement); | - | ||||||||||||||||||
2046 | target->m_modelObjects.append(targetElement); | - | ||||||||||||||||||
2047 | } executed 824 times by 1 test: end of block Executed by:
| 824 | ||||||||||||||||||
2048 | - | |||||||||||||||||||
2049 | // now emit the change notifications required. This can be safely done, as we're only emitting changes, moves and inserts, | - | ||||||||||||||||||
2050 | // so the model indices can't be out of bounds | - | ||||||||||||||||||
2051 | // | - | ||||||||||||||||||
2052 | // to ensure things are kept in the correct order, emit inserts and moves first. This shouls ensure all persistent | - | ||||||||||||||||||
2053 | // model indices are updated correctly | - | ||||||||||||||||||
2054 | int rowsInserted = 0; | - | ||||||||||||||||||
2055 | for (int i = 0 ; i < target->m_modelObjects.count() ; ++i) {
| 824-1018 | ||||||||||||||||||
2056 | DynamicRoleModelNode *element = target->m_modelObjects.at(i); | - | ||||||||||||||||||
2057 | ElementSync &s = elementHash.find(element->getUid()).value(); | - | ||||||||||||||||||
2058 | Q_ASSERT(s.srcIndex >= 0); | - | ||||||||||||||||||
2059 | s.srcIndex += rowsInserted; | - | ||||||||||||||||||
2060 | if (s.srcIndex != s.targetIndex) {
| 100-724 | ||||||||||||||||||
2061 | if (s.targetIndex == -1) {
| 0-724 | ||||||||||||||||||
2062 | target->beginInsertRows(QModelIndex(), i, i); | - | ||||||||||||||||||
2063 | target->endInsertRows(); | - | ||||||||||||||||||
2064 | } else { executed 724 times by 1 test: end of block Executed by:
| 724 | ||||||||||||||||||
2065 | target->beginMoveRows(QModelIndex(), i, i, QModelIndex(), s.srcIndex); | - | ||||||||||||||||||
2066 | target->endMoveRows(); | - | ||||||||||||||||||
2067 | } never executed: end of block | 0 | ||||||||||||||||||
2068 | hasChanges = true; | - | ||||||||||||||||||
2069 | ++rowsInserted; | - | ||||||||||||||||||
2070 | } executed 724 times by 1 test: end of block Executed by:
| 724 | ||||||||||||||||||
2071 | if (s.targetIndex != -1 && !s.changedRoles.isEmpty()) {
| 38-724 | ||||||||||||||||||
2072 | QModelIndex idx = target->createIndex(i, 0); | - | ||||||||||||||||||
2073 | emit target->dataChanged(idx, idx, s.changedRoles); | - | ||||||||||||||||||
2074 | hasChanges = true; | - | ||||||||||||||||||
2075 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||||||||
2076 | } executed 824 times by 1 test: end of block Executed by:
| 824 | ||||||||||||||||||
2077 | return hasChanges; executed 1018 times by 1 test: return hasChanges; Executed by:
| 1018 | ||||||||||||||||||
2078 | } | - | ||||||||||||||||||
2079 | - | |||||||||||||||||||
2080 | void QQmlListModel::emitItemsChanged(int index, int count, const QVector<int> &roles) | - | ||||||||||||||||||
2081 | { | - | ||||||||||||||||||
2082 | if (count <= 0)
| 0-458 | ||||||||||||||||||
2083 | return; never executed: return; | 0 | ||||||||||||||||||
2084 | - | |||||||||||||||||||
2085 | if (m_mainThread)
| 206-252 | ||||||||||||||||||
2086 | emit dataChanged(createIndex(index, 0), createIndex(index + count - 1, 0), roles);; executed 252 times by 3 tests: dataChanged(createIndex(index, 0), createIndex(index + count - 1, 0), roles); Executed by:
| 252 | ||||||||||||||||||
2087 | } executed 458 times by 3 tests: end of block Executed by:
| 458 | ||||||||||||||||||
2088 | - | |||||||||||||||||||
2089 | void QQmlListModel::emitItemsAboutToBeInserted(int index, int count) | - | ||||||||||||||||||
2090 | { | - | ||||||||||||||||||
2091 | Q_ASSERT(index >= 0 && count >= 0); | - | ||||||||||||||||||
2092 | if (m_mainThread)
| 1098-2224 | ||||||||||||||||||
2093 | beginInsertRows(QModelIndex(), index, index + count - 1); executed 2224 times by 9 tests: beginInsertRows(QModelIndex(), index, index + count - 1); Executed by:
| 2224 | ||||||||||||||||||
2094 | } executed 3322 times by 9 tests: end of block Executed by:
| 3322 | ||||||||||||||||||
2095 | - | |||||||||||||||||||
2096 | void QQmlListModel::emitItemsInserted() | - | ||||||||||||||||||
2097 | { | - | ||||||||||||||||||
2098 | if (m_mainThread) {
| 1098-2224 | ||||||||||||||||||
2099 | endInsertRows(); | - | ||||||||||||||||||
2100 | emit countChanged(); | - | ||||||||||||||||||
2101 | } executed 2224 times by 9 tests: end of block Executed by:
| 2224 | ||||||||||||||||||
2102 | } executed 3322 times by 9 tests: end of block Executed by:
| 3322 | ||||||||||||||||||
2103 | - | |||||||||||||||||||
2104 | QQmlListModelWorkerAgent *QQmlListModel::agent() | - | ||||||||||||||||||
2105 | { | - | ||||||||||||||||||
2106 | if (m_agent)
| 904-952 | ||||||||||||||||||
2107 | return m_agent; executed 952 times by 2 tests: return m_agent; Executed by:
| 952 | ||||||||||||||||||
2108 | - | |||||||||||||||||||
2109 | m_agent = new QQmlListModelWorkerAgent(this); | - | ||||||||||||||||||
2110 | return m_agent; executed 904 times by 2 tests: return m_agent; Executed by:
| 904 | ||||||||||||||||||
2111 | } | - | ||||||||||||||||||
2112 | - | |||||||||||||||||||
2113 | QModelIndex QQmlListModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||
2114 | { | - | ||||||||||||||||||
2115 | return row >= 0 && row < count() && column == 0 && !parent.isValid() executed 10815 times by 9 tests: return row >= 0 && row < count() && column == 0 && !parent.isValid() ? createIndex(row, column) : QModelIndex(); Executed by:
| 10815 | ||||||||||||||||||
2116 | ? createIndex(row, column) executed 10815 times by 9 tests: return row >= 0 && row < count() && column == 0 && !parent.isValid() ? createIndex(row, column) : QModelIndex(); Executed by:
| 10815 | ||||||||||||||||||
2117 | : QModelIndex(); executed 10815 times by 9 tests: return row >= 0 && row < count() && column == 0 && !parent.isValid() ? createIndex(row, column) : QModelIndex(); Executed by:
| 10815 | ||||||||||||||||||
2118 | } | - | ||||||||||||||||||
2119 | - | |||||||||||||||||||
2120 | int QQmlListModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||
2121 | { | - | ||||||||||||||||||
2122 | return !parent.isValid() ? count() : 0; executed 18716 times by 12 tests: return !parent.isValid() ? count() : 0; Executed by:
| 18716 | ||||||||||||||||||
2123 | } | - | ||||||||||||||||||
2124 | - | |||||||||||||||||||
2125 | QVariant QQmlListModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||
2126 | { | - | ||||||||||||||||||
2127 | return data(index.row(), role); executed 10503 times by 9 tests: return data(index.row(), role); Executed by:
| 10503 | ||||||||||||||||||
2128 | } | - | ||||||||||||||||||
2129 | - | |||||||||||||||||||
2130 | bool QQmlListModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||
2131 | { | - | ||||||||||||||||||
2132 | const int row = index.row(); | - | ||||||||||||||||||
2133 | if (row >= count() || row < 0)
| 0-4 | ||||||||||||||||||
2134 | return false; never executed: return false; | 0 | ||||||||||||||||||
2135 | - | |||||||||||||||||||
2136 | if (m_dynamicRoles) {
| 0-4 | ||||||||||||||||||
2137 | const QByteArray property = m_roles.at(role).toUtf8(); | - | ||||||||||||||||||
2138 | if (m_modelObjects[row]->setValue(property, value)) {
| 0 | ||||||||||||||||||
2139 | emitItemsChanged(row, 1, QVector<int>(1, role)); | - | ||||||||||||||||||
2140 | return true; never executed: return true; | 0 | ||||||||||||||||||
2141 | } | - | ||||||||||||||||||
2142 | } else { never executed: end of block | 0 | ||||||||||||||||||
2143 | const ListLayout::Role &r = m_listModel->getExistingRole(role); | - | ||||||||||||||||||
2144 | const int roleIndex = m_listModel->setOrCreateProperty(row, r.name, value); | - | ||||||||||||||||||
2145 | if (roleIndex != -1) {
| 0-4 | ||||||||||||||||||
2146 | emitItemsChanged(row, 1, QVector<int>(1, role)); | - | ||||||||||||||||||
2147 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
2148 | } | - | ||||||||||||||||||
2149 | } never executed: end of block | 0 | ||||||||||||||||||
2150 | - | |||||||||||||||||||
2151 | return false; never executed: return false; | 0 | ||||||||||||||||||
2152 | } | - | ||||||||||||||||||
2153 | - | |||||||||||||||||||
2154 | QVariant QQmlListModel::data(int index, int role) const | - | ||||||||||||||||||
2155 | { | - | ||||||||||||||||||
2156 | QVariant v; | - | ||||||||||||||||||
2157 | - | |||||||||||||||||||
2158 | if (index >= count() || index < 0)
| 0-11687 | ||||||||||||||||||
2159 | return v; never executed: return v; | 0 | ||||||||||||||||||
2160 | - | |||||||||||||||||||
2161 | if (m_dynamicRoles)
| 102-11585 | ||||||||||||||||||
2162 | v = m_modelObjects[index]->getValue(m_roles[role]); executed 102 times by 2 tests: v = m_modelObjects[index]->getValue(m_roles[role]); Executed by:
| 102 | ||||||||||||||||||
2163 | else | - | ||||||||||||||||||
2164 | v = m_listModel->getProperty(index, role, this, engine()); executed 11585 times by 13 tests: v = m_listModel->getProperty(index, role, this, engine()); Executed by:
| 11585 | ||||||||||||||||||
2165 | - | |||||||||||||||||||
2166 | return v; executed 11687 times by 13 tests: return v; Executed by:
| 11687 | ||||||||||||||||||
2167 | } | - | ||||||||||||||||||
2168 | - | |||||||||||||||||||
2169 | QHash<int, QByteArray> QQmlListModel::roleNames() const | - | ||||||||||||||||||
2170 | { | - | ||||||||||||||||||
2171 | QHash<int, QByteArray> roleNames; | - | ||||||||||||||||||
2172 | - | |||||||||||||||||||
2173 | if (m_dynamicRoles) {
| 88-734 | ||||||||||||||||||
2174 | for (int i = 0 ; i < m_roles.count() ; ++i)
| 88-300 | ||||||||||||||||||
2175 | roleNames.insert(i, m_roles.at(i).toUtf8()); executed 300 times by 2 tests: roleNames.insert(i, m_roles.at(i).toUtf8()); Executed by:
| 300 | ||||||||||||||||||
2176 | } else { executed 88 times by 2 tests: end of block Executed by:
| 88 | ||||||||||||||||||
2177 | for (int i = 0 ; i < m_listModel->roleCount() ; ++i) {
| 734-1128 | ||||||||||||||||||
2178 | const ListLayout::Role &r = m_listModel->getExistingRole(i); | - | ||||||||||||||||||
2179 | roleNames.insert(i, r.name.toUtf8()); | - | ||||||||||||||||||
2180 | } executed 1128 times by 11 tests: end of block Executed by:
| 1128 | ||||||||||||||||||
2181 | } executed 734 times by 11 tests: end of block Executed by:
| 734 | ||||||||||||||||||
2182 | - | |||||||||||||||||||
2183 | return roleNames; executed 822 times by 11 tests: return roleNames; Executed by:
| 822 | ||||||||||||||||||
2184 | } | - | ||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | /*! | - | ||||||||||||||||||
2187 | \qmlproperty bool ListModel::dynamicRoles | - | ||||||||||||||||||
2188 | - | |||||||||||||||||||
2189 | By default, the type of a role is fixed the first time | - | ||||||||||||||||||
2190 | the role is used. For example, if you create a role called | - | ||||||||||||||||||
2191 | "data" and assign a number to it, you can no longer assign | - | ||||||||||||||||||
2192 | a string to the "data" role. However, when the dynamicRoles | - | ||||||||||||||||||
2193 | property is enabled, the type of a given role is not fixed | - | ||||||||||||||||||
2194 | and can be different between elements. | - | ||||||||||||||||||
2195 | - | |||||||||||||||||||
2196 | The dynamicRoles property must be set before any data is | - | ||||||||||||||||||
2197 | added to the ListModel, and must be set from the main | - | ||||||||||||||||||
2198 | thread. | - | ||||||||||||||||||
2199 | - | |||||||||||||||||||
2200 | A ListModel that has data statically defined (via the | - | ||||||||||||||||||
2201 | ListElement QML syntax) cannot have the dynamicRoles | - | ||||||||||||||||||
2202 | property enabled. | - | ||||||||||||||||||
2203 | - | |||||||||||||||||||
2204 | There is a significant performance cost to using a | - | ||||||||||||||||||
2205 | ListModel with dynamic roles enabled. The cost varies | - | ||||||||||||||||||
2206 | from platform to platform but is typically somewhere | - | ||||||||||||||||||
2207 | between 4-6x slower than using static role types. | - | ||||||||||||||||||
2208 | - | |||||||||||||||||||
2209 | Due to the performance cost of using dynamic roles, | - | ||||||||||||||||||
2210 | they are disabled by default. | - | ||||||||||||||||||
2211 | */ | - | ||||||||||||||||||
2212 | void QQmlListModel::setDynamicRoles(bool enableDynamicRoles) | - | ||||||||||||||||||
2213 | { | - | ||||||||||||||||||
2214 | if (m_mainThread && m_agent == nullptr) {
| 0-1454 | ||||||||||||||||||
2215 | if (enableDynamicRoles) {
| 706-748 | ||||||||||||||||||
2216 | if (m_layout->roleCount())
| 2-746 | ||||||||||||||||||
2217 | qmlWarning(this) << tr("unable to enable dynamic roles as this model is not empty"); executed 2 times by 1 test: qmlWarning(this) << tr("unable to enable dynamic roles as this model is not empty"); Executed by:
| 2 | ||||||||||||||||||
2218 | else | - | ||||||||||||||||||
2219 | m_dynamicRoles = true; executed 746 times by 2 tests: m_dynamicRoles = true; Executed by:
| 746 | ||||||||||||||||||
2220 | } else { | - | ||||||||||||||||||
2221 | if (m_roles.count()) {
| 2-704 | ||||||||||||||||||
2222 | qmlWarning(this) << tr("unable to enable static roles as this model is not empty"); | - | ||||||||||||||||||
2223 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
2224 | m_dynamicRoles = false; | - | ||||||||||||||||||
2225 | } executed 704 times by 2 tests: end of block Executed by:
| 704 | ||||||||||||||||||
2226 | } | - | ||||||||||||||||||
2227 | } else { | - | ||||||||||||||||||
2228 | qmlWarning(this) << tr("dynamic role setting must be made from the main thread, before any worker scripts are created"); | - | ||||||||||||||||||
2229 | } never executed: end of block | 0 | ||||||||||||||||||
2230 | } | - | ||||||||||||||||||
2231 | - | |||||||||||||||||||
2232 | /*! | - | ||||||||||||||||||
2233 | \qmlproperty int ListModel::count | - | ||||||||||||||||||
2234 | The number of data entries in the model. | - | ||||||||||||||||||
2235 | */ | - | ||||||||||||||||||
2236 | int QQmlListModel::count() const | - | ||||||||||||||||||
2237 | { | - | ||||||||||||||||||
2238 | return m_dynamicRoles ? m_modelObjects.count() : m_listModel->elementCount(); executed 48668 times by 14 tests: return m_dynamicRoles ? m_modelObjects.count() : m_listModel->elementCount(); Executed by:
| 48668 | ||||||||||||||||||
2239 | } | - | ||||||||||||||||||
2240 | - | |||||||||||||||||||
2241 | /*! | - | ||||||||||||||||||
2242 | \qmlmethod ListModel::clear() | - | ||||||||||||||||||
2243 | - | |||||||||||||||||||
2244 | Deletes all content from the model. | - | ||||||||||||||||||
2245 | - | |||||||||||||||||||
2246 | \sa append(), remove() | - | ||||||||||||||||||
2247 | */ | - | ||||||||||||||||||
2248 | void QQmlListModel::clear() | - | ||||||||||||||||||
2249 | { | - | ||||||||||||||||||
2250 | removeElements(0, count()); | - | ||||||||||||||||||
2251 | } executed 80 times by 4 tests: end of block Executed by:
| 80 | ||||||||||||||||||
2252 | - | |||||||||||||||||||
2253 | /*! | - | ||||||||||||||||||
2254 | \qmlmethod ListModel::remove(int index, int count = 1) | - | ||||||||||||||||||
2255 | - | |||||||||||||||||||
2256 | Deletes the content at \a index from the model. | - | ||||||||||||||||||
2257 | - | |||||||||||||||||||
2258 | \sa clear() | - | ||||||||||||||||||
2259 | */ | - | ||||||||||||||||||
2260 | void QQmlListModel::remove(QQmlV4Function *args) | - | ||||||||||||||||||
2261 | { | - | ||||||||||||||||||
2262 | int argLength = args->length(); | - | ||||||||||||||||||
2263 | - | |||||||||||||||||||
2264 | if (argLength == 1 || argLength == 2) {
| 24-238 | ||||||||||||||||||
2265 | QV4::Scope scope(args->v4engine()); | - | ||||||||||||||||||
2266 | int index = QV4::ScopedValue(scope, (*args)[0])->toInt32(); | - | ||||||||||||||||||
2267 | int removeCount = (argLength == 2 ? QV4::ScopedValue(scope, (*args)[1])->toInt32() : 1);
| 190-214 | ||||||||||||||||||
2268 | - | |||||||||||||||||||
2269 | if (index < 0 || index+removeCount > count() || removeCount <= 0) {
| 12-392 | ||||||||||||||||||
2270 | qmlWarning(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count()); | - | ||||||||||||||||||
2271 | return; executed 72 times by 2 tests: return; Executed by:
| 72 | ||||||||||||||||||
2272 | } | - | ||||||||||||||||||
2273 | - | |||||||||||||||||||
2274 | removeElements(index, removeCount); | - | ||||||||||||||||||
2275 | } else { executed 332 times by 6 tests: end of block Executed by:
| 332 | ||||||||||||||||||
2276 | qmlWarning(this) << tr("remove: incorrect number of arguments"); | - | ||||||||||||||||||
2277 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
2278 | } | - | ||||||||||||||||||
2279 | - | |||||||||||||||||||
2280 | void QQmlListModel::removeElements(int index, int removeCount) | - | ||||||||||||||||||
2281 | { | - | ||||||||||||||||||
2282 | Q_ASSERT(index >= 0 && removeCount >= 0); | - | ||||||||||||||||||
2283 | - | |||||||||||||||||||
2284 | if (!removeCount)
| 4-408 | ||||||||||||||||||
2285 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
2286 | - | |||||||||||||||||||
2287 | if (m_mainThread)
| 148-260 | ||||||||||||||||||
2288 | beginRemoveRows(QModelIndex(), index, index + removeCount - 1); executed 260 times by 6 tests: beginRemoveRows(QModelIndex(), index, index + removeCount - 1); Executed by:
| 260 | ||||||||||||||||||
2289 | - | |||||||||||||||||||
2290 | QVector<std::function<void()>> toDestroy; | - | ||||||||||||||||||
2291 | if (m_dynamicRoles) {
| 132-276 | ||||||||||||||||||
2292 | for (int i=0 ; i < removeCount ; ++i) {
| 132-158 | ||||||||||||||||||
2293 | auto modelObject = m_modelObjects[index+i]; | - | ||||||||||||||||||
2294 | toDestroy.append([modelObject](){ | - | ||||||||||||||||||
2295 | delete modelObject; | - | ||||||||||||||||||
2296 | }); executed 158 times by 2 tests: end of block Executed by:
| 158 | ||||||||||||||||||
2297 | } executed 158 times by 2 tests: end of block Executed by:
| 158 | ||||||||||||||||||
2298 | m_modelObjects.remove(index, removeCount); | - | ||||||||||||||||||
2299 | } else { executed 132 times by 2 tests: end of block Executed by:
| 132 | ||||||||||||||||||
2300 | toDestroy = m_listModel->remove(index, removeCount); | - | ||||||||||||||||||
2301 | } executed 276 times by 6 tests: end of block Executed by:
| 276 | ||||||||||||||||||
2302 | - | |||||||||||||||||||
2303 | if (m_mainThread) {
| 148-260 | ||||||||||||||||||
2304 | endRemoveRows(); | - | ||||||||||||||||||
2305 | emit countChanged(); | - | ||||||||||||||||||
2306 | } executed 260 times by 6 tests: end of block Executed by:
| 260 | ||||||||||||||||||
2307 | for (const auto &destroyer : toDestroy) | - | ||||||||||||||||||
2308 | destroyer(); executed 506 times by 6 tests: destroyer(); Executed by:
| 506 | ||||||||||||||||||
2309 | } executed 408 times by 6 tests: end of block Executed by:
| 408 | ||||||||||||||||||
2310 | - | |||||||||||||||||||
2311 | /*! | - | ||||||||||||||||||
2312 | \qmlmethod ListModel::insert(int index, jsobject dict) | - | ||||||||||||||||||
2313 | - | |||||||||||||||||||
2314 | Adds a new item to the list model at position \a index, with the | - | ||||||||||||||||||
2315 | values in \a dict. | - | ||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | \code | - | ||||||||||||||||||
2318 | fruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) | - | ||||||||||||||||||
2319 | \endcode | - | ||||||||||||||||||
2320 | - | |||||||||||||||||||
2321 | The \a index must be to an existing item in the list, or one past | - | ||||||||||||||||||
2322 | the end of the list (equivalent to append). | - | ||||||||||||||||||
2323 | - | |||||||||||||||||||
2324 | \sa set(), append() | - | ||||||||||||||||||
2325 | */ | - | ||||||||||||||||||
2326 | - | |||||||||||||||||||
2327 | void QQmlListModel::insert(QQmlV4Function *args) | - | ||||||||||||||||||
2328 | { | - | ||||||||||||||||||
2329 | if (args->length() == 2) {
| 12-538 | ||||||||||||||||||
2330 | QV4::Scope scope(args->v4engine()); | - | ||||||||||||||||||
2331 | QV4::ScopedValue arg0(scope, (*args)[0]); | - | ||||||||||||||||||
2332 | int index = arg0->toInt32(); | - | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | if (index < 0 || index > count()) {
| 12-526 | ||||||||||||||||||
2335 | qmlWarning(this) << tr("insert: index %1 out of range").arg(index); | - | ||||||||||||||||||
2336 | return; executed 24 times by 2 tests: return; Executed by:
| 24 | ||||||||||||||||||
2337 | } | - | ||||||||||||||||||
2338 | - | |||||||||||||||||||
2339 | QV4::ScopedObject argObject(scope, (*args)[1]); | - | ||||||||||||||||||
2340 | QV4::ScopedArrayObject objectArray(scope, (*args)[1]); | - | ||||||||||||||||||
2341 | if (objectArray) {
| 24-490 | ||||||||||||||||||
2342 | QV4::ScopedObject argObject(scope); | - | ||||||||||||||||||
2343 | - | |||||||||||||||||||
2344 | int objectArrayLength = objectArray->getLength(); | - | ||||||||||||||||||
2345 | emitItemsAboutToBeInserted(index, objectArrayLength); | - | ||||||||||||||||||
2346 | for (int i=0 ; i < objectArrayLength ; ++i) {
| 24-72 | ||||||||||||||||||
2347 | argObject = objectArray->get(i); | - | ||||||||||||||||||
2348 | - | |||||||||||||||||||
2349 | if (m_dynamicRoles) {
| 36 | ||||||||||||||||||
2350 | m_modelObjects.insert(index+i, DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); | - | ||||||||||||||||||
2351 | } else { executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||
2352 | m_listModel->insert(index+i, argObject); | - | ||||||||||||||||||
2353 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||
2354 | } | - | ||||||||||||||||||
2355 | emitItemsInserted(); | - | ||||||||||||||||||
2356 | } else if (argObject) { executed 24 times by 2 tests: end of block Executed by:
| 24-466 | ||||||||||||||||||
2357 | emitItemsAboutToBeInserted(index, 1); | - | ||||||||||||||||||
2358 | - | |||||||||||||||||||
2359 | if (m_dynamicRoles) {
| 54-412 | ||||||||||||||||||
2360 | m_modelObjects.insert(index, DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); | - | ||||||||||||||||||
2361 | } else { executed 54 times by 2 tests: end of block Executed by:
| 54 | ||||||||||||||||||
2362 | m_listModel->insert(index, argObject); | - | ||||||||||||||||||
2363 | } executed 412 times by 5 tests: end of block Executed by:
| 412 | ||||||||||||||||||
2364 | - | |||||||||||||||||||
2365 | emitItemsInserted(); | - | ||||||||||||||||||
2366 | } else { executed 466 times by 5 tests: end of block Executed by:
| 466 | ||||||||||||||||||
2367 | qmlWarning(this) << tr("insert: value is not an object"); | - | ||||||||||||||||||
2368 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
2369 | } else { | - | ||||||||||||||||||
2370 | qmlWarning(this) << tr("insert: value is not an object"); | - | ||||||||||||||||||
2371 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2372 | } | - | ||||||||||||||||||
2373 | - | |||||||||||||||||||
2374 | /*! | - | ||||||||||||||||||
2375 | \qmlmethod ListModel::move(int from, int to, int n) | - | ||||||||||||||||||
2376 | - | |||||||||||||||||||
2377 | Moves \a n items \a from one position \a to another. | - | ||||||||||||||||||
2378 | - | |||||||||||||||||||
2379 | The from and to ranges must exist; for example, to move the first 3 items | - | ||||||||||||||||||
2380 | to the end of the list: | - | ||||||||||||||||||
2381 | - | |||||||||||||||||||
2382 | \code | - | ||||||||||||||||||
2383 | fruitModel.move(0, fruitModel.count - 3, 3) | - | ||||||||||||||||||
2384 | \endcode | - | ||||||||||||||||||
2385 | - | |||||||||||||||||||
2386 | \sa append() | - | ||||||||||||||||||
2387 | */ | - | ||||||||||||||||||
2388 | void QQmlListModel::move(int from, int to, int n) | - | ||||||||||||||||||
2389 | { | - | ||||||||||||||||||
2390 | if (n == 0 || from == to)
| 0-190 | ||||||||||||||||||
2391 | return; never executed: return; | 0 | ||||||||||||||||||
2392 | if (!canMove(from, to, n)) {
| 48-142 | ||||||||||||||||||
2393 | qmlWarning(this) << tr("move: out of range"); | - | ||||||||||||||||||
2394 | return; executed 48 times by 2 tests: return; Executed by:
| 48 | ||||||||||||||||||
2395 | } | - | ||||||||||||||||||
2396 | - | |||||||||||||||||||
2397 | if (m_mainThread)
| 70-72 | ||||||||||||||||||
2398 | beginMoveRows(QModelIndex(), from, from + n - 1, QModelIndex(), to > from ? to + n : to); executed 70 times by 4 tests: beginMoveRows(QModelIndex(), from, from + n - 1, QModelIndex(), to > from ? to + n : to); Executed by:
| 70 | ||||||||||||||||||
2399 | - | |||||||||||||||||||
2400 | if (m_dynamicRoles) {
| 54-88 | ||||||||||||||||||
2401 | - | |||||||||||||||||||
2402 | int realFrom = from; | - | ||||||||||||||||||
2403 | int realTo = to; | - | ||||||||||||||||||
2404 | int realN = n; | - | ||||||||||||||||||
2405 | - | |||||||||||||||||||
2406 | if (from > to) {
| 12-42 | ||||||||||||||||||
2407 | // Only move forwards - flip if backwards moving | - | ||||||||||||||||||
2408 | int tfrom = from; | - | ||||||||||||||||||
2409 | int tto = to; | - | ||||||||||||||||||
2410 | realFrom = tto; | - | ||||||||||||||||||
2411 | realTo = tto+n; | - | ||||||||||||||||||
2412 | realN = tfrom-tto; | - | ||||||||||||||||||
2413 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2414 | - | |||||||||||||||||||
2415 | QPODVector<DynamicRoleModelNode *, 4> store; | - | ||||||||||||||||||
2416 | for (int i=0 ; i < (realTo-realFrom) ; ++i)
| 54 | ||||||||||||||||||
2417 | store.append(m_modelObjects[realFrom+realN+i]); executed 54 times by 2 tests: store.append(m_modelObjects[realFrom+realN+i]); Executed by:
| 54 | ||||||||||||||||||
2418 | for (int i=0 ; i < realN ; ++i)
| 54-78 | ||||||||||||||||||
2419 | store.append(m_modelObjects[realFrom+i]); executed 78 times by 2 tests: store.append(m_modelObjects[realFrom+i]); Executed by:
| 78 | ||||||||||||||||||
2420 | for (int i=0 ; i < store.count() ; ++i)
| 54-132 | ||||||||||||||||||
2421 | m_modelObjects[realFrom+i] = store[i]; executed 132 times by 2 tests: m_modelObjects[realFrom+i] = store[i]; Executed by:
| 132 | ||||||||||||||||||
2422 | - | |||||||||||||||||||
2423 | } else { executed 54 times by 2 tests: end of block Executed by:
| 54 | ||||||||||||||||||
2424 | m_listModel->move(from, to, n); | - | ||||||||||||||||||
2425 | } executed 88 times by 5 tests: end of block Executed by:
| 88 | ||||||||||||||||||
2426 | - | |||||||||||||||||||
2427 | if (m_mainThread)
| 70-72 | ||||||||||||||||||
2428 | endMoveRows(); executed 70 times by 4 tests: endMoveRows(); Executed by:
| 70 | ||||||||||||||||||
2429 | } executed 142 times by 5 tests: end of block Executed by:
| 142 | ||||||||||||||||||
2430 | - | |||||||||||||||||||
2431 | /*! | - | ||||||||||||||||||
2432 | \qmlmethod ListModel::append(jsobject dict) | - | ||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | Adds a new item to the end of the list model, with the | - | ||||||||||||||||||
2435 | values in \a dict. | - | ||||||||||||||||||
2436 | - | |||||||||||||||||||
2437 | \code | - | ||||||||||||||||||
2438 | fruitModel.append({"cost": 5.95, "name":"Pizza"}) | - | ||||||||||||||||||
2439 | \endcode | - | ||||||||||||||||||
2440 | - | |||||||||||||||||||
2441 | \sa set(), remove() | - | ||||||||||||||||||
2442 | */ | - | ||||||||||||||||||
2443 | void QQmlListModel::append(QQmlV4Function *args) | - | ||||||||||||||||||
2444 | { | - | ||||||||||||||||||
2445 | if (args->length() == 1) {
| 12-2834 | ||||||||||||||||||
2446 | QV4::Scope scope(args->v4engine()); | - | ||||||||||||||||||
2447 | QV4::ScopedObject argObject(scope, (*args)[0]); | - | ||||||||||||||||||
2448 | QV4::ScopedArrayObject objectArray(scope, (*args)[0]); | - | ||||||||||||||||||
2449 | - | |||||||||||||||||||
2450 | if (objectArray) {
| 26-2808 | ||||||||||||||||||
2451 | QV4::ScopedObject argObject(scope); | - | ||||||||||||||||||
2452 | - | |||||||||||||||||||
2453 | int objectArrayLength = objectArray->getLength(); | - | ||||||||||||||||||
2454 | if (objectArrayLength > 0) {
| 2-24 | ||||||||||||||||||
2455 | int index = count(); | - | ||||||||||||||||||
2456 | emitItemsAboutToBeInserted(index, objectArrayLength); | - | ||||||||||||||||||
2457 | - | |||||||||||||||||||
2458 | for (int i=0 ; i < objectArrayLength ; ++i) {
| 24-72 | ||||||||||||||||||
2459 | argObject = objectArray->get(i); | - | ||||||||||||||||||
2460 | - | |||||||||||||||||||
2461 | if (m_dynamicRoles) {
| 36 | ||||||||||||||||||
2462 | m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); | - | ||||||||||||||||||
2463 | } else { executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||
2464 | m_listModel->append(argObject); | - | ||||||||||||||||||
2465 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||
2466 | } | - | ||||||||||||||||||
2467 | - | |||||||||||||||||||
2468 | emitItemsInserted(); | - | ||||||||||||||||||
2469 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
2470 | } else if (argObject) { executed 26 times by 2 tests: end of block Executed by:
| 24-2784 | ||||||||||||||||||
2471 | int index; | - | ||||||||||||||||||
2472 | - | |||||||||||||||||||
2473 | if (m_dynamicRoles) {
| 938-1846 | ||||||||||||||||||
2474 | index = m_modelObjects.count(); | - | ||||||||||||||||||
2475 | emitItemsAboutToBeInserted(index, 1); | - | ||||||||||||||||||
2476 | m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this)); | - | ||||||||||||||||||
2477 | } else { executed 938 times by 2 tests: end of block Executed by:
| 938 | ||||||||||||||||||
2478 | index = m_listModel->elementCount(); | - | ||||||||||||||||||
2479 | emitItemsAboutToBeInserted(index, 1); | - | ||||||||||||||||||
2480 | m_listModel->append(argObject); | - | ||||||||||||||||||
2481 | } executed 1846 times by 8 tests: end of block Executed by:
| 1846 | ||||||||||||||||||
2482 | - | |||||||||||||||||||
2483 | emitItemsInserted(); | - | ||||||||||||||||||
2484 | } else { executed 2784 times by 8 tests: end of block Executed by:
| 2784 | ||||||||||||||||||
2485 | qmlWarning(this) << tr("append: value is not an object"); | - | ||||||||||||||||||
2486 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
2487 | } else { | - | ||||||||||||||||||
2488 | qmlWarning(this) << tr("append: value is not an object"); | - | ||||||||||||||||||
2489 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2490 | } | - | ||||||||||||||||||
2491 | - | |||||||||||||||||||
2492 | /*! | - | ||||||||||||||||||
2493 | \qmlmethod object ListModel::get(int index) | - | ||||||||||||||||||
2494 | - | |||||||||||||||||||
2495 | Returns the item at \a index in the list model. This allows the item | - | ||||||||||||||||||
2496 | data to be accessed or modified from JavaScript: | - | ||||||||||||||||||
2497 | - | |||||||||||||||||||
2498 | \code | - | ||||||||||||||||||
2499 | Component.onCompleted: { | - | ||||||||||||||||||
2500 | fruitModel.append({"cost": 5.95, "name":"Jackfruit"}); | - | ||||||||||||||||||
2501 | console.log(fruitModel.get(0).cost); | - | ||||||||||||||||||
2502 | fruitModel.get(0).cost = 10.95; | - | ||||||||||||||||||
2503 | } | - | ||||||||||||||||||
2504 | \endcode | - | ||||||||||||||||||
2505 | - | |||||||||||||||||||
2506 | The \a index must be an element in the list. | - | ||||||||||||||||||
2507 | - | |||||||||||||||||||
2508 | Note that properties of the returned object that are themselves objects | - | ||||||||||||||||||
2509 | will also be models, and this get() method is used to access elements: | - | ||||||||||||||||||
2510 | - | |||||||||||||||||||
2511 | \code | - | ||||||||||||||||||
2512 | fruitModel.append(..., "attributes": | - | ||||||||||||||||||
2513 | [{"name":"spikes","value":"7mm"}, | - | ||||||||||||||||||
2514 | {"name":"color","value":"green"}]); | - | ||||||||||||||||||
2515 | fruitModel.get(0).attributes.get(1).value; // == "green" | - | ||||||||||||||||||
2516 | \endcode | - | ||||||||||||||||||
2517 | - | |||||||||||||||||||
2518 | \warning The returned object is not guaranteed to remain valid. It | - | ||||||||||||||||||
2519 | should not be used in \l{Property Binding}{property bindings}. | - | ||||||||||||||||||
2520 | - | |||||||||||||||||||
2521 | \sa append() | - | ||||||||||||||||||
2522 | */ | - | ||||||||||||||||||
2523 | QQmlV4Handle QQmlListModel::get(int index) const | - | ||||||||||||||||||
2524 | { | - | ||||||||||||||||||
2525 | QV4::Scope scope(engine()); | - | ||||||||||||||||||
2526 | QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue()); | - | ||||||||||||||||||
2527 | - | |||||||||||||||||||
2528 | if (index >= 0 && index < count()) {
| 12-1514 | ||||||||||||||||||
2529 | - | |||||||||||||||||||
2530 | if (m_dynamicRoles) {
| 544-958 | ||||||||||||||||||
2531 | DynamicRoleModelNode *object = m_modelObjects[index]; | - | ||||||||||||||||||
2532 | result = QV4::QObjectWrapper::wrap(scope.engine, object); | - | ||||||||||||||||||
2533 | } else { executed 544 times by 2 tests: end of block Executed by:
| 544 | ||||||||||||||||||
2534 | QObject *object = m_listModel->getOrCreateModelObject(const_cast<QQmlListModel *>(this), index); | - | ||||||||||||||||||
2535 | QQmlData *ddata = QQmlData::get(object); | - | ||||||||||||||||||
2536 | if (ddata->jsWrapper.isNullOrUndefined()) {
| 298-660 | ||||||||||||||||||
2537 | result = scope.engine->memoryManager->allocate<QV4::ModelObject>(object, const_cast<QQmlListModel *>(this)); | - | ||||||||||||||||||
2538 | // Keep track of the QObjectWrapper in persistent value storage | - | ||||||||||||||||||
2539 | ddata->jsWrapper.set(scope.engine, result); | - | ||||||||||||||||||
2540 | } else { executed 660 times by 8 tests: end of block Executed by:
| 660 | ||||||||||||||||||
2541 | result = ddata->jsWrapper.value(); | - | ||||||||||||||||||
2542 | } executed 298 times by 5 tests: end of block Executed by:
| 298 | ||||||||||||||||||
2543 | } | - | ||||||||||||||||||
2544 | } | - | ||||||||||||||||||
2545 | - | |||||||||||||||||||
2546 | return QQmlV4Handle(result); executed 1526 times by 8 tests: return QQmlV4Handle(result); Executed by:
| 1526 | ||||||||||||||||||
2547 | } | - | ||||||||||||||||||
2548 | - | |||||||||||||||||||
2549 | /*! | - | ||||||||||||||||||
2550 | \qmlmethod ListModel::set(int index, jsobject dict) | - | ||||||||||||||||||
2551 | - | |||||||||||||||||||
2552 | Changes the item at \a index in the list model with the | - | ||||||||||||||||||
2553 | values in \a dict. Properties not appearing in \a dict | - | ||||||||||||||||||
2554 | are left unchanged. | - | ||||||||||||||||||
2555 | - | |||||||||||||||||||
2556 | \code | - | ||||||||||||||||||
2557 | fruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) | - | ||||||||||||||||||
2558 | \endcode | - | ||||||||||||||||||
2559 | - | |||||||||||||||||||
2560 | If \a index is equal to count() then a new item is appended to the | - | ||||||||||||||||||
2561 | list. Otherwise, \a index must be an element in the list. | - | ||||||||||||||||||
2562 | - | |||||||||||||||||||
2563 | \sa append() | - | ||||||||||||||||||
2564 | */ | - | ||||||||||||||||||
2565 | void QQmlListModel::set(int index, const QQmlV4Handle &handle) | - | ||||||||||||||||||
2566 | { | - | ||||||||||||||||||
2567 | QV4::Scope scope(engine()); | - | ||||||||||||||||||
2568 | QV4::ScopedObject object(scope, handle); | - | ||||||||||||||||||
2569 | - | |||||||||||||||||||
2570 | if (!object) {
| 12-296 | ||||||||||||||||||
2571 | qmlWarning(this) << tr("set: value is not an object"); | - | ||||||||||||||||||
2572 | return; executed 12 times by 2 tests: return; Executed by:
| 12 | ||||||||||||||||||
2573 | } | - | ||||||||||||||||||
2574 | if (index > count() || index < 0) {
| 0-296 | ||||||||||||||||||
2575 | qmlWarning(this) << tr("set: index %1 out of range").arg(index); | - | ||||||||||||||||||
2576 | return; executed 12 times by 2 tests: return; Executed by:
| 12 | ||||||||||||||||||
2577 | } | - | ||||||||||||||||||
2578 | - | |||||||||||||||||||
2579 | - | |||||||||||||||||||
2580 | if (index == count()) {
| 24-260 | ||||||||||||||||||
2581 | emitItemsAboutToBeInserted(index, 1); | - | ||||||||||||||||||
2582 | - | |||||||||||||||||||
2583 | if (m_dynamicRoles) {
| 12 | ||||||||||||||||||
2584 | m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(object), this)); | - | ||||||||||||||||||
2585 | } else { executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2586 | m_listModel->insert(index, object); | - | ||||||||||||||||||
2587 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
2588 | - | |||||||||||||||||||
2589 | emitItemsInserted(); | - | ||||||||||||||||||
2590 | } else { executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||||||||||||||
2591 | - | |||||||||||||||||||
2592 | QVector<int> roles; | - | ||||||||||||||||||
2593 | - | |||||||||||||||||||
2594 | if (m_dynamicRoles) {
| 122-138 | ||||||||||||||||||
2595 | m_modelObjects[index]->updateValues(scope.engine->variantMapFromJS(object), roles); | - | ||||||||||||||||||
2596 | } else { executed 138 times by 2 tests: end of block Executed by:
| 138 | ||||||||||||||||||
2597 | m_listModel->set(index, object, &roles); | - | ||||||||||||||||||
2598 | } executed 122 times by 2 tests: end of block Executed by:
| 122 | ||||||||||||||||||
2599 | - | |||||||||||||||||||
2600 | if (roles.count())
| 30-230 | ||||||||||||||||||
2601 | emitItemsChanged(index, 1, roles); executed 230 times by 2 tests: emitItemsChanged(index, 1, roles); Executed by:
| 230 | ||||||||||||||||||
2602 | } executed 260 times by 2 tests: end of block Executed by:
| 260 | ||||||||||||||||||
2603 | } | - | ||||||||||||||||||
2604 | - | |||||||||||||||||||
2605 | /*! | - | ||||||||||||||||||
2606 | \qmlmethod ListModel::setProperty(int index, string property, variant value) | - | ||||||||||||||||||
2607 | - | |||||||||||||||||||
2608 | Changes the \a property of the item at \a index in the list model to \a value. | - | ||||||||||||||||||
2609 | - | |||||||||||||||||||
2610 | \code | - | ||||||||||||||||||
2611 | fruitModel.setProperty(3, "cost", 5.95) | - | ||||||||||||||||||
2612 | \endcode | - | ||||||||||||||||||
2613 | - | |||||||||||||||||||
2614 | The \a index must be an element in the list. | - | ||||||||||||||||||
2615 | - | |||||||||||||||||||
2616 | \sa append() | - | ||||||||||||||||||
2617 | */ | - | ||||||||||||||||||
2618 | void QQmlListModel::setProperty(int index, const QString& property, const QVariant& value) | - | ||||||||||||||||||
2619 | { | - | ||||||||||||||||||
2620 | if (count() == 0 || index >= count() || index < 0) {
| 0-132 | ||||||||||||||||||
2621 | qmlWarning(this) << tr("set: index %1 out of range").arg(index); | - | ||||||||||||||||||
2622 | return; executed 36 times by 2 tests: return; Executed by:
| 36 | ||||||||||||||||||
2623 | } | - | ||||||||||||||||||
2624 | - | |||||||||||||||||||
2625 | if (m_dynamicRoles) {
| 56-64 | ||||||||||||||||||
2626 | int roleIndex = m_roles.indexOf(property); | - | ||||||||||||||||||
2627 | if (roleIndex == -1) {
| 0-56 | ||||||||||||||||||
2628 | roleIndex = m_roles.count(); | - | ||||||||||||||||||
2629 | m_roles.append(property); | - | ||||||||||||||||||
2630 | } never executed: end of block | 0 | ||||||||||||||||||
2631 | if (m_modelObjects[index]->setValue(property.toUtf8(), value))
| 4-52 | ||||||||||||||||||
2632 | emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); executed 52 times by 2 tests: emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); Executed by:
| 52 | ||||||||||||||||||
2633 | } else { executed 56 times by 2 tests: end of block Executed by:
| 56 | ||||||||||||||||||
2634 | int roleIndex = m_listModel->setOrCreateProperty(index, property, value); | - | ||||||||||||||||||
2635 | if (roleIndex != -1)
| 4-60 | ||||||||||||||||||
2636 | emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); executed 60 times by 3 tests: emitItemsChanged(index, 1, QVector<int>(1, roleIndex)); Executed by:
| 60 | ||||||||||||||||||
2637 | } executed 64 times by 3 tests: end of block Executed by:
| 64 | ||||||||||||||||||
2638 | } | - | ||||||||||||||||||
2639 | - | |||||||||||||||||||
2640 | /*! | - | ||||||||||||||||||
2641 | \qmlmethod ListModel::sync() | - | ||||||||||||||||||
2642 | - | |||||||||||||||||||
2643 | Writes any unsaved changes to the list model after it has been modified | - | ||||||||||||||||||
2644 | from a worker script. | - | ||||||||||||||||||
2645 | */ | - | ||||||||||||||||||
2646 | void QQmlListModel::sync() | - | ||||||||||||||||||
2647 | { | - | ||||||||||||||||||
2648 | // This is just a dummy method to make it look like sync() exists in | - | ||||||||||||||||||
2649 | // ListModel (and not just QQmlListModelWorkerAgent) and to let | - | ||||||||||||||||||
2650 | // us document sync(). | - | ||||||||||||||||||
2651 | qmlWarning(this) << "List sync() can only be called from a WorkerScript"; | - | ||||||||||||||||||
2652 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
2653 | - | |||||||||||||||||||
2654 | bool QQmlListModelParser::verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding) | - | ||||||||||||||||||
2655 | { | - | ||||||||||||||||||
2656 | if (binding->type >= QV4::CompiledData::Binding::Type_Object) {
| 1928-2826 | ||||||||||||||||||
2657 | const quint32 targetObjectIndex = binding->value.objectIndex; | - | ||||||||||||||||||
2658 | const QV4::CompiledData::Object *target = qmlUnit->objectAt(targetObjectIndex); | - | ||||||||||||||||||
2659 | QString objName = qmlUnit->stringAt(target->inheritedTypeNameIndex); | - | ||||||||||||||||||
2660 | if (objName != listElementTypeName) {
| 388-1540 | ||||||||||||||||||
2661 | const QMetaObject *mo = resolveType(objName); | - | ||||||||||||||||||
2662 | if (mo != &QQmlListElement::staticMetaObject) {
| 2-386 | ||||||||||||||||||
2663 | error(target, QQmlListModel::tr("ListElement: cannot contain nested elements")); | - | ||||||||||||||||||
2664 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
2665 | } | - | ||||||||||||||||||
2666 | listElementTypeName = objName; // cache right name for next time | - | ||||||||||||||||||
2667 | } executed 386 times by 14 tests: end of block Executed by:
| 386 | ||||||||||||||||||
2668 | - | |||||||||||||||||||
2669 | if (!qmlUnit->stringAt(target->idNameIndex).isEmpty()) {
| 2-1924 | ||||||||||||||||||
2670 | error(target->locationOfIdProperty, QQmlListModel::tr("ListElement: cannot use reserved \"id\" property")); | - | ||||||||||||||||||
2671 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
2672 | } | - | ||||||||||||||||||
2673 | - | |||||||||||||||||||
2674 | const QV4::CompiledData::Binding *binding = target->bindingTable(); | - | ||||||||||||||||||
2675 | for (quint32 i = 0; i < target->nBindings; ++i, ++binding) {
| 1912-2896 | ||||||||||||||||||
2676 | QString propName = qmlUnit->stringAt(binding->propertyNameIndex); | - | ||||||||||||||||||
2677 | if (propName.isEmpty()) {
| 2-2894 | ||||||||||||||||||
2678 | error(binding, QQmlListModel::tr("ListElement: cannot contain nested elements")); | - | ||||||||||||||||||
2679 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
2680 | } | - | ||||||||||||||||||
2681 | if (!verifyProperty(qmlUnit, binding))
| 10-2884 | ||||||||||||||||||
2682 | return false; executed 10 times by 1 test: return false; Executed by:
| 10 | ||||||||||||||||||
2683 | } executed 2884 times by 14 tests: end of block Executed by:
| 2884 | ||||||||||||||||||
2684 | } else if (binding->type == QV4::CompiledData::Binding::Type_Script) { executed 1912 times by 14 tests: end of block Executed by:
| 100-2726 | ||||||||||||||||||
2685 | QString scriptStr = binding->valueAsScriptString(qmlUnit); | - | ||||||||||||||||||
2686 | if (!binding->isFunctionExpression() && !definesEmptyList(scriptStr)) {
| 0-100 | ||||||||||||||||||
2687 | QByteArray script = scriptStr.toUtf8(); | - | ||||||||||||||||||
2688 | bool ok; | - | ||||||||||||||||||
2689 | evaluateEnum(script, &ok); | - | ||||||||||||||||||
2690 | if (!ok) {
| 8-90 | ||||||||||||||||||
2691 | error(binding, QQmlListModel::tr("ListElement: cannot use script for property value")); | - | ||||||||||||||||||
2692 | return false; executed 8 times by 1 test: return false; Executed by:
| 8 | ||||||||||||||||||
2693 | } | - | ||||||||||||||||||
2694 | } executed 90 times by 2 tests: end of block Executed by:
| 90 | ||||||||||||||||||
2695 | } executed 92 times by 2 tests: end of block Executed by:
| 92 | ||||||||||||||||||
2696 | - | |||||||||||||||||||
2697 | return true; executed 4730 times by 14 tests: return true; Executed by:
| 4730 | ||||||||||||||||||
2698 | } | - | ||||||||||||||||||
2699 | - | |||||||||||||||||||
2700 | bool QQmlListModelParser::applyProperty(QV4::CompiledData::CompilationUnit *compilationUnit, const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex) | - | ||||||||||||||||||
2701 | { | - | ||||||||||||||||||
2702 | const QString elementName = qmlUnit->stringAt(binding->propertyNameIndex); | - | ||||||||||||||||||
2703 | - | |||||||||||||||||||
2704 | bool roleSet = false; | - | ||||||||||||||||||
2705 | if (binding->type >= QV4::CompiledData::Binding::Type_Object) {
| 3280-4404 | ||||||||||||||||||
2706 | const quint32 targetObjectIndex = binding->value.objectIndex; | - | ||||||||||||||||||
2707 | const QV4::CompiledData::Object *target = qmlUnit->objectAt(targetObjectIndex); | - | ||||||||||||||||||
2708 | - | |||||||||||||||||||
2709 | ListModel *subModel = nullptr; | - | ||||||||||||||||||
2710 | if (outterElementIndex == -1) {
| 64-3216 | ||||||||||||||||||
2711 | subModel = model; | - | ||||||||||||||||||
2712 | } else { executed 3216 times by 13 tests: end of block Executed by:
| 3216 | ||||||||||||||||||
2713 | const ListLayout::Role &role = model->getOrCreateListRole(elementName); | - | ||||||||||||||||||
2714 | if (role.type == ListLayout::Role::List) {
| 2-62 | ||||||||||||||||||
2715 | subModel = model->getListProperty(outterElementIndex, role); | - | ||||||||||||||||||
2716 | if (subModel == nullptr) {
| 30-32 | ||||||||||||||||||
2717 | subModel = new ListModel(role.subLayout, nullptr); | - | ||||||||||||||||||
2718 | QVariant vModel = QVariant::fromValue(subModel); | - | ||||||||||||||||||
2719 | model->setOrCreateProperty(outterElementIndex, elementName, vModel); | - | ||||||||||||||||||
2720 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
2721 | } executed 62 times by 2 tests: end of block Executed by:
| 62 | ||||||||||||||||||
2722 | } executed 64 times by 2 tests: end of block Executed by:
| 64 | ||||||||||||||||||
2723 | - | |||||||||||||||||||
2724 | int elementIndex = subModel ? subModel->appendElement() : -1;
| 2-3278 | ||||||||||||||||||
2725 | - | |||||||||||||||||||
2726 | const QV4::CompiledData::Binding *subBinding = target->bindingTable(); | - | ||||||||||||||||||
2727 | for (quint32 i = 0; i < target->nBindings; ++i, ++subBinding) {
| 3280-4468 | ||||||||||||||||||
2728 | roleSet |= applyProperty(compilationUnit, qmlUnit, subBinding, subModel, elementIndex); | - | ||||||||||||||||||
2729 | } executed 4468 times by 13 tests: end of block Executed by:
| 4468 | ||||||||||||||||||
2730 | - | |||||||||||||||||||
2731 | } else { executed 3280 times by 13 tests: end of block Executed by:
| 3280 | ||||||||||||||||||
2732 | QVariant value; | - | ||||||||||||||||||
2733 | - | |||||||||||||||||||
2734 | if (binding->isTranslationBinding()) {
| 8-4396 | ||||||||||||||||||
2735 | value = QVariant::fromValue<const QV4::CompiledData::Binding*>(binding); | - | ||||||||||||||||||
2736 | } else if (binding->evaluatesToString()) { executed 8 times by 3 tests: end of block Executed by:
| 8-3944 | ||||||||||||||||||
2737 | value = binding->valueAsString(qmlUnit); | - | ||||||||||||||||||
2738 | } else if (binding->type == QV4::CompiledData::Binding::Type_Number) { executed 3944 times by 11 tests: end of block Executed by:
| 148-3944 | ||||||||||||||||||
2739 | value = binding->valueAsNumber(); | - | ||||||||||||||||||
2740 | } else if (binding->type == QV4::CompiledData::Binding::Type_Boolean) { executed 304 times by 4 tests: end of block Executed by:
| 56-304 | ||||||||||||||||||
2741 | value = binding->valueAsBoolean(); | - | ||||||||||||||||||
2742 | } else if (binding->type == QV4::CompiledData::Binding::Type_Script) { executed 56 times by 3 tests: end of block Executed by:
| 0-92 | ||||||||||||||||||
2743 | QString scriptStr = binding->valueAsScriptString(qmlUnit); | - | ||||||||||||||||||
2744 | if (definesEmptyList(scriptStr)) {
| 2-90 | ||||||||||||||||||
2745 | const ListLayout::Role &role = model->getOrCreateListRole(elementName); | - | ||||||||||||||||||
2746 | ListModel *emptyModel = new ListModel(role.subLayout, nullptr); | - | ||||||||||||||||||
2747 | value = QVariant::fromValue(emptyModel); | - | ||||||||||||||||||
2748 | } else if (binding->isFunctionExpression()) { executed 2 times by 1 test: end of block Executed by:
| 0-90 | ||||||||||||||||||
2749 | QQmlBinding::Identifier id = binding->value.compiledScriptIndex; | - | ||||||||||||||||||
2750 | Q_ASSERT(id != QQmlBinding::Invalid); | - | ||||||||||||||||||
2751 | - | |||||||||||||||||||
2752 | auto v4 = compilationUnit->engine; | - | ||||||||||||||||||
2753 | QV4::Scope scope(v4); | - | ||||||||||||||||||
2754 | // for now we do not provide a context object; data from the ListElement must be passed to the function | - | ||||||||||||||||||
2755 | QV4::ScopedContext context(scope, QV4::QmlContext::create(v4->rootContext(), QQmlContextData::get(qmlContext(model->m_modelCache)), nullptr)); | - | ||||||||||||||||||
2756 | QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::createScriptFunction(context, compilationUnit->runtimeFunctions[id])); | - | ||||||||||||||||||
2757 | - | |||||||||||||||||||
2758 | QV4::ReturnedValue result = function->call(v4->globalObject, nullptr, 0); | - | ||||||||||||||||||
2759 | - | |||||||||||||||||||
2760 | QJSValue v; | - | ||||||||||||||||||
2761 | QJSValuePrivate::setValue(&v, v4, result); | - | ||||||||||||||||||
2762 | value.setValue<QJSValue>(v); | - | ||||||||||||||||||
2763 | } else { never executed: end of block | 0 | ||||||||||||||||||
2764 | QByteArray script = scriptStr.toUtf8(); | - | ||||||||||||||||||
2765 | bool ok; | - | ||||||||||||||||||
2766 | value = evaluateEnum(script, &ok); | - | ||||||||||||||||||
2767 | } executed 90 times by 2 tests: end of block Executed by:
| 90 | ||||||||||||||||||
2768 | } else { | - | ||||||||||||||||||
2769 | Q_UNREACHABLE(); | - | ||||||||||||||||||
2770 | } never executed: end of block | 0 | ||||||||||||||||||
2771 | - | |||||||||||||||||||
2772 | model->setOrCreateProperty(outterElementIndex, elementName, value); | - | ||||||||||||||||||
2773 | roleSet = true; | - | ||||||||||||||||||
2774 | } executed 4404 times by 13 tests: end of block Executed by:
| 4404 | ||||||||||||||||||
2775 | return roleSet; executed 7684 times by 13 tests: return roleSet; Executed by:
| 7684 | ||||||||||||||||||
2776 | } | - | ||||||||||||||||||
2777 | - | |||||||||||||||||||
2778 | void QQmlListModelParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings) | - | ||||||||||||||||||
2779 | { | - | ||||||||||||||||||
2780 | listElementTypeName = QString(); // unknown | - | ||||||||||||||||||
2781 | - | |||||||||||||||||||
2782 | for (const QV4::CompiledData::Binding *binding : bindings) { | - | ||||||||||||||||||
2783 | QString propName = qmlUnit->stringAt(binding->propertyNameIndex); | - | ||||||||||||||||||
2784 | if (!propName.isEmpty()) { // isn't default property
| 2-1860 | ||||||||||||||||||
2785 | error(binding, QQmlListModel::tr("ListModel: undefined property '%1'").arg(propName)); | - | ||||||||||||||||||
2786 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
2787 | } | - | ||||||||||||||||||
2788 | if (!verifyProperty(qmlUnit, binding))
| 14-1846 | ||||||||||||||||||
2789 | return; executed 14 times by 1 test: return; Executed by:
| 14 | ||||||||||||||||||
2790 | } executed 1846 times by 14 tests: end of block Executed by:
| 1846 | ||||||||||||||||||
2791 | } executed 372 times by 14 tests: end of block Executed by:
| 372 | ||||||||||||||||||
2792 | - | |||||||||||||||||||
2793 | void QQmlListModelParser::applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) | - | ||||||||||||||||||
2794 | { | - | ||||||||||||||||||
2795 | QQmlListModel *rv = static_cast<QQmlListModel *>(obj); | - | ||||||||||||||||||
2796 | - | |||||||||||||||||||
2797 | rv->m_engine = qmlEngine(rv)->handle(); | - | ||||||||||||||||||
2798 | rv->m_compilationUnit = compilationUnit; | - | ||||||||||||||||||
2799 | - | |||||||||||||||||||
2800 | const QV4::CompiledData::Unit *qmlUnit = compilationUnit->data; | - | ||||||||||||||||||
2801 | - | |||||||||||||||||||
2802 | bool setRoles = false; | - | ||||||||||||||||||
2803 | - | |||||||||||||||||||
2804 | for (const QV4::CompiledData::Binding *binding : bindings) { | - | ||||||||||||||||||
2805 | if (binding->type != QV4::CompiledData::Binding::Type_Object)
| 0-3216 | ||||||||||||||||||
2806 | continue; never executed: continue; | 0 | ||||||||||||||||||
2807 | setRoles |= applyProperty(compilationUnit, qmlUnit, binding, rv->m_listModel, /*outter element index*/-1); | - | ||||||||||||||||||
2808 | } executed 3216 times by 13 tests: end of block Executed by:
| 3216 | ||||||||||||||||||
2809 | - | |||||||||||||||||||
2810 | if (setRoles == false)
| 4-696 | ||||||||||||||||||
2811 | qmlWarning(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set."; executed 4 times by 1 test: qmlWarning(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set."; Executed by:
| 4 | ||||||||||||||||||
2812 | } executed 700 times by 13 tests: end of block Executed by:
| 700 | ||||||||||||||||||
2813 | - | |||||||||||||||||||
2814 | bool QQmlListModelParser::definesEmptyList(const QString &s) | - | ||||||||||||||||||
2815 | { | - | ||||||||||||||||||
2816 | if (s.startsWith(QLatin1Char('[')) && s.endsWith(QLatin1Char(']'))) {
| 0-188 | ||||||||||||||||||
2817 | for (int i=1; i<s.length()-1; i++) {
| 4-56 | ||||||||||||||||||
2818 | if (!s[i].isSpace())
| 0-56 | ||||||||||||||||||
2819 | return false; never executed: return false; | 0 | ||||||||||||||||||
2820 | } executed 56 times by 1 test: end of block Executed by:
| 56 | ||||||||||||||||||
2821 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
2822 | } | - | ||||||||||||||||||
2823 | return false; executed 188 times by 2 tests: return false; Executed by:
| 188 | ||||||||||||||||||
2824 | } | - | ||||||||||||||||||
2825 | - | |||||||||||||||||||
2826 | - | |||||||||||||||||||
2827 | /*! | - | ||||||||||||||||||
2828 | \qmltype ListElement | - | ||||||||||||||||||
2829 | \instantiates QQmlListElement | - | ||||||||||||||||||
2830 | \inqmlmodule QtQml.Models | - | ||||||||||||||||||
2831 | \brief Defines a data item in a ListModel. | - | ||||||||||||||||||
2832 | \ingroup qtquick-models | - | ||||||||||||||||||
2833 | - | |||||||||||||||||||
2834 | List elements are defined inside ListModel definitions, and represent items in a | - | ||||||||||||||||||
2835 | list that will be displayed using ListView or \l Repeater items. | - | ||||||||||||||||||
2836 | - | |||||||||||||||||||
2837 | List elements are defined like other QML elements except that they contain | - | ||||||||||||||||||
2838 | a collection of \e role definitions instead of properties. Using the same | - | ||||||||||||||||||
2839 | syntax as property definitions, roles both define how the data is accessed | - | ||||||||||||||||||
2840 | and include the data itself. | - | ||||||||||||||||||
2841 | - | |||||||||||||||||||
2842 | The names used for roles must begin with a lower-case letter and should be | - | ||||||||||||||||||
2843 | common to all elements in a given model. Values must be simple constants; either | - | ||||||||||||||||||
2844 | strings (quoted and optionally within a call to QT_TR_NOOP), boolean values | - | ||||||||||||||||||
2845 | (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter). | - | ||||||||||||||||||
2846 | - | |||||||||||||||||||
2847 | Beginning with Qt 5.11 ListElement also allows assigning a function declaration to | - | ||||||||||||||||||
2848 | a role. This allows the definition of ListElements with callable actions. | - | ||||||||||||||||||
2849 | - | |||||||||||||||||||
2850 | \section1 Referencing Roles | - | ||||||||||||||||||
2851 | - | |||||||||||||||||||
2852 | The role names are used by delegates to obtain data from list elements. | - | ||||||||||||||||||
2853 | Each role name is accessible in the delegate's scope, and refers to the | - | ||||||||||||||||||
2854 | corresponding role in the current element. Where a role name would be | - | ||||||||||||||||||
2855 | ambiguous to use, it can be accessed via the \l{ListView::}{model} | - | ||||||||||||||||||
2856 | property (e.g., \c{model.cost} instead of \c{cost}). | - | ||||||||||||||||||
2857 | - | |||||||||||||||||||
2858 | \section1 Example Usage | - | ||||||||||||||||||
2859 | - | |||||||||||||||||||
2860 | The following model defines a series of list elements, each of which | - | ||||||||||||||||||
2861 | contain "name" and "cost" roles and their associated values. | - | ||||||||||||||||||
2862 | - | |||||||||||||||||||
2863 | \snippet qml/listmodel/listelements.qml model | - | ||||||||||||||||||
2864 | - | |||||||||||||||||||
2865 | The delegate obtains the name and cost for each element by simply referring | - | ||||||||||||||||||
2866 | to \c name and \c cost: | - | ||||||||||||||||||
2867 | - | |||||||||||||||||||
2868 | \snippet qml/listmodel/listelements.qml view | - | ||||||||||||||||||
2869 | - | |||||||||||||||||||
2870 | \sa ListModel | - | ||||||||||||||||||
2871 | */ | - | ||||||||||||||||||
2872 | - | |||||||||||||||||||
2873 | QT_END_NAMESPACE | - | ||||||||||||||||||
2874 | - | |||||||||||||||||||
2875 | #include "moc_qqmllistmodel_p.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |