OpenCoverage

qqmlobjectmodel.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/types/qqmlobjectmodel.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qqmlobjectmodel_p.h"-
41-
42#include <QtCore/qcoreapplication.h>-
43#include <QtQml/qqmlcontext.h>-
44#include <QtQml/qqmlengine.h>-
45#include <QtQml/qqmlinfo.h>-
46-
47#include <private/qqmlchangeset_p.h>-
48#include <private/qqmlglobal_p.h>-
49#include <private/qobject_p.h>-
50#include <private/qpodvector_p.h>-
51-
52#include <QtCore/qhash.h>-
53#include <QtCore/qlist.h>-
54-
55QT_BEGIN_NAMESPACE-
56-
57QHash<QObject*, QQmlObjectModelAttached*> QQmlObjectModelAttached::attachedProperties;-
58-
59-
60class QQmlObjectModelPrivate : public QObjectPrivate-
61{-
62 Q_DECLARE_PUBLIC(QQmlObjectModel)-
63public:-
64 class Item {-
65 public:-
66 Item(QObject *i) : item(i), ref(0) {}
executed 154 times by 6 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
154
67-
68 void addRef() { ++ref; }
executed 384 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
384
69 bool deref() { return --ref == 0; }
executed 258 times by 5 tests: return --ref == 0;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
258
70-
71 QObject *item;-
72 int ref;-
73 };-
74-
75 QQmlObjectModelPrivate() : QObjectPrivate(), moveId(0) {}
executed 52 times by 7 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
  • tst_qtqmlmodules
52
76-
77 static void children_append(QQmlListProperty<QObject> *prop, QObject *item) {-
78 int index = static_cast<QQmlObjectModelPrivate *>(prop->data)->children.count();-
79 static_cast<QQmlObjectModelPrivate *>(prop->data)->insert(index, item);-
80 }
executed 138 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
138
81-
82 static int children_count(QQmlListProperty<QObject> *prop) {-
83 return static_cast<QQmlObjectModelPrivate *>(prop->data)->children.count();
executed 26 times by 1 test: return static_cast<QQmlObjectModelPrivate *>(prop->data)->children.count();
Executed by:
  • tst_examples
26
84 }-
85-
86 static QObject *children_at(QQmlListProperty<QObject> *prop, int index) {-
87 return static_cast<QQmlObjectModelPrivate *>(prop->data)->children.at(index).item;
executed 6 times by 1 test: return static_cast<QQmlObjectModelPrivate *>(prop->data)->children.at(index).item;
Executed by:
  • tst_examples
6
88 }-
89-
90 static void children_clear(QQmlListProperty<QObject> *prop) {-
91 static_cast<QQmlObjectModelPrivate *>(prop->data)->clear();-
92 }
never executed: end of block
0
93-
94 void insert(int index, QObject *item) {-
95 Q_Q(QQmlObjectModel);-
96 children.insert(index, Item(item));-
97 for (int i = index; i < children.count(); ++i) {
i < children.count()Description
TRUEevaluated 174 times by 6 tests
Evaluated by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 154 times by 6 tests
Evaluated by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
154-174
98 QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item);-
99 attached->setIndex(i);-
100 }
executed 174 times by 6 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
174
101 QQmlChangeSet changeSet;-
102 changeSet.insert(index, 1);-
103 emit q->modelUpdated(changeSet, false);-
104 emit q->countChanged();-
105 emit q->childrenChanged();-
106 }
executed 154 times by 6 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
154
107-
108 void move(int from, int to, int n) {-
109 Q_Q(QQmlObjectModel);-
110 if (from > to) {
from > toDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlobjectmodel
FALSEevaluated 8 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
2-8
111 // Only move forwards - flip if backwards moving-
112 int tfrom = from;-
113 int tto = to;-
114 from = tto;-
115 to = tto+n;-
116 n = tfrom-tto;-
117 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlobjectmodel
2
118-
119 QPODVector<QQmlObjectModelPrivate::Item, 4> store;-
120 for (int i = 0; i < to - from; ++i)
i < to - fromDescription
TRUEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10
121 store.append(children[from + n + i]);
executed 10 times by 4 tests: store.append(children[from + n + i]);
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10
122 for (int i = 0; i < n; ++i)
i < nDescription
TRUEevaluated 18 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10-18
123 store.append(children[from + i]);
executed 18 times by 4 tests: store.append(children[from + i]);
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
18
124-
125 for (int i = 0; i < store.count(); ++i) {
i < store.count()Description
TRUEevaluated 28 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10-28
126 children[from + i] = store[i];-
127 QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(from + i).item);-
128 attached->setIndex(from + i);-
129 }
executed 28 times by 4 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
28
130-
131 QQmlChangeSet changeSet;-
132 changeSet.move(from, to, n, ++moveId);-
133 emit q->modelUpdated(changeSet, false);-
134 emit q->childrenChanged();-
135 }
executed 10 times by 4 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10
136-
137 void remove(int index, int n) {-
138 Q_Q(QQmlObjectModel);-
139 for (int i = index; i < index + n; ++i) {
i < index + nDescription
TRUEevaluated 28 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
FALSEevaluated 14 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
14-28
140 QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item);-
141 attached->setIndex(-1);-
142 }
executed 28 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
28
143 children.erase(children.begin() + index, children.begin() + index + n);-
144 for (int i = index; i < children.count(); ++i) {
i < children.count()Description
TRUEevaluated 10 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
FALSEevaluated 14 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
10-14
145 QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item);-
146 attached->setIndex(i);-
147 }
executed 10 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
10
148 QQmlChangeSet changeSet;-
149 changeSet.remove(index, n);-
150 emit q->modelUpdated(changeSet, false);-
151 emit q->countChanged();-
152 emit q->childrenChanged();-
153 }
executed 14 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
14
154-
155 void clear() {-
156 Q_Q(QQmlObjectModel);-
157 for (const Item &child : qAsConst(children))-
158 emit q->destroyingItem(child.item);
executed 16 times by 3 tests: q->destroyingItem(child.item);
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
16
159 remove(0, children.count());-
160 }
executed 6 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
6
161-
162 int indexOf(QObject *item) const {-
163 for (int i = 0; i < children.count(); ++i)
i < children.count()Description
TRUEevaluated 3518 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 34 times by 2 tests
Evaluated by:
  • tst_qquicklistview
  • tst_qquickrepeater
34-3518
164 if (children.at(i).item == item)
children.at(i).item == itemDescription
TRUEevaluated 1754 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 1764 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
1754-1764
165 return i;
executed 1754 times by 5 tests: return i;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
1754
166 return -1;
executed 34 times by 2 tests: return -1;
Executed by:
  • tst_qquicklistview
  • tst_qquickrepeater
34
167 }-
168-
169 uint moveId;-
170 QList<Item> children;-
171};-
172-
173-
174/*!-
175 \qmltype ObjectModel-
176 \instantiates QQmlObjectModel-
177 \inqmlmodule QtQml.Models-
178 \ingroup qtquick-models-
179 \brief Defines a set of items to be used as a model.-
180-
181 An ObjectModel contains the visual items to be used in a view.-
182 When an ObjectModel is used in a view, the view does not require-
183 a delegate since the ObjectModel already contains the visual-
184 delegate (items).-
185-
186 An item can determine its index within the-
187 model via the \l{ObjectModel::index}{index} attached property.-
188-
189 The example below places three colored rectangles in a ListView.-
190 \code-
191 import QtQuick 2.0-
192 import QtQml.Models 2.1-
193-
194 Rectangle {-
195 ObjectModel {-
196 id: itemModel-
197 Rectangle { height: 30; width: 80; color: "red" }-
198 Rectangle { height: 30; width: 80; color: "green" }-
199 Rectangle { height: 30; width: 80; color: "blue" }-
200 }-
201-
202 ListView {-
203 anchors.fill: parent-
204 model: itemModel-
205 }-
206 }-
207 \endcode-
208-
209 \image visualitemmodel.png-
210-
211 \sa {Qt Quick Examples - Views}-
212*/-
213/*!-
214 \qmltype VisualItemModel-
215 \instantiates QQmlObjectModel-
216 \inqmlmodule QtQuick-
217 \brief Defines a set of objects to be used as a model.-
218-
219 The VisualItemModel type contains the objects to be used-
220 as a model.-
221-
222 This element is now primarily available as ObjectModel in the QtQml.Models module.-
223 VisualItemModel continues to be provided, with the same implementation, in \c QtQuick for-
224 compatibility reasons.-
225-
226 For full details about the type, see the \l ObjectModel documentation.-
227-
228 \sa {QtQml.Models::ObjectModel}-
229*/-
230-
231QQmlObjectModel::QQmlObjectModel(QObject *parent)-
232 : QQmlInstanceModel(*(new QQmlObjectModelPrivate), parent)-
233{-
234}
executed 52 times by 7 tests: end of block
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
  • tst_qtqmlmodules
52
235-
236/*!-
237 \qmlattachedproperty int QtQml.Models::ObjectModel::index-
238 This attached property holds the index of this delegate's item within the model.-
239-
240 It is attached to each instance of the delegate.-
241*/-
242-
243QQmlListProperty<QObject> QQmlObjectModel::children()-
244{-
245 Q_D(QQmlObjectModel);-
246 return QQmlListProperty<QObject>(this,
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
247 d,
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
248 d->children_append,
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
249 d->children_count,
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
250 d->children_at,
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
251 d->children_clear);
executed 50 times by 5 tests: return QQmlListProperty<QObject>(this, d, d->children_append, d->children_count, d->children_at, d->children_clear);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
50
252}-
253-
254/*!-
255 \qmlproperty int QtQml.Models::ObjectModel::count-
256-
257 The number of items in the model. This property is readonly.-
258*/-
259int QQmlObjectModel::count() const-
260{-
261 Q_D(const QQmlObjectModel);-
262 return d->children.count();
executed 4276 times by 6 tests: return d->children.count();
Executed by:
  • tst_examples
  • tst_qqmlobjectmodel
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
4276
263}-
264-
265bool QQmlObjectModel::isValid() const-
266{-
267 return true;
executed 1588 times by 5 tests: return true;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
1588
268}-
269-
270QObject *QQmlObjectModel::object(int index, QQmlIncubator::IncubationMode)-
271{-
272 Q_D(QQmlObjectModel);-
273 QQmlObjectModelPrivate::Item &item = d->children[index];-
274 item.addRef();-
275 if (item.ref == 1) {
item.ref == 1Description
TRUEevaluated 228 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 156 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
156-228
276 emit initItem(index, item.item);-
277 emit createdItem(index, item.item);-
278 }
executed 228 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
228
279 return item.item;
executed 384 times by 5 tests: return item.item;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
384
280}-
281-
282QQmlInstanceModel::ReleaseFlags QQmlObjectModel::release(QObject *item)-
283{-
284 Q_D(QQmlObjectModel);-
285 int idx = d->indexOf(item);-
286 if (idx >= 0) {
idx >= 0Description
TRUEevaluated 258 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • tst_qquicklistview
  • tst_qquickrepeater
22-258
287 if (!d->children[idx].deref())
!d->children[idx].deref()Description
TRUEevaluated 128 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
FALSEevaluated 130 times by 5 tests
Evaluated by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
128-130
288 return QQmlInstanceModel::Referenced;
executed 128 times by 5 tests: return QQmlInstanceModel::Referenced;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
128
289 }
executed 130 times by 5 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
130
290 return nullptr;
executed 152 times by 5 tests: return nullptr;
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
152
291}-
292-
293QString QQmlObjectModel::stringValue(int index, const QString &name)-
294{-
295 Q_D(QQmlObjectModel);-
296 if (index < 0 || index >= d->children.count())
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index >= d->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
297 return QString();
never executed: return QString();
0
298 return QQmlEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString();
never executed: return QQmlEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString();
0
299}-
300-
301QQmlIncubator::Status QQmlObjectModel::incubationStatus(int)-
302{-
303 return QQmlIncubator::Ready;
never executed: return QQmlIncubator::Ready;
0
304}-
305-
306int QQmlObjectModel::indexOf(QObject *item, QObject *) const-
307{-
308 Q_D(const QQmlObjectModel);-
309 return d->indexOf(item);
executed 1508 times by 4 tests: return d->indexOf(item);
Executed by:
  • tst_examples
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickpathview
1508
310}-
311-
312QQmlObjectModelAttached *QQmlObjectModel::qmlAttachedProperties(QObject *obj)-
313{-
314 return QQmlObjectModelAttached::properties(obj);
executed 52 times by 3 tests: return QQmlObjectModelAttached::properties(obj);
Executed by:
  • tst_qquickgridview
  • tst_qquicklistview
  • tst_qquickrepeater
52
315}-
316-
317/*!-
318 \qmlmethod object QtQml.Models::ObjectModel::get(int index)-
319 \since 5.6-
320-
321 Returns the item at \a index in the model. This allows the item-
322 to be accessed or modified from JavaScript:-
323-
324 \code-
325 Component.onCompleted: {-
326 objectModel.append(objectComponent.createObject())-
327 console.log(objectModel.get(0).objectName);-
328 objectModel.get(0).objectName = "first";-
329 }-
330 \endcode-
331-
332 The \a index must be an element in the list.-
333-
334 \sa append()-
335*/-
336QObject *QQmlObjectModel::get(int index) const-
337{-
338 Q_D(const QQmlObjectModel);-
339 if (index < 0 || index >= d->children.count())
index < 0Description
TRUEnever evaluated
FALSEevaluated 114 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
index >= d->children.count()Description
TRUEnever evaluated
FALSEevaluated 114 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
0-114
340 return nullptr;
never executed: return nullptr;
0
341 return d->children.at(index).item;
executed 114 times by 3 tests: return d->children.at(index).item;
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
114
342}-
343-
344/*!-
345 \qmlmethod QtQml.Models::ObjectModel::append(object item)-
346 \since 5.6-
347-
348 Appends a new item to the end of the model.-
349-
350 \code-
351 objectModel.append(objectComponent.createObject())-
352 \endcode-
353-
354 \sa insert(), remove()-
355*/-
356void QQmlObjectModel::append(QObject *object)-
357{-
358 Q_D(QQmlObjectModel);-
359 d->insert(count(), object);-
360}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
8
361-
362/*!-
363 \qmlmethod QtQml.Models::ObjectModel::insert(int index, object item)-
364 \since 5.6-
365-
366 Inserts a new item to the model at position \a index.-
367-
368 \code-
369 objectModel.insert(2, objectComponent.createObject())-
370 \endcode-
371-
372 The \a index must be to an existing item in the list, or one past-
373 the end of the list (equivalent to append).-
374-
375 \sa append(), remove()-
376*/-
377void QQmlObjectModel::insert(int index, QObject *object)-
378{-
379 Q_D(QQmlObjectModel);-
380 if (index < 0 || index > count()) {
index < 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
index > count()Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
0-8
381 qmlWarning(this) << tr("insert: index %1 out of range").arg(index);-
382 return;
never executed: return;
0
383 }-
384 d->insert(index, object);-
385}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
8
386-
387/*!-
388 \qmlmethod QtQml.Models::ObjectModel::move(int from, int to, int n = 1)-
389 \since 5.6-
390-
391 Moves \a n items \a from one position \a to another.-
392-
393 The from and to ranges must exist; for example, to move the first 3 items-
394 to the end of the model:-
395-
396 \code-
397 objectModel.move(0, objectModel.count - 3, 3)-
398 \endcode-
399-
400 \sa append()-
401*/-
402void QQmlObjectModel::move(int from, int to, int n)-
403{-
404 Q_D(QQmlObjectModel);-
405 if (n <= 0 || from == to)
n <= 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
from == toDescription
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
0-10
406 return;
never executed: return;
0
407 if (from < 0 || to < 0 || from + n > count() || to + n > count()) {
from < 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
to < 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
from + n > count()Description
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
to + n > count()Description
TRUEnever evaluated
FALSEevaluated 10 times by 4 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
0-10
408 qmlWarning(this) << tr("move: out of range");-
409 return;
never executed: return;
0
410 }-
411 d->move(from, to, n);-
412}
executed 10 times by 4 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickpathview
  • tst_qquickrepeater
10
413-
414/*!-
415 \qmlmethod QtQml.Models::ObjectModel::remove(int index, int n = 1)-
416 \since 5.6-
417-
418 Removes the items at \a index from the model.-
419-
420 \sa clear()-
421*/-
422void QQmlObjectModel::remove(int index, int n)-
423{-
424 Q_D(QQmlObjectModel);-
425 if (index < 0 || n <= 0 || index + n > count()) {
index < 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
n <= 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
index + n > count()Description
TRUEnever evaluated
FALSEevaluated 8 times by 3 tests
Evaluated by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
0-8
426 qmlWarning(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+n).arg(count());-
427 return;
never executed: return;
0
428 }-
429 d->remove(index, n);-
430}
executed 8 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
8
431-
432/*!-
433 \qmlmethod QtQml.Models::ObjectModel::clear()-
434 \since 5.6-
435-
436 Clears all items from the model.-
437-
438 \sa append(), remove()-
439*/-
440void QQmlObjectModel::clear()-
441{-
442 Q_D(QQmlObjectModel);-
443 d->clear();-
444}
executed 6 times by 3 tests: end of block
Executed by:
  • tst_qqmlobjectmodel
  • tst_qquicklistview
  • tst_qquickrepeater
6
445-
446QT_END_NAMESPACE-
447-
448#include "moc_qqmlobjectmodel_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0