itemmodels/qabstractitemmodel.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore 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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qabstractitemmodel.h" -
43#include <private/qabstractitemmodel_p.h> -
44#include <qdatastream.h> -
45#include <qstringlist.h> -
46#include <qsize.h> -
47#include <qmimedata.h> -
48#include <qdebug.h> -
49#include <qvector.h> -
50#include <qstack.h> -
51#include <qbitarray.h> -
52 -
53#include <limits.h> -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index) -
58{ -
59 Q_ASSERT(index.isValid()); // we will _never_ insert an invalid index in the list
executed (the execution status of this line is deduced): qt_noop();
-
60 QPersistentModelIndexData *d = 0;
executed (the execution status of this line is deduced): QPersistentModelIndexData *d = 0;
-
61 QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model());
executed (the execution status of this line is deduced): QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model());
-
62 QHash<QModelIndex, QPersistentModelIndexData *> &indexes = model->d_func()->persistent.indexes;
executed (the execution status of this line is deduced): QHash<QModelIndex, QPersistentModelIndexData *> &indexes = model->d_func()->persistent.indexes;
-
63 const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = indexes.find(index);
executed (the execution status of this line is deduced): const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = indexes.find(index);
-
64 if (it != indexes.end()) {
evaluated: it != indexes.end()
TRUEFALSE
yes
Evaluation Count:79776
yes
Evaluation Count:25197
25197-79776
65 d = (*it);
executed (the execution status of this line is deduced): d = (*it);
-
66 } else {
executed: }
Execution Count:79776
79776
67 d = new QPersistentModelIndexData(index);
executed (the execution status of this line is deduced): d = new QPersistentModelIndexData(index);
-
68 indexes.insert(index, d);
executed (the execution status of this line is deduced): indexes.insert(index, d);
-
69 }
executed: }
Execution Count:25197
25197
70 Q_ASSERT(d);
executed (the execution status of this line is deduced): qt_noop();
-
71 return d;
executed: return d;
Execution Count:104973
104973
72} -
73 -
74void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) -
75{ -
76 Q_ASSERT(data);
executed (the execution status of this line is deduced): qt_noop();
-
77 Q_ASSERT(data->ref.load() == 0);
executed (the execution status of this line is deduced): qt_noop();
-
78 QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->model);
executed (the execution status of this line is deduced): QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->model);
-
79 // a valid persistent model index with a null model pointer can only happen if the model was destroyed -
80 if (model) {
evaluated: model
TRUEFALSE
yes
Evaluation Count:22461
yes
Evaluation Count:2732
2732-22461
81 QAbstractItemModelPrivate *p = model->d_func();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate *p = model->d_func();
-
82 Q_ASSERT(p);
executed (the execution status of this line is deduced): qt_noop();
-
83 p->removePersistentIndexData(data);
executed (the execution status of this line is deduced): p->removePersistentIndexData(data);
-
84 }
executed: }
Execution Count:22461
22461
85 delete data;
executed (the execution status of this line is deduced): delete data;
-
86}
executed: }
Execution Count:25193
25193
87 -
88/*! -
89 \class QPersistentModelIndex -
90 \inmodule QtCore -
91 \ingroup shared -
92 -
93 \brief The QPersistentModelIndex class is used to locate data in a data model. -
94 -
95 \ingroup model-view -
96 -
97 A QPersistentModelIndex is a model index that can be stored by an -
98 application, and later used to access information in a model. -
99 Unlike the QModelIndex class, it is safe to store a -
100 QPersistentModelIndex since the model will ensure that references -
101 to items will continue to be valid as long as they can be accessed -
102 by the model. -
103 -
104 It is good practice to check that persistent model indexes are valid -
105 before using them. -
106 -
107 \sa {Model/View Programming}, QModelIndex, QAbstractItemModel -
108*/ -
109 -
110 -
111/*! -
112 \fn QPersistentModelIndex::QPersistentModelIndex() -
113 -
114 \internal -
115*/ -
116 -
117QPersistentModelIndex::QPersistentModelIndex() -
118 : d(0) -
119{ -
120}
executed: }
Execution Count:46845
46845
121 -
122/*! -
123 \fn QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) -
124 -
125 Creates a new QPersistentModelIndex that is a copy of the \a other persistent -
126 model index. -
127*/ -
128 -
129QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) -
130 : d(other.d) -
131{ -
132 if (d) d->ref.ref();
executed: d->ref.ref();
Execution Count:80449
evaluated: d
TRUEFALSE
yes
Evaluation Count:80449
yes
Evaluation Count:1586
1586-80449
133}
executed: }
Execution Count:82035
82035
134 -
135/*! -
136 Creates a new QPersistentModelIndex that is a copy of the model \a index. -
137*/ -
138 -
139QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index) -
140 : d(0) -
141{ -
142 if (index.isValid()) {
evaluated: index.isValid()
TRUEFALSE
yes
Evaluation Count:80276
yes
Evaluation Count:478
478-80276
143 d = QPersistentModelIndexData::create(index);
executed (the execution status of this line is deduced): d = QPersistentModelIndexData::create(index);
-
144 d->ref.ref();
executed (the execution status of this line is deduced): d->ref.ref();
-
145 }
executed: }
Execution Count:80276
80276
146}
executed: }
Execution Count:80754
80754
147 -
148/*! -
149 \fn QPersistentModelIndex::~QPersistentModelIndex() -
150 -
151 \internal -
152*/ -
153 -
154QPersistentModelIndex::~QPersistentModelIndex() -
155{ -
156 if (d && !d->ref.deref()) {
evaluated: d
TRUEFALSE
yes
Evaluation Count:183434
yes
Evaluation Count:22466
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:17032
yes
Evaluation Count:166402
17032-183434
157 QPersistentModelIndexData::destroy(d);
executed (the execution status of this line is deduced): QPersistentModelIndexData::destroy(d);
-
158 d = 0;
executed (the execution status of this line is deduced): d = 0;
-
159 }
executed: }
Execution Count:17032
17032
160}
executed: }
Execution Count:205900
205900
161 -
162/*! -
163 Returns true if this persistent model index is equal to the \a other -
164 persistent model index; otherwise returns false. -
165 -
166 All values in the persistent model index are used when comparing -
167 with another persistent model index. -
168*/ -
169 -
170bool QPersistentModelIndex::operator==(const QPersistentModelIndex &other) const -
171{ -
172 if (d && other.d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:45063
yes
Evaluation Count:551
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:40743
yes
Evaluation Count:4320
551-45063
173 return d->index == other.d->index;
executed: return d->index == other.d->index;
Execution Count:40743
40743
174 return d == other.d;
executed: return d == other.d;
Execution Count:4871
4871
175} -
176 -
177/*! -
178 \since 4.1 -
179 -
180 Returns true if this persistent model index is smaller than the \a other -
181 persistent model index; otherwise returns false. -
182 -
183 All values in the persistent model index are used when comparing -
184 with another persistent model index. -
185*/ -
186 -
187bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const -
188{ -
189 if (d && other.d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:1511
no
Evaluation Count:0
partially evaluated: other.d
TRUEFALSE
yes
Evaluation Count:1511
no
Evaluation Count:0
0-1511
190 return d->index < other.d->index;
executed: return d->index < other.d->index;
Execution Count:1511
1511
191 -
192 return d < other.d;
never executed: return d < other.d;
0
193} -
194 -
195/*! -
196 \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &other) const -
197 \since 4.2 -
198 -
199 Returns true if this persistent model index is not equal to the \a -
200 other persistent model index; otherwise returns false. -
201*/ -
202 -
203/*! -
204 Sets the persistent model index to refer to the same item in a model -
205 as the \a other persistent model index. -
206*/ -
207 -
208QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIndex &other) -
209{ -
210 if (d == other.d)
evaluated: d == other.d
TRUEFALSE
yes
Evaluation Count:5701
yes
Evaluation Count:15996
5701-15996
211 return *this;
executed: return *this;
Execution Count:5701
5701
212 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:14352
yes
Evaluation Count:1644
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:6751
yes
Evaluation Count:7601
1644-14352
213 QPersistentModelIndexData::destroy(d);
executed: QPersistentModelIndexData::destroy(d);
Execution Count:6751
6751
214 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
215 if (d) d->ref.ref();
executed: d->ref.ref();
Execution Count:15979
evaluated: d
TRUEFALSE
yes
Evaluation Count:15979
yes
Evaluation Count:17
17-15979
216 return *this;
executed: return *this;
Execution Count:15996
15996
217} -
218/*! -
219 \fn void QPersistentModelIndex::swap(QPersistentModelIndex &other) -
220 \since 5.0 -
221 -
222 Swaps this persistent modelindex with \a other. This function is -
223 very fast and never fails. -
224*/ -
225 -
226/*! -
227 Sets the persistent model index to refer to the same item in a model -
228 as the \a other model index. -
229*/ -
230 -
231QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other) -
232{ -
233 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:3609
yes
Evaluation Count:36092
evaluated: !d->ref.deref()
TRUEFALSE
yes
Evaluation Count:1410
yes
Evaluation Count:2199
1410-36092
234 QPersistentModelIndexData::destroy(d);
executed: QPersistentModelIndexData::destroy(d);
Execution Count:1410
1410
235 if (other.isValid()) {
evaluated: other.isValid()
TRUEFALSE
yes
Evaluation Count:24697
yes
Evaluation Count:15004
15004-24697
236 d = QPersistentModelIndexData::create(other);
executed (the execution status of this line is deduced): d = QPersistentModelIndexData::create(other);
-
237 if (d) d->ref.ref();
executed: d->ref.ref();
Execution Count:24697
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:24697
no
Evaluation Count:0
0-24697
238 } else {
executed: }
Execution Count:24697
24697
239 d = 0;
executed (the execution status of this line is deduced): d = 0;
-
240 }
executed: }
Execution Count:15004
15004
241 return *this;
executed: return *this;
Execution Count:39701
39701
242} -
243 -
244/*! -
245 \fn QPersistentModelIndex::operator const QModelIndex&() const -
246 -
247 Cast operator that returns a const QModelIndex&. -
248*/ -
249 -
250QPersistentModelIndex::operator const QModelIndex&() const -
251{ -
252 static const QModelIndex invalid; -
253 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:129164
yes
Evaluation Count:413968
129164-413968
254 return d->index;
executed: return d->index;
Execution Count:129164
129164
255 return invalid;
executed: return invalid;
Execution Count:413968
413968
256} -
257 -
258/*! -
259 \fn bool QPersistentModelIndex::operator==(const QModelIndex &other) const -
260 -
261 Returns true if this persistent model index refers to the same location as -
262 the \a other model index; otherwise returns false. -
263 -
264 All values in the persistent model index are used when comparing with -
265 another model index. -
266*/ -
267 -
268bool QPersistentModelIndex::operator==(const QModelIndex &other) const -
269{ -
270 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:702
yes
Evaluation Count:584
584-702
271 return d->index == other;
executed: return d->index == other;
Execution Count:702
702
272 return !other.isValid();
executed: return !other.isValid();
Execution Count:584
584
273} -
274 -
275/*! -
276 \fn bool QPersistentModelIndex::operator!=(const QModelIndex &other) const -
277 -
278 Returns true if this persistent model index does not refer to the same -
279 location as the \a other model index; otherwise returns false. -
280*/ -
281 -
282bool QPersistentModelIndex::operator!=(const QModelIndex &other) const -
283{ -
284 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:163
no
Evaluation Count:0
0-163
285 return d->index != other;
executed: return d->index != other;
Execution Count:163
163
286 return other.isValid();
never executed: return other.isValid();
0
287} -
288 -
289/*! -
290 \fn int QPersistentModelIndex::row() const -
291 -
292 Returns the row this persistent model index refers to. -
293*/ -
294 -
295int QPersistentModelIndex::row() const -
296{ -
297 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:227230
yes
Evaluation Count:2418
2418-227230
298 return d->index.row();
executed: return d->index.row();
Execution Count:227230
227230
299 return -1;
executed: return -1;
Execution Count:2418
2418
300} -
301 -
302/*! -
303 \fn int QPersistentModelIndex::column() const -
304 -
305 Returns the column this persistent model index refers to. -
306*/ -
307 -
308int QPersistentModelIndex::column() const -
309{ -
310 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:177108
yes
Evaluation Count:1719
1719-177108
311 return d->index.column();
executed: return d->index.column();
Execution Count:177108
177108
312 return -1;
executed: return -1;
Execution Count:1719
1719
313} -
314 -
315/*! -
316 \fn void *QPersistentModelIndex::internalPointer() const -
317 -
318 \internal -
319 -
320 Returns a \c{void} \c{*} pointer used by the model to associate the index with -
321 the internal data structure. -
322*/ -
323 -
324void *QPersistentModelIndex::internalPointer() const -
325{ -
326 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:89
no
Evaluation Count:0
0-89
327 return d->index.internalPointer();
executed: return d->index.internalPointer();
Execution Count:89
89
328 return 0;
never executed: return 0;
0
329} -
330 -
331/*! -
332 \fn quintptr QPersistentModelIndex::internalId() const -
333 -
334 \internal -
335 -
336 Returns a \c{quintptr} used by the model to associate the index with -
337 the internal data structure. -
338*/ -
339 -
340quintptr QPersistentModelIndex::internalId() const -
341{ -
342 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
343 return d->index.internalId();
executed: return d->index.internalId();
Execution Count:4
4
344 return 0;
never executed: return 0;
0
345} -
346 -
347/*! -
348 Returns the parent QModelIndex for this persistent index, or an invalid -
349 QModelIndex if it has no parent. -
350 -
351 \sa child(), sibling(), model() -
352*/ -
353QModelIndex QPersistentModelIndex::parent() const -
354{ -
355 if (d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:171723
yes
Evaluation Count:760
760-171723
356 return d->index.parent();
executed: return d->index.parent();
Execution Count:171723
171723
357 return QModelIndex();
executed: return QModelIndex();
Execution Count:760
760
358} -
359 -
360/*! -
361 Returns the sibling at \a row and \a column or an invalid QModelIndex if -
362 there is no sibling at this position. -
363 -
364 \sa parent(), child() -
365*/ -
366 -
367QModelIndex QPersistentModelIndex::sibling(int row, int column) const -
368{ -
369 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
370 return d->index.sibling(row, column);
executed: return d->index.sibling(row, column);
Execution Count:8
8
371 return QModelIndex();
never executed: return QModelIndex();
0
372} -
373 -
374/*! -
375 Returns the child of the model index that is stored in the given \a row -
376 and \a column. -
377 -
378 \sa parent(), sibling() -
379*/ -
380 -
381QModelIndex QPersistentModelIndex::child(int row, int column) const -
382{ -
383 if (d)
never evaluated: d
0
384 return d->index.child(row, column);
never executed: return d->index.child(row, column);
0
385 return QModelIndex();
never executed: return QModelIndex();
0
386} -
387 -
388/*! -
389 Returns the data for the given \a role for the item referred to by the -
390 index. -
391 -
392 \sa Qt::ItemDataRole, QAbstractItemModel::setData() -
393*/ -
394QVariant QPersistentModelIndex::data(int role) const -
395{ -
396 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:69
no
Evaluation Count:0
0-69
397 return d->index.data(role);
executed: return d->index.data(role);
Execution Count:69
69
398 return QVariant();
never executed: return QVariant();
0
399} -
400 -
401/*! -
402 \since 4.2 -
403 -
404 Returns the flags for the item referred to by the index. -
405*/ -
406Qt::ItemFlags QPersistentModelIndex::flags() const -
407{ -
408 if (d)
never evaluated: d
0
409 return d->index.flags();
never executed: return d->index.flags();
0
410 return 0;
never executed: return 0;
0
411} -
412 -
413/*! -
414 Returns the model that the index belongs to. -
415*/ -
416const QAbstractItemModel *QPersistentModelIndex::model() const -
417{ -
418 if (d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:34614
no
Evaluation Count:0
0-34614
419 return d->index.model();
executed: return d->index.model();
Execution Count:34614
34614
420 return 0;
never executed: return 0;
0
421} -
422 -
423/*! -
424 \fn bool QPersistentModelIndex::isValid() const -
425 -
426 Returns true if this persistent model index is valid; otherwise returns -
427 false. -
428 -
429 A valid index belongs to a model, and has non-negative row and column -
430 numbers. -
431 -
432 \sa model(), row(), column() -
433*/ -
434 -
435bool QPersistentModelIndex::isValid() const -
436{ -
437 return d && d->index.isValid();
executed: return d && d->index.isValid();
Execution Count:120046
120046
438} -
439 -
440#ifndef QT_NO_DEBUG_STREAM -
441QDebug operator<<(QDebug dbg, const QModelIndex &idx) -
442{ -
443 dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column()
executed (the execution status of this line is deduced): dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column()
-
444 << ',' << idx.internalPointer() << ',' << idx.model() << ')';
executed (the execution status of this line is deduced): << ',' << idx.internalPointer() << ',' << idx.model() << ')';
-
445 return dbg.space();
executed: return dbg.space();
Execution Count:13
13
446} -
447 -
448QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) -
449{ -
450 if (idx.d)
never evaluated: idx.d
0
451 dbg << idx.d->index;
never executed: dbg << idx.d->index;
0
452 else -
453 dbg << QModelIndex();
never executed: dbg << QModelIndex();
0
454 return dbg;
never executed: return dbg;
0
455} -
456#endif -
457 -
458class QEmptyItemModel : public QAbstractItemModel -
459{ -
460public: -
461 explicit QEmptyItemModel(QObject *parent = 0) : QAbstractItemModel(parent) {}
executed: }
Execution Count:36
36
462 QModelIndex index(int, int, const QModelIndex &) const { return QModelIndex(); }
executed: return QModelIndex();
Execution Count:23
23
463 QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
never executed: return QModelIndex();
0
464 int rowCount(const QModelIndex &) const { return 0; }
executed: return 0;
Execution Count:1341
1341
465 int columnCount(const QModelIndex &) const { return 0; }
executed: return 0;
Execution Count:2229
2229
466 bool hasChildren(const QModelIndex &) const { return false; }
executed: return false;
Execution Count:174
174
467 QVariant data(const QModelIndex &, int) const { return QVariant(); }
executed: return QVariant();
Execution Count:1030
1030
468}; -
469 -
470Q_GLOBAL_STATIC(QEmptyItemModel, qEmptyModel)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:184036
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:184000
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:36
no
Evaluation Count:0
0-184036
471 -
472QAbstractItemModel *QAbstractItemModelPrivate::staticEmptyModel() -
473{ -
474 return qEmptyModel();
executed: return qEmptyModel();
Execution Count:184036
184036
475} -
476 -
477namespace { -
478 struct DefaultRoleNames : public QHash<int, QByteArray> -
479 { -
480 DefaultRoleNames() { -
481 (*this)[Qt::DisplayRole] = "display";
executed (the execution status of this line is deduced): (*this)[Qt::DisplayRole] = "display";
-
482 (*this)[Qt::DecorationRole] = "decoration";
executed (the execution status of this line is deduced): (*this)[Qt::DecorationRole] = "decoration";
-
483 (*this)[Qt::EditRole] = "edit";
executed (the execution status of this line is deduced): (*this)[Qt::EditRole] = "edit";
-
484 (*this)[Qt::ToolTipRole] = "toolTip";
executed (the execution status of this line is deduced): (*this)[Qt::ToolTipRole] = "toolTip";
-
485 (*this)[Qt::StatusTipRole] = "statusTip";
executed (the execution status of this line is deduced): (*this)[Qt::StatusTipRole] = "statusTip";
-
486 (*this)[Qt::WhatsThisRole] = "whatsThis";
executed (the execution status of this line is deduced): (*this)[Qt::WhatsThisRole] = "whatsThis";
-
487 }
executed: }
Execution Count:45
45
488 }; -
489} -
490 -
491Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:4640
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:45
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:4595
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-4640
492 -
493const QHash<int,QByteArray> &QAbstractItemModelPrivate::defaultRoleNames() -
494{ -
495 return *qDefaultRoleNames();
executed: return *qDefaultRoleNames();
Execution Count:4640
4640
496} -
497 -
498 -
499static uint typeOfVariant(const QVariant &value) -
500{ -
501 //return 0 for integer, 1 for floating point and 2 for other -
502 switch (value.userType()) { -
503 case QVariant::Bool: -
504 case QVariant::Int: -
505 case QVariant::UInt: -
506 case QVariant::LongLong: -
507 case QVariant::ULongLong: -
508 case QVariant::Char: -
509 case QMetaType::Short: -
510 case QMetaType::UShort: -
511 case QMetaType::UChar: -
512 case QMetaType::ULong: -
513 case QMetaType::Long: -
514 return 0;
executed: return 0;
Execution Count:2
2
515 case QVariant::Double: -
516 case QMetaType::Float: -
517 return 1;
never executed: return 1;
0
518 default: -
519 return 2;
executed: return 2;
Execution Count:19798
19798
520 } -
521}
never executed: }
0
522 -
523/*! -
524 \internal -
525 return true if \a value contains a numerical type -
526 -
527 This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort. -
528*/ -
529bool QAbstractItemModelPrivate::variantLessThan(const QVariant &v1, const QVariant &v2) -
530{ -
531 switch(qMax(typeOfVariant(v1), typeOfVariant(v2))) -
532 { -
533 case 0: //integer type -
534 return v1.toLongLong() < v2.toLongLong();
executed: return v1.toLongLong() < v2.toLongLong();
Execution Count:1
1
535 case 1: //floating point -
536 return v1.toReal() < v2.toReal();
never executed: return v1.toReal() < v2.toReal();
0
537 default: -
538 return v1.toString().localeAwareCompare(v2.toString()) < 0;
executed: return v1.toString().localeAwareCompare(v2.toString()) < 0;
Execution Count:9899
9899
539 } -
540}
never executed: }
0
541 -
542void QAbstractItemModelPrivate::removePersistentIndexData(QPersistentModelIndexData *data) -
543{ -
544 if (data->index.isValid()) {
evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:22459
yes
Evaluation Count:2
2-22459
545 int removed = persistent.indexes.remove(data->index);
executed (the execution status of this line is deduced): int removed = persistent.indexes.remove(data->index);
-
546 Q_ASSERT_X(removed == 1, "QPersistentModelIndex::~QPersistentModelIndex",
executed (the execution status of this line is deduced): qt_noop();
-
547 "persistent model indexes corrupted"); //maybe the index was somewhat invalid? -
548 // This assert may happen if the model use changePersistentIndex in a way that could result on two -
549 // QPersistentModelIndex pointing to the same index. -
550 Q_UNUSED(removed);
executed (the execution status of this line is deduced): (void)removed;;
-
551 }
executed: }
Execution Count:22459
22459
552 // make sure our optimization still works -
553 for (int i = persistent.moved.count() - 1; i >= 0; --i) {
partially evaluated: i >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22461
0-22461
554 int idx = persistent.moved[i].indexOf(data);
never executed (the execution status of this line is deduced): int idx = persistent.moved[i].indexOf(data);
-
555 if (idx >= 0)
never evaluated: idx >= 0
0
556 persistent.moved[i].remove(idx);
never executed: persistent.moved[i].remove(idx);
0
557 }
never executed: }
0
558 // update the references to invalidated persistent indexes -
559 for (int i = persistent.invalidated.count() - 1; i >= 0; --i) {
partially evaluated: i >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22461
0-22461
560 int idx = persistent.invalidated[i].indexOf(data);
never executed (the execution status of this line is deduced): int idx = persistent.invalidated[i].indexOf(data);
-
561 if (idx >= 0)
never evaluated: idx >= 0
0
562 persistent.invalidated[i].remove(idx);
never executed: persistent.invalidated[i].remove(idx);
0
563 }
never executed: }
0
564 -
565}
executed: }
Execution Count:22461
22461
566 -
567void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex &parent, -
568 int first, int last) -
569{ -
570 Q_Q(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModel * const q = q_func();
-
571 Q_UNUSED(last);
executed (the execution status of this line is deduced): (void)last;;
-
572 QVector<QPersistentModelIndexData *> persistent_moved;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved;
-
573 if (first < q->rowCount(parent)) {
evaluated: first < q->rowCount(parent)
TRUEFALSE
yes
Evaluation Count:2173
yes
Evaluation Count:108360
2173-108360
574 for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
executed (the execution status of this line is deduced): for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
-
575 it != persistent.indexes.constEnd(); ++it) {
evaluated: it != persistent.indexes.constEnd()
TRUEFALSE
yes
Evaluation Count:7452
yes
Evaluation Count:2173
2173-7452
576 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
577 const QModelIndex &index = data->index;
executed (the execution status of this line is deduced): const QModelIndex &index = data->index;
-
578 if (index.row() >= first && index.isValid() && index.parent() == parent) {
evaluated: index.row() >= first
TRUEFALSE
yes
Evaluation Count:6112
yes
Evaluation Count:1340
partially evaluated: index.isValid()
TRUEFALSE
yes
Evaluation Count:6112
no
Evaluation Count:0
evaluated: index.parent() == parent
TRUEFALSE
yes
Evaluation Count:6083
yes
Evaluation Count:29
0-6112
579 persistent_moved.append(data);
executed (the execution status of this line is deduced): persistent_moved.append(data);
-
580 }
executed: }
Execution Count:6083
6083
581 }
executed: }
Execution Count:7452
7452
582 }
executed: }
Execution Count:2173
2173
583 persistent.moved.push(persistent_moved);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved);
-
584}
executed: }
Execution Count:110533
110533
585 -
586void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent, -
587 int first, int last) -
588{ -
589 QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
-
590 int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
executed (the execution status of this line is deduced): int count = (last - first) + 1;
-
591 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
-
592 it != persistent_moved.constEnd(); ++it) {
evaluated: it != persistent_moved.constEnd()
TRUEFALSE
yes
Evaluation Count:6083
yes
Evaluation Count:110533
6083-110533
593 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
594 QModelIndex old = data->index;
executed (the execution status of this line is deduced): QModelIndex old = data->index;
-
595 persistent.indexes.erase(persistent.indexes.find(old));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(old));
-
596 data->index = q_func()->index(old.row() + count, old.column(), parent);
executed (the execution status of this line is deduced): data->index = q_func()->index(old.row() + count, old.column(), parent);
-
597 if (data->index.isValid()) {
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:6083
no
Evaluation Count:0
0-6083
598 persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): persistent.insertMultiAtEnd(data->index, data);
-
599 } else {
executed: }
Execution Count:6083
6083
600 qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func();
never executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qabstractitemmodel.cpp", 600, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func();
-
601 }
never executed: }
0
602 } -
603}
executed: }
Execution Count:110533
110533
604 -
605void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) -
606{ -
607 QVector<QPersistentModelIndexData *> persistent_moved_explicitly;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved_explicitly;
-
608 QVector<QPersistentModelIndexData *> persistent_moved_in_source;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved_in_source;
-
609 QVector<QPersistentModelIndexData *> persistent_moved_in_destination;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved_in_destination;
-
610 -
611 QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it;
executed (the execution status of this line is deduced): QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it;
-
612 const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator begin = persistent.indexes.constBegin();
executed (the execution status of this line is deduced): const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator begin = persistent.indexes.constBegin();
-
613 const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator end = persistent.indexes.constEnd();
executed (the execution status of this line is deduced): const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator end = persistent.indexes.constEnd();
-
614 -
615 const bool sameParent = (srcParent == destinationParent);
executed (the execution status of this line is deduced): const bool sameParent = (srcParent == destinationParent);
-
616 const bool movingUp = (srcFirst > destinationChild);
executed (the execution status of this line is deduced): const bool movingUp = (srcFirst > destinationChild);
-
617 -
618 for ( it = begin; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:2617
yes
Evaluation Count:64
64-2617
619 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
620 const QModelIndex &index = data->index;
executed (the execution status of this line is deduced): const QModelIndex &index = data->index;
-
621 const QModelIndex &parent = index.parent();
executed (the execution status of this line is deduced): const QModelIndex &parent = index.parent();
-
622 const bool isSourceIndex = (parent == srcParent);
executed (the execution status of this line is deduced): const bool isSourceIndex = (parent == srcParent);
-
623 const bool isDestinationIndex = (parent == destinationParent);
executed (the execution status of this line is deduced): const bool isDestinationIndex = (parent == destinationParent);
-
624 -
625 int childPosition;
executed (the execution status of this line is deduced): int childPosition;
-
626 if (orientation == Qt::Vertical)
partially evaluated: orientation == Qt::Vertical
TRUEFALSE
yes
Evaluation Count:2617
no
Evaluation Count:0
0-2617
627 childPosition = index.row();
executed: childPosition = index.row();
Execution Count:2617
2617
628 else -
629 childPosition = index.column();
never executed: childPosition = index.column();
0
630 -
631 if (!index.isValid() || !(isSourceIndex || isDestinationIndex ) )
partially evaluated: !index.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2617
evaluated: isSourceIndex
TRUEFALSE
yes
Evaluation Count:1312
yes
Evaluation Count:1305
evaluated: isDestinationIndex
TRUEFALSE
yes
Evaluation Count:823
yes
Evaluation Count:482
0-2617
632 continue;
executed: continue;
Execution Count:482
482
633 -
634 if (!sameParent && isDestinationIndex) {
evaluated: !sameParent
TRUEFALSE
yes
Evaluation Count:1655
yes
Evaluation Count:480
evaluated: isDestinationIndex
TRUEFALSE
yes
Evaluation Count:823
yes
Evaluation Count:832
480-1655
635 if (childPosition >= destinationChild)
evaluated: childPosition >= destinationChild
TRUEFALSE
yes
Evaluation Count:376
yes
Evaluation Count:447
376-447
636 persistent_moved_in_destination.append(data);
executed: persistent_moved_in_destination.append(data);
Execution Count:376
376
637 continue;
executed: continue;
Execution Count:823
823
638 } -
639 -
640 if (sameParent && movingUp && childPosition < destinationChild)
evaluated: sameParent
TRUEFALSE
yes
Evaluation Count:480
yes
Evaluation Count:832
evaluated: movingUp
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:320
evaluated: childPosition < destinationChild
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:132
28-832
641 continue;
executed: continue;
Execution Count:28
28
642 -
643 if (sameParent && !movingUp && childPosition < srcFirst )
evaluated: sameParent
TRUEFALSE
yes
Evaluation Count:452
yes
Evaluation Count:832
evaluated: !movingUp
TRUEFALSE
yes
Evaluation Count:320
yes
Evaluation Count:132
evaluated: childPosition < srcFirst
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:272
48-832
644 continue;
executed: continue;
Execution Count:48
48
645 -
646 if (!sameParent && childPosition < srcFirst)
evaluated: !sameParent
TRUEFALSE
yes
Evaluation Count:832
yes
Evaluation Count:404
evaluated: childPosition < srcFirst
TRUEFALSE
yes
Evaluation Count:386
yes
Evaluation Count:446
386-832
647 continue;
executed: continue;
Execution Count:386
386
648 -
649 if (sameParent && (childPosition > srcLast) && (childPosition >= destinationChild ))
evaluated: sameParent
TRUEFALSE
yes
Evaluation Count:404
yes
Evaluation Count:446
evaluated: (childPosition > srcLast)
TRUEFALSE
yes
Evaluation Count:192
yes
Evaluation Count:212
evaluated: (childPosition >= destinationChild )
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:144
48-446
650 continue;
executed: continue;
Execution Count:48
48
651 -
652 if ((childPosition <= srcLast) && (childPosition >= srcFirst)) {
evaluated: (childPosition <= srcLast)
TRUEFALSE
yes
Evaluation Count:463
yes
Evaluation Count:339
evaluated: (childPosition >= srcFirst)
TRUEFALSE
yes
Evaluation Count:387
yes
Evaluation Count:76
76-463
653 persistent_moved_explicitly.append(data);
executed (the execution status of this line is deduced): persistent_moved_explicitly.append(data);
-
654 } else {
executed: }
Execution Count:387
387
655 persistent_moved_in_source.append(data);
executed (the execution status of this line is deduced): persistent_moved_in_source.append(data);
-
656 }
executed: }
Execution Count:415
415
657 } -
658 persistent.moved.push(persistent_moved_explicitly);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved_explicitly);
-
659 persistent.moved.push(persistent_moved_in_source);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved_in_source);
-
660 persistent.moved.push(persistent_moved_in_destination);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved_in_destination);
-
661}
executed: }
Execution Count:64
64
662 -
663/*! -
664 \internal -
665 -
666 Moves persistent indexes \a indexes by amount \a change. The change will be either a change in row value or a change in -
667 column value depending on the value of \a orientation. The indexes may also be moved to a different parent if \a parent -
668 differs from the existing parent for the index. -
669*/ -
670void QAbstractItemModelPrivate::movePersistentIndexes(QVector<QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation) -
671{ -
672 QVector<QPersistentModelIndexData *>::const_iterator it;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *>::const_iterator it;
-
673 const QVector<QPersistentModelIndexData *>::const_iterator begin = indexes.constBegin();
executed (the execution status of this line is deduced): const QVector<QPersistentModelIndexData *>::const_iterator begin = indexes.constBegin();
-
674 const QVector<QPersistentModelIndexData *>::const_iterator end = indexes.constEnd();
executed (the execution status of this line is deduced): const QVector<QPersistentModelIndexData *>::const_iterator end = indexes.constEnd();
-
675 -
676 for (it = begin; it != end; ++it)
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:1178
yes
Evaluation Count:192
192-1178
677 { -
678 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
679 -
680 int row = data->index.row();
executed (the execution status of this line is deduced): int row = data->index.row();
-
681 int column = data->index.column();
executed (the execution status of this line is deduced): int column = data->index.column();
-
682 -
683 if (Qt::Vertical == orientation)
partially evaluated: Qt::Vertical == orientation
TRUEFALSE
yes
Evaluation Count:1178
no
Evaluation Count:0
0-1178
684 row += change;
executed: row += change;
Execution Count:1178
1178
685 else -
686 column += change;
never executed: column += change;
0
687 -
688 persistent.indexes.erase(persistent.indexes.find(data->index));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(data->index));
-
689 data->index = q_func()->index(row, column, parent);
executed (the execution status of this line is deduced): data->index = q_func()->index(row, column, parent);
-
690 if (data->index.isValid()) {
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:1178
no
Evaluation Count:0
0-1178
691 persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): persistent.insertMultiAtEnd(data->index, data);
-
692 } else {
executed: }
Execution Count:1178
1178
693 qWarning() << "QAbstractItemModel::endMoveRows: Invalid index (" << row << "," << column << ") in model" << q_func();
never executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qabstractitemmodel.cpp", 693, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endMoveRows: Invalid index (" << row << "," << column << ") in model" << q_func();
-
694 }
never executed: }
0
695 } -
696}
executed: }
Execution Count:192
192
697 -
698void QAbstractItemModelPrivate::itemsMoved(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) -
699{ -
700 QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop();
-
701 QVector<QPersistentModelIndexData *> moved_in_source = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> moved_in_source = persistent.moved.pop();
-
702 QVector<QPersistentModelIndexData *> moved_explicitly = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> moved_explicitly = persistent.moved.pop();
-
703 -
704 const bool sameParent = (sourceParent == destinationParent);
executed (the execution status of this line is deduced): const bool sameParent = (sourceParent == destinationParent);
-
705 const bool movingUp = (sourceFirst > destinationChild);
executed (the execution status of this line is deduced): const bool movingUp = (sourceFirst > destinationChild);
-
706 -
707 const int explicit_change = (!sameParent || movingUp) ? destinationChild - sourceFirst : destinationChild - sourceLast - 1 ;
evaluated: !sameParent
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:18
evaluated: movingUp
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:8
8-46
708 const int source_change = (!sameParent || !movingUp) ? -1*(sourceLast - sourceFirst + 1) : sourceLast - sourceFirst + 1 ;
evaluated: !sameParent
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:18
evaluated: !movingUp
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:10
8-46
709 const int destination_change = sourceLast - sourceFirst + 1;
executed (the execution status of this line is deduced): const int destination_change = sourceLast - sourceFirst + 1;
-
710 -
711 movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation);
executed (the execution status of this line is deduced): movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation);
-
712 movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation);
executed (the execution status of this line is deduced): movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation);
-
713 movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation);
executed (the execution status of this line is deduced): movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation);
-
714}
executed: }
Execution Count:64
64
715 -
716void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent, -
717 int first, int last) -
718{ -
719 QVector<QPersistentModelIndexData *> persistent_moved;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved;
-
720 QVector<QPersistentModelIndexData *> persistent_invalidated;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_invalidated;
-
721 // find the persistent indexes that are affected by the change, either by being in the removed subtree -
722 // or by being on the same level and below the removed rows -
723 for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
executed (the execution status of this line is deduced): for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
-
724 it != persistent.indexes.constEnd(); ++it) {
evaluated: it != persistent.indexes.constEnd()
TRUEFALSE
yes
Evaluation Count:2547
yes
Evaluation Count:2024
2024-2547
725 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
726 bool level_changed = false;
executed (the execution status of this line is deduced): bool level_changed = false;
-
727 QModelIndex current = data->index;
executed (the execution status of this line is deduced): QModelIndex current = data->index;
-
728 while (current.isValid()) {
evaluated: current.isValid()
TRUEFALSE
yes
Evaluation Count:2824
yes
Evaluation Count:130
130-2824
729 QModelIndex current_parent = current.parent();
executed (the execution status of this line is deduced): QModelIndex current_parent = current.parent();
-
730 if (current_parent == parent) { // on the same level as the change
evaluated: current_parent == parent
TRUEFALSE
yes
Evaluation Count:2417
yes
Evaluation Count:407
407-2417
731 if (!level_changed && current.row() > last) // below the removed rows
evaluated: !level_changed
TRUEFALSE
yes
Evaluation Count:2367
yes
Evaluation Count:50
evaluated: current.row() > last
TRUEFALSE
yes
Evaluation Count:1075
yes
Evaluation Count:1292
50-2367
732 persistent_moved.append(data);
executed: persistent_moved.append(data);
Execution Count:1075
1075
733 else if (current.row() <= last && current.row() >= first) // in the removed subtree
partially evaluated: current.row() <= last
TRUEFALSE
yes
Evaluation Count:1342
no
Evaluation Count:0
evaluated: current.row() >= first
TRUEFALSE
yes
Evaluation Count:279
yes
Evaluation Count:1063
0-1342
734 persistent_invalidated.append(data);
executed: persistent_invalidated.append(data);
Execution Count:279
279
735 break;
executed: break;
Execution Count:2417
2417
736 } -
737 current = current_parent;
executed (the execution status of this line is deduced): current = current_parent;
-
738 level_changed = true;
executed (the execution status of this line is deduced): level_changed = true;
-
739 }
executed: }
Execution Count:407
407
740 }
executed: }
Execution Count:2547
2547
741 -
742 persistent.moved.push(persistent_moved);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved);
-
743 persistent.invalidated.push(persistent_invalidated);
executed (the execution status of this line is deduced): persistent.invalidated.push(persistent_invalidated);
-
744}
executed: }
Execution Count:2024
2024
745 -
746void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent, -
747 int first, int last) -
748{ -
749 QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
-
750 int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
executed (the execution status of this line is deduced): int count = (last - first) + 1;
-
751 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
-
752 it != persistent_moved.constEnd(); ++it) {
evaluated: it != persistent_moved.constEnd()
TRUEFALSE
yes
Evaluation Count:1075
yes
Evaluation Count:2024
1075-2024
753 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
754 QModelIndex old = data->index;
executed (the execution status of this line is deduced): QModelIndex old = data->index;
-
755 persistent.indexes.erase(persistent.indexes.find(old));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(old));
-
756 data->index = q_func()->index(old.row() - count, old.column(), parent);
executed (the execution status of this line is deduced): data->index = q_func()->index(old.row() - count, old.column(), parent);
-
757 if (data->index.isValid()) {
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:1075
no
Evaluation Count:0
0-1075
758 persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): persistent.insertMultiAtEnd(data->index, data);
-
759 } else {
executed: }
Execution Count:1075
1075
760 qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func();
never executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qabstractitemmodel.cpp", 760, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func();
-
761 }
never executed: }
0
762 } -
763 QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
-
764 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
-
765 it != persistent_invalidated.constEnd(); ++it) {
evaluated: it != persistent_invalidated.constEnd()
TRUEFALSE
yes
Evaluation Count:279
yes
Evaluation Count:2024
279-2024
766 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
767 persistent.indexes.erase(persistent.indexes.find(data->index));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(data->index));
-
768 data->index = QModelIndex();
executed (the execution status of this line is deduced): data->index = QModelIndex();
-
769 data->model = 0;
executed (the execution status of this line is deduced): data->model = 0;
-
770 }
executed: }
Execution Count:279
279
771}
executed: }
Execution Count:2024
2024
772 -
773void QAbstractItemModelPrivate::columnsAboutToBeInserted(const QModelIndex &parent, -
774 int first, int last) -
775{ -
776 Q_Q(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModel * const q = q_func();
-
777 Q_UNUSED(last);
executed (the execution status of this line is deduced): (void)last;;
-
778 QVector<QPersistentModelIndexData *> persistent_moved;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved;
-
779 if (first < q->columnCount(parent)) {
evaluated: first < q->columnCount(parent)
TRUEFALSE
yes
Evaluation Count:335
yes
Evaluation Count:10476
335-10476
780 for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
executed (the execution status of this line is deduced): for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
-
781 it != persistent.indexes.constEnd(); ++it) {
evaluated: it != persistent.indexes.constEnd()
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:335
51-335
782 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
783 const QModelIndex &index = data->index;
executed (the execution status of this line is deduced): const QModelIndex &index = data->index;
-
784 if (index.column() >= first && index.isValid() && index.parent() == parent)
evaluated: index.column() >= first
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:25
partially evaluated: index.isValid()
TRUEFALSE
yes
Evaluation Count:26
no
Evaluation Count:0
evaluated: index.parent() == parent
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:15
0-26
785 persistent_moved.append(data);
executed: persistent_moved.append(data);
Execution Count:11
11
786 }
executed: }
Execution Count:51
51
787 }
executed: }
Execution Count:335
335
788 persistent.moved.push(persistent_moved);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved);
-
789}
executed: }
Execution Count:10811
10811
790 -
791void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent, -
792 int first, int last) -
793{ -
794 QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
-
795 int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
executed (the execution status of this line is deduced): int count = (last - first) + 1;
-
796 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
-
797 it != persistent_moved.constEnd(); ++it) {
evaluated: it != persistent_moved.constEnd()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:10811
11-10811
798 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
799 QModelIndex old = data->index;
executed (the execution status of this line is deduced): QModelIndex old = data->index;
-
800 persistent.indexes.erase(persistent.indexes.find(old));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(old));
-
801 data->index = q_func()->index(old.row(), old.column() + count, parent);
executed (the execution status of this line is deduced): data->index = q_func()->index(old.row(), old.column() + count, parent);
-
802 if (data->index.isValid()) {
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
803 persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): persistent.insertMultiAtEnd(data->index, data);
-
804 } else {
executed: }
Execution Count:11
11
805 qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func();
never executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qabstractitemmodel.cpp", 805, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func();
-
806 }
never executed: }
0
807 } -
808}
executed: }
Execution Count:10811
10811
809 -
810void QAbstractItemModelPrivate::columnsAboutToBeRemoved(const QModelIndex &parent, -
811 int first, int last) -
812{ -
813 QVector<QPersistentModelIndexData *> persistent_moved;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved;
-
814 QVector<QPersistentModelIndexData *> persistent_invalidated;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_invalidated;
-
815 // find the persistent indexes that are affected by the change, either by being in the removed subtree -
816 // or by being on the same level and to the right of the removed columns -
817 for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
executed (the execution status of this line is deduced): for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin();
-
818 it != persistent.indexes.constEnd(); ++it) {
evaluated: it != persistent.indexes.constEnd()
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:204
96-204
819 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
820 bool level_changed = false;
executed (the execution status of this line is deduced): bool level_changed = false;
-
821 QModelIndex current = data->index;
executed (the execution status of this line is deduced): QModelIndex current = data->index;
-
822 while (current.isValid()) {
evaluated: current.isValid()
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:35
35-97
823 QModelIndex current_parent = current.parent();
executed (the execution status of this line is deduced): QModelIndex current_parent = current.parent();
-
824 if (current_parent == parent) { // on the same level as the change
evaluated: current_parent == parent
TRUEFALSE
yes
Evaluation Count:61
yes
Evaluation Count:36
36-61
825 if (!level_changed && current.column() > last) // right of the removed columns
evaluated: !level_changed
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:1
evaluated: current.column() > last
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:45
1-60
826 persistent_moved.append(data);
executed: persistent_moved.append(data);
Execution Count:15
15
827 else if (current.column() <= last && current.column() >= first) // in the removed subtree
partially evaluated: current.column() <= last
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
evaluated: current.column() >= first
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:22
0-46
828 persistent_invalidated.append(data);
executed: persistent_invalidated.append(data);
Execution Count:24
24
829 break;
executed: break;
Execution Count:61
61
830 } -
831 current = current_parent;
executed (the execution status of this line is deduced): current = current_parent;
-
832 level_changed = true;
executed (the execution status of this line is deduced): level_changed = true;
-
833 }
executed: }
Execution Count:36
36
834 }
executed: }
Execution Count:96
96
835 -
836 persistent.moved.push(persistent_moved);
executed (the execution status of this line is deduced): persistent.moved.push(persistent_moved);
-
837 persistent.invalidated.push(persistent_invalidated);
executed (the execution status of this line is deduced): persistent.invalidated.push(persistent_invalidated);
-
838 -
839}
executed: }
Execution Count:204
204
840 -
841void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, -
842 int first, int last) -
843{ -
844 QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop();
-
845 int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
executed (the execution status of this line is deduced): int count = (last - first) + 1;
-
846 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin();
-
847 it != persistent_moved.constEnd(); ++it) {
evaluated: it != persistent_moved.constEnd()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:204
15-204
848 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
849 QModelIndex old = data->index;
executed (the execution status of this line is deduced): QModelIndex old = data->index;
-
850 persistent.indexes.erase(persistent.indexes.find(old));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(old));
-
851 data->index = q_func()->index(old.row(), old.column() - count, parent);
executed (the execution status of this line is deduced): data->index = q_func()->index(old.row(), old.column() - count, parent);
-
852 if (data->index.isValid()) {
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:15
no
Evaluation Count:0
0-15
853 persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): persistent.insertMultiAtEnd(data->index, data);
-
854 } else {
executed: }
Execution Count:15
15
855 qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func();
never executed (the execution status of this line is deduced): QMessageLogger("itemmodels/qabstractitemmodel.cpp", 855, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func();
-
856 }
never executed: }
0
857 } -
858 QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
-
859 for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin();
-
860 it != persistent_invalidated.constEnd(); ++it) {
evaluated: it != persistent_invalidated.constEnd()
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:204
24-204
861 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
862 persistent.indexes.erase(persistent.indexes.find(data->index));
executed (the execution status of this line is deduced): persistent.indexes.erase(persistent.indexes.find(data->index));
-
863 data->index = QModelIndex();
executed (the execution status of this line is deduced): data->index = QModelIndex();
-
864 data->model = 0;
executed (the execution status of this line is deduced): data->model = 0;
-
865 }
executed: }
Execution Count:24
24
866}
executed: }
Execution Count:204
204
867 -
868/*! -
869 \class QModelIndex -
870 \inmodule QtCore -
871 -
872 \brief The QModelIndex class is used to locate data in a data model. -
873 -
874 \ingroup model-view -
875 -
876 -
877 This class is used as an index into item models derived from -
878 QAbstractItemModel. The index is used by item views, delegates, and -
879 selection models to locate an item in the model. -
880 -
881 New QModelIndex objects are created by the model using the -
882 QAbstractItemModel::createIndex() function. An \e invalid model index can -
883 be constructed with the QModelIndex constructor. Invalid indexes are often -
884 used as parent indexes when referring to top-level items in a model. -
885 -
886 Model indexes refer to items in models, and contain all the information -
887 required to specify their locations in those models. Each index is located -
888 in a given row and column, and may have a parent index; use row(), -
889 column(), and parent() to obtain this information. Each top-level item in a -
890 model is represented by a model index that does not have a parent index - -
891 in this case, parent() will return an invalid model index, equivalent to an -
892 index constructed with the zero argument form of the QModelIndex() -
893 constructor. -
894 -
895 To obtain a model index that refers to an existing item in a model, call -
896 QAbstractItemModel::index() with the required row and column values, and -
897 the model index of the parent. When referring to top-level items in a -
898 model, supply QModelIndex() as the parent index. -
899 -
900 The model() function returns the model that the index references as a -
901 QAbstractItemModel. The child() function is used to examine items held -
902 under the index in the model. The sibling() function allows you to traverse -
903 items in the model on the same level as the index. -
904 -
905 \note Model indexes should be used immediately and then discarded. You -
906 should not rely on indexes to remain valid after calling model functions -
907 that change the structure of the model or delete items. If you need to -
908 keep a model index over time use a QPersistentModelIndex. -
909 -
910 \sa {Model/View Programming}, QPersistentModelIndex, QAbstractItemModel -
911*/ -
912 -
913/*! -
914 \fn QModelIndex::QModelIndex() -
915 -
916 Creates a new empty model index. This type of model index is used to -
917 indicate that the position in the model is invalid. -
918 -
919 \sa isValid(), QAbstractItemModel -
920*/ -
921 -
922/*! -
923 \fn QModelIndex::QModelIndex(int row, int column, void *data, const QAbstractItemModel *model) -
924 -
925 \internal -
926 -
927 Creates a new model index at the given \a row and \a column, -
928 pointing to some \a data. -
929*/ -
930 -
931/*! -
932 \fn int QModelIndex::row() const -
933 -
934 Returns the row this model index refers to. -
935*/ -
936 -
937 -
938/*! -
939 \fn int QModelIndex::column() const -
940 -
941 Returns the column this model index refers to. -
942*/ -
943 -
944 -
945/*! -
946 \fn void *QModelIndex::internalPointer() const -
947 -
948 Returns a \c{void} \c{*} pointer used by the model to associate -
949 the index with the internal data structure. -
950 -
951 \sa QAbstractItemModel::createIndex() -
952*/ -
953 -
954/*! -
955 \fn void *QModelIndex::internalId() const -
956 -
957 Returns a \c{qint64} used by the model to associate -
958 the index with the internal data structure. -
959 -
960 \sa QAbstractItemModel::createIndex() -
961*/ -
962 -
963/*! -
964 \fn bool QModelIndex::isValid() const -
965 -
966 Returns true if this model index is valid; otherwise returns false. -
967 -
968 A valid index belongs to a model, and has non-negative row and column -
969 numbers. -
970 -
971 \sa model(), row(), column() -
972*/ -
973 -
974/*! -
975 \fn const QAbstractItemModel *QModelIndex::model() const -
976 -
977 Returns a pointer to the model containing the item that this index -
978 refers to. -
979 -
980 A const pointer to the model is returned because calls to non-const -
981 functions of the model might invalidate the model index and possibly -
982 crash your application. -
983*/ -
984 -
985/*! -
986 \fn QModelIndex QModelIndex::sibling(int row, int column) const -
987 -
988 Returns the sibling at \a row and \a column. If there is no sibling at this -
989 position, an invalid QModelIndex is returned. -
990 -
991 \sa parent(), child() -
992*/ -
993 -
994/*! -
995 \fn QModelIndex QModelIndex::child(int row, int column) const -
996 -
997 Returns the child of the model index that is stored in the given \a row and -
998 \a column. -
999 -
1000 \note This function does not work for an invalid model index which is often -
1001 used as the root index. -
1002 -
1003 \sa parent(), sibling() -
1004*/ -
1005 -
1006/*! -
1007 \fn QVariant QModelIndex::data(int role) const -
1008 -
1009 Returns the data for the given \a role for the item referred to by the -
1010 index. -
1011*/ -
1012 -
1013/*! -
1014 \fn Qt::ItemFlags QModelIndex::flags() const -
1015 \since 4.2 -
1016 -
1017 Returns the flags for the item referred to by the index. -
1018*/ -
1019 -
1020/*! -
1021 \fn bool QModelIndex::operator==(const QModelIndex &other) const -
1022 -
1023 Returns true if this model index refers to the same location as the -
1024 \a other model index; otherwise returns false. -
1025 -
1026 All values in the model index are used when comparing with another model -
1027 index. -
1028*/ -
1029 -
1030 -
1031/*! -
1032 \fn bool QModelIndex::operator!=(const QModelIndex &other) const -
1033 -
1034 Returns true if this model index does not refer to the same location as -
1035 the \a other model index; otherwise returns false. -
1036*/ -
1037 -
1038 -
1039/*! -
1040 \fn QModelIndex QModelIndex::parent() const -
1041 -
1042 Returns the parent of the model index, or QModelIndex() if it has no -
1043 parent. -
1044 -
1045 \sa child(), sibling(), model() -
1046*/ -
1047 -
1048/*! -
1049 \class QAbstractItemModel -
1050 \inmodule QtCore -
1051 -
1052 \brief The QAbstractItemModel class provides the abstract interface for -
1053 item model classes. -
1054 -
1055 \ingroup model-view -
1056 -
1057 -
1058 The QAbstractItemModel class defines the standard interface that item -
1059 models must use to be able to interoperate with other components in the -
1060 model/view architecture. It is not supposed to be instantiated directly. -
1061 Instead, you should subclass it to create new models. -
1062 -
1063 The QAbstractItemModel class is one of the \l{Model/View Classes} -
1064 and is part of Qt's \l{Model/View Programming}{model/view framework}. It -
1065 can be used as the underlying data model for the item view elements in -
1066 QML or the item view classes in the Qt Widgets module. -
1067 -
1068 If you need a model to use with an item view such as QML's List View -
1069 element or the C++ widgets QListView or QTableView, you should consider -
1070 subclassing QAbstractListModel or QAbstractTableModel instead of this class. -
1071 -
1072 The underlying data model is exposed to views and delegates as a hierarchy -
1073 of tables. If you do not make use of the hierarchy, then the model is a -
1074 simple table of rows and columns. Each item has a unique index specified by -
1075 a QModelIndex. -
1076 -
1077 \image modelindex-no-parent.png -
1078 -
1079 Every item of data that can be accessed via a model has an associated model -
1080 index. You can obtain this model index using the index() function. Each -
1081 index may have a sibling() index; child items have a parent() index. -
1082 -
1083 Each item has a number of data elements associated with it and they can be -
1084 retrieved by specifying a role (see \l Qt::ItemDataRole) to the model's -
1085 data() function. Data for all available roles can be obtained at the same -
1086 time using the itemData() function. -
1087 -
1088 Data for each role is set using a particular \l Qt::ItemDataRole. Data for -
1089 individual roles are set individually with setData(), or they can be set -
1090 for all roles with setItemData(). -
1091 -
1092 Items can be queried with flags() (see \l Qt::ItemFlag) to see if they can -
1093 be selected, dragged, or manipulated in other ways. -
1094 -
1095 If an item has child objects, hasChildren() returns true for the -
1096 corresponding index. -
1097 -
1098 The model has a rowCount() and a columnCount() for each level of the -
1099 hierarchy. Rows and columns can be inserted and removed with insertRows(), -
1100 insertColumns(), removeRows(), and removeColumns(). -
1101 -
1102 The model emits signals to indicate changes. For example, dataChanged() is -
1103 emitted whenever items of data made available by the model are changed. -
1104 Changes to the headers supplied by the model cause headerDataChanged() to -
1105 be emitted. If the structure of the underlying data changes, the model can -
1106 emit layoutChanged() to indicate to any attached views that they should -
1107 redisplay any items shown, taking the new structure into account. -
1108 -
1109 The items available through the model can be searched for particular data -
1110 using the match() function. -
1111 -
1112 To sort the model, you can use sort(). -
1113 -
1114 -
1115 \section1 Subclassing -
1116 -
1117 \note Some general guidelines for subclassing models are available in the -
1118 \l{Model Subclassing Reference}. -
1119 -
1120 When subclassing QAbstractItemModel, at the very least you must implement -
1121 index(), parent(), rowCount(), columnCount(), and data(). These functions -
1122 are used in all read-only models, and form the basis of editable models. -
1123 -
1124 You can also reimplement hasChildren() to provide special behavior for -
1125 models where the implementation of rowCount() is expensive. This makes it -
1126 possible for models to restrict the amount of data requested by views, and -
1127 can be used as a way to implement lazy population of model data. -
1128 -
1129 To enable editing in your model, you must also implement setData(), and -
1130 reimplement flags() to ensure that \c ItemIsEditable is returned. You can -
1131 also reimplement headerData() and setHeaderData() to control the way the -
1132 headers for your model are presented. -
1133 -
1134 The dataChanged() and headerDataChanged() signals must be emitted -
1135 explicitly when reimplementing the setData() and setHeaderData() functions, -
1136 respectively. -
1137 -
1138 Custom models need to create model indexes for other components to use. To -
1139 do this, call createIndex() with suitable row and column numbers for the -
1140 item, and an identifier for it, either as a pointer or as an integer value. -
1141 The combination of these values must be unique for each item. Custom models -
1142 typically use these unique identifiers in other reimplemented functions to -
1143 retrieve item data and access information about the item's parents and -
1144 children. See the \l{Simple Tree Model Example} for more information about -
1145 unique identifiers. -
1146 -
1147 It is not necessary to support every role defined in Qt::ItemDataRole. -
1148 Depending on the type of data contained within a model, it may only be -
1149 useful to implement the data() function to return valid information for -
1150 some of the more common roles. Most models provide at least a textual -
1151 representation of item data for the Qt::DisplayRole, and well-behaved -
1152 models should also provide valid information for the Qt::ToolTipRole and -
1153 Qt::WhatsThisRole. Supporting these roles enables models to be used with -
1154 standard Qt views. However, for some models that handle highly-specialized -
1155 data, it may be appropriate to provide data only for user-defined roles. -
1156 -
1157 Models that provide interfaces to resizable data structures can provide -
1158 implementations of insertRows(), removeRows(), insertColumns(),and -
1159 removeColumns(). When implementing these functions, it is important to -
1160 notify any connected views about changes to the model's dimensions both -
1161 \e before and \e after they occur: -
1162 -
1163 \list -
1164 \li An insertRows() implementation must call beginInsertRows() \e before -
1165 inserting new rows into the data structure, and endInsertRows() -
1166 \e{immediately afterwards}. -
1167 \li An insertColumns() implementation must call beginInsertColumns() -
1168 \e before inserting new columns into the data structure, and -
1169 endInsertColumns() \e{immediately afterwards}. -
1170 \li A removeRows() implementation must call beginRemoveRows() \e before -
1171 the rows are removed from the data structure, and endRemoveRows() -
1172 \e{immediately afterwards}. -
1173 \li A removeColumns() implementation must call beginRemoveColumns() -
1174 \e before the columns are removed from the data structure, and -
1175 endRemoveColumns() \e{immediately afterwards}. -
1176 \endlist -
1177 -
1178 The \e private signals that these functions emit give attached components -
1179 the chance to take action before any data becomes unavailable. The -
1180 encapsulation of the insert and remove operations with these begin and end -
1181 functions also enables the model to manage \l{QPersistentModelIndex} -
1182 {persistent model indexes} correctly. \b{If you want selections to be -
1183 handled properly, you must ensure that you call these functions.} If you -
1184 insert or remove an item with children, you do not need to call these -
1185 functions for the child items. In other words, the parent item will take -
1186 care of its child items. -
1187 -
1188 To create models that populate incrementally, you can reimplement -
1189 fetchMore() and canFetchMore(). If the reimplementation of fetchMore() adds -
1190 rows to the model, \l{QAbstractItemModel::}{beginInsertRows()} and -
1191 \l{QAbstractItemModel::}{endInsertRows()} must be called. -
1192 -
1193 \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex, -
1194 QAbstractItemView, {Using drag and drop with item views}, -
1195 {Simple DOM Model Example}, {Simple Tree Model Example}, -
1196 {Editable Tree Model Example}, {Fetch More Example} -
1197*/ -
1198 -
1199/*! -
1200 \fn QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const = 0 -
1201 -
1202 Returns the index of the item in the model specified by the given \a row, -
1203 \a column and \a parent index. -
1204 -
1205 When reimplementing this function in a subclass, call createIndex() to -
1206 generate model indexes that other components can use to refer to items in -
1207 your model. -
1208 -
1209 \sa createIndex() -
1210*/ -
1211 -
1212/*! -
1213 \fn bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent) -
1214 -
1215 Inserts a single column before the given \a column in the child items of -
1216 the \a parent specified. -
1217 -
1218 Returns true if the column is inserted; otherwise returns false. -
1219 -
1220 \sa insertColumns(), insertRow(), removeColumn() -
1221*/ -
1222 -
1223/*! -
1224 \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent) -
1225 -
1226 Inserts a single row before the given \a row in the child items of the -
1227 \a parent specified. -
1228 -
1229 \note This function calls the virtual method insertRows. -
1230 -
1231 Returns true if the row is inserted; otherwise returns false. -
1232 -
1233 \sa insertRows(), insertColumn(), removeRow() -
1234*/ -
1235 -
1236/*! -
1237 \fn QObject *QAbstractItemModel::parent() const -
1238 \internal -
1239*/ -
1240 -
1241/*! -
1242 \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 -
1243 -
1244 Returns the parent of the model item with the given \a index. If the item -
1245 has no parent, an invalid QModelIndex is returned. -
1246 -
1247 A common convention used in models that expose tree data structures is that -
1248 only items in the first column have children. For that case, when -
1249 reimplementing this function in a subclass the column of the returned -
1250 QModelIndex would be 0. -
1251 -
1252 When reimplementing this function in a subclass, be careful to avoid -
1253 calling QModelIndex member functions, such as QModelIndex::parent(), since -
1254 indexes belonging to your model will simply call your implementation, -
1255 leading to infinite recursion. -
1256 -
1257 \sa createIndex() -
1258*/ -
1259 -
1260/*! -
1261 \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent) -
1262 -
1263 Removes the given \a column from the child items of the \a parent -
1264 specified. -
1265 -
1266 Returns true if the column is removed; otherwise returns false. -
1267 -
1268 \sa removeColumns(), removeRow(), insertColumn() -
1269*/ -
1270 -
1271/*! -
1272 \fn bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent) -
1273 -
1274 Removes the given \a row from the child items of the \a parent specified. -
1275 -
1276 Returns true if the row is removed; otherwise returns false. -
1277 -
1278 This is a convenience function that calls removeRows(). The -
1279 QAbstractItemModel implementation of removeRows() does nothing. -
1280 -
1281 \sa removeRows(), removeColumn(), insertRow() -
1282*/ -
1283 -
1284/*! -
1285 \fn bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild) -
1286 -
1287 On models that support this, moves \a sourceColumn from \a sourceParent to \a destinationChild under -
1288 \a destinationParent. -
1289 -
1290 Returns true if the columns were successfully moved; otherwise returns -
1291 false. -
1292 -
1293 \sa moveRows(), moveColumn() -
1294*/ -
1295 -
1296/*! -
1297 \fn bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild) -
1298 -
1299 On models that support this, moves \a sourceColumn from \a sourceParent to \a destinationChild under -
1300 \a destinationParent. -
1301 -
1302 Returns true if the columns were successfully moved; otherwise returns -
1303 false. -
1304 -
1305 \sa moveColumns(), moveRow() -
1306*/ -
1307 -
1308 -
1309/*! -
1310 \fn void QAbstractItemModel::headerDataChanged(Qt::Orientation orientation, int first, int last) -
1311 -
1312 This signal is emitted whenever a header is changed. The \a orientation -
1313 indicates whether the horizontal or vertical header has changed. The -
1314 sections in the header from the \a first to the \a last need to be updated. -
1315 -
1316 When reimplementing the setHeaderData() function, this signal must be -
1317 emitted explicitly. -
1318 -
1319 If you are changing the number of columns or rows you do not need to emit -
1320 this signal, but use the begin/end functions (refer to the section on -
1321 subclassing in the QAbstractItemModel class description for details). -
1322 -
1323 \sa headerData(), setHeaderData(), dataChanged() -
1324*/ -
1325 -
1326 -
1327/*! -
1328 \enum QAbstractItemModel::LayoutChangeHint -
1329 -
1330 This enum describes the way the model changes layout. -
1331 -
1332 \value NoLayoutChangeHint No hint is available. -
1333 \value VerticalSortHint Rows are being sorted. -
1334 \value HorizontalSortHint Columns are being sorted. -
1335 -
1336 Note that VerticalSortHint and HorizontalSortHint carry the meaning that -
1337 items are being moved within the same parent, not moved to a different -
1338 parent in the model, and not filtered out or in. -
1339*/ -
1340 -
1341/*! -
1342 \fn void QAbstractItemModel::layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) -
1343 \since 5.0 -
1344 -
1345 This signal is emitted just before the layout of a model is changed. -
1346 Components connected to this signal use it to adapt to changes in the -
1347 model's layout. -
1348 -
1349 Subclasses should update any persistent model indexes after emitting -
1350 layoutAboutToBeChanged(). -
1351 -
1352 The optional \a parents parameter is used to give a more specific notification -
1353 about what parts of the layout of the model are changing. An empty list indicates -
1354 a change to the layout of the entire model. The order of elements in the \a parents list is not significant. The optional \a hint parameter is used -
1355 to give a hint about what is happening while the model is relayouting. -
1356 -
1357 \sa layoutChanged(), changePersistentIndex() -
1358*/ -
1359 -
1360/*! -
1361 \fn void QAbstractItemModel::layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) -
1362 \since 5.0 -
1363 -
1364 This signal is emitted whenever the layout of items exposed by the model -
1365 has changed; for example, when the model has been sorted. When this signal -
1366 is received by a view, it should update the layout of items to reflect this -
1367 change. -
1368 -
1369 When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you -
1370 emit layoutAboutToBeChanged() before changing the order of items or -
1371 altering the structure of the data you expose to views, and emit -
1372 layoutChanged() after changing the layout. -
1373 -
1374 The optional \a parents parameter is used to give a more specific notification -
1375 about what parts of the layout of the model are changing. An empty list indicates -
1376 a change to the layout of the entire model. The order of elements in the \a parents list is not significant. The optional \a hint parameter is used -
1377 to give a hint about what is happening while the model is relayouting. -
1378 -
1379 Subclasses should update any persistent model indexes before emitting -
1380 layoutChanged(). In other words, when the structure changes: -
1381 -
1382 \list -
1383 \li emit layoutAboutToBeChanged -
1384 \li Remember the QModelIndex that will change -
1385 \li Update your internal data -
1386 \li Call changePersistentIndex() -
1387 \li emit layoutChanged -
1388 \endlist -
1389 -
1390 \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), -
1391 changePersistentIndex() -
1392*/ -
1393 -
1394/*! -
1395 Constructs an abstract item model with the given \a parent. -
1396*/ -
1397QAbstractItemModel::QAbstractItemModel(QObject *parent) -
1398 : QObject(*new QAbstractItemModelPrivate, parent) -
1399{ -
1400}
executed: }
Execution Count:1434
1434
1401 -
1402/*! -
1403 \internal -
1404*/ -
1405QAbstractItemModel::QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent) -
1406 : QObject(dd, parent) -
1407{ -
1408}
executed: }
Execution Count:3206
3206
1409 -
1410/*! -
1411 Destroys the abstract item model. -
1412*/ -
1413QAbstractItemModel::~QAbstractItemModel() -
1414{ -
1415 d_func()->invalidatePersistentIndexes();
executed (the execution status of this line is deduced): d_func()->invalidatePersistentIndexes();
-
1416}
executed: }
Execution Count:4475
4475
1417 -
1418 -
1419/*! -
1420 \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const -
1421 -
1422 Returns the number of rows under the given \a parent. When the parent is -
1423 valid it means that rowCount is returning the number of children of parent. -
1424 -
1425 \note When implementing a table based model, rowCount() should return 0 -
1426 when the parent is valid. -
1427 -
1428 \sa columnCount() -
1429*/ -
1430 -
1431/*! -
1432 \fn int QAbstractItemModel::columnCount(const QModelIndex &parent) const -
1433 -
1434 Returns the number of columns for the children of the given \a parent. -
1435 -
1436 In most subclasses, the number of columns is independent of the \a parent. -
1437 -
1438 For example: -
1439 -
1440 \snippet ../widgets/itemviews/simpledommodel/dommodel.cpp 2 -
1441 -
1442 \note When implementing a table based model, columnCount() should return 0 -
1443 when the parent is valid. -
1444 -
1445 \sa rowCount() -
1446*/ -
1447 -
1448/*! -
1449 \fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) -
1450 -
1451 This signal is emitted whenever the data in an existing item changes. -
1452 -
1453 If the items are of the same parent, the affected ones are those between -
1454 \a topLeft and \a bottomRight inclusive. If the items do not have the same -
1455 parent, the behavior is undefined. -
1456 -
1457 When reimplementing the setData() function, this signal must be emitted -
1458 explicitly. -
1459 -
1460 The optional \a roles argument can be used to specify which data roles have actually -
1461 been modified. An empty vector in the roles argument means that all roles should be -
1462 considered modified. The order of elements in the roles argument does not have any -
1463 relevance. -
1464 -
1465 \sa headerDataChanged(), setData(), layoutChanged() -
1466*/ -
1467 -
1468/*! -
1469 \fn void QAbstractItemModel::rowsInserted(const QModelIndex &parent, int start, int end) -
1470 -
1471 This signal is emitted after rows have been inserted into the -
1472 model. The new items are those between \a start and \a end -
1473 inclusive, under the given \a parent item. -
1474 -
1475 \note Components connected to this signal use it to adapt to changes in the -
1476 model's dimensions. It can only be emitted by the QAbstractItemModel -
1477 implementation, and cannot be explicitly emitted in subclass code. -
1478 -
1479 \sa insertRows(), beginInsertRows() -
1480*/ -
1481 -
1482/*! -
1483 \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) -
1484 -
1485 This signal is emitted just before rows are inserted into the model. The -
1486 new items will be positioned between \a start and \a end inclusive, under -
1487 the given \a parent item. -
1488 -
1489 \note Components connected to this signal use it to adapt to changes -
1490 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1491 implementation, and cannot be explicitly emitted in subclass code. -
1492 -
1493 \sa insertRows(), beginInsertRows() -
1494*/ -
1495 -
1496/*! -
1497 \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int start, int end) -
1498 -
1499 This signal is emitted after rows have been removed from the model. The -
1500 removed items are those between \a start and \a end inclusive, under the -
1501 given \a parent item. -
1502 -
1503 \note Components connected to this signal use it to adapt to changes -
1504 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1505 implementation, and cannot be explicitly emitted in subclass code. -
1506 -
1507 \sa removeRows(), beginRemoveRows() -
1508*/ -
1509 -
1510/*! -
1511 \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -
1512 -
1513 This signal is emitted just before rows are removed from the model. The -
1514 items that will be removed are those between \a start and \a end inclusive, -
1515 under the given \a parent item. -
1516 -
1517 \note Components connected to this signal use it to adapt to changes -
1518 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1519 implementation, and cannot be explicitly emitted in subclass code. -
1520 -
1521 \sa removeRows(), beginRemoveRows() -
1522*/ -
1523 -
1524/*! -
1525 \fn void QAbstractItemModel::rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) -
1526 \since 4.6 -
1527 -
1528 This signal is emitted after rows have been moved within the -
1529 model. The items between \a sourceStart and \a sourceEnd -
1530 inclusive, under the given \a sourceParent item have been moved to \a destinationParent -
1531 starting at the row \a destinationRow. -
1532 -
1533 \b{Note:} Components connected to this signal use it to adapt to changes -
1534 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1535 implementation, and cannot be explicitly emitted in subclass code. -
1536 -
1537 \sa beginMoveRows() -
1538*/ -
1539 -
1540/*! -
1541 \fn void QAbstractItemModel::rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) -
1542 \since 4.6 -
1543 -
1544 This signal is emitted just before rows are moved within the -
1545 model. The items that will be moved are those between \a sourceStart and \a sourceEnd -
1546 inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent -
1547 starting at the row \a destinationRow. -
1548 -
1549 \b{Note:} Components connected to this signal use it to adapt to changes -
1550 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1551 implementation, and cannot be explicitly emitted in subclass code. -
1552 -
1553 \sa beginMoveRows() -
1554*/ -
1555 -
1556/*! -
1557 \fn void QAbstractItemModel::columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) -
1558 \since 4.6 -
1559 -
1560 This signal is emitted after columns have been moved within the -
1561 model. The items between \a sourceStart and \a sourceEnd -
1562 inclusive, under the given \a sourceParent item have been moved to \a destinationParent -
1563 starting at the column \a destinationColumn. -
1564 -
1565 \b{Note:} Components connected to this signal use it to adapt to changes -
1566 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1567 implementation, and cannot be explicitly emitted in subclass code. -
1568 -
1569 \sa beginMoveRows() -
1570*/ -
1571 -
1572/*! -
1573 \fn void QAbstractItemModel::columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) -
1574 \since 4.6 -
1575 -
1576 This signal is emitted just before columns are moved within the -
1577 model. The items that will be moved are those between \a sourceStart and \a sourceEnd -
1578 inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent -
1579 starting at the column \a destinationColumn. -
1580 -
1581 \b{Note:} Components connected to this signal use it to adapt to changes -
1582 in the model's dimensions. It can only be emitted by the QAbstractItemModel -
1583 implementation, and cannot be explicitly emitted in subclass code. -
1584 -
1585 \sa beginMoveRows() -
1586*/ -
1587 -
1588/*! -
1589 \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int start, int end) -
1590 -
1591 This signal is emitted after columns have been inserted into the model. The -
1592 new items are those between \a start and \a end inclusive, under the given -
1593 \a parent item. -
1594 -
1595 \note Components connected to this signal use it to adapt to changes in the -
1596 model's dimensions. It can only be emitted by the QAbstractItemModel -
1597 implementation, and cannot be explicitly emitted in subclass code. -
1598 -
1599 \sa insertColumns(), beginInsertColumns() -
1600*/ -
1601 -
1602/*! -
1603 \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int start, int end) -
1604 -
1605 This signal is emitted just before columns are inserted into the model. The -
1606 new items will be positioned between \a start and \a end inclusive, under -
1607 the given \a parent item. -
1608 -
1609 \note Components connected to this signal use it to adapt to changes in the -
1610 model's dimensions. It can only be emitted by the QAbstractItemModel -
1611 implementation, and cannot be explicitly emitted in subclass code. -
1612 -
1613 \sa insertColumns(), beginInsertColumns() -
1614*/ -
1615 -
1616/*! -
1617 \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int start, int end) -
1618 -
1619 This signal is emitted after columns have been removed from the model. -
1620 The removed items are those between \a start and \a end inclusive, -
1621 under the given \a parent item. -
1622 -
1623 \note Components connected to this signal use it to adapt to changes in -
1624 the model's dimensions. It can only be emitted by the QAbstractItemModel -
1625 implementation, and cannot be explicitly emitted in subclass code. -
1626 -
1627 \sa removeColumns(), beginRemoveColumns() -
1628*/ -
1629 -
1630/*! -
1631 \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) -
1632 -
1633 This signal is emitted just before columns are removed from the model. The -
1634 items to be removed are those between \a start and \a end inclusive, under -
1635 the given \a parent item. -
1636 -
1637 \note Components connected to this signal use it to adapt to changes in the -
1638 model's dimensions. It can only be emitted by the QAbstractItemModel -
1639 implementation, and cannot be explicitly emitted in subclass code. -
1640 -
1641 \sa removeColumns(), beginRemoveColumns() -
1642*/ -
1643 -
1644/*! -
1645 Returns true if the model returns a valid QModelIndex for \a row and -
1646 \a column with \a parent, otherwise returns false. -
1647*/ -
1648bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const -
1649{ -
1650 if (row < 0 || column < 0)
evaluated: row < 0
TRUEFALSE
yes
Evaluation Count:896
yes
Evaluation Count:174055
evaluated: column < 0
TRUEFALSE
yes
Evaluation Count:1331
yes
Evaluation Count:172724
896-174055
1651 return false;
executed: return false;
Execution Count:2227
2227
1652 return row < rowCount(parent) && column < columnCount(parent);
executed: return row < rowCount(parent) && column < columnCount(parent);
Execution Count:172724
172724
1653} -
1654 -
1655 -
1656/*! -
1657 Returns true if \a parent has any children; otherwise returns false. -
1658 -
1659 Use rowCount() on the parent to find out the number of children. -
1660 -
1661 \sa parent(), index() -
1662*/ -
1663bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const -
1664{ -
1665 return (rowCount(parent) > 0) && (columnCount(parent) > 0);
executed: return (rowCount(parent) > 0) && (columnCount(parent) > 0);
Execution Count:2129
2129
1666} -
1667 -
1668/*! -
1669 \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const -
1670 -
1671 Returns the sibling at \a row and \a column for the item at \a index, or an -
1672 invalid QModelIndex if there is no sibling at that location. -
1673 -
1674 sibling() is just a convenience function that finds the item's parent, and -
1675 uses it to retrieve the index of the child item in the specified \a row and -
1676 \a column. -
1677 -
1678 This method can optionally be overridden for implementation-specific optimization. -
1679 -
1680 \sa index(), QModelIndex::row(), QModelIndex::column() -
1681*/ -
1682QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &idx) const -
1683{ -
1684 return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx));
executed: return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx));
Execution Count:14101
14101
1685} -
1686 -
1687 -
1688/*! -
1689 Returns a map with values for all predefined roles in the model for the -
1690 item at the given \a index. -
1691 -
1692 Reimplement this function if you want to extend the default behavior of -
1693 this function to include custom roles in the map. -
1694 -
1695 \sa Qt::ItemDataRole, data() -
1696*/ -
1697QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const -
1698{ -
1699 QMap<int, QVariant> roles;
executed (the execution status of this line is deduced): QMap<int, QVariant> roles;
-
1700 for (int i = 0; i < Qt::UserRole; ++i) {
evaluated: i < Qt::UserRole
TRUEFALSE
yes
Evaluation Count:110336
yes
Evaluation Count:431
431-110336
1701 QVariant variantData = data(index, i);
executed (the execution status of this line is deduced): QVariant variantData = data(index, i);
-
1702 if (variantData.isValid())
evaluated: variantData.isValid()
TRUEFALSE
yes
Evaluation Count:101120
yes
Evaluation Count:9216
9216-101120
1703 roles.insert(i, variantData);
executed: roles.insert(i, variantData);
Execution Count:101120
101120
1704 }
executed: }
Execution Count:110336
110336
1705 return roles;
executed: return roles;
Execution Count:431
431
1706} -
1707 -
1708/*! -
1709 Sets the \a role data for the item at \a index to \a value. -
1710 -
1711 Returns true if successful; otherwise returns false. -
1712 -
1713 The dataChanged() signal should be emitted if the data was successfully -
1714 set. -
1715 -
1716 The base class implementation returns false. This function and data() must -
1717 be reimplemented for editable models. -
1718 -
1719 \sa Qt::ItemDataRole, data(), itemData() -
1720*/ -
1721bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role) -
1722{ -
1723 Q_UNUSED(index);
executed (the execution status of this line is deduced): (void)index;;
-
1724 Q_UNUSED(value);
executed (the execution status of this line is deduced): (void)value;;
-
1725 Q_UNUSED(role);
executed (the execution status of this line is deduced): (void)role;;
-
1726 return false;
executed: return false;
Execution Count:25
25
1727} -
1728 -
1729/*! -
1730 \fn QVariant QAbstractItemModel::data(const QModelIndex &index, int role) const = 0 -
1731 -
1732 Returns the data stored under the given \a role for the item referred to -
1733 by the \a index. -
1734 -
1735 \note If you do not have a value to return, return an \b invalid -
1736 QVariant instead of returning 0. -
1737 -
1738 \sa Qt::ItemDataRole, setData(), headerData() -
1739*/ -
1740 -
1741/*! -
1742 Sets the role data for the item at \a index to the associated value in -
1743 \a roles, for every Qt::ItemDataRole. -
1744 -
1745 Returns true if successful; otherwise returns false. -
1746 -
1747 Roles that are not in \a roles will not be modified. -
1748 -
1749 \sa setData(), data(), itemData() -
1750*/ -
1751bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) -
1752{ -
1753 bool b = true;
executed (the execution status of this line is deduced): bool b = true;
-
1754 for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
evaluated: it != roles.end()
TRUEFALSE
yes
Evaluation Count:11776
yes
Evaluation Count:56
56-11776
1755 b = b && setData(index, it.value(), it.key());
executed: b = b && setData(index, it.value(), it.key());
Execution Count:11776
partially evaluated: b
TRUEFALSE
yes
Evaluation Count:11776
no
Evaluation Count:0
partially evaluated: setData(index, it.value(), it.key())
TRUEFALSE
yes
Evaluation Count:11776
no
Evaluation Count:0
0-11776
1756 return b;
executed: return b;
Execution Count:56
56
1757} -
1758 -
1759/*! -
1760 Returns a list of MIME types that can be used to describe a list of model -
1761 indexes. -
1762 -
1763 \sa mimeData() -
1764*/ -
1765QStringList QAbstractItemModel::mimeTypes() const -
1766{ -
1767 QStringList types;
executed (the execution status of this line is deduced): QStringList types;
-
1768 types << QLatin1String("application/x-qabstractitemmodeldatalist");
executed (the execution status of this line is deduced): types << QLatin1String("application/x-qabstractitemmodeldatalist");
-
1769 return types;
executed: return types;
Execution Count:145
145
1770} -
1771 -
1772/*! -
1773 Returns an object that contains serialized items of data corresponding to -
1774 the list of \a indexes specified. The formats used to describe the encoded -
1775 data is obtained from the mimeTypes() function. -
1776 -
1777 If the list of indexes is empty, or there are no supported MIME types, 0 is -
1778 returned rather than a serialized empty list. -
1779 -
1780 \sa mimeTypes(), dropMimeData() -
1781*/ -
1782QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const -
1783{ -
1784 if (indexes.count() <= 0)
partially evaluated: indexes.count() <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1785 return 0;
never executed: return 0;
0
1786 QStringList types = mimeTypes();
executed (the execution status of this line is deduced): QStringList types = mimeTypes();
-
1787 if (types.isEmpty())
partially evaluated: types.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1788 return 0;
never executed: return 0;
0
1789 QMimeData *data = new QMimeData();
executed (the execution status of this line is deduced): QMimeData *data = new QMimeData();
-
1790 QString format = types.at(0);
executed (the execution status of this line is deduced): QString format = types.at(0);
-
1791 QByteArray encoded;
executed (the execution status of this line is deduced): QByteArray encoded;
-
1792 QDataStream stream(&encoded, QIODevice::WriteOnly);
executed (the execution status of this line is deduced): QDataStream stream(&encoded, QIODevice::WriteOnly);
-
1793 encodeData(indexes, stream);
executed (the execution status of this line is deduced): encodeData(indexes, stream);
-
1794 data->setData(format, encoded);
executed (the execution status of this line is deduced): data->setData(format, encoded);
-
1795 return data;
executed: return data;
Execution Count:12
12
1796} -
1797 -
1798/*! -
1799 Returns whether a model can accept a drop of data. -
1800 -
1801 This can be used to indicate whether a drop of certain data is allowed, for example -
1802 by using a 'forbidden' emblem on a mouse cursor during a drag operation. -
1803 -
1804 This method returns true by default. Reimplementations can return whether the -
1805 \a data can be dropped at \a row, \a column, \a parent with \a action. -
1806 -
1807 \sa dropMimeData(), {Using drag and drop with item views} -
1808 */ -
1809bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, -
1810 int row, int column, -
1811 const QModelIndex &parent) const -
1812{ -
1813 Q_UNUSED(data)
never executed (the execution status of this line is deduced): (void)data;
-
1814 Q_UNUSED(action)
never executed (the execution status of this line is deduced): (void)action;
-
1815 Q_UNUSED(row)
never executed (the execution status of this line is deduced): (void)row;
-
1816 Q_UNUSED(column)
never executed (the execution status of this line is deduced): (void)column;
-
1817 Q_UNUSED(parent)
never executed (the execution status of this line is deduced): (void)parent;
-
1818 return true;
never executed: return true;
0
1819} -
1820 -
1821/*! -
1822 Handles the \a data supplied by a drag and drop operation that ended with -
1823 the given \a action. -
1824 -
1825 Returns true if the data and action can be handled by the model; otherwise -
1826 returns false. -
1827 -
1828 The specified \a row, \a column and \a parent indicate the location of an -
1829 item in the model where the operation ended. It is the responsibility of -
1830 the model to complete the action at the correct location. -
1831 -
1832 For instance, a drop action on an item in a QTreeView can result in new -
1833 items either being inserted as children of the item specified by \a row, -
1834 \a column, and \a parent, or as siblings of the item. -
1835 -
1836 When \a row and \a column are -1 it means that the dropped data should be -
1837 considered as dropped directly on \a parent. Usually this will mean -
1838 appending the data as child items of \a parent. If \a row and column are -
1839 greater than or equal zero, it means that the drop occurred just before the -
1840 specified \a row and \a column in the specified \a parent. -
1841 -
1842 \sa supportedDropActions(), canDropMimeData(), {Using drag and drop with item views} -
1843*/ -
1844bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, -
1845 int row, int column, const QModelIndex &parent) -
1846{ -
1847 // check if the action is supported -
1848 if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
partially evaluated: !data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
partially evaluated: action == Qt::CopyAction
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
never evaluated: action == Qt::MoveAction
0-12
1849 return false;
never executed: return false;
0
1850 // check if the format is supported -
1851 QStringList types = mimeTypes();
executed (the execution status of this line is deduced): QStringList types = mimeTypes();
-
1852 if (types.isEmpty())
partially evaluated: types.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1853 return false;
never executed: return false;
0
1854 QString format = types.at(0);
executed (the execution status of this line is deduced): QString format = types.at(0);
-
1855 if (!data->hasFormat(format))
partially evaluated: !data->hasFormat(format)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1856 return false;
never executed: return false;
0
1857 if (row > rowCount(parent))
evaluated: row > rowCount(parent)
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:8
4-8
1858 row = rowCount(parent);
executed: row = rowCount(parent);
Execution Count:4
4
1859 if (row == -1)
partially evaluated: row == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1860 row = rowCount(parent);
never executed: row = rowCount(parent);
0
1861 if (column == -1)
partially evaluated: column == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
1862 column = 0;
never executed: column = 0;
0
1863 // decode and insert -
1864 QByteArray encoded = data->data(format);
executed (the execution status of this line is deduced): QByteArray encoded = data->data(format);
-
1865 QDataStream stream(&encoded, QIODevice::ReadOnly);
executed (the execution status of this line is deduced): QDataStream stream(&encoded, QIODevice::ReadOnly);
-
1866 return decodeData(row, column, parent, stream);
executed: return decodeData(row, column, parent, stream);
Execution Count:12
12
1867} -
1868 -
1869/*! -
1870 \since 4.2 -
1871 -
1872 Returns the drop actions supported by this model. -
1873 -
1874 The default implementation returns Qt::CopyAction. Reimplement this -
1875 function if you wish to support additional actions. You must also -
1876 reimplement the dropMimeData() function to handle the additional -
1877 operations. -
1878 -
1879 \sa dropMimeData(), Qt::DropActions, {Using drag and drop with item -
1880 views} -
1881*/ -
1882Qt::DropActions QAbstractItemModel::supportedDropActions() const -
1883{ -
1884 return Qt::CopyAction;
executed: return Qt::CopyAction;
Execution Count:91
91
1885} -
1886 -
1887/*! -
1888 Returns the actions supported by the data in this model. -
1889 -
1890 The default implementation returns supportedDropActions() unless specific -
1891 values have been set with setSupportedDragActions(). -
1892 -
1893 supportedDragActions() is used by QAbstractItemView::startDrag() as the -
1894 default values when a drag occurs. -
1895 -
1896 \sa Qt::DropActions, {Using drag and drop with item views} -
1897*/ -
1898Qt::DropActions QAbstractItemModel::supportedDragActions() const -
1899{ -
1900 Q_D(const QAbstractItemModel);
executed (the execution status of this line is deduced): const QAbstractItemModelPrivate * const d = d_func();
-
1901 if (d->supportedDragActions != -1)
partially evaluated: d->supportedDragActions != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1902 return d->supportedDragActions;
never executed: return d->supportedDragActions;
0
1903 return supportedDropActions();
executed: return supportedDropActions();
Execution Count:1
1
1904} -
1905 -
1906/*! -
1907 \internal -
1908 */ -
1909void QAbstractItemModel::doSetSupportedDragActions(Qt::DropActions actions) -
1910{ -
1911 Q_D(QAbstractItemModel);
never executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
1912 d->supportedDragActions = actions;
never executed (the execution status of this line is deduced): d->supportedDragActions = actions;
-
1913}
never executed: }
0
1914 -
1915/*! -
1916 \since 4.2 -
1917 \obsolete -
1918 \fn void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions) -
1919 -
1920 Sets the supported drag \a actions for the items in the model. -
1921 -
1922 \sa supportedDragActions(), {Using drag and drop with item views} -
1923*/ -
1924 -
1925/*! -
1926 \note The base class implementation of this function does nothing and -
1927 returns false. -
1928 -
1929 On models that support this, inserts \a count rows into the model before -
1930 the given \a row. Items in the new row will be children of the item -
1931 represented by the \a parent model index. -
1932 -
1933 If \a row is 0, the rows are prepended to any existing rows in the parent. -
1934 -
1935 If \a row is rowCount(), the rows are appended to any existing rows in the -
1936 parent. -
1937 -
1938 If \a parent has no children, a single column with \a count rows is -
1939 inserted. -
1940 -
1941 Returns true if the rows were successfully inserted; otherwise returns -
1942 false. -
1943 -
1944 If you implement your own model, you can reimplement this function if you -
1945 want to support insertions. Alternatively, you can provide your own API for -
1946 altering the data. In either case, you will need to call -
1947 beginInsertRows() and endInsertRows() to notify other components that the -
1948 model has changed. -
1949 -
1950 \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() -
1951*/ -
1952bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) -
1953{ -
1954 return false;
never executed: return false;
0
1955} -
1956 -
1957/*! -
1958 On models that support this, inserts \a count new columns into the model -
1959 before the given \a column. The items in each new column will be children -
1960 of the item represented by the \a parent model index. -
1961 -
1962 If \a column is 0, the columns are prepended to any existing columns. -
1963 -
1964 If \a column is columnCount(), the columns are appended to any existing -
1965 columns. -
1966 -
1967 If \a parent has no children, a single row with \a count columns is -
1968 inserted. -
1969 -
1970 Returns true if the columns were successfully inserted; otherwise returns -
1971 false. -
1972 -
1973 The base class implementation does nothing and returns false. -
1974 -
1975 If you implement your own model, you can reimplement this function if you -
1976 want to support insertions. Alternatively, you can provide your own API for -
1977 altering the data. -
1978 -
1979 \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() -
1980*/ -
1981bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) -
1982{ -
1983 return false;
executed: return false;
Execution Count:76
76
1984} -
1985 -
1986/*! -
1987 On models that support this, removes \a count rows starting with the given -
1988 \a row under parent \a parent from the model. -
1989 -
1990 Returns true if the rows were successfully removed; otherwise returns -
1991 false. -
1992 -
1993 The base class implementation does nothing and returns false. -
1994 -
1995 If you implement your own model, you can reimplement this function if you -
1996 want to support removing. Alternatively, you can provide your own API for -
1997 altering the data. -
1998 -
1999 \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), -
2000 endRemoveRows() -
2001*/ -
2002bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) -
2003{ -
2004 return false;
never executed: return false;
0
2005} -
2006 -
2007/*! -
2008 On models that support this, removes \a count columns starting with the -
2009 given \a column under parent \a parent from the model. -
2010 -
2011 Returns true if the columns were successfully removed; otherwise returns -
2012 false. -
2013 -
2014 The base class implementation does nothing and returns false. -
2015 -
2016 If you implement your own model, you can reimplement this function if you -
2017 want to support removing. Alternatively, you can provide your own API for -
2018 altering the data. -
2019 -
2020 \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), -
2021 endRemoveColumns() -
2022*/ -
2023bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &) -
2024{ -
2025 return false;
executed: return false;
Execution Count:132
132
2026} -
2027 -
2028/*! -
2029 On models that support this, moves \a count rows starting with the given -
2030 \a sourceRow under parent \a sourceParent to row \a destinationChild under -
2031 parent \a destinationParent. -
2032 -
2033 Returns true if the rows were successfully moved; otherwise returns -
2034 false. -
2035 -
2036 The base class implementation does nothing and returns false. -
2037 -
2038 If you implement your own model, you can reimplement this function if you -
2039 want to support moving. Alternatively, you can provide your own API for -
2040 altering the data. -
2041 -
2042 \sa beginMoveRows(), endMoveRows() -
2043*/ -
2044bool QAbstractItemModel::moveRows(const QModelIndex &, int , int , const QModelIndex &, int) -
2045{ -
2046 return false;
never executed: return false;
0
2047} -
2048 -
2049/*! -
2050 On models that support this, moves \a count columns starting with the given -
2051 \a sourceColumn under parent \a sourceParent to column \a destinationChild under -
2052 parent \a destinationParent. -
2053 -
2054 Returns true if the columns were successfully moved; otherwise returns -
2055 false. -
2056 -
2057 The base class implementation does nothing and returns false. -
2058 -
2059 If you implement your own model, you can reimplement this function if you -
2060 want to support moving. Alternatively, you can provide your own API for -
2061 altering the data. -
2062 -
2063 \sa beginMoveColumns(), endMoveColumns() -
2064*/ -
2065bool QAbstractItemModel::moveColumns(const QModelIndex &, int , int , const QModelIndex &, int) -
2066{ -
2067 return false;
never executed: return false;
0
2068} -
2069 -
2070/*! -
2071 Fetches any available data for the items with the parent specified by the -
2072 \a parent index. -
2073 -
2074 Reimplement this if you are populating your model incrementally. -
2075 -
2076 The default implementation does nothing. -
2077 -
2078 \sa canFetchMore() -
2079*/ -
2080void QAbstractItemModel::fetchMore(const QModelIndex &) -
2081{ -
2082 // do nothing -
2083} -
2084 -
2085/*! -
2086 Returns true if there is more data available for \a parent; otherwise -
2087 returns false. -
2088 -
2089 The default implementation always returns false. -
2090 -
2091 If canFetchMore() returns true, QAbstractItemView will call fetchMore(). -
2092 However, the fetchMore() function is only called when the model is being -
2093 populated incrementally. -
2094 -
2095 \sa fetchMore() -
2096*/ -
2097bool QAbstractItemModel::canFetchMore(const QModelIndex &) const -
2098{ -
2099 return false;
executed: return false;
Execution Count:5989
5989
2100} -
2101 -
2102/*! -
2103 Returns the item flags for the given \a index. -
2104 -
2105 The base class implementation returns a combination of flags that enables -
2106 the item (\c ItemIsEnabled) and allows it to be selected -
2107 (\c ItemIsSelectable). -
2108 -
2109 \sa Qt::ItemFlags -
2110*/ -
2111Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const -
2112{ -
2113 Q_D(const QAbstractItemModel);
executed (the execution status of this line is deduced): const QAbstractItemModelPrivate * const d = d_func();
-
2114 if (!d->indexValid(index))
evaluated: !d->indexValid(index)
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:27800
36-27800
2115 return 0;
executed: return 0;
Execution Count:36
36
2116 -
2117 return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
executed: return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
Execution Count:27800
27800
2118} -
2119 -
2120/*! -
2121 Sorts the model by \a column in the given \a order. -
2122 -
2123 The base class implementation does nothing. -
2124*/ -
2125void QAbstractItemModel::sort(int column, Qt::SortOrder order) -
2126{ -
2127 Q_UNUSED(column);
executed (the execution status of this line is deduced): (void)column;;
-
2128 Q_UNUSED(order);
executed (the execution status of this line is deduced): (void)order;;
-
2129 // do nothing -
2130}
executed: }
Execution Count:398
398
2131 -
2132/*! -
2133 Returns a model index for the buddy of the item represented by \a index. -
2134 When the user wants to edit an item, the view will call this function to -
2135 check whether another item in the model should be edited instead. Then, the -
2136 view will construct a delegate using the model index returned by the buddy -
2137 item. -
2138 -
2139 The default implementation of this function has each item as its own buddy. -
2140*/ -
2141QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const -
2142{ -
2143 return index;
executed: return index;
Execution Count:18902
18902
2144} -
2145 -
2146/*! -
2147 Returns a list of indexes for the items in the column of the \a start index -
2148 where data stored under the given \a role matches the specified \a value. -
2149 The way the search is performed is defined by the \a flags given. The list -
2150 that is returned may be empty. Note also that the order of results in the -
2151 list may not correspond to the order in the model, if for example a proxy -
2152 model is used. The order of the results can not be relied upon. -
2153 -
2154 The search begins from the \a start index, and continues until the number -
2155 of matching data items equals \a hits, the search reaches the last row, or -
2156 the search reaches \a start again - depending on whether \c MatchWrap is -
2157 specified in \a flags. If you want to search for all matching items, use -
2158 \a hits = -1. -
2159 -
2160 By default, this function will perform a wrapping, string-based comparison -
2161 on all items, searching for items that begin with the search term specified -
2162 by \a value. -
2163 -
2164 \note The default implementation of this function only searches columns. -
2165 Reimplement this function to include a different search behavior. -
2166*/ -
2167QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, -
2168 const QVariant &value, int hits, -
2169 Qt::MatchFlags flags) const -
2170{ -
2171 QModelIndexList result;
executed (the execution status of this line is deduced): QModelIndexList result;
-
2172 uint matchType = flags & 0x0F;
executed (the execution status of this line is deduced): uint matchType = flags & 0x0F;
-
2173 Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
evaluated: flags & Qt::MatchCaseSensitive
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:199
23-199
2174 bool recurse = flags & Qt::MatchRecursive;
executed (the execution status of this line is deduced): bool recurse = flags & Qt::MatchRecursive;
-
2175 bool wrap = flags & Qt::MatchWrap;
executed (the execution status of this line is deduced): bool wrap = flags & Qt::MatchWrap;
-
2176 bool allHits = (hits == -1);
executed (the execution status of this line is deduced): bool allHits = (hits == -1);
-
2177 QString text; // only convert to a string if it is needed
executed (the execution status of this line is deduced): QString text;
-
2178 QModelIndex p = parent(start);
executed (the execution status of this line is deduced): QModelIndex p = parent(start);
-
2179 int from = start.row();
executed (the execution status of this line is deduced): int from = start.row();
-
2180 int to = rowCount(p);
executed (the execution status of this line is deduced): int to = rowCount(p);
-
2181 -
2182 // iterates twice if wrapping -
2183 for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
evaluated: wrap
TRUEFALSE
yes
Evaluation Count:474
yes
Evaluation Count:128
evaluated: i < 2
TRUEFALSE
yes
Evaluation Count:316
yes
Evaluation Count:158
evaluated: !wrap
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:158
evaluated: i < 1
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:64
64-474
2184 for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {
evaluated: (r < to)
TRUEFALSE
yes
Evaluation Count:2323
yes
Evaluation Count:349
evaluated: allHits
TRUEFALSE
yes
Evaluation Count:88
yes
Evaluation Count:2235
evaluated: result.count() < hits
TRUEFALSE
yes
Evaluation Count:2204
yes
Evaluation Count:31
31-2323
2185 QModelIndex idx = index(r, start.column(), p);
executed (the execution status of this line is deduced): QModelIndex idx = index(r, start.column(), p);
-
2186 if (!idx.isValid())
evaluated: !idx.isValid()
TRUEFALSE
yes
Evaluation Count:1854
yes
Evaluation Count:438
438-1854
2187 continue;
executed: continue;
Execution Count:1854
1854
2188 QVariant v = data(idx, role);
executed (the execution status of this line is deduced): QVariant v = data(idx, role);
-
2189 // QVariant based matching -
2190 if (matchType == Qt::MatchExactly) {
evaluated: matchType == Qt::MatchExactly
TRUEFALSE
yes
Evaluation Count:95
yes
Evaluation Count:343
95-343
2191 if (value == v)
evaluated: value == v
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:70
25-70
2192 result.append(idx);
executed: result.append(idx);
Execution Count:25
25
2193 } else { // QString based matching
executed: }
Execution Count:95
95
2194 if (text.isEmpty()) // lazy conversion
evaluated: text.isEmpty()
TRUEFALSE
yes
Evaluation Count:126
yes
Evaluation Count:217
126-217
2195 text = value.toString();
executed: text = value.toString();
Execution Count:126
126
2196 QString t = v.toString();
executed (the execution status of this line is deduced): QString t = v.toString();
-
2197 switch (matchType) { -
2198 case Qt::MatchRegExp: -
2199 if (QRegExp(text, cs).exactMatch(t))
evaluated: QRegExp(text, cs).exactMatch(t)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:6
2-6
2200 result.append(idx);
executed: result.append(idx);
Execution Count:2
2
2201 break;
executed: break;
Execution Count:8
8
2202 case Qt::MatchWildcard: -
2203 if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
evaluated: QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
2204 result.append(idx);
executed: result.append(idx);
Execution Count:3
3
2205 break;
executed: break;
Execution Count:4
4
2206 case Qt::MatchStartsWith: -
2207 if (t.startsWith(text, cs))
evaluated: t.startsWith(text, cs)
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:278
20-278
2208 result.append(idx);
executed: result.append(idx);
Execution Count:20
20
2209 break;
executed: break;
Execution Count:298
298
2210 case Qt::MatchEndsWith: -
2211 if (t.endsWith(text, cs))
evaluated: t.endsWith(text, cs)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
2212 result.append(idx);
executed: result.append(idx);
Execution Count:2
2
2213 break;
executed: break;
Execution Count:4
4
2214 case Qt::MatchFixedString: -
2215 if (t.compare(text, cs) == 0)
evaluated: t.compare(text, cs) == 0
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:17
8-17
2216 result.append(idx);
executed: result.append(idx);
Execution Count:8
8
2217 break;
executed: break;
Execution Count:25
25
2218 case Qt::MatchContains: -
2219 default: -
2220 if (t.contains(text, cs))
evaluated: t.contains(text, cs)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
2221 result.append(idx);
executed: result.append(idx);
Execution Count:3
3
2222 }
executed: }
Execution Count:4
4
2223 }
executed: }
Execution Count:343
343
2224 if (recurse && hasChildren(idx)) { // search the hierarchy
evaluated: recurse
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:398
evaluated: hasChildren(idx)
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:27
13-398
2225 result += match(index(0, idx.column(), idx), role,
executed (the execution status of this line is deduced): result += match(index(0, idx.column(), idx), role,
-
2226 (text.isEmpty() ? value : text),
executed (the execution status of this line is deduced): (text.isEmpty() ? value : text),
-
2227 (allHits ? -1 : hits - result.count()), flags);
executed (the execution status of this line is deduced): (allHits ? -1 : hits - result.count()), flags);
-
2228 }
executed: }
Execution Count:13
13
2229 }
executed: }
Execution Count:438
438
2230 // prepare for the next iteration -
2231 from = 0;
executed (the execution status of this line is deduced): from = 0;
-
2232 to = start.row();
executed (the execution status of this line is deduced): to = start.row();
-
2233 }
executed: }
Execution Count:380
380
2234 return result;
executed: return result;
Execution Count:222
222
2235} -
2236 -
2237/*! -
2238 Returns the row and column span of the item represented by \a index. -
2239 -
2240 \note Currently, span is not used. -
2241*/ -
2242 -
2243QSize QAbstractItemModel::span(const QModelIndex &) const -
2244{ -
2245 return QSize(1, 1);
executed: return QSize(1, 1);
Execution Count:122
122
2246} -
2247 -
2248/*! -
2249 \fn void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames) -
2250 \since 4.6 -
2251 \obsolete -
2252 -
2253 This function is obsolete. Reimplement roleNames() instead. -
2254 -
2255 Sets the model's role names to \a roleNames. -
2256 -
2257 This function allows mapping of role identifiers to role property names in -
2258 scripting languages. -
2259 -
2260 \sa roleNames() -
2261*/ -
2262 -
2263/*! -
2264 \internal -
2265 */ -
2266void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames) -
2267{ -
2268 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2269 d->roleNames = roleNames;
executed (the execution status of this line is deduced): d->roleNames = roleNames;
-
2270}
executed: }
Execution Count:2
2
2271 -
2272/*! -
2273 \since 4.6 -
2274 -
2275 Returns the model's role names. -
2276 -
2277*/ -
2278QHash<int,QByteArray> QAbstractItemModel::roleNames() const -
2279{ -
2280 Q_D(const QAbstractItemModel);
executed (the execution status of this line is deduced): const QAbstractItemModelPrivate * const d = d_func();
-
2281 return d->roleNames;
executed: return d->roleNames;
Execution Count:1709
1709
2282} -
2283 -
2284/*! -
2285 Lets the model know that it should submit cached information to permanent -
2286 storage. This function is typically used for row editing. -
2287 -
2288 Returns true if there is no error; otherwise returns false. -
2289 -
2290 \sa revert() -
2291*/ -
2292 -
2293bool QAbstractItemModel::submit() -
2294{ -
2295 return true;
executed: return true;
Execution Count:2840
2840
2296} -
2297 -
2298/*! -
2299 Lets the model know that it should discard cached information. This -
2300 function is typically used for row editing. -
2301 -
2302 \sa submit() -
2303*/ -
2304 -
2305void QAbstractItemModel::revert() -
2306{ -
2307 // do nothing -
2308} -
2309 -
2310/*! -
2311 Returns the data for the given \a role and \a section in the header with -
2312 the specified \a orientation. -
2313 -
2314 For horizontal headers, the section number corresponds to the column -
2315 number. Similarly, for vertical headers, the section number corresponds to -
2316 the row number. -
2317 -
2318 \sa Qt::ItemDataRole, setHeaderData(), QHeaderView -
2319*/ -
2320 -
2321QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const -
2322{ -
2323 Q_UNUSED(orientation);
executed (the execution status of this line is deduced): (void)orientation;;
-
2324 if (role == Qt::DisplayRole)
evaluated: role == Qt::DisplayRole
TRUEFALSE
yes
Evaluation Count:20912
yes
Evaluation Count:69134
20912-69134
2325 return section + 1;
executed: return section + 1;
Execution Count:20912
20912
2326 return QVariant();
executed: return QVariant();
Execution Count:69134
69134
2327} -
2328 -
2329/*! -
2330 Sets the data for the given \a role and \a section in the header with the -
2331 specified \a orientation to the \a value supplied. -
2332 -
2333 Returns true if the header's data was updated; otherwise returns false. -
2334 -
2335 When reimplementing this function, the headerDataChanged() signal must be -
2336 emitted explicitly. -
2337 -
2338 \sa Qt::ItemDataRole, headerData() -
2339*/ -
2340 -
2341bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, -
2342 const QVariant &value, int role) -
2343{ -
2344 Q_UNUSED(section);
executed (the execution status of this line is deduced): (void)section;;
-
2345 Q_UNUSED(orientation);
executed (the execution status of this line is deduced): (void)orientation;;
-
2346 Q_UNUSED(value);
executed (the execution status of this line is deduced): (void)value;;
-
2347 Q_UNUSED(role);
executed (the execution status of this line is deduced): (void)role;;
-
2348 return false;
executed: return false;
Execution Count:84
84
2349} -
2350 -
2351/*! -
2352 \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const -
2353 -
2354 Creates a model index for the given \a row and \a column with the internal -
2355 pointer \a ptr. -
2356 -
2357 When using a QSortFilterProxyModel, its indexes have their own internal -
2358 pointer. It is not advisable to access this internal pointer outside of the -
2359 model. Use the data() function instead. -
2360 -
2361 This function provides a consistent interface that model subclasses must -
2362 use to create model indexes. -
2363*/ -
2364 -
2365/*! -
2366 \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, quintptr id) const -
2367 -
2368 Creates a model index for the given \a row and \a column with the internal -
2369 identifier, \a id. -
2370 -
2371 This function provides a consistent interface that model subclasses must -
2372 use to create model indexes. -
2373 -
2374 \sa QModelIndex::internalId() -
2375*/ -
2376 -
2377/*! -
2378 \internal -
2379*/ -
2380void QAbstractItemModel::encodeData(const QModelIndexList &indexes, QDataStream &stream) const -
2381{ -
2382 QModelIndexList::ConstIterator it = indexes.begin();
executed (the execution status of this line is deduced): QModelIndexList::ConstIterator it = indexes.begin();
-
2383 for (; it != indexes.end(); ++it)
evaluated: it != indexes.end()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2384 stream << (*it).row() << (*it).column() << itemData(*it);
executed: stream << (*it).row() << (*it).column() << itemData(*it);
Execution Count:46
46
2385}
executed: }
Execution Count:12
12
2386 -
2387/*! -
2388 \internal -
2389 */ -
2390bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &parent, -
2391 QDataStream &stream) -
2392{ -
2393 int top = INT_MAX;
executed (the execution status of this line is deduced): int top = 2147483647;
-
2394 int left = INT_MAX;
executed (the execution status of this line is deduced): int left = 2147483647;
-
2395 int bottom = 0;
executed (the execution status of this line is deduced): int bottom = 0;
-
2396 int right = 0;
executed (the execution status of this line is deduced): int right = 0;
-
2397 QVector<int> rows, columns;
executed (the execution status of this line is deduced): QVector<int> rows, columns;
-
2398 QVector<QMap<int, QVariant> > data;
executed (the execution status of this line is deduced): QVector<QMap<int, QVariant> > data;
-
2399 -
2400 while (!stream.atEnd()) {
evaluated: !stream.atEnd()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2401 int r, c;
executed (the execution status of this line is deduced): int r, c;
-
2402 QMap<int, QVariant> v;
executed (the execution status of this line is deduced): QMap<int, QVariant> v;
-
2403 stream >> r >> c >> v;
executed (the execution status of this line is deduced): stream >> r >> c >> v;
-
2404 rows.append(r);
executed (the execution status of this line is deduced): rows.append(r);
-
2405 columns.append(c);
executed (the execution status of this line is deduced): columns.append(c);
-
2406 data.append(v);
executed (the execution status of this line is deduced): data.append(v);
-
2407 top = qMin(r, top);
executed (the execution status of this line is deduced): top = qMin(r, top);
-
2408 left = qMin(c, left);
executed (the execution status of this line is deduced): left = qMin(c, left);
-
2409 bottom = qMax(r, bottom);
executed (the execution status of this line is deduced): bottom = qMax(r, bottom);
-
2410 right = qMax(c, right);
executed (the execution status of this line is deduced): right = qMax(c, right);
-
2411 }
executed: }
Execution Count:46
46
2412 -
2413 // insert the dragged items into the table, use a bit array to avoid overwriting items, -
2414 // since items from different tables can have the same row and column -
2415 int dragRowCount = 0;
executed (the execution status of this line is deduced): int dragRowCount = 0;
-
2416 int dragColumnCount = right - left + 1;
executed (the execution status of this line is deduced): int dragColumnCount = right - left + 1;
-
2417 -
2418 // Compute the number of continuous rows upon insertion and modify the rows to match -
2419 QVector<int> rowsToInsert(bottom + 1);
executed (the execution status of this line is deduced): QVector<int> rowsToInsert(bottom + 1);
-
2420 for (int i = 0; i < rows.count(); ++i)
evaluated: i < rows.count()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2421 rowsToInsert[rows.at(i)] = 1;
executed: rowsToInsert[rows.at(i)] = 1;
Execution Count:46
46
2422 for (int i = 0; i < rowsToInsert.count(); ++i) {
evaluated: i < rowsToInsert.count()
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:12
12-24
2423 if (rowsToInsert[i] == 1){
evaluated: rowsToInsert[i] == 1
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:2
2-22
2424 rowsToInsert[i] = dragRowCount;
executed (the execution status of this line is deduced): rowsToInsert[i] = dragRowCount;
-
2425 ++dragRowCount;
executed (the execution status of this line is deduced): ++dragRowCount;
-
2426 }
executed: }
Execution Count:22
22
2427 }
executed: }
Execution Count:24
24
2428 for (int i = 0; i < rows.count(); ++i)
evaluated: i < rows.count()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2429 rows[i] = top + rowsToInsert[rows[i]];
executed: rows[i] = top + rowsToInsert[rows[i]];
Execution Count:46
46
2430 -
2431 QBitArray isWrittenTo(dragRowCount * dragColumnCount);
executed (the execution status of this line is deduced): QBitArray isWrittenTo(dragRowCount * dragColumnCount);
-
2432 -
2433 // make space in the table for the dropped data -
2434 int colCount = columnCount(parent);
executed (the execution status of this line is deduced): int colCount = columnCount(parent);
-
2435 if (colCount == 0) {
partially evaluated: colCount == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
2436 insertColumns(colCount, dragColumnCount - colCount, parent);
never executed (the execution status of this line is deduced): insertColumns(colCount, dragColumnCount - colCount, parent);
-
2437 colCount = columnCount(parent);
never executed (the execution status of this line is deduced): colCount = columnCount(parent);
-
2438 }
never executed: }
0
2439 insertRows(row, dragRowCount, parent);
executed (the execution status of this line is deduced): insertRows(row, dragRowCount, parent);
-
2440 -
2441 row = qMax(0, row);
executed (the execution status of this line is deduced): row = qMax(0, row);
-
2442 column = qMax(0, column);
executed (the execution status of this line is deduced): column = qMax(0, column);
-
2443 -
2444 QVector<QPersistentModelIndex> newIndexes(data.size());
executed (the execution status of this line is deduced): QVector<QPersistentModelIndex> newIndexes(data.size());
-
2445 // set the data in the table -
2446 for (int j = 0; j < data.size(); ++j) {
evaluated: j < data.size()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2447 int relativeRow = rows.at(j) - top;
executed (the execution status of this line is deduced): int relativeRow = rows.at(j) - top;
-
2448 int relativeColumn = columns.at(j) - left;
executed (the execution status of this line is deduced): int relativeColumn = columns.at(j) - left;
-
2449 int destinationRow = relativeRow + row;
executed (the execution status of this line is deduced): int destinationRow = relativeRow + row;
-
2450 int destinationColumn = relativeColumn + column;
executed (the execution status of this line is deduced): int destinationColumn = relativeColumn + column;
-
2451 int flat = (relativeRow * dragColumnCount) + relativeColumn;
executed (the execution status of this line is deduced): int flat = (relativeRow * dragColumnCount) + relativeColumn;
-
2452 // if the item was already written to, or we just can't fit it in the table, create a new row -
2453 if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
evaluated: destinationColumn >= colCount
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:37
evaluated: isWrittenTo.testBit(flat)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:34
3-37
2454 destinationColumn = qBound(column, destinationColumn, colCount - 1);
executed (the execution status of this line is deduced): destinationColumn = qBound(column, destinationColumn, colCount - 1);
-
2455 destinationRow = row + dragRowCount;
executed (the execution status of this line is deduced): destinationRow = row + dragRowCount;
-
2456 insertRows(row + dragRowCount, 1, parent);
executed (the execution status of this line is deduced): insertRows(row + dragRowCount, 1, parent);
-
2457 flat = (dragRowCount * dragColumnCount) + relativeColumn;
executed (the execution status of this line is deduced): flat = (dragRowCount * dragColumnCount) + relativeColumn;
-
2458 isWrittenTo.resize(++dragRowCount * dragColumnCount);
executed (the execution status of this line is deduced): isWrittenTo.resize(++dragRowCount * dragColumnCount);
-
2459 }
executed: }
Execution Count:12
12
2460 if (!isWrittenTo.testBit(flat)) {
partially evaluated: !isWrittenTo.testBit(flat)
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
0-46
2461 newIndexes[j] = index(destinationRow, destinationColumn, parent);
executed (the execution status of this line is deduced): newIndexes[j] = index(destinationRow, destinationColumn, parent);
-
2462 isWrittenTo.setBit(flat);
executed (the execution status of this line is deduced): isWrittenTo.setBit(flat);
-
2463 }
executed: }
Execution Count:46
46
2464 }
executed: }
Execution Count:46
46
2465 -
2466 for(int k = 0; k < newIndexes.size(); k++) {
evaluated: k < newIndexes.size()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:12
12-46
2467 if (newIndexes.at(k).isValid())
partially evaluated: newIndexes.at(k).isValid()
TRUEFALSE
yes
Evaluation Count:46
no
Evaluation Count:0
0-46
2468 setItemData(newIndexes.at(k), data.at(k));
executed: setItemData(newIndexes.at(k), data.at(k));
Execution Count:46
46
2469 }
executed: }
Execution Count:46
46
2470 -
2471 return true;
executed: return true;
Execution Count:12
12
2472} -
2473 -
2474/*! -
2475 Begins a row insertion operation. -
2476 -
2477 When reimplementing insertRows() in a subclass, you must call this function -
2478 \e before inserting data into the model's underlying data store. -
2479 -
2480 The \a parent index corresponds to the parent into which the new rows are -
2481 inserted; \a first and \a last are the row numbers that the new rows will -
2482 have after they have been inserted. -
2483 -
2484 \table 80% -
2485 \row -
2486 \li \inlineimage modelview-begin-insert-rows.png Inserting rows -
2487 \li Specify the first and last row numbers for the span of rows you -
2488 want to insert into an item in a model. -
2489 -
2490 For example, as shown in the diagram, we insert three rows before -
2491 row 2, so \a first is 2 and \a last is 4: -
2492 -
2493 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 0 -
2494 -
2495 This inserts the three new rows as rows 2, 3, and 4. -
2496 \row -
2497 \li \inlineimage modelview-begin-append-rows.png Appending rows -
2498 \li To append rows, insert them after the last row. -
2499 -
2500 For example, as shown in the diagram, we append two rows to a -
2501 collection of 4 existing rows (ending in row 3), so \a first is 4 -
2502 and \a last is 5: -
2503 -
2504 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1 -
2505 -
2506 This appends the two new rows as rows 4 and 5. -
2507 \endtable -
2508 -
2509 \note This function emits the rowsAboutToBeInserted() signal which -
2510 connected views (or proxies) must handle before the data is inserted. -
2511 Otherwise, the views may end up in an invalid state. -
2512 \sa endInsertRows() -
2513*/ -
2514void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last) -
2515{ -
2516 Q_ASSERT(first >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2517 Q_ASSERT(last >= first);
executed (the execution status of this line is deduced): qt_noop();
-
2518 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2519 d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
executed (the execution status of this line is deduced): d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
-
2520 emit rowsAboutToBeInserted(parent, first, last, QPrivateSignal());
executed (the execution status of this line is deduced): rowsAboutToBeInserted(parent, first, last, QPrivateSignal());
-
2521 d->rowsAboutToBeInserted(parent, first, last);
executed (the execution status of this line is deduced): d->rowsAboutToBeInserted(parent, first, last);
-
2522}
executed: }
Execution Count:110533
110533
2523 -
2524/*! -
2525 Ends a row insertion operation. -
2526 -
2527 When reimplementing insertRows() in a subclass, you must call this function -
2528 \e after inserting data into the model's underlying data store. -
2529 -
2530 \sa beginInsertRows() -
2531*/ -
2532void QAbstractItemModel::endInsertRows() -
2533{ -
2534 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2535 QAbstractItemModelPrivate::Change change = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change change = d->changes.pop();
-
2536 d->rowsInserted(change.parent, change.first, change.last);
executed (the execution status of this line is deduced): d->rowsInserted(change.parent, change.first, change.last);
-
2537 emit rowsInserted(change.parent, change.first, change.last, QPrivateSignal());
executed (the execution status of this line is deduced): rowsInserted(change.parent, change.first, change.last, QPrivateSignal());
-
2538}
executed: }
Execution Count:110533
110533
2539 -
2540/*! -
2541 Begins a row removal operation. -
2542 -
2543 When reimplementing removeRows() in a subclass, you must call this -
2544 function \e before removing data from the model's underlying data store. -
2545 -
2546 The \a parent index corresponds to the parent from which the new rows are -
2547 removed; \a first and \a last are the row numbers of the rows to be -
2548 removed. -
2549 -
2550 \table 80% -
2551 \row -
2552 \li \inlineimage modelview-begin-remove-rows.png Removing rows -
2553 \li Specify the first and last row numbers for the span of rows you -
2554 want to remove from an item in a model. -
2555 -
2556 For example, as shown in the diagram, we remove the two rows from -
2557 row 2 to row 3, so \a first is 2 and \a last is 3: -
2558 -
2559 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 2 -
2560 \endtable -
2561 -
2562 \note This function emits the rowsAboutToBeRemoved() signal which connected -
2563 views (or proxies) must handle before the data is removed. Otherwise, the -
2564 views may end up in an invalid state. -
2565 -
2566 \sa endRemoveRows() -
2567*/ -
2568void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) -
2569{ -
2570 Q_ASSERT(first >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2571 Q_ASSERT(last >= first);
executed (the execution status of this line is deduced): qt_noop();
-
2572 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2573 d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
executed (the execution status of this line is deduced): d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
-
2574 emit rowsAboutToBeRemoved(parent, first, last, QPrivateSignal());
executed (the execution status of this line is deduced): rowsAboutToBeRemoved(parent, first, last, QPrivateSignal());
-
2575 d->rowsAboutToBeRemoved(parent, first, last);
executed (the execution status of this line is deduced): d->rowsAboutToBeRemoved(parent, first, last);
-
2576}
executed: }
Execution Count:1998
1998
2577 -
2578/*! -
2579 Ends a row removal operation. -
2580 -
2581 When reimplementing removeRows() in a subclass, you must call this function -
2582 \e after removing data from the model's underlying data store. -
2583 -
2584 \sa beginRemoveRows() -
2585*/ -
2586void QAbstractItemModel::endRemoveRows() -
2587{ -
2588 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2589 QAbstractItemModelPrivate::Change change = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change change = d->changes.pop();
-
2590 d->rowsRemoved(change.parent, change.first, change.last);
executed (the execution status of this line is deduced): d->rowsRemoved(change.parent, change.first, change.last);
-
2591 emit rowsRemoved(change.parent, change.first, change.last, QPrivateSignal());
executed (the execution status of this line is deduced): rowsRemoved(change.parent, change.first, change.last, QPrivateSignal());
-
2592}
executed: }
Execution Count:1998
1998
2593 -
2594/*! -
2595 Returns whether a move operation is valid. -
2596 -
2597 A move operation is not allowed if it moves a continuous range of rows to a destination within -
2598 itself, or if it attempts to move a row to one of its own descendants. -
2599 -
2600 \internal -
2601*/ -
2602bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int start, int end, const QModelIndex &destinationParent, int destinationStart, Qt::Orientation orientation) -
2603{ -
2604 // Don't move the range within itself. -
2605 if (destinationParent == srcParent)
evaluated: destinationParent == srcParent
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:106
43-106
2606 return !(destinationStart >= start && destinationStart <= end + 1);
executed: return !(destinationStart >= start && destinationStart <= end + 1);
Execution Count:43
43
2607 -
2608 QModelIndex destinationAncestor = destinationParent;
executed (the execution status of this line is deduced): QModelIndex destinationAncestor = destinationParent;
-
2609 int pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
partially evaluated: (Qt::Vertical == orientation)
TRUEFALSE
yes
Evaluation Count:106
no
Evaluation Count:0
0-106
2610 forever {
executed (the execution status of this line is deduced): for(;;) {
-
2611 if (destinationAncestor == srcParent) {
evaluated: destinationAncestor == srcParent
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:270
75-270
2612 if (pos >= start && pos <= end)
evaluated: pos >= start
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:8
evaluated: pos <= end
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:7
7-67
2613 return false;
executed: return false;
Execution Count:60
60
2614 break;
executed: break;
Execution Count:15
15
2615 } -
2616 -
2617 if (!destinationAncestor.isValid())
evaluated: !destinationAncestor.isValid()
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:239
31-239
2618 break;
executed: break;
Execution Count:31
31
2619 -
2620 pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
partially evaluated: (Qt::Vertical == orientation)
TRUEFALSE
yes
Evaluation Count:239
no
Evaluation Count:0
0-239
2621 destinationAncestor = destinationAncestor.parent();
executed (the execution status of this line is deduced): destinationAncestor = destinationAncestor.parent();
-
2622 }
executed: }
Execution Count:239
239
2623 -
2624 return true;
executed: return true;
Execution Count:46
46
2625} -
2626 -
2627/*! -
2628 \since 4.6 -
2629 -
2630 Begins a row move operation. -
2631 -
2632 When reimplementing a subclass, this method simplifies moving -
2633 entities in your model. This method is responsible for moving -
2634 persistent indexes in the model, which you would otherwise be -
2635 required to do yourself. Using beginMoveRows and endMoveRows -
2636 is an alternative to emitting layoutAboutToBeChanged and -
2637 layoutChanged directly along with changePersistentIndexes. -
2638 -
2639 The \a sourceParent index corresponds to the parent from which the -
2640 rows are moved; \a sourceFirst and \a sourceLast are the first and last -
2641 row numbers of the rows to be moved. The \a destinationParent index -
2642 corresponds to the parent into which those rows are moved. The \a -
2643 destinationChild is the row to which the rows will be moved. That -
2644 is, the index at row \a sourceFirst in \a sourceParent will become -
2645 row \a destinationChild in \a destinationParent, followed by all other -
2646 rows up to \a sourceLast. -
2647 -
2648 However, when moving rows down in the same parent (\a sourceParent -
2649 and \a destinationParent are equal), the rows will be placed before the -
2650 \a destinationChild index. That is, if you wish to move rows 0 and 1 so -
2651 they will become rows 1 and 2, \a destinationChild should be 3. In this -
2652 case, the new index for the source row \c i (which is between -
2653 \a sourceFirst and \a sourceLast) is equal to -
2654 \c {(destinationChild-sourceLast-1+i)}. -
2655 -
2656 Note that if \a sourceParent and \a destinationParent are the same, -
2657 you must ensure that the \a destinationChild is not within the range -
2658 of \a sourceFirst and \a sourceLast + 1. You must also ensure that you -
2659 do not attempt to move a row to one of its own children or ancestors. -
2660 This method returns false if either condition is true, in which case you -
2661 should abort your move operation. -
2662 -
2663 \table 80% -
2664 \row -
2665 \li \inlineimage modelview-move-rows-1.png Moving rows to another parent -
2666 \li Specify the first and last row numbers for the span of rows in -
2667 the source parent you want to move in the model. Also specify -
2668 the row in the destination parent to move the span to. -
2669 -
2670 For example, as shown in the diagram, we move three rows from -
2671 row 2 to 4 in the source, so \a sourceFirst is 2 and \a sourceLast is 4. -
2672 We move those items to above row 2 in the destination, so \a destinationChild is 2. -
2673 -
2674 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 6 -
2675 -
2676 This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in -
2677 the destination. Other affected siblings are displaced accordingly. -
2678 \row -
2679 \li \inlineimage modelview-move-rows-2.png Moving rows to append to another parent -
2680 \li To append rows to another parent, move them to after the last row. -
2681 -
2682 For example, as shown in the diagram, we move three rows to a -
2683 collection of 6 existing rows (ending in row 5), so \a destinationChild is 6: -
2684 -
2685 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7 -
2686 -
2687 This moves the target rows to the end of the target parent as 6, 7 and 8. -
2688 \row -
2689 \li \inlineimage modelview-move-rows-3.png Moving rows in the same parent up -
2690 \li To move rows within the same parent, specify the row to move them to. -
2691 -
2692 For example, as shown in the diagram, we move one item from row 2 to row 0, -
2693 so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0. -
2694 -
2695 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8 -
2696 -
2697 Note that other rows may be displaced accordingly. Note also that when moving -
2698 items within the same parent you should not attempt invalid or no-op moves. In -
2699 the above example, item 2 is at row 2 before the move, so it can not be moved -
2700 to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where -
2701 it is already) -
2702 -
2703 \row -
2704 \li \inlineimage modelview-move-rows-4.png Moving rows in the same parent down -
2705 \li To move rows within the same parent, specify the row to move them to. -
2706 -
2707 For example, as shown in the diagram, we move one item from row 2 to row 4, -
2708 so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4. -
2709 -
2710 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9 -
2711 -
2712 Note that other rows may be displaced accordingly. -
2713 \endtable -
2714 -
2715 \sa endMoveRows() -
2716*/ -
2717bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) -
2718{ -
2719 Q_ASSERT(sourceFirst >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2720 Q_ASSERT(sourceLast >= sourceFirst);
executed (the execution status of this line is deduced): qt_noop();
-
2721 Q_ASSERT(destinationChild >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2722 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2723 -
2724 if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)) {
evaluated: !d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)
TRUEFALSE
yes
Evaluation Count:85
yes
Evaluation Count:63
63-85
2725 return false;
executed: return false;
Execution Count:85
85
2726 } -
2727 -
2728 QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
-
2729 sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
evaluated: sourceParent.isValid()
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:24
evaluated: sourceParent.row() >= destinationChild
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:14
evaluated: sourceParent.parent() == destinationParent
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:15
10-39
2730 d->changes.push(sourceChange);
executed (the execution status of this line is deduced): d->changes.push(sourceChange);
-
2731 int destinationLast = destinationChild + (sourceLast - sourceFirst);
executed (the execution status of this line is deduced): int destinationLast = destinationChild + (sourceLast - sourceFirst);
-
2732 QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
-
2733 destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
evaluated: destinationParent.isValid()
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:26
evaluated: destinationParent.row() >= sourceLast
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:21
evaluated: destinationParent.parent() == sourceParent
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:9
7-37
2734 d->changes.push(destinationChange);
executed (the execution status of this line is deduced): d->changes.push(destinationChange);
-
2735 -
2736 emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal());
executed (the execution status of this line is deduced): rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal());
-
2737 d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical);
executed (the execution status of this line is deduced): d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical);
-
2738 return true;
executed: return true;
Execution Count:63
63
2739} -
2740 -
2741/*! -
2742 Ends a row move operation. -
2743 -
2744 When implementing a subclass, you must call this -
2745 function \e after moving data within the model's underlying data -
2746 store. -
2747 -
2748 \sa beginMoveRows() -
2749 -
2750 \since 4.6 -
2751*/ -
2752void QAbstractItemModel::endMoveRows() -
2753{ -
2754 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2755 -
2756 QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
-
2757 QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
-
2758 -
2759 QModelIndex adjustedSource = removeChange.parent;
executed (the execution status of this line is deduced): QModelIndex adjustedSource = removeChange.parent;
-
2760 QModelIndex adjustedDestination = insertChange.parent;
executed (the execution status of this line is deduced): QModelIndex adjustedDestination = insertChange.parent;
-
2761 -
2762 const int numMoved = removeChange.last - removeChange.first + 1;
executed (the execution status of this line is deduced): const int numMoved = removeChange.last - removeChange.first + 1;
-
2763 if (insertChange.needsAdjust)
evaluated: insertChange.needsAdjust
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:56
7-56
2764 adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer());
executed: adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer());
Execution Count:7
7
2765 -
2766 if (removeChange.needsAdjust)
evaluated: removeChange.needsAdjust
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:53
10-53
2767 adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer());
executed: adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer());
Execution Count:10
10
2768 -
2769 d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical);
executed (the execution status of this line is deduced): d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical);
-
2770 -
2771 emit rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal());
executed (the execution status of this line is deduced): rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal());
-
2772}
executed: }
Execution Count:63
63
2773 -
2774/*! -
2775 Begins a column insertion operation. -
2776 -
2777 When reimplementing insertColumns() in a subclass, you must call this -
2778 function \e before inserting data into the model's underlying data store. -
2779 -
2780 The \a parent index corresponds to the parent into which the new columns -
2781 are inserted; \a first and \a last are the column numbers of the new -
2782 columns will have after they have been inserted. -
2783 -
2784 \table 80% -
2785 \row -
2786 \li \inlineimage modelview-begin-insert-columns.png Inserting columns -
2787 \li Specify the first and last column numbers for the span of columns -
2788 you want to insert into an item in a model. -
2789 -
2790 For example, as shown in the diagram, we insert three columns -
2791 before column 4, so \a first is 4 and \a last is 6: -
2792 -
2793 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 3 -
2794 -
2795 This inserts the three new columns as columns 4, 5, and 6. -
2796 \row -
2797 \li \inlineimage modelview-begin-append-columns.png Appending columns -
2798 \li To append columns, insert them after the last column. -
2799 -
2800 For example, as shown in the diagram, we append three columns to a -
2801 collection of six existing columns (ending in column 5), so -
2802 \a first is 6 and \a last is 8: -
2803 -
2804 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4 -
2805 -
2806 This appends the two new columns as columns 6, 7, and 8. -
2807 \endtable -
2808 -
2809 \note This function emits the columnsAboutToBeInserted() signal which -
2810 connected views (or proxies) must handle before the data is inserted. -
2811 Otherwise, the views may end up in an invalid state. -
2812 -
2813 \sa endInsertColumns() -
2814*/ -
2815void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last) -
2816{ -
2817 Q_ASSERT(first >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2818 Q_ASSERT(last >= first);
executed (the execution status of this line is deduced): qt_noop();
-
2819 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2820 d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
executed (the execution status of this line is deduced): d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
-
2821 emit columnsAboutToBeInserted(parent, first, last, QPrivateSignal());
executed (the execution status of this line is deduced): columnsAboutToBeInserted(parent, first, last, QPrivateSignal());
-
2822 d->columnsAboutToBeInserted(parent, first, last);
executed (the execution status of this line is deduced): d->columnsAboutToBeInserted(parent, first, last);
-
2823}
executed: }
Execution Count:10811
10811
2824 -
2825/*! -
2826 Ends a column insertion operation. -
2827 -
2828 When reimplementing insertColumns() in a subclass, you must call this -
2829 function \e after inserting data into the model's underlying data -
2830 store. -
2831 -
2832 \sa beginInsertColumns() -
2833*/ -
2834void QAbstractItemModel::endInsertColumns() -
2835{ -
2836 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2837 QAbstractItemModelPrivate::Change change = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change change = d->changes.pop();
-
2838 d->columnsInserted(change.parent, change.first, change.last);
executed (the execution status of this line is deduced): d->columnsInserted(change.parent, change.first, change.last);
-
2839 emit columnsInserted(change.parent, change.first, change.last, QPrivateSignal());
executed (the execution status of this line is deduced): columnsInserted(change.parent, change.first, change.last, QPrivateSignal());
-
2840}
executed: }
Execution Count:10811
10811
2841 -
2842/*! -
2843 Begins a column removal operation. -
2844 -
2845 When reimplementing removeColumns() in a subclass, you must call this -
2846 function \e before removing data from the model's underlying data store. -
2847 -
2848 The \a parent index corresponds to the parent from which the new columns -
2849 are removed; \a first and \a last are the column numbers of the first and -
2850 last columns to be removed. -
2851 -
2852 \table 80% -
2853 \row -
2854 \li \inlineimage modelview-begin-remove-columns.png Removing columns -
2855 \li Specify the first and last column numbers for the span of columns -
2856 you want to remove from an item in a model. -
2857 -
2858 For example, as shown in the diagram, we remove the three columns -
2859 from column 4 to column 6, so \a first is 4 and \a last is 6: -
2860 -
2861 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 5 -
2862 \endtable -
2863 -
2864 \note This function emits the columnsAboutToBeRemoved() signal which -
2865 connected views (or proxies) must handle before the data is removed. -
2866 Otherwise, the views may end up in an invalid state. -
2867 -
2868 \sa endRemoveColumns() -
2869*/ -
2870void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) -
2871{ -
2872 Q_ASSERT(first >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2873 Q_ASSERT(last >= first);
executed (the execution status of this line is deduced): qt_noop();
-
2874 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2875 d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
executed (the execution status of this line is deduced): d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last));
-
2876 emit columnsAboutToBeRemoved(parent, first, last, QPrivateSignal());
executed (the execution status of this line is deduced): columnsAboutToBeRemoved(parent, first, last, QPrivateSignal());
-
2877 d->columnsAboutToBeRemoved(parent, first, last);
executed (the execution status of this line is deduced): d->columnsAboutToBeRemoved(parent, first, last);
-
2878}
executed: }
Execution Count:204
204
2879 -
2880/*! -
2881 Ends a column removal operation. -
2882 -
2883 When reimplementing removeColumns() in a subclass, you must call this -
2884 function \e after removing data from the model's underlying data store. -
2885 -
2886 \sa beginRemoveColumns() -
2887*/ -
2888void QAbstractItemModel::endRemoveColumns() -
2889{ -
2890 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2891 QAbstractItemModelPrivate::Change change = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change change = d->changes.pop();
-
2892 d->columnsRemoved(change.parent, change.first, change.last);
executed (the execution status of this line is deduced): d->columnsRemoved(change.parent, change.first, change.last);
-
2893 emit columnsRemoved(change.parent, change.first, change.last, QPrivateSignal());
executed (the execution status of this line is deduced): columnsRemoved(change.parent, change.first, change.last, QPrivateSignal());
-
2894}
executed: }
Execution Count:204
204
2895 -
2896/*! -
2897 Begins a column move operation. -
2898 -
2899 When reimplementing a subclass, this method simplifies moving -
2900 entities in your model. This method is responsible for moving -
2901 persistent indexes in the model, which you would otherwise be -
2902 required to do yourself. Using beginMoveRows and endMoveRows -
2903 is an alternative to emitting layoutAboutToBeChanged and -
2904 layoutChanged directly along with changePersistentIndexes. -
2905 -
2906 The \a sourceParent index corresponds to the parent from which the -
2907 columns are moved; \a sourceFirst and \a sourceLast are the first and last -
2908 column numbers of the columns to be moved. The \a destinationParent index -
2909 corresponds to the parent into which those columns are moved. The \a -
2910 destinationChild is the column to which the columns will be moved. That -
2911 is, the index at column \a sourceFirst in \a sourceParent will become -
2912 column \a destinationChild in \a destinationParent, followed by all other -
2913 columns up to \a sourceLast. -
2914 -
2915 However, when moving columns down in the same parent (\a sourceParent -
2916 and \a destinationParent are equal), the columns will be placed before the -
2917 \a destinationChild index. That is, if you wish to move columns 0 and 1 so -
2918 they will become columns 1 and 2, \a destinationChild should be 3. In this -
2919 case, the new index for the source column \c i (which is between -
2920 \a sourceFirst and \a sourceLast) is equal to -
2921 \c {(destinationChild-sourceLast-1+i)}. -
2922 -
2923 Note that if \a sourceParent and \a destinationParent are the same, -
2924 you must ensure that the \a destinationChild is not within the range -
2925 of \a sourceFirst and \a sourceLast + 1. You must also ensure that you -
2926 do not attempt to move a column to one of its own children or ancestors. -
2927 This method returns false if either condition is true, in which case you -
2928 should abort your move operation. -
2929 -
2930 \sa endMoveColumns() -
2931 -
2932 \since 4.6 -
2933*/ -
2934bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) -
2935{ -
2936 Q_ASSERT(sourceFirst >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2937 Q_ASSERT(sourceLast >= sourceFirst);
executed (the execution status of this line is deduced): qt_noop();
-
2938 Q_ASSERT(destinationChild >= 0);
executed (the execution status of this line is deduced): qt_noop();
-
2939 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2940 -
2941 if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)) {
partially evaluated: !d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
2942 return false;
never executed: return false;
0
2943 } -
2944 -
2945 QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast);
-
2946 sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
partially evaluated: sourceParent.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: sourceParent.row() >= destinationChild
never evaluated: sourceParent.parent() == destinationParent
0-1
2947 d->changes.push(sourceChange);
executed (the execution status of this line is deduced): d->changes.push(sourceChange);
-
2948 int destinationLast = destinationChild + (sourceLast - sourceFirst);
executed (the execution status of this line is deduced): int destinationLast = destinationChild + (sourceLast - sourceFirst);
-
2949 QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast);
-
2950 destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
partially evaluated: destinationParent.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: destinationParent.row() >= sourceLast
never evaluated: destinationParent.parent() == sourceParent
0-1
2951 d->changes.push(destinationChange);
executed (the execution status of this line is deduced): d->changes.push(destinationChange);
-
2952 -
2953 d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal);
executed (the execution status of this line is deduced): d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal);
-
2954 -
2955 emit columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal());
executed (the execution status of this line is deduced): columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal());
-
2956 return true;
executed: return true;
Execution Count:1
1
2957} -
2958 -
2959/*! -
2960 Ends a column move operation. -
2961 -
2962 When implementing a subclass, you must call this -
2963 function \e after moving data within the model's underlying data -
2964 store. -
2965 -
2966 \sa beginMoveColumns() -
2967 -
2968 \since 4.6 -
2969*/ -
2970void QAbstractItemModel::endMoveColumns() -
2971{ -
2972 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
2973 -
2974 QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change insertChange = d->changes.pop();
-
2975 QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
executed (the execution status of this line is deduced): QAbstractItemModelPrivate::Change removeChange = d->changes.pop();
-
2976 -
2977 QModelIndex adjustedSource = removeChange.parent;
executed (the execution status of this line is deduced): QModelIndex adjustedSource = removeChange.parent;
-
2978 QModelIndex adjustedDestination = insertChange.parent;
executed (the execution status of this line is deduced): QModelIndex adjustedDestination = insertChange.parent;
-
2979 -
2980 const int numMoved = removeChange.last - removeChange.first + 1;
executed (the execution status of this line is deduced): const int numMoved = removeChange.last - removeChange.first + 1;
-
2981 if (insertChange.needsAdjust)
partially evaluated: insertChange.needsAdjust
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
2982 adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer());
never executed: adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer());
0
2983 -
2984 if (removeChange.needsAdjust)
partially evaluated: removeChange.needsAdjust
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
2985 adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer());
never executed: adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer());
0
2986 -
2987 d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal);
executed (the execution status of this line is deduced): d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal);
-
2988 -
2989 emit columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal());
executed (the execution status of this line is deduced): columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal());
-
2990}
executed: }
Execution Count:1
1
2991 -
2992/*! -
2993 \fn void QAbstractItemModel::reset() -
2994 \obsolete -
2995 -
2996 Resets the model to its original state in any attached views. -
2997 -
2998 This function emits the signals modelAboutToBeReset() and modelReset(). -
2999 -
3000 \note Use beginResetModel() and endResetModel() instead whenever possible. -
3001 Use this method only if there is no way to call beginResetModel() before invalidating the model. -
3002 Otherwise it could lead to unexpected behaviour, especially when used with proxy models. -
3003 -
3004 For example, in this code both signals modelAboutToBeReset() and modelReset() -
3005 are emitted \e after the data changes: -
3006 -
3007 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 10 -
3008 -
3009 Instead you should use: -
3010 -
3011 \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 11 -
3012*/ -
3013 -
3014/*! -
3015 Begins a model reset operation. -
3016 -
3017 A reset operation resets the model to its current state in any attached views. -
3018 -
3019 \note Any views attached to this model will be reset as well. -
3020 -
3021 When a model is reset it means that any previous data reported from the -
3022 model is now invalid and has to be queried for again. This also means that -
3023 the current item and any selected items will become invalid. -
3024 -
3025 When a model radically changes its data it can sometimes be easier to just -
3026 call this function rather than emit dataChanged() to inform other -
3027 components when the underlying data source, or its structure, has changed. -
3028 -
3029 You must call this function before resetting any internal data structures in your model -
3030 or proxy model. -
3031 -
3032 This function emits the signal modelAboutToBeReset(). -
3033 -
3034 \sa modelAboutToBeReset(), modelReset(), endResetModel() -
3035 \since 4.6 -
3036*/ -
3037void QAbstractItemModel::beginResetModel() -
3038{ -
3039 emit modelAboutToBeReset(QPrivateSignal());
executed (the execution status of this line is deduced): modelAboutToBeReset(QPrivateSignal());
-
3040}
executed: }
Execution Count:6861
6861
3041 -
3042/*! -
3043 Completes a model reset operation. -
3044 -
3045 You must call this function after resetting any internal data structure in your model -
3046 or proxy model. -
3047 -
3048 This function emits the signal modelReset(). -
3049 -
3050 \sa beginResetModel() -
3051 \since 4.6 -
3052*/ -
3053void QAbstractItemModel::endResetModel() -
3054{ -
3055 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
3056 d->invalidatePersistentIndexes();
executed (the execution status of this line is deduced): d->invalidatePersistentIndexes();
-
3057 emit modelReset(QPrivateSignal());
executed (the execution status of this line is deduced): modelReset(QPrivateSignal());
-
3058}
executed: }
Execution Count:6860
6860
3059 -
3060/*! -
3061 Changes the QPersistentModelIndex that is equal to the given \a from model -
3062 index to the given \a to model index. -
3063 -
3064 If no persistent model index equal to the given \a from model index was -
3065 found, nothing is changed. -
3066 -
3067 \sa persistentIndexList(), changePersistentIndexList() -
3068*/ -
3069void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to) -
3070{ -
3071 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
3072 if (d->persistent.indexes.isEmpty())
partially evaluated: d->persistent.indexes.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
3073 return;
never executed: return;
0
3074 // find the data and reinsert it sorted -
3075 const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from);
executed (the execution status of this line is deduced): const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from);
-
3076 if (it != d->persistent.indexes.end()) {
partially evaluated: it != d->persistent.indexes.end()
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
3077 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
3078 d->persistent.indexes.erase(it);
executed (the execution status of this line is deduced): d->persistent.indexes.erase(it);
-
3079 data->index = to;
executed (the execution status of this line is deduced): data->index = to;
-
3080 if (to.isValid())
partially evaluated: to.isValid()
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
3081 d->persistent.insertMultiAtEnd(to, data);
executed: d->persistent.insertMultiAtEnd(to, data);
Execution Count:12
12
3082 else -
3083 data->model = 0;
never executed: data->model = 0;
0
3084 } -
3085}
executed: }
Execution Count:12
12
3086 -
3087/*! -
3088 \since 4.1 -
3089 -
3090 Changes the QPersistentModelIndexes that is equal to the indexes in the -
3091 given \a from model index list to the given \a to model index list. -
3092 -
3093 If no persistent model indexes equal to the indexes in the given \a from -
3094 model index list was found, nothing is changed. -
3095 -
3096 \sa persistentIndexList(), changePersistentIndex() -
3097*/ -
3098void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, -
3099 const QModelIndexList &to) -
3100{ -
3101 Q_D(QAbstractItemModel);
executed (the execution status of this line is deduced): QAbstractItemModelPrivate * const d = d_func();
-
3102 if (d->persistent.indexes.isEmpty())
evaluated: d->persistent.indexes.isEmpty()
TRUEFALSE
yes
Evaluation Count:4523
yes
Evaluation Count:556
556-4523
3103 return;
executed: return;
Execution Count:4523
4523
3104 QVector<QPersistentModelIndexData *> toBeReinserted;
executed (the execution status of this line is deduced): QVector<QPersistentModelIndexData *> toBeReinserted;
-
3105 toBeReinserted.reserve(to.count());
executed (the execution status of this line is deduced): toBeReinserted.reserve(to.count());
-
3106 for (int i = 0; i < from.count(); ++i) {
evaluated: i < from.count()
TRUEFALSE
yes
Evaluation Count:1194
yes
Evaluation Count:556
556-1194
3107 if (from.at(i) == to.at(i))
evaluated: from.at(i) == to.at(i)
TRUEFALSE
yes
Evaluation Count:592
yes
Evaluation Count:602
592-602
3108 continue;
executed: continue;
Execution Count:592
592
3109 const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i));
executed (the execution status of this line is deduced): const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i));
-
3110 if (it != d->persistent.indexes.end()) {
evaluated: it != d->persistent.indexes.end()
TRUEFALSE
yes
Evaluation Count:476
yes
Evaluation Count:126
126-476
3111 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
3112 d->persistent.indexes.erase(it);
executed (the execution status of this line is deduced): d->persistent.indexes.erase(it);
-
3113 data->index = to.at(i);
executed (the execution status of this line is deduced): data->index = to.at(i);
-
3114 if (data->index.isValid())
partially evaluated: data->index.isValid()
TRUEFALSE
yes
Evaluation Count:476
no
Evaluation Count:0
0-476
3115 toBeReinserted << data;
executed: toBeReinserted << data;
Execution Count:476
476
3116 else -
3117 data->model = 0;
never executed: data->model = 0;
0
3118 } -
3119 }
executed: }
Execution Count:602
602
3120 -
3121 for (QVector<QPersistentModelIndexData *>::const_iterator it = toBeReinserted.constBegin();
executed (the execution status of this line is deduced): for (QVector<QPersistentModelIndexData *>::const_iterator it = toBeReinserted.constBegin();
-
3122 it != toBeReinserted.constEnd() ; ++it) {
evaluated: it != toBeReinserted.constEnd()
TRUEFALSE
yes
Evaluation Count:476
yes
Evaluation Count:556
476-556
3123 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
3124 d->persistent.insertMultiAtEnd(data->index, data);
executed (the execution status of this line is deduced): d->persistent.insertMultiAtEnd(data->index, data);
-
3125 }
executed: }
Execution Count:476
476
3126}
executed: }
Execution Count:556
556
3127 -
3128/*! -
3129 \since 4.2 -
3130 -
3131 Returns the list of indexes stored as persistent indexes in the model. -
3132*/ -
3133QModelIndexList QAbstractItemModel::persistentIndexList() const -
3134{ -
3135 Q_D(const QAbstractItemModel);
executed (the execution status of this line is deduced): const QAbstractItemModelPrivate * const d = d_func();
-
3136 QModelIndexList result;
executed (the execution status of this line is deduced): QModelIndexList result;
-
3137 for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin();
executed (the execution status of this line is deduced): for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin();
-
3138 it != d->persistent.indexes.constEnd(); ++it) {
evaluated: it != d->persistent.indexes.constEnd()
TRUEFALSE
yes
Evaluation Count:560
yes
Evaluation Count:793
560-793
3139 QPersistentModelIndexData *data = *it;
executed (the execution status of this line is deduced): QPersistentModelIndexData *data = *it;
-
3140 result.append(data->index);
executed (the execution status of this line is deduced): result.append(data->index);
-
3141 }
executed: }
Execution Count:560
560
3142 return result;
executed: return result;
Execution Count:793
793
3143} -
3144 -
3145 -
3146/*! -
3147 \class QAbstractTableModel -
3148 \inmodule QtCore -
3149 \brief The QAbstractTableModel class provides an abstract model that can be -
3150 subclassed to create table models. -
3151 -
3152 \ingroup model-view -
3153 -
3154 QAbstractTableModel provides a standard interface for models that represent -
3155 their data as a two-dimensional array of items. It is not used directly, -
3156 but must be subclassed. -
3157 -
3158 Since the model provides a more specialized interface than -
3159 QAbstractItemModel, it is not suitable for use with tree views, although it -
3160 can be used to provide data to a QListView. If you need to represent a -
3161 simple list of items, and only need a model to contain a single column of -
3162 data, subclassing the QAbstractListModel may be more appropriate. -
3163 -
3164 The rowCount() and columnCount() functions return the dimensions of the -
3165 table. To retrieve a model index corresponding to an item in the model, use -
3166 index() and provide only the row and column numbers. -
3167 -
3168 \section1 Subclassing -
3169 -
3170 When subclassing QAbstractTableModel, you must implement rowCount(), -
3171 columnCount(), and data(). Default implementations of the index() and -
3172 parent() functions are provided by QAbstractTableModel. -
3173 Well behaved models will also implement headerData(). -
3174 -
3175 Editable models need to implement setData(), and implement flags() to -
3176 return a value containing -
3177 \l{Qt::ItemFlags}{Qt::ItemIsEditable}. -
3178 -
3179 Models that provide interfaces to resizable data structures can -
3180 provide implementations of insertRows(), removeRows(), insertColumns(), -
3181 and removeColumns(). When implementing these functions, it is -
3182 important to call the appropriate functions so that all connected views -
3183 are aware of any changes: -
3184 -
3185 \list -
3186 \li An insertRows() implementation must call beginInsertRows() -
3187 \e before inserting new rows into the data structure, and it must -
3188 call endInsertRows() \e{immediately afterwards}. -
3189 \li An insertColumns() implementation must call beginInsertColumns() -
3190 \e before inserting new columns into the data structure, and it must -
3191 call endInsertColumns() \e{immediately afterwards}. -
3192 \li A removeRows() implementation must call beginRemoveRows() -
3193 \e before the rows are removed from the data structure, and it must -
3194 call endRemoveRows() \e{immediately afterwards}. -
3195 \li A removeColumns() implementation must call beginRemoveColumns() -
3196 \e before the columns are removed from the data structure, and it must -
3197 call endRemoveColumns() \e{immediately afterwards}. -
3198 \endlist -
3199 -
3200 \note Some general guidelines for subclassing models are available in the -
3201 \l{Model Subclassing Reference}. -
3202 -
3203 \note -
3204 -
3205 \sa {Model Classes}, QAbstractItemModel, QAbstractListModel, -
3206 {Pixelator Example} -
3207*/ -
3208 -
3209/*! -
3210 Constructs an abstract table model for the given \a parent. -
3211*/ -
3212 -
3213QAbstractTableModel::QAbstractTableModel(QObject *parent) -
3214 : QAbstractItemModel(parent) -
3215{ -
3216 -
3217}
executed: }
Execution Count:405
405
3218 -
3219/*! -
3220 \internal -
3221 -
3222 Constructs an abstract table model with \a dd and the given \a parent. -
3223*/ -
3224 -
3225QAbstractTableModel::QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent) -
3226 : QAbstractItemModel(dd, parent) -
3227{ -
3228 -
3229}
executed: }
Execution Count:287
287
3230 -
3231/*! -
3232 Destroys the abstract table model. -
3233*/ -
3234 -
3235QAbstractTableModel::~QAbstractTableModel() -
3236{ -
3237 -
3238} -
3239 -
3240/*! -
3241 \fn QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const -
3242 -
3243 Returns the index of the data in \a row and \a column with \a parent. -
3244 -
3245 \sa parent() -
3246*/ -
3247 -
3248QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent) const -
3249{ -
3250 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
executed: return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
Execution Count:55659
55659
3251} -
3252 -
3253/*! -
3254 \fn QModelIndex QAbstractTableModel::parent(const QModelIndex &index) const -
3255 -
3256 Returns the parent of the model item with the given \a index. -
3257 -
3258 \sa index(), hasChildren() -
3259*/ -
3260 -
3261QModelIndex QAbstractTableModel::parent(const QModelIndex &) const -
3262{ -
3263 return QModelIndex();
executed: return QModelIndex();
Execution Count:42276
42276
3264} -
3265 -
3266bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const -
3267{ -
3268 if (parent.model() == this || !parent.isValid())
evaluated: parent.model() == this
TRUEFALSE
yes
Evaluation Count:2453
yes
Evaluation Count:254
partially evaluated: !parent.isValid()
TRUEFALSE
yes
Evaluation Count:254
no
Evaluation Count:0
0-2453
3269 return rowCount(parent) > 0 && columnCount(parent) > 0;
executed: return rowCount(parent) > 0 && columnCount(parent) > 0;
Execution Count:2707
2707
3270 return false;
never executed: return false;
0
3271} -
3272 -
3273/*! -
3274 \class QAbstractListModel -
3275 \inmodule QtCore -
3276 \brief The QAbstractListModel class provides an abstract model that can be -
3277 subclassed to create one-dimensional list models. -
3278 -
3279 \ingroup model-view -
3280 -
3281 QAbstractListModel provides a standard interface for models that represent -
3282 their data as a simple non-hierarchical sequence of items. It is not used -
3283 directly, but must be subclassed. -
3284 -
3285 Since the model provides a more specialized interface than -
3286 QAbstractItemModel, it is not suitable for use with tree views; you will -
3287 need to subclass QAbstractItemModel if you want to provide a model for -
3288 that purpose. If you need to use a number of list models to manage data, -
3289 it may be more appropriate to subclass QAbstractTableModel class instead. -
3290 -
3291 Simple models can be created by subclassing this class and implementing -
3292 the minimum number of required functions. For example, we could implement -
3293 a simple read-only QStringList-based model that provides a list of strings -
3294 to a QListView widget. In such a case, we only need to implement the -
3295 rowCount() function to return the number of items in the list, and the -
3296 data() function to retrieve items from the list. -
3297 -
3298 Since the model represents a one-dimensional structure, the rowCount() -
3299 function returns the total number of items in the model. The columnCount() -
3300 function is implemented for interoperability with all kinds of views, but -
3301 by default informs views that the model contains only one column. -
3302 -
3303 \section1 Subclassing -
3304 -
3305 When subclassing QAbstractListModel, you must provide implementations -
3306 of the rowCount() and data() functions. Well behaved models also provide -
3307 a headerData() implementation. -
3308 -
3309 For editable list models, you must also provide an implementation of -
3310 setData(), implement the flags() function so that it returns a value -
3311 containing \l{Qt::ItemFlags}{Qt::ItemIsEditable}. -
3312 -
3313 Note that QAbstractListModel provides a default implementation of -
3314 columnCount() that informs views that there is only a single column -
3315 of items in this model. -
3316 -
3317 Models that provide interfaces to resizable list-like data structures -
3318 can provide implementations of insertRows() and removeRows(). When -
3319 implementing these functions, it is important to call the appropriate -
3320 functions so that all connected views are aware of any changes: -
3321 -
3322 \list -
3323 \li An insertRows() implementation must call beginInsertRows() -
3324 \e before inserting new rows into the data structure, and it must -
3325 call endInsertRows() \e{immediately afterwards}. -
3326 \li A removeRows() implementation must call beginRemoveRows() -
3327 \e before the rows are removed from the data structure, and it must -
3328 call endRemoveRows() \e{immediately afterwards}. -
3329 \endlist -
3330 -
3331 \note Some general guidelines for subclassing models are available in the -
3332 \l{Model Subclassing Reference}. -
3333 -
3334 \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemView, -
3335 QAbstractTableModel, {Item Views Puzzle Example} -
3336*/ -
3337 -
3338/*! -
3339 Constructs an abstract list model with the given \a parent. -
3340*/ -
3341 -
3342QAbstractListModel::QAbstractListModel(QObject *parent) -
3343 : QAbstractItemModel(parent) -
3344{ -
3345 -
3346}
executed: }
Execution Count:503
503
3347 -
3348/*! -
3349 \internal -
3350 -
3351 Constructs an abstract list model with \a dd and the given \a parent. -
3352*/ -
3353 -
3354QAbstractListModel::QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent) -
3355 : QAbstractItemModel(dd, parent) -
3356{ -
3357 -
3358}
never executed: }
0
3359 -
3360/*! -
3361 Destroys the abstract list model. -
3362*/ -
3363 -
3364QAbstractListModel::~QAbstractListModel() -
3365{ -
3366 -
3367} -
3368 -
3369/*! -
3370 \fn QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const -
3371 -
3372 Returns the index of the data in \a row and \a column with \a parent. -
3373 -
3374 \sa parent() -
3375*/ -
3376 -
3377QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &parent) const -
3378{ -
3379 return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
executed: return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
Execution Count:92779
92779
3380} -
3381 -
3382/*! -
3383 Returns the parent of the model item with the given \a index. -
3384 -
3385 \sa index(), hasChildren() -
3386*/ -
3387 -
3388QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const -
3389{ -
3390 return QModelIndex();
executed: return QModelIndex();
Execution Count:32744
32744
3391} -
3392 -
3393/*! -
3394 \internal -
3395 -
3396 Returns the number of columns in the list with the given \a parent. -
3397 -
3398 \sa rowCount() -
3399*/ -
3400 -
3401int QAbstractListModel::columnCount(const QModelIndex &parent) const -
3402{ -
3403 return parent.isValid() ? 0 : 1;
executed: return parent.isValid() ? 0 : 1;
Execution Count:88191
88191
3404} -
3405 -
3406bool QAbstractListModel::hasChildren(const QModelIndex &parent) const -
3407{ -
3408 return parent.isValid() ? false : (rowCount() > 0);
executed: return parent.isValid() ? false : (rowCount() > 0);
Execution Count:502
502
3409} -
3410 -
3411/*! -
3412 \typedef QModelIndexList -
3413 \relates QModelIndex -
3414 -
3415 Synonym for QList<QModelIndex>. -
3416*/ -
3417 -
3418/*! -
3419 \reimp -
3420*/ -
3421bool QAbstractTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, -
3422 int row, int column, const QModelIndex &parent) -
3423{ -
3424 if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
never evaluated: !data
never evaluated: action == Qt::CopyAction
never evaluated: action == Qt::MoveAction
0
3425 return false;
never executed: return false;
0
3426 -
3427 QStringList types = mimeTypes();
never executed (the execution status of this line is deduced): QStringList types = mimeTypes();
-
3428 if (types.isEmpty())
never evaluated: types.isEmpty()
0
3429 return false;
never executed: return false;
0
3430 QString format = types.at(0);
never executed (the execution status of this line is deduced): QString format = types.at(0);
-
3431 if (!data->hasFormat(format))
never evaluated: !data->hasFormat(format)
0
3432 return false;
never executed: return false;
0
3433 -
3434 QByteArray encoded = data->data(format);
never executed (the execution status of this line is deduced): QByteArray encoded = data->data(format);
-
3435 QDataStream stream(&encoded, QIODevice::ReadOnly);
never executed (the execution status of this line is deduced): QDataStream stream(&encoded, QIODevice::ReadOnly);
-
3436 -
3437 // if the drop is on an item, replace the data in the items -
3438 if (parent.isValid() && row == -1 && column == -1) {
never evaluated: parent.isValid()
never evaluated: row == -1
never evaluated: column == -1
0
3439 int top = INT_MAX;
never executed (the execution status of this line is deduced): int top = 2147483647;
-
3440 int left = INT_MAX;
never executed (the execution status of this line is deduced): int left = 2147483647;
-
3441 QVector<int> rows, columns;
never executed (the execution status of this line is deduced): QVector<int> rows, columns;
-
3442 QVector<QMap<int, QVariant> > data;
never executed (the execution status of this line is deduced): QVector<QMap<int, QVariant> > data;
-
3443 -
3444 while (!stream.atEnd()) {
never evaluated: !stream.atEnd()
0
3445 int r, c;
never executed (the execution status of this line is deduced): int r, c;
-
3446 QMap<int, QVariant> v;
never executed (the execution status of this line is deduced): QMap<int, QVariant> v;
-
3447 stream >> r >> c >> v;
never executed (the execution status of this line is deduced): stream >> r >> c >> v;
-
3448 rows.append(r);
never executed (the execution status of this line is deduced): rows.append(r);
-
3449 columns.append(c);
never executed (the execution status of this line is deduced): columns.append(c);
-
3450 data.append(v);
never executed (the execution status of this line is deduced): data.append(v);
-
3451 top = qMin(r, top);
never executed (the execution status of this line is deduced): top = qMin(r, top);
-
3452 left = qMin(c, left);
never executed (the execution status of this line is deduced): left = qMin(c, left);
-
3453 }
never executed: }
0
3454 -
3455 for (int i = 0; i < data.size(); ++i) {
never evaluated: i < data.size()
0
3456 int r = (rows.at(i) - top) + parent.row();
never executed (the execution status of this line is deduced): int r = (rows.at(i) - top) + parent.row();
-
3457 int c = (columns.at(i) - left) + parent.column();
never executed (the execution status of this line is deduced): int c = (columns.at(i) - left) + parent.column();
-
3458 if (hasIndex(r, c))
never evaluated: hasIndex(r, c)
0
3459 setItemData(index(r, c), data.at(i));
never executed: setItemData(index(r, c), data.at(i));
0
3460 }
never executed: }
0
3461 -
3462 return true;
never executed: return true;
0
3463 } -
3464 -
3465 // otherwise insert new rows for the data -
3466 return decodeData(row, column, parent, stream);
never executed: return decodeData(row, column, parent, stream);
0
3467} -
3468 -
3469/*! -
3470 \reimp -
3471*/ -
3472bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, -
3473 int row, int column, const QModelIndex &parent) -
3474{ -
3475 if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
never evaluated: !data
never evaluated: action == Qt::CopyAction
never evaluated: action == Qt::MoveAction
0
3476 return false;
never executed: return false;
0
3477 -
3478 QStringList types = mimeTypes();
never executed (the execution status of this line is deduced): QStringList types = mimeTypes();
-
3479 if (types.isEmpty())
never evaluated: types.isEmpty()
0
3480 return false;
never executed: return false;
0
3481 QString format = types.at(0);
never executed (the execution status of this line is deduced): QString format = types.at(0);
-
3482 if (!data->hasFormat(format))
never evaluated: !data->hasFormat(format)
0
3483 return false;
never executed: return false;
0
3484 -
3485 QByteArray encoded = data->data(format);
never executed (the execution status of this line is deduced): QByteArray encoded = data->data(format);
-
3486 QDataStream stream(&encoded, QIODevice::ReadOnly);
never executed (the execution status of this line is deduced): QDataStream stream(&encoded, QIODevice::ReadOnly);
-
3487 -
3488 // if the drop is on an item, replace the data in the items -
3489 if (parent.isValid() && row == -1 && column == -1) {
never evaluated: parent.isValid()
never evaluated: row == -1
never evaluated: column == -1
0
3490 int top = INT_MAX;
never executed (the execution status of this line is deduced): int top = 2147483647;
-
3491 int left = INT_MAX;
never executed (the execution status of this line is deduced): int left = 2147483647;
-
3492 QVector<int> rows, columns;
never executed (the execution status of this line is deduced): QVector<int> rows, columns;
-
3493 QVector<QMap<int, QVariant> > data;
never executed (the execution status of this line is deduced): QVector<QMap<int, QVariant> > data;
-
3494 -
3495 while (!stream.atEnd()) {
never evaluated: !stream.atEnd()
0
3496 int r, c;
never executed (the execution status of this line is deduced): int r, c;
-
3497 QMap<int, QVariant> v;
never executed (the execution status of this line is deduced): QMap<int, QVariant> v;
-
3498 stream >> r >> c >> v;
never executed (the execution status of this line is deduced): stream >> r >> c >> v;
-
3499 rows.append(r);
never executed (the execution status of this line is deduced): rows.append(r);
-
3500 columns.append(c);
never executed (the execution status of this line is deduced): columns.append(c);
-
3501 data.append(v);
never executed (the execution status of this line is deduced): data.append(v);
-
3502 top = qMin(r, top);
never executed (the execution status of this line is deduced): top = qMin(r, top);
-
3503 left = qMin(c, left);
never executed (the execution status of this line is deduced): left = qMin(c, left);
-
3504 }
never executed: }
0
3505 -
3506 for (int i = 0; i < data.size(); ++i) {
never evaluated: i < data.size()
0
3507 int r = (rows.at(i) - top) + parent.row();
never executed (the execution status of this line is deduced): int r = (rows.at(i) - top) + parent.row();
-
3508 if (columns.at(i) == left && hasIndex(r, 0))
never evaluated: columns.at(i) == left
never evaluated: hasIndex(r, 0)
0
3509 setItemData(index(r), data.at(i));
never executed: setItemData(index(r), data.at(i));
0
3510 }
never executed: }
0
3511 -
3512 return true;
never executed: return true;
0
3513 } -
3514 -
3515 if (row == -1)
never evaluated: row == -1
0
3516 row = rowCount(parent);
never executed: row = rowCount(parent);
0
3517 -
3518 // otherwise insert new rows for the data -
3519 return decodeData(row, column, parent, stream);
never executed: return decodeData(row, column, parent, stream);
0
3520} -
3521 -
3522/*! -
3523 \fn QAbstractItemModel::modelAboutToBeReset() -
3524 \since 4.2 -
3525 -
3526 This signal is emitted when reset() is called, before the model's internal -
3527 state (e.g. persistent model indexes) has been invalidated. -
3528 -
3529 \sa beginResetModel(), modelReset() -
3530*/ -
3531 -
3532/*! -
3533 \fn QAbstractItemModel::modelReset() -
3534 \since 4.1 -
3535 -
3536 This signal is emitted when reset() or endResetModel() is called, after the -
3537 model's internal state (e.g. persistent model indexes) has been invalidated. -
3538 -
3539 Note that if a model is reset it should be considered that all information -
3540 previously retrieved from it is invalid. This includes but is not limited -
3541 to the rowCount() and columnCount(), flags(), data retrieved through data(), -
3542 and roleNames(). -
3543 -
3544 \sa endResetModel(), modelAboutToBeReset() -
3545*/ -
3546 -
3547/*! -
3548 \fn bool QModelIndex::operator<(const QModelIndex &other) const -
3549 \since 4.1 -
3550 -
3551 Returns true if this model index is smaller than the \a other -
3552 model index; otherwise returns false. -
3553 -
3554 The less than calculation is not directly useful to developers - the way that indexes -
3555 with different parents compare is not defined. This operator only exists so that the -
3556 class can be used with QMap. -
3557*/ -
3558 -
3559/*! -
3560 \fn uint qHash(const QPersistentModelIndex &index, uint seed = 0) -
3561 \since 5.0 -
3562 \relates QPersistentModelIndex -
3563 -
3564 Returns a hash of the QPersistentModelIndex \a index, using \a seed to -
3565 seed the calculation. -
3566*/ -
3567 -
3568 -
3569/*! -
3570 \internal -
3571 QHash::insertMulti insert the value before the old value. and find() return the new value. -
3572 We need insertMultiAtEnd because we don't want to overwrite the old one, which should be removed later -
3573 -
3574 There should be only one instance QPersistentModelIndexData per index, but in some intermediate state there may be -
3575 severals of PersistantModelIndex pointing to the same index, but one is already updated, and the other one is not. -
3576 This make sure than when updating the first one we don't overwrite the second one in the hash, and the second one -
3577 will be updated right later. -
3578 */ -
3579void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& key, QPersistentModelIndexData *data) -
3580{ -
3581 QHash<QModelIndex,QPersistentModelIndexData *>::iterator newIt =
executed (the execution status of this line is deduced): QHash<QModelIndex,QPersistentModelIndexData *>::iterator newIt =
-
3582 indexes.insertMulti(key, data);
executed (the execution status of this line is deduced): indexes.insertMulti(key, data);
-
3583 QHash<QModelIndex,QPersistentModelIndexData *>::iterator it = newIt + 1;
executed (the execution status of this line is deduced): QHash<QModelIndex,QPersistentModelIndexData *>::iterator it = newIt + 1;
-
3584 while (it != indexes.end() && it.key() == key) {
evaluated: it != indexes.end()
TRUEFALSE
yes
Evaluation Count:6405
yes
Evaluation Count:2461
evaluated: it.key() == key
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:6389
16-6405
3585 qSwap(*newIt,*it);
executed (the execution status of this line is deduced): qSwap(*newIt,*it);
-
3586 newIt = it;
executed (the execution status of this line is deduced): newIt = it;
-
3587 ++it;
executed (the execution status of this line is deduced): ++it;
-
3588 }
executed: }
Execution Count:16
16
3589}
executed: }
Execution Count:8850
8850
3590 -
3591QT_END_NAMESPACE -
3592 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial