OpenCoverage

qqmlinstantiator.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/types/qqmlinstantiator.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 Research In Motion.-
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 "qqmlinstantiator_p.h"-
41#include "qqmlinstantiator_p_p.h"-
42#include <QtQml/QQmlContext>-
43#include <QtQml/QQmlComponent>-
44#include <QtQml/QQmlInfo>-
45#include <QtQml/QQmlError>-
46#include <QtQml/private/qqmlobjectmodel_p.h>-
47#if QT_CONFIG(qml_delegate_model)-
48#include <QtQml/private/qqmldelegatemodel_p.h>-
49#endif-
50-
51QT_BEGIN_NAMESPACE-
52-
53QQmlInstantiatorPrivate::QQmlInstantiatorPrivate()-
54 : componentComplete(true)-
55 , effectiveReset(false)-
56 , active(true)-
57 , async(false)-
58#if QT_CONFIG(qml_delegate_model)-
59 , ownModel(false)-
60#endif-
61 , requestedIndex(-1)-
62 , model(QVariant(1))-
63 , instanceModel(nullptr)-
64 , delegate(nullptr)-
65{-
66}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
67-
68QQmlInstantiatorPrivate::~QQmlInstantiatorPrivate()-
69{-
70 qDeleteAll(objects);-
71}
never executed: end of block
0
72-
73void QQmlInstantiatorPrivate::clear()-
74{-
75 Q_Q(QQmlInstantiator);-
76 if (!instanceModel)
!instanceModelDescription
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-20
77 return;
never executed: return;
0
78 if (!objects.count())
!objects.count()Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-18
79 return;
executed 18 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
18
80-
81 for (int i=0; i < objects.count(); i++) {
i < objects.count()Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-20
82 q->objectRemoved(i, objects[i]);-
83 instanceModel->release(objects[i]);-
84 }
executed 20 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
20
85 objects.clear();-
86 q->objectChanged();-
87}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
2
88-
89QObject *QQmlInstantiatorPrivate::modelObject(int index, bool async)-
90{-
91 requestedIndex = index;-
92 QObject *o = instanceModel->object(index, async ? QQmlIncubator::Asynchronous : QQmlIncubator::AsynchronousIfNested);-
93 requestedIndex = -1;-
94 return o;
executed 104 times by 1 test: return o;
Executed by:
  • tst_qqmlinstantiator
104
95}-
96-
97-
98void QQmlInstantiatorPrivate::regenerate()-
99{-
100 Q_Q(QQmlInstantiator);-
101 if (!componentComplete)
!componentCompleteDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-20
102 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
2
103-
104 int prevCount = q->count();-
105-
106 clear();-
107-
108 if (!active || !instanceModel || !instanceModel->count() || !instanceModel->isValid()) {
!activeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
!instanceModelDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
!instanceModel->count()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
!instanceModel->isValid()Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-18
109 if (prevCount)
prevCountDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-4
110 q->countChanged();
never executed: q->countChanged();
0
111 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
4
112 }-
113-
114 for (int i = 0; i < instanceModel->count(); i++) {
i < instanceModel->count()Description
TRUEevaluated 96 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
16-96
115 QObject *object = modelObject(i, async);-
116 // If the item was already created we won't get a createdItem-
117 if (object)
objectDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 40 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
40-56
118 _q_createdItem(i, object);
executed 56 times by 1 test: _q_createdItem(i, object);
Executed by:
  • tst_qqmlinstantiator
56
119 }
executed 96 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
96
120 if (q->count() != prevCount)
q->count() != prevCountDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
4-12
121 q->countChanged();
executed 12 times by 1 test: q->countChanged();
Executed by:
  • tst_qqmlinstantiator
12
122}
executed 16 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
16
123-
124void QQmlInstantiatorPrivate::_q_createdItem(int idx, QObject* item)-
125{-
126 Q_Q(QQmlInstantiator);-
127 if (objects.contains(item)) //Case when it was created synchronously in regenerate
objects.contains(item)Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 104 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
64-104
128 return;
executed 64 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
64
129 if (requestedIndex != idx) // Asynchronous creation, reference the object
requestedIndex != idxDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 64 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
40-64
130 (void)instanceModel->object(idx);
executed 40 times by 1 test: (void)instanceModel->object(idx);
Executed by:
  • tst_qqmlinstantiator
40
131 item->setParent(q);-
132 if (objects.size() < idx + 1) {
objects.size() < idx + 1Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 44 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
44-60
133 int modelCount = instanceModel->count();-
134 if (objects.capacity() < modelCount)
objects.capaci...) < modelCountDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
14-46
135 objects.reserve(modelCount);
executed 14 times by 1 test: objects.reserve(modelCount);
Executed by:
  • tst_qqmlinstantiator
14
136 objects.resize(idx + 1);-
137 }
executed 60 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
60
138 if (QObject *o = objects.at(idx))
QObject *o = objects.at(idx)Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-104
139 instanceModel->release(o);
never executed: instanceModel->release(o);
0
140 objects.replace(idx, item);-
141 if (objects.count() == 1)
objects.count() == 1Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 90 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
14-90
142 q->objectChanged();
executed 14 times by 1 test: q->objectChanged();
Executed by:
  • tst_qqmlinstantiator
14
143 q->objectAdded(idx, item);-
144}
executed 104 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
104
145-
146void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bool reset)-
147{-
148 Q_Q(QQmlInstantiator);-
149-
150 if (!componentComplete || effectiveReset)
!componentCompleteDescription
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
effectiveResetDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-14
151 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
4
152-
153 if (reset) {
resetDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-10
154 regenerate();-
155 if (changeSet.difference() != 0)
changeSet.difference() != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
156 q->countChanged();
never executed: q->countChanged();
0
157 return;
never executed: return;
0
158 }-
159-
160 int difference = 0;-
161 QHash<int, QVector<QPointer<QObject> > > moved;-
162 const QVector<QQmlChangeSet::Change> &removes = changeSet.removes();-
163 for (const QQmlChangeSet::Change &remove : removes) {-
164 int index = qMin(remove.index, objects.count());-
165 int count = qMin(remove.index + remove.count, objects.count()) - index;-
166 if (remove.isMove()) {
remove.isMove()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-2
167 moved.insert(remove.moveId, objects.mid(index, count));-
168 objects.erase(-
169 objects.begin() + index,-
170 objects.begin() + index + count);-
171 } else while (count--) {
never executed: end of block
count--Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-2
172 QObject *obj = objects.at(index);-
173 objects.remove(index);-
174 q->objectRemoved(index, obj);-
175 if (obj)
objDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-2
176 instanceModel->release(obj);
executed 2 times by 1 test: instanceModel->release(obj);
Executed by:
  • tst_qqmlinstantiator
2
177 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
2
178-
179 difference -= remove.count;-
180 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
2
181-
182 const QVector<QQmlChangeSet::Change> &inserts = changeSet.inserts();-
183 for (const QQmlChangeSet::Change &insert : inserts) {-
184 int index = qMin(insert.index, objects.count());-
185 if (insert.isMove()) {
insert.isMove()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-8
186 QVector<QPointer<QObject> > movedObjects = moved.value(insert.moveId);-
187 objects = objects.mid(0, index) + movedObjects + objects.mid(index);-
188 } else {
never executed: end of block
0
189 if (insert.index <= objects.size())
insert.index <= objects.size()Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-8
190 objects.insert(insert.index, insert.count, nullptr);
executed 8 times by 1 test: objects.insert(insert.index, insert.count, nullptr);
Executed by:
  • tst_qqmlinstantiator
8
191 for (int i = 0; i < insert.count; ++i) {
i < insert.countDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
8
192 int modelIndex = index + i;-
193 QObject* obj = modelObject(modelIndex, async);-
194 if (obj)
objDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-8
195 _q_createdItem(modelIndex, obj);
executed 8 times by 1 test: _q_createdItem(modelIndex, obj);
Executed by:
  • tst_qqmlinstantiator
8
196 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
8
197 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
8
198 difference += insert.count;-
199 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
8
200-
201 if (difference != 0)
difference != 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-10
202 q->countChanged();
executed 10 times by 1 test: q->countChanged();
Executed by:
  • tst_qqmlinstantiator
10
203}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
10
204-
205#if QT_CONFIG(qml_delegate_model)-
206void QQmlInstantiatorPrivate::makeModel()-
207{-
208 Q_Q(QQmlInstantiator);-
209 QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q), q);-
210 instanceModel = delegateModel;-
211 ownModel = true;-
212 delegateModel->setDelegate(delegate);-
213 delegateModel->classBegin(); //Pretend it was made in QML-
214 if (componentComplete)
componentCompleteDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-16
215 delegateModel->componentComplete();
executed 16 times by 1 test: delegateModel->componentComplete();
Executed by:
  • tst_qqmlinstantiator
16
216}
executed 16 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
16
217#endif-
218-
219-
220/*!-
221 \qmltype Instantiator-
222 \instantiates QQmlInstantiator-
223 \inqmlmodule QtQml-
224 \brief Dynamically creates objects.-
225-
226 A Instantiator can be used to control the dynamic creation of objects, or to dynamically-
227 create multiple objects from a template.-
228-
229 The Instantiator element will manage the objects it creates. Those objects are parented to the-
230 Instantiator and can also be deleted by the Instantiator if the Instantiator's properties change. Objects-
231 can also be destroyed dynamically through other means, and the Instantiator will not recreate-
232 them unless the properties of the Instantiator change.-
233-
234*/-
235QQmlInstantiator::QQmlInstantiator(QObject *parent)-
236 : QObject(*(new QQmlInstantiatorPrivate), parent)-
237{-
238}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
239-
240QQmlInstantiator::~QQmlInstantiator()-
241{-
242}-
243-
244/*!-
245 \qmlsignal QtQml::Instantiator::objectAdded(int index, QtObject object)-
246-
247 This signal is emitted when an object is added to the Instantiator. The \a index-
248 parameter holds the index which the object has been given, and the \a object-
249 parameter holds the \l QtObject that has been added.-
250-
251 The corresponding handler is \c onObjectAdded.-
252*/-
253-
254/*!-
255 \qmlsignal QtQml::Instantiator::objectRemoved(int index, QtObject object)-
256-
257 This signal is emitted when an object is removed from the Instantiator. The \a index-
258 parameter holds the index which the object had been given, and the \a object-
259 parameter holds the \l QtObject that has been removed.-
260-
261 Do not keep a reference to \a object if it was created by this Instantiator, as-
262 in these cases it will be deleted shortly after the signal is handled.-
263-
264 The corresponding handler is \c onObjectRemoved.-
265*/-
266/*!-
267 \qmlproperty bool QtQml::Instantiator::active-
268-
269 When active is true, and the delegate component is ready, the Instantiator will-
270 create objects according to the model. When active is false, no objects-
271 will be created and any previously created objects will be destroyed.-
272-
273 Default is true.-
274*/-
275bool QQmlInstantiator::isActive() const-
276{-
277 Q_D(const QQmlInstantiator);-
278 return d->active;
executed 16 times by 1 test: return d->active;
Executed by:
  • tst_qqmlinstantiator
16
279}-
280-
281void QQmlInstantiator::setActive(bool newVal)-
282{-
283 Q_D(QQmlInstantiator);-
284 if (newVal == d->active)
newVal == d->activeDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-4
285 return;
never executed: return;
0
286 d->active = newVal;-
287 emit activeChanged();-
288 d->regenerate();-
289}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
4
290-
291/*!-
292 \qmlproperty bool QtQml::Instantiator::asynchronous-
293-
294 When asynchronous is true the Instantiator will attempt to create objects-
295 asynchronously. This means that objects may not be available immediately,-
296 even if active is set to true.-
297-
298 You can use the objectAdded signal to respond to items being created.-
299-
300 Default is false.-
301*/-
302bool QQmlInstantiator::isAsync() const-
303{-
304 Q_D(const QQmlInstantiator);-
305 return d->async;
never executed: return d->async;
0
306}-
307-
308void QQmlInstantiator::setAsync(bool newVal)-
309{-
310 Q_D(QQmlInstantiator);-
311 if (newVal == d->async)
newVal == d->asyncDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-2
312 return;
never executed: return;
0
313 d->async = newVal;-
314 emit asynchronousChanged();-
315}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
2
316-
317-
318/*!-
319 \qmlproperty int QtQml::Instantiator::count-
320-
321 The number of objects the Instantiator is currently managing.-
322*/-
323-
324int QQmlInstantiator::count() const-
325{-
326 Q_D(const QQmlInstantiator);-
327 return d->objects.count();
executed 56 times by 1 test: return d->objects.count();
Executed by:
  • tst_qqmlinstantiator
56
328}-
329-
330/*!-
331 \qmlproperty QtQml::Component QtQml::Instantiator::delegate-
332 \default-
333-
334 The component used to create all objects.-
335-
336 Note that an extra variable, index, will be available inside instances of the-
337 delegate. This variable refers to the index of the instance inside the Instantiator,-
338 and can be used to obtain the object through the objectAt method of the Instantiator.-
339-
340 If this property is changed, all instances using the old delegate will be destroyed-
341 and new instances will be created using the new delegate.-
342*/-
343QQmlComponent* QQmlInstantiator::delegate()-
344{-
345 Q_D(QQmlInstantiator);-
346 return d->delegate;
executed 6 times by 1 test: return d->delegate;
Executed by:
  • tst_qqmlinstantiator
6
347}-
348-
349void QQmlInstantiator::setDelegate(QQmlComponent* c)-
350{-
351 Q_D(QQmlInstantiator);-
352 if (c == d->delegate)
c == d->delegateDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-18
353 return;
never executed: return;
0
354-
355 d->delegate = c;-
356 emit delegateChanged();-
357-
358#if QT_CONFIG(qml_delegate_model)-
359 if (!d->ownModel)
!d->ownModelDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-18
360 return;
executed 18 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
18
361-
362 if (QQmlDelegateModel *dModel = qobject_cast<QQmlDelegateModel*>(d->instanceModel))
QQmlDelegateMo...instanceModel)Description
TRUEnever evaluated
FALSEnever evaluated
0
363 dModel->setDelegate(c);
never executed: dModel->setDelegate(c);
0
364 if (d->componentComplete)
d->componentCompleteDescription
TRUEnever evaluated
FALSEnever evaluated
0
365 d->regenerate();
never executed: d->regenerate();
0
366#endif-
367}
never executed: end of block
0
368-
369/*!-
370 \qmlproperty variant QtQml::Instantiator::model-
371-
372 This property can be set to any of the supported \l {qml-data-models}{data models}:-
373-
374 \list-
375 \li A number that indicates the number of delegates to be created by the repeater-
376 \li A model (e.g. a ListModel item, or a QAbstractItemModel subclass)-
377 \li A string list-
378 \li An object list-
379 \endlist-
380-
381 The type of model affects the properties that are exposed to the \l delegate.-
382-
383 Default value is 1, which creates a single delegate instance.-
384-
385 \sa {qml-data-models}{Data Models}-
386*/-
387-
388QVariant QQmlInstantiator::model() const-
389{-
390 Q_D(const QQmlInstantiator);-
391 return d->model;
never executed: return d->model;
0
392}-
393-
394void QQmlInstantiator::setModel(const QVariant &v)-
395{-
396 Q_D(QQmlInstantiator);-
397 if (d->model == v)
d->model == vDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 32 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-32
398 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
2
399-
400 d->model = v;-
401 //Don't actually set model until componentComplete in case it wants to create its delegates immediately-
402 if (!d->componentComplete)
!d->componentCompleteDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
14-18
403 return;
executed 14 times by 1 test: return;
Executed by:
  • tst_qqmlinstantiator
14
404-
405 QQmlInstanceModel *prevModel = d->instanceModel;-
406 QObject *object = qvariant_cast<QObject*>(v);-
407 QQmlInstanceModel *vim = nullptr;-
408 if (object && (vim = qobject_cast<QQmlInstanceModel *>(object))) {
objectDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
(vim = qobject...el *>(object))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-16
409#if QT_CONFIG(qml_delegate_model)-
410 if (d->ownModel) {
d->ownModelDescription
TRUEnever evaluated
FALSEnever evaluated
0
411 delete d->instanceModel;-
412 prevModel = nullptr;-
413 d->ownModel = false;-
414 }
never executed: end of block
0
415#endif-
416 d->instanceModel = vim;-
417#if QT_CONFIG(qml_delegate_model)-
418 } else if (v != QVariant(0)){
never executed: end of block
v != QVariant(0)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-18
419 if (!d->ownModel)
!d->ownModelDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-16
420 d->makeModel();
executed 16 times by 1 test: d->makeModel();
Executed by:
  • tst_qqmlinstantiator
16
421-
422 if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel *>(d->instanceModel)) {
QQmlDelegateMo...instanceModel)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-18
423 d->effectiveReset = true;-
424 dataModel->setModel(v);-
425 d->effectiveReset = false;-
426 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
427#endif-
428 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
429-
430 if (d->instanceModel != prevModel) {
d->instanceModel != prevModelDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
2-16
431 if (prevModel) {
prevModelDescription
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-16
432 disconnect(prevModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)),-
433 this, SLOT(_q_modelUpdated(QQmlChangeSet,bool)));-
434 disconnect(prevModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(_q_createdItem(int,QObject*)));-
435 //disconnect(prevModel, SIGNAL(initItem(int,QObject*)), this, SLOT(initItem(int,QObject*)));-
436 }
never executed: end of block
0
437-
438 if (d->instanceModel) {
d->instanceModelDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-16
439 connect(d->instanceModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)),-
440 this, SLOT(_q_modelUpdated(QQmlChangeSet,bool)));-
441 connect(d->instanceModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(_q_createdItem(int,QObject*)));-
442 //connect(d->instanceModel, SIGNAL(initItem(int,QObject*)), this, SLOT(initItem(int,QObject*)));-
443 }
executed 16 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
16
444 }
executed 16 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
16
445-
446 d->regenerate();-
447 emit modelChanged();-
448}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
449-
450/*!-
451 \qmlproperty QtObject QtQml::Instantiator::object-
452-
453 This is a reference to the first created object, intended as a convenience-
454 for the case where only one object has been created.-
455*/-
456QObject *QQmlInstantiator::object() const-
457{-
458 Q_D(const QQmlInstantiator);-
459 if (d->objects.count())
d->objects.count()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-4
460 return d->objects[0];
executed 4 times by 1 test: return d->objects[0];
Executed by:
  • tst_qqmlinstantiator
4
461 return nullptr;
never executed: return nullptr;
0
462}-
463-
464/*!-
465 \qmlmethod QtObject QtQml::Instantiator::objectAt(int index)-
466-
467 Returns a reference to the object with the given \a index.-
468*/-
469QObject *QQmlInstantiator::objectAt(int index) const-
470{-
471 Q_D(const QQmlInstantiator);-
472 if (index >= 0 && index < d->objects.count())
index >= 0Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
index < d->objects.count()Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
FALSEnever evaluated
0-78
473 return d->objects[index];
executed 78 times by 1 test: return d->objects[index];
Executed by:
  • tst_qqmlinstantiator
78
474 return nullptr;
never executed: return nullptr;
0
475}-
476-
477/*!-
478 \internal-
479*/-
480void QQmlInstantiator::classBegin()-
481{-
482 Q_D(QQmlInstantiator);-
483 d->componentComplete = false;-
484}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
485-
486/*!-
487 \internal-
488*/-
489void QQmlInstantiator::componentComplete()-
490{-
491 Q_D(QQmlInstantiator);-
492 d->componentComplete = true;-
493#if QT_CONFIG(qml_delegate_model)-
494 if (d->ownModel) {
d->ownModelDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qqmlinstantiator
0-18
495 static_cast<QQmlDelegateModel*>(d->instanceModel)->componentComplete();-
496 d->regenerate();-
497 } else
never executed: end of block
0
498#endif-
499 {-
500 QVariant realModel = d->model;-
501 d->model = QVariant(0);-
502 setModel(realModel); //If realModel == d->model this won't do anything, but that's fine since the model's 0-
503 //setModel calls regenerate-
504 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlinstantiator
18
505}-
506-
507QT_END_NAMESPACE-
508-
509#include "moc_qqmlinstantiator_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0