Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/types/qqmllistmodel_p_p.h |
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 | #ifndef QQMLLISTMODEL_P_P_H | - |
41 | #define QQMLLISTMODEL_P_P_H | - |
42 | - | |
43 | // | - |
44 | // W A R N I N G | - |
45 | // ------------- | - |
46 | // | - |
47 | // This file is not part of the Qt API. It exists purely as an | - |
48 | // implementation detail. This header file may change from version to | - |
49 | // version without notice, or even be removed. | - |
50 | // | - |
51 | // We mean it. | - |
52 | // | - |
53 | - | |
54 | #include "qqmllistmodel_p.h" | - |
55 | #include <private/qqmlengine_p.h> | - |
56 | #include <private/qqmlopenmetaobject_p.h> | - |
57 | #include <private/qv4qobjectwrapper_p.h> | - |
58 | #include <qqml.h> | - |
59 | - | |
60 | QT_REQUIRE_CONFIG(qml_list_model); | - |
61 | - | |
62 | QT_BEGIN_NAMESPACE | - |
63 | - | |
64 | - | |
65 | class DynamicRoleModelNode; | - |
66 | - | |
67 | class DynamicRoleModelNodeMetaObject : public QQmlOpenMetaObject | - |
68 | { | - |
69 | public: | - |
70 | DynamicRoleModelNodeMetaObject(DynamicRoleModelNode *object); | - |
71 | ~DynamicRoleModelNodeMetaObject(); | - |
72 | - | |
73 | bool m_enabled; | - |
74 | - | |
75 | protected: | - |
76 | void propertyWrite(int index) override; | - |
77 | void propertyWritten(int index) override; | - |
78 | - | |
79 | private: | - |
80 | DynamicRoleModelNode *m_owner; | - |
81 | }; | - |
82 | - | |
83 | class DynamicRoleModelNode : public QObject | - |
84 | { | - |
85 | Q_OBJECT | - |
86 | public: | - |
87 | DynamicRoleModelNode(QQmlListModel *owner, int uid); | - |
88 | - | |
89 | static DynamicRoleModelNode *create(const QVariantMap &obj, QQmlListModel *owner); | - |
90 | - | |
91 | void updateValues(const QVariantMap &object, QVector<int> &roles); | - |
92 | - | |
93 | QVariant getValue(const QString &name) const | - |
94 | { | - |
95 | return m_meta->value(name.toUtf8()); executed 102 times by 2 tests: return m_meta->value(name.toUtf8()); Executed by:
| 102 |
96 | } | - |
97 | - | |
98 | bool setValue(const QByteArray &name, const QVariant &val) | - |
99 | { | - |
100 | return m_meta->setValue(name, val); executed 1172 times by 2 tests: return m_meta->setValue(name, val); Executed by:
| 1172 |
101 | } | - |
102 | - | |
103 | void setNodeUpdatesEnabled(bool enable) | - |
104 | { | - |
105 | m_meta->m_enabled = enable; | - |
106 | } executed 2238 times by 2 tests: end of block Executed by:
| 2238 |
107 | - | |
108 | int getUid() const | - |
109 | { | - |
110 | return m_uid; executed 3452 times by 1 test: return m_uid; Executed by:
| 3452 |
111 | } | - |
112 | - | |
113 | static QVector<int> sync(DynamicRoleModelNode *src, DynamicRoleModelNode *target); | - |
114 | - | |
115 | private: | - |
116 | QQmlListModel *m_owner; | - |
117 | int m_uid; | - |
118 | DynamicRoleModelNodeMetaObject *m_meta; | - |
119 | - | |
120 | friend class DynamicRoleModelNodeMetaObject; | - |
121 | }; | - |
122 | - | |
123 | class ModelNodeMetaObject : public QQmlOpenMetaObject | - |
124 | { | - |
125 | public: | - |
126 | ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex); | - |
127 | ~ModelNodeMetaObject(); | - |
128 | - | |
129 | QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *object) override; | - |
130 | - | |
131 | static ModelNodeMetaObject *get(QObject *obj); | - |
132 | - | |
133 | bool m_enabled; | - |
134 | QQmlListModel *m_model; | - |
135 | int m_elementIndex; | - |
136 | - | |
137 | void updateValues(); | - |
138 | void updateValues(const QVector<int> &roles); | - |
139 | - | |
140 | bool initialized() const { return m_initialized; } executed 58 times by 2 tests: return m_initialized; Executed by:
| 58 |
141 | - | |
142 | protected: | - |
143 | void propertyWritten(int index) override; | - |
144 | - | |
145 | private: | - |
146 | using QQmlOpenMetaObject::setValue; | - |
147 | - | |
148 | void emitDirectNotifies(const int *changedRoles, int roleCount); | - |
149 | - | |
150 | void initialize(); | - |
151 | bool m_initialized; | - |
152 | }; | - |
153 | - | |
154 | namespace QV4 { | - |
155 | - | |
156 | namespace Heap { | - |
157 | - | |
158 | struct ModelObject : public QObjectWrapper { | - |
159 | void init(QObject *object, QQmlListModel *model) | - |
160 | { | - |
161 | QObjectWrapper::init(object); | - |
162 | m_model = model; | - |
163 | QObjectPrivate *op = QObjectPrivate::get(object); | - |
164 | m_nodeModelMetaObject = static_cast<ModelNodeMetaObject *>(op->metaObject); | - |
165 | } executed 660 times by 8 tests: end of block Executed by:
| 660 |
166 | void destroy() { QObjectWrapper::destroy(); } executed 660 times by 8 tests: end of block Executed by:
| 660 |
167 | int elementIndex() const { return m_nodeModelMetaObject->m_elementIndex; } executed 922 times by 8 tests: return m_nodeModelMetaObject->m_elementIndex; Executed by:
| 922 |
168 | QQmlListModel *m_model; | - |
169 | ModelNodeMetaObject *m_nodeModelMetaObject; | - |
170 | }; | - |
171 | - | |
172 | } | - |
173 | - | |
174 | struct ModelObject : public QObjectWrapper | - |
175 | { | - |
176 | V4_OBJECT2(ModelObject, QObjectWrapper) never executed: end of block never executed: end of block executed 1980 times by 8 tests: return &static_vtbl; Executed by:
executed 4102 times by 8 tests: return static_cast<QV4::Heap::ModelObject *>(m()); Executed by:
executed 3442 times by 8 tests: return dptr; Executed by:
| 0-4102 |
177 | V4_NEEDS_DESTROY executed 660 times by 8 tests: end of block Executed by:
| 660 |
178 | - | |
179 | protected: | - |
180 | static bool virtualPut(Managed *m, PropertyKey id, const Value& value, Value *receiver); | - |
181 | static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); | - |
182 | static void virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); | - |
183 | }; | - |
184 | - | |
185 | } // namespace QV4 | - |
186 | - | |
187 | class ListLayout | - |
188 | { | - |
189 | public: | - |
190 | ListLayout() : currentBlock(0), currentBlockOffset(0) {} executed 2584 times by 15 tests: end of block Executed by:
| 2584 |
191 | ListLayout(const ListLayout *other); | - |
192 | ~ListLayout(); | - |
193 | - | |
194 | class Role | - |
195 | { | - |
196 | public: | - |
197 | - | |
198 | Role() : type(Invalid), blockIndex(-1), blockOffset(-1), index(-1), subLayout(0) {} executed 2118 times by 15 tests: end of block Executed by:
| 2118 |
199 | explicit Role(const Role *other); | - |
200 | ~Role(); | - |
201 | - | |
202 | // This enum must be kept in sync with the roleTypeNames variable in qqmllistmodel.cpp | - |
203 | enum DataType | - |
204 | { | - |
205 | Invalid = -1, | - |
206 | - | |
207 | String, | - |
208 | Number, | - |
209 | Bool, | - |
210 | List, | - |
211 | QObject, | - |
212 | VariantMap, | - |
213 | DateTime, | - |
214 | Function, | - |
215 | - | |
216 | MaxDataType | - |
217 | }; | - |
218 | - | |
219 | QString name; | - |
220 | DataType type; | - |
221 | int blockIndex; | - |
222 | int blockOffset; | - |
223 | int index; | - |
224 | ListLayout *subLayout; | - |
225 | }; | - |
226 | - | |
227 | const Role *getRoleOrCreate(const QString &key, const QVariant &data); | - |
228 | const Role &getRoleOrCreate(QV4::String *key, Role::DataType type); | - |
229 | const Role &getRoleOrCreate(const QString &key, Role::DataType type); | - |
230 | - | |
231 | const Role &getExistingRole(int index) const { return *roles.at(index); } executed 25109 times by 15 tests: return *roles.at(index); Executed by:
| 25109 |
232 | const Role *getExistingRole(const QString &key) const; | - |
233 | const Role *getExistingRole(QV4::String *key) const; | - |
234 | - | |
235 | int roleCount() const { return roles.count(); } executed 32663 times by 15 tests: return roles.count(); Executed by:
| 32663 |
236 | - | |
237 | static void sync(ListLayout *src, ListLayout *target); | - |
238 | - | |
239 | private: | - |
240 | const Role &createRole(const QString &key, Role::DataType type); | - |
241 | - | |
242 | int currentBlock; | - |
243 | int currentBlockOffset; | - |
244 | QVector<Role *> roles; | - |
245 | QStringHash<Role *> roleHash; | - |
246 | }; | - |
247 | - | |
248 | struct StringOrTranslation | - |
249 | { | - |
250 | explicit StringOrTranslation(const QString &s); | - |
251 | explicit StringOrTranslation(const QV4::CompiledData::Binding *binding); | - |
252 | ~StringOrTranslation(); | - |
253 | bool isSet() const { return d.flag(); } executed 14227 times by 14 tests: return d.flag(); Executed by:
| 14227 |
254 | bool isTranslation() const { return d.isT2(); } executed 6 times by 2 tests: return d.isT2(); Executed by:
| 6 |
255 | void setString(const QString &s); | - |
256 | void setTranslation(const QV4::CompiledData::Binding *binding); | - |
257 | QString toString(const QQmlListModel *owner) const; | - |
258 | QString asString() const; | - |
259 | private: | - |
260 | void clear(); | - |
261 | QBiPointer<QStringData, const QV4::CompiledData::Binding> d; | - |
262 | }; | - |
263 | - | |
264 | /*! | - |
265 | \internal | - |
266 | */ | - |
267 | class ListElement | - |
268 | { | - |
269 | public: | - |
270 | - | |
271 | ListElement(); | - |
272 | ListElement(int existingUid); | - |
273 | ~ListElement(); | - |
274 | - | |
275 | static QVector<int> sync(ListElement *src, ListLayout *srcLayout, ListElement *target, ListLayout *targetLayout); | - |
276 | - | |
277 | enum | - |
278 | { | - |
279 | BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelNodeMetaObject *) | - |
280 | }; | - |
281 | - | |
282 | private: | - |
283 | - | |
284 | void destroy(ListLayout *layout); | - |
285 | - | |
286 | int setVariantProperty(const ListLayout::Role &role, const QVariant &d); | - |
287 | - | |
288 | int setJsProperty(const ListLayout::Role &role, const QV4::Value &d, QV4::ExecutionEngine *eng); | - |
289 | - | |
290 | int setStringProperty(const ListLayout::Role &role, const QString &s); | - |
291 | int setDoubleProperty(const ListLayout::Role &role, double n); | - |
292 | int setBoolProperty(const ListLayout::Role &role, bool b); | - |
293 | int setListProperty(const ListLayout::Role &role, ListModel *m); | - |
294 | int setQObjectProperty(const ListLayout::Role &role, QObject *o); | - |
295 | int setVariantMapProperty(const ListLayout::Role &role, QV4::Object *o); | - |
296 | int setVariantMapProperty(const ListLayout::Role &role, QVariantMap *m); | - |
297 | int setDateTimeProperty(const ListLayout::Role &role, const QDateTime &dt); | - |
298 | int setFunctionProperty(const ListLayout::Role &role, const QJSValue &f); | - |
299 | int setTranslationProperty(const ListLayout::Role &role, const QV4::CompiledData::Binding *b); | - |
300 | - | |
301 | void setStringPropertyFast(const ListLayout::Role &role, const QString &s); | - |
302 | void setDoublePropertyFast(const ListLayout::Role &role, double n); | - |
303 | void setBoolPropertyFast(const ListLayout::Role &role, bool b); | - |
304 | void setQObjectPropertyFast(const ListLayout::Role &role, QObject *o); | - |
305 | void setListPropertyFast(const ListLayout::Role &role, ListModel *m); | - |
306 | void setVariantMapFast(const ListLayout::Role &role, QV4::Object *o); | - |
307 | void setDateTimePropertyFast(const ListLayout::Role &role, const QDateTime &dt); | - |
308 | void setFunctionPropertyFast(const ListLayout::Role &role, const QJSValue &f); | - |
309 | - | |
310 | void clearProperty(const ListLayout::Role &role); | - |
311 | - | |
312 | QVariant getProperty(const ListLayout::Role &role, const QQmlListModel *owner, QV4::ExecutionEngine *eng); | - |
313 | ListModel *getListProperty(const ListLayout::Role &role); | - |
314 | StringOrTranslation *getStringProperty(const ListLayout::Role &role); | - |
315 | QObject *getQObjectProperty(const ListLayout::Role &role); | - |
316 | QPointer<QObject> *getGuardProperty(const ListLayout::Role &role); | - |
317 | QVariantMap *getVariantMapProperty(const ListLayout::Role &role); | - |
318 | QDateTime *getDateTimeProperty(const ListLayout::Role &role); | - |
319 | QJSValue *getFunctionProperty(const ListLayout::Role &role); | - |
320 | - | |
321 | inline char *getPropertyMemory(const ListLayout::Role &role); | - |
322 | - | |
323 | int getUid() const { return uid; } executed 2844 times by 1 test: return uid; Executed by:
| 2844 |
324 | - | |
325 | ModelNodeMetaObject *objectCache(); | - |
326 | - | |
327 | char data[BLOCK_SIZE]; | - |
328 | ListElement *next; | - |
329 | - | |
330 | int uid; | - |
331 | QObject *m_objectCache; | - |
332 | - | |
333 | friend class ListModel; | - |
334 | }; | - |
335 | - | |
336 | /*! | - |
337 | \internal | - |
338 | */ | - |
339 | class ListModel | - |
340 | { | - |
341 | public: | - |
342 | - | |
343 | ListModel(ListLayout *layout, QQmlListModel *modelCache); | - |
344 | ~ListModel() {} | - |
345 | - | |
346 | void destroy(); | - |
347 | - | |
348 | int setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data); | - |
349 | int setExistingProperty(int uid, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng); | - |
350 | - | |
351 | QVariant getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng); | - |
352 | ListModel *getListProperty(int elementIndex, const ListLayout::Role &role); | - |
353 | - | |
354 | int roleCount() const | - |
355 | { | - |
356 | return m_layout->roleCount(); executed 1952 times by 11 tests: return m_layout->roleCount(); Executed by:
| 1952 |
357 | } | - |
358 | - | |
359 | const ListLayout::Role &getExistingRole(int index) const | - |
360 | { | - |
361 | return m_layout->getExistingRole(index); executed 1378 times by 11 tests: return m_layout->getExistingRole(index); Executed by:
| 1378 |
362 | } | - |
363 | - | |
364 | const ListLayout::Role *getExistingRole(QV4::String *key) const | - |
365 | { | - |
366 | return m_layout->getExistingRole(key); executed 852 times by 8 tests: return m_layout->getExistingRole(key); Executed by:
| 852 |
367 | } | - |
368 | - | |
369 | const ListLayout::Role &getOrCreateListRole(const QString &name) | - |
370 | { | - |
371 | return m_layout->getRoleOrCreate(name, ListLayout::Role::List); executed 66 times by 2 tests: return m_layout->getRoleOrCreate(name, ListLayout::Role::List); Executed by:
| 66 |
372 | } | - |
373 | - | |
374 | int elementCount() const | - |
375 | { | - |
376 | return elements.count(); executed 44602 times by 14 tests: return elements.count(); Executed by:
| 44602 |
377 | } | - |
378 | - | |
379 | void set(int elementIndex, QV4::Object *object, QVector<int> *roles); | - |
380 | void set(int elementIndex, QV4::Object *object); | - |
381 | - | |
382 | int append(QV4::Object *object); | - |
383 | void insert(int elementIndex, QV4::Object *object); | - |
384 | - | |
385 | Q_REQUIRED_RESULT QVector<std::function<void()>> remove(int index, int count); | - |
386 | - | |
387 | int appendElement(); | - |
388 | void insertElement(int index); | - |
389 | - | |
390 | void move(int from, int to, int n); | - |
391 | - | |
392 | static bool sync(ListModel *src, ListModel *target); | - |
393 | - | |
394 | QObject *getOrCreateModelObject(QQmlListModel *model, int elementIndex); | - |
395 | - | |
396 | private: | - |
397 | QPODVector<ListElement *, 4> elements; | - |
398 | ListLayout *m_layout; | - |
399 | - | |
400 | QQmlListModel *m_modelCache; | - |
401 | - | |
402 | struct ElementSync | - |
403 | { | - |
404 | ListElement *src = nullptr; | - |
405 | ListElement *target = nullptr; | - |
406 | int srcIndex = -1; | - |
407 | int targetIndex = -1; | - |
408 | QVector<int> changedRoles; | - |
409 | }; | - |
410 | - | |
411 | void newElement(int index); | - |
412 | - | |
413 | void updateCacheIndices(int start = 0, int end = -1); | - |
414 | - | |
415 | friend class ListElement; | - |
416 | friend class QQmlListModelWorkerAgent; | - |
417 | friend class QQmlListModelParser; | - |
418 | }; | - |
419 | - | |
420 | QT_END_NAMESPACE | - |
421 | - | |
422 | Q_DECLARE_METATYPE(ListModel *); | - |
423 | - | |
424 | #endif // QQUICKLISTMODEL_P_P_H | - |
Source code | Switch to Preprocessed file |