Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qabstractitemmodel.h" | - | ||||||||||||||||||||||||
35 | #include <private/qabstractitemmodel_p.h> | - | ||||||||||||||||||||||||
36 | #include <qdatastream.h> | - | ||||||||||||||||||||||||
37 | #include <qstringlist.h> | - | ||||||||||||||||||||||||
38 | #include <qsize.h> | - | ||||||||||||||||||||||||
39 | #include <qmimedata.h> | - | ||||||||||||||||||||||||
40 | #include <qdebug.h> | - | ||||||||||||||||||||||||
41 | #include <qvector.h> | - | ||||||||||||||||||||||||
42 | #include <qstack.h> | - | ||||||||||||||||||||||||
43 | #include <qbitarray.h> | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | #include <limits.h> | - | ||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||
49 | QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index) | - | ||||||||||||||||||||||||
50 | { | - | ||||||||||||||||||||||||
51 | Q_ASSERT(index.isValid()); // we will _never_ insert an invalid index in the list | - | ||||||||||||||||||||||||
52 | QPersistentModelIndexData *d = 0; | - | ||||||||||||||||||||||||
53 | QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model()); | - | ||||||||||||||||||||||||
54 | QHash<QModelIndex, QPersistentModelIndexData *> &indexes = model->d_func()->persistent.indexes; | - | ||||||||||||||||||||||||
55 | const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = indexes.find(index); | - | ||||||||||||||||||||||||
56 | if (it != indexes.end()) {
| 25692-81850 | ||||||||||||||||||||||||
57 | d = (*it); | - | ||||||||||||||||||||||||
58 | } else { executed 81850 times by 34 tests: end of block Executed by:
| 81850 | ||||||||||||||||||||||||
59 | d = new QPersistentModelIndexData(index); | - | ||||||||||||||||||||||||
60 | indexes.insert(index, d); | - | ||||||||||||||||||||||||
61 | } executed 25692 times by 41 tests: end of block Executed by:
| 25692 | ||||||||||||||||||||||||
62 | Q_ASSERT(d); | - | ||||||||||||||||||||||||
63 | return d; executed 107542 times by 41 tests: return d; Executed by:
| 107542 | ||||||||||||||||||||||||
64 | } | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) | - | ||||||||||||||||||||||||
67 | { | - | ||||||||||||||||||||||||
68 | Q_ASSERT(data); | - | ||||||||||||||||||||||||
69 | Q_ASSERT(data->ref.load() == 0); | - | ||||||||||||||||||||||||
70 | QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->model); | - | ||||||||||||||||||||||||
71 | // a valid persistent model index with a null model pointer can only happen if the model was destroyed | - | ||||||||||||||||||||||||
72 | if (model) {
| 4526-21152 | ||||||||||||||||||||||||
73 | QAbstractItemModelPrivate *p = model->d_func(); | - | ||||||||||||||||||||||||
74 | Q_ASSERT(p); | - | ||||||||||||||||||||||||
75 | p->removePersistentIndexData(data); | - | ||||||||||||||||||||||||
76 | } executed 21152 times by 38 tests: end of block Executed by:
| 21152 | ||||||||||||||||||||||||
77 | delete data; | - | ||||||||||||||||||||||||
78 | } executed 25678 times by 43 tests: end of block Executed by:
| 25678 | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | /*! | - | ||||||||||||||||||||||||
81 | \class QPersistentModelIndex | - | ||||||||||||||||||||||||
82 | \inmodule QtCore | - | ||||||||||||||||||||||||
83 | \ingroup shared | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | \brief The QPersistentModelIndex class is used to locate data in a data model. | - | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | \ingroup model-view | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | A QPersistentModelIndex is a model index that can be stored by an | - | ||||||||||||||||||||||||
90 | application, and later used to access information in a model. | - | ||||||||||||||||||||||||
91 | Unlike the QModelIndex class, it is safe to store a | - | ||||||||||||||||||||||||
92 | QPersistentModelIndex since the model will ensure that references | - | ||||||||||||||||||||||||
93 | to items will continue to be valid as long as they can be accessed | - | ||||||||||||||||||||||||
94 | by the model. | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | It is good practice to check that persistent model indexes are valid | - | ||||||||||||||||||||||||
97 | before using them. | - | ||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | \sa {Model/View Programming}, QModelIndex, QAbstractItemModel | - | ||||||||||||||||||||||||
100 | */ | - | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | /*! | - | ||||||||||||||||||||||||
103 | \fn QPersistentModelIndex::QPersistentModelIndex(QPersistentModelIndex &&other) | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | Move-constructs a QPersistentModelIndex instance, making it point at the same | - | ||||||||||||||||||||||||
106 | object that \a other was pointing to. | - | ||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | \since 5.2 | - | ||||||||||||||||||||||||
109 | */ | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | /*! | - | ||||||||||||||||||||||||
112 | \fn QPersistentModelIndex &QPersistentModelIndex::operator=(QPersistentModelIndex &&other) | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | Move-assigns \a other to this QPersistentModelIndex instance. | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | \since 5.2 | - | ||||||||||||||||||||||||
117 | */ | - | ||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | /*! | - | ||||||||||||||||||||||||
121 | \fn QPersistentModelIndex::QPersistentModelIndex() | - | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | \internal | - | ||||||||||||||||||||||||
124 | */ | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | QPersistentModelIndex::QPersistentModelIndex() | - | ||||||||||||||||||||||||
127 | : d(0) | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | } executed 37895 times by 49 tests: end of block Executed by:
| 37895 | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | /*! | - | ||||||||||||||||||||||||
132 | \fn QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) | - | ||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | Creates a new QPersistentModelIndex that is a copy of the \a other persistent | - | ||||||||||||||||||||||||
135 | model index. | - | ||||||||||||||||||||||||
136 | */ | - | ||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) | - | ||||||||||||||||||||||||
139 | : d(other.d) | - | ||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||
141 | if (d) d->ref.ref(); executed 85101 times by 34 tests: d->ref.ref(); Executed by:
| 1764-85101 | ||||||||||||||||||||||||
142 | } executed 86865 times by 37 tests: end of block Executed by:
| 86865 | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | /*! | - | ||||||||||||||||||||||||
145 | Creates a new QPersistentModelIndex that is a copy of the model \a index. | - | ||||||||||||||||||||||||
146 | */ | - | ||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index) | - | ||||||||||||||||||||||||
149 | : d(0) | - | ||||||||||||||||||||||||
150 | { | - | ||||||||||||||||||||||||
151 | if (index.isValid()) {
| 612-99822 | ||||||||||||||||||||||||
152 | d = QPersistentModelIndexData::create(index); | - | ||||||||||||||||||||||||
153 | d->ref.ref(); | - | ||||||||||||||||||||||||
154 | } executed 99822 times by 41 tests: end of block Executed by:
| 99822 | ||||||||||||||||||||||||
155 | } executed 100434 times by 43 tests: end of block Executed by:
| 100434 | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | /*! | - | ||||||||||||||||||||||||
158 | \fn QPersistentModelIndex::~QPersistentModelIndex() | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | \internal | - | ||||||||||||||||||||||||
161 | */ | - | ||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||
163 | QPersistentModelIndex::~QPersistentModelIndex() | - | ||||||||||||||||||||||||
164 | { | - | ||||||||||||||||||||||||
165 | if (d && !d->ref.deref()) {
| 17662-187982 | ||||||||||||||||||||||||
166 | QPersistentModelIndexData::destroy(d); | - | ||||||||||||||||||||||||
167 | d = 0; | - | ||||||||||||||||||||||||
168 | } executed 17662 times by 43 tests: end of block Executed by:
| 17662 | ||||||||||||||||||||||||
169 | } executed 222524 times by 53 tests: end of block Executed by:
| 222524 | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | /*! | - | ||||||||||||||||||||||||
172 | Returns \c{true} if this persistent model index is equal to the \a other | - | ||||||||||||||||||||||||
173 | persistent model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | All values in the persistent model index are used when comparing | - | ||||||||||||||||||||||||
176 | with another persistent model index. | - | ||||||||||||||||||||||||
177 | */ | - | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | bool QPersistentModelIndex::operator==(const QPersistentModelIndex &other) const | - | ||||||||||||||||||||||||
180 | { | - | ||||||||||||||||||||||||
181 | if (d && other.d)
| 703-41174 | ||||||||||||||||||||||||
182 | return d->index == other.d->index; executed 39583 times by 27 tests: return d->index == other.d->index; Executed by:
| 39583 | ||||||||||||||||||||||||
183 | return d == other.d; executed 2294 times by 15 tests: return d == other.d; Executed by:
| 2294 | ||||||||||||||||||||||||
184 | } | - | ||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||
186 | /*! | - | ||||||||||||||||||||||||
187 | \since 4.1 | - | ||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||
189 | Returns \c{true} if this persistent model index is smaller than the \a other | - | ||||||||||||||||||||||||
190 | persistent model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | All values in the persistent model index are used when comparing | - | ||||||||||||||||||||||||
193 | with another persistent model index. | - | ||||||||||||||||||||||||
194 | */ | - | ||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||
196 | bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const | - | ||||||||||||||||||||||||
197 | { | - | ||||||||||||||||||||||||
198 | if (d && other.d)
| 0-1896 | ||||||||||||||||||||||||
199 | return d->index < other.d->index; executed 1896 times by 8 tests: return d->index < other.d->index; Executed by:
| 1896 | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | return d < other.d; never executed: return d < other.d; | 0 | ||||||||||||||||||||||||
202 | } | - | ||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | /*! | - | ||||||||||||||||||||||||
205 | \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &other) const | - | ||||||||||||||||||||||||
206 | \since 4.2 | - | ||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||
208 | Returns \c{true} if this persistent model index is not equal to the \a | - | ||||||||||||||||||||||||
209 | other persistent model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
210 | */ | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | /*! | - | ||||||||||||||||||||||||
213 | Sets the persistent model index to refer to the same item in a model | - | ||||||||||||||||||||||||
214 | as the \a other persistent model index. | - | ||||||||||||||||||||||||
215 | */ | - | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIndex &other) | - | ||||||||||||||||||||||||
218 | { | - | ||||||||||||||||||||||||
219 | if (d == other.d)
| 152-14713 | ||||||||||||||||||||||||
220 | return *this; executed 152 times by 10 tests: return *this; Executed by:
| 152 | ||||||||||||||||||||||||
221 | if (d && !d->ref.deref())
| 282-14431 | ||||||||||||||||||||||||
222 | QPersistentModelIndexData::destroy(d); executed 5981 times by 8 tests: QPersistentModelIndexData::destroy(d); Executed by:
| 5981 | ||||||||||||||||||||||||
223 | d = other.d; | - | ||||||||||||||||||||||||
224 | if (d) d->ref.ref(); executed 14696 times by 21 tests: d->ref.ref(); Executed by:
| 17-14696 | ||||||||||||||||||||||||
225 | return *this; executed 14713 times by 21 tests: return *this; Executed by:
| 14713 | ||||||||||||||||||||||||
226 | } | - | ||||||||||||||||||||||||
227 | /*! | - | ||||||||||||||||||||||||
228 | \fn void QPersistentModelIndex::swap(QPersistentModelIndex &other) | - | ||||||||||||||||||||||||
229 | \since 5.0 | - | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | Swaps this persistent modelindex with \a other. This function is | - | ||||||||||||||||||||||||
232 | very fast and never fails. | - | ||||||||||||||||||||||||
233 | */ | - | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | /*! | - | ||||||||||||||||||||||||
236 | Sets the persistent model index to refer to the same item in a model | - | ||||||||||||||||||||||||
237 | as the \a other model index. | - | ||||||||||||||||||||||||
238 | */ | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other) | - | ||||||||||||||||||||||||
241 | { | - | ||||||||||||||||||||||||
242 | if (d && !d->ref.deref())
| 2035-22786 | ||||||||||||||||||||||||
243 | QPersistentModelIndexData::destroy(d); executed 2035 times by 26 tests: QPersistentModelIndexData::destroy(d); Executed by:
| 2035 | ||||||||||||||||||||||||
244 | if (other.isValid()) {
| 7720-19966 | ||||||||||||||||||||||||
245 | d = QPersistentModelIndexData::create(other); | - | ||||||||||||||||||||||||
246 | if (d) d->ref.ref(); executed 7720 times by 32 tests: d->ref.ref(); Executed by:
| 0-7720 | ||||||||||||||||||||||||
247 | } else { executed 7720 times by 32 tests: end of block Executed by:
| 7720 | ||||||||||||||||||||||||
248 | d = 0; | - | ||||||||||||||||||||||||
249 | } executed 19966 times by 43 tests: end of block Executed by:
| 19966 | ||||||||||||||||||||||||
250 | return *this; executed 27686 times by 44 tests: return *this; Executed by:
| 27686 | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | /*! | - | ||||||||||||||||||||||||
254 | \fn QPersistentModelIndex::operator const QModelIndex&() const | - | ||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||
256 | Cast operator that returns a const QModelIndex&. | - | ||||||||||||||||||||||||
257 | */ | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | QPersistentModelIndex::operator const QModelIndex&() const | - | ||||||||||||||||||||||||
260 | { | - | ||||||||||||||||||||||||
261 | static const QModelIndex invalid; | - | ||||||||||||||||||||||||
262 | if (d)
| 112865-524411 | ||||||||||||||||||||||||
263 | return d->index; executed 112865 times by 40 tests: return d->index; Executed by:
| 112865 | ||||||||||||||||||||||||
264 | return invalid; executed 524411 times by 48 tests: return invalid; Executed by:
| 524411 | ||||||||||||||||||||||||
265 | } | - | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | /*! | - | ||||||||||||||||||||||||
268 | \fn bool QPersistentModelIndex::operator==(const QModelIndex &other) const | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | Returns \c{true} if this persistent model index refers to the same location as | - | ||||||||||||||||||||||||
271 | the \a other model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
272 | - | |||||||||||||||||||||||||
273 | All values in the persistent model index are used when comparing with | - | ||||||||||||||||||||||||
274 | another model index. | - | ||||||||||||||||||||||||
275 | */ | - | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | bool QPersistentModelIndex::operator==(const QModelIndex &other) const | - | ||||||||||||||||||||||||
278 | { | - | ||||||||||||||||||||||||
279 | if (d)
| 809-1842 | ||||||||||||||||||||||||
280 | return d->index == other; executed 809 times by 9 tests: return d->index == other; Executed by:
| 809 | ||||||||||||||||||||||||
281 | return !other.isValid(); executed 1842 times by 22 tests: return !other.isValid(); Executed by:
| 1842 | ||||||||||||||||||||||||
282 | } | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | /*! | - | ||||||||||||||||||||||||
285 | \fn bool QPersistentModelIndex::operator!=(const QModelIndex &other) const | - | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | Returns \c{true} if this persistent model index does not refer to the same | - | ||||||||||||||||||||||||
288 | location as the \a other model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
289 | */ | - | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | bool QPersistentModelIndex::operator!=(const QModelIndex &other) const | - | ||||||||||||||||||||||||
292 | { | - | ||||||||||||||||||||||||
293 | if (d)
| 2-179 | ||||||||||||||||||||||||
294 | return d->index != other; executed 179 times by 3 tests: return d->index != other; Executed by:
| 179 | ||||||||||||||||||||||||
295 | return other.isValid(); executed 2 times by 1 test: return other.isValid(); Executed by:
| 2 | ||||||||||||||||||||||||
296 | } | - | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | /*! | - | ||||||||||||||||||||||||
299 | \fn int QPersistentModelIndex::row() const | - | ||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | Returns the row this persistent model index refers to. | - | ||||||||||||||||||||||||
302 | */ | - | ||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||
304 | int QPersistentModelIndex::row() const | - | ||||||||||||||||||||||||
305 | { | - | ||||||||||||||||||||||||
306 | if (d)
| 3910-274431 | ||||||||||||||||||||||||
307 | return d->index.row(); executed 274431 times by 39 tests: return d->index.row(); Executed by:
| 274431 | ||||||||||||||||||||||||
308 | return -1; executed 3910 times by 36 tests: return -1; Executed by:
| 3910 | ||||||||||||||||||||||||
309 | } | - | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | /*! | - | ||||||||||||||||||||||||
312 | \fn int QPersistentModelIndex::column() const | - | ||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
314 | Returns the column this persistent model index refers to. | - | ||||||||||||||||||||||||
315 | */ | - | ||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||
317 | int QPersistentModelIndex::column() const | - | ||||||||||||||||||||||||
318 | { | - | ||||||||||||||||||||||||
319 | if (d)
| 1931-207290 | ||||||||||||||||||||||||
320 | return d->index.column(); executed 207290 times by 34 tests: return d->index.column(); Executed by:
| 207290 | ||||||||||||||||||||||||
321 | return -1; executed 1931 times by 28 tests: return -1; Executed by:
| 1931 | ||||||||||||||||||||||||
322 | } | - | ||||||||||||||||||||||||
323 | - | |||||||||||||||||||||||||
324 | /*! | - | ||||||||||||||||||||||||
325 | \fn void *QPersistentModelIndex::internalPointer() const | - | ||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||
327 | \internal | - | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | Returns a \c{void} \c{*} pointer used by the model to associate the index with | - | ||||||||||||||||||||||||
330 | the internal data structure. | - | ||||||||||||||||||||||||
331 | */ | - | ||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||
333 | void *QPersistentModelIndex::internalPointer() const | - | ||||||||||||||||||||||||
334 | { | - | ||||||||||||||||||||||||
335 | if (d)
| 0-108 | ||||||||||||||||||||||||
336 | return d->index.internalPointer(); executed 108 times by 2 tests: return d->index.internalPointer(); Executed by:
| 108 | ||||||||||||||||||||||||
337 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | /*! | - | ||||||||||||||||||||||||
341 | \fn quintptr QPersistentModelIndex::internalId() const | - | ||||||||||||||||||||||||
342 | - | |||||||||||||||||||||||||
343 | \internal | - | ||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||
345 | Returns a \c{quintptr} used by the model to associate the index with | - | ||||||||||||||||||||||||
346 | the internal data structure. | - | ||||||||||||||||||||||||
347 | */ | - | ||||||||||||||||||||||||
348 | - | |||||||||||||||||||||||||
349 | quintptr QPersistentModelIndex::internalId() const | - | ||||||||||||||||||||||||
350 | { | - | ||||||||||||||||||||||||
351 | if (d)
| 0-4 | ||||||||||||||||||||||||
352 | return d->index.internalId(); executed 4 times by 1 test: return d->index.internalId(); Executed by:
| 4 | ||||||||||||||||||||||||
353 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
354 | } | - | ||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||
356 | /*! | - | ||||||||||||||||||||||||
357 | Returns the parent QModelIndex for this persistent index, or an invalid | - | ||||||||||||||||||||||||
358 | QModelIndex if it has no parent. | - | ||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||
360 | \sa child(), sibling(), model() | - | ||||||||||||||||||||||||
361 | */ | - | ||||||||||||||||||||||||
362 | QModelIndex QPersistentModelIndex::parent() const | - | ||||||||||||||||||||||||
363 | { | - | ||||||||||||||||||||||||
364 | if (d)
| 3309-208739 | ||||||||||||||||||||||||
365 | return d->index.parent(); executed 208739 times by 30 tests: return d->index.parent(); Executed by:
| 208739 | ||||||||||||||||||||||||
366 | return QModelIndex(); executed 3309 times by 11 tests: return QModelIndex(); Executed by:
| 3309 | ||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | /*! | - | ||||||||||||||||||||||||
370 | Returns the sibling at \a row and \a column or an invalid QModelIndex if | - | ||||||||||||||||||||||||
371 | there is no sibling at this position. | - | ||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||
373 | \sa parent(), child() | - | ||||||||||||||||||||||||
374 | */ | - | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | QModelIndex QPersistentModelIndex::sibling(int row, int column) const | - | ||||||||||||||||||||||||
377 | { | - | ||||||||||||||||||||||||
378 | if (d)
| 0-13 | ||||||||||||||||||||||||
379 | return d->index.sibling(row, column); executed 13 times by 2 tests: return d->index.sibling(row, column); Executed by:
| 13 | ||||||||||||||||||||||||
380 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
381 | } | - | ||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||
383 | /*! | - | ||||||||||||||||||||||||
384 | Returns the child of the model index that is stored in the given \a row | - | ||||||||||||||||||||||||
385 | and \a column. | - | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | \sa parent(), sibling() | - | ||||||||||||||||||||||||
388 | */ | - | ||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||
390 | QModelIndex QPersistentModelIndex::child(int row, int column) const | - | ||||||||||||||||||||||||
391 | { | - | ||||||||||||||||||||||||
392 | if (d)
| 0 | ||||||||||||||||||||||||
393 | return d->index.child(row, column); never executed: return d->index.child(row, column); | 0 | ||||||||||||||||||||||||
394 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
395 | } | - | ||||||||||||||||||||||||
396 | - | |||||||||||||||||||||||||
397 | /*! | - | ||||||||||||||||||||||||
398 | Returns the data for the given \a role for the item referred to by the | - | ||||||||||||||||||||||||
399 | index. | - | ||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||
401 | \sa Qt::ItemDataRole, QAbstractItemModel::setData() | - | ||||||||||||||||||||||||
402 | */ | - | ||||||||||||||||||||||||
403 | QVariant QPersistentModelIndex::data(int role) const | - | ||||||||||||||||||||||||
404 | { | - | ||||||||||||||||||||||||
405 | if (d)
| 0-232 | ||||||||||||||||||||||||
406 | return d->index.data(role); executed 232 times by 6 tests: return d->index.data(role); Executed by:
| 232 | ||||||||||||||||||||||||
407 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
408 | } | - | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | /*! | - | ||||||||||||||||||||||||
411 | \since 4.2 | - | ||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | Returns the flags for the item referred to by the index. | - | ||||||||||||||||||||||||
414 | */ | - | ||||||||||||||||||||||||
415 | Qt::ItemFlags QPersistentModelIndex::flags() const | - | ||||||||||||||||||||||||
416 | { | - | ||||||||||||||||||||||||
417 | if (d)
| 0-841 | ||||||||||||||||||||||||
418 | return d->index.flags(); executed 841 times by 3 tests: return d->index.flags(); Executed by:
| 841 | ||||||||||||||||||||||||
419 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
420 | } | - | ||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||
422 | /*! | - | ||||||||||||||||||||||||
423 | Returns the model that the index belongs to. | - | ||||||||||||||||||||||||
424 | */ | - | ||||||||||||||||||||||||
425 | const QAbstractItemModel *QPersistentModelIndex::model() const | - | ||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||
427 | if (d)
| 0-38769 | ||||||||||||||||||||||||
428 | return d->index.model(); executed 38769 times by 23 tests: return d->index.model(); Executed by:
| 38769 | ||||||||||||||||||||||||
429 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
430 | } | - | ||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | /*! | - | ||||||||||||||||||||||||
433 | \fn bool QPersistentModelIndex::isValid() const | - | ||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||
435 | Returns \c{true} if this persistent model index is valid; otherwise returns | - | ||||||||||||||||||||||||
436 | \c{false}. | - | ||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||
438 | A valid index belongs to a model, and has non-negative row and column | - | ||||||||||||||||||||||||
439 | numbers. | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | \sa model(), row(), column() | - | ||||||||||||||||||||||||
442 | */ | - | ||||||||||||||||||||||||
443 | - | |||||||||||||||||||||||||
444 | bool QPersistentModelIndex::isValid() const | - | ||||||||||||||||||||||||
445 | { | - | ||||||||||||||||||||||||
446 | return d && d->index.isValid(); executed 148185 times by 42 tests: return d && d->index.isValid(); Executed by:
| 1791-148185 | ||||||||||||||||||||||||
447 | } | - | ||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
450 | QDebug operator<<(QDebug dbg, const QModelIndex &idx) | - | ||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||
452 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
453 | dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column() | - | ||||||||||||||||||||||||
454 | << ',' << idx.internalPointer() << ',' << idx.model() << ')'; | - | ||||||||||||||||||||||||
455 | return dbg; executed 15 times by 3 tests: return dbg; Executed by:
| 15 | ||||||||||||||||||||||||
456 | } | - | ||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) | - | ||||||||||||||||||||||||
459 | { | - | ||||||||||||||||||||||||
460 | if (idx.d)
| 0-1 | ||||||||||||||||||||||||
461 | dbg << idx.d->index; never executed: dbg << idx.d->index; | 0 | ||||||||||||||||||||||||
462 | else | - | ||||||||||||||||||||||||
463 | dbg << QModelIndex(); executed 1 time by 1 test: dbg << QModelIndex(); Executed by:
| 1 | ||||||||||||||||||||||||
464 | return dbg; executed 1 time by 1 test: return dbg; Executed by:
| 1 | ||||||||||||||||||||||||
465 | } | - | ||||||||||||||||||||||||
466 | #endif | - | ||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||
468 | class QEmptyItemModel : public QAbstractItemModel | - | ||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||
470 | public: | - | ||||||||||||||||||||||||
471 | explicit QEmptyItemModel(QObject *parent = 0) : QAbstractItemModel(parent) {} executed 45 times by 45 tests: end of block Executed by:
| 45 | ||||||||||||||||||||||||
472 | QModelIndex index(int, int, const QModelIndex &) const Q_DECL_OVERRIDE { return QModelIndex(); } executed 56 times by 5 tests: return QModelIndex(); Executed by:
| 56 | ||||||||||||||||||||||||
473 | QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE { return QModelIndex(); } never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
474 | int rowCount(const QModelIndex &) const Q_DECL_OVERRIDE { return 0; } executed 1601 times by 24 tests: return 0; Executed by:
| 1601 | ||||||||||||||||||||||||
475 | int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE { return 0; } executed 2500 times by 32 tests: return 0; Executed by:
| 2500 | ||||||||||||||||||||||||
476 | bool hasChildren(const QModelIndex &) const Q_DECL_OVERRIDE { return false; } executed 252 times by 8 tests: return false; Executed by:
| 252 | ||||||||||||||||||||||||
477 | QVariant data(const QModelIndex &, int) const Q_DECL_OVERRIDE { return QVariant(); } executed 1030 times by 2 tests: return QVariant(); Executed by:
| 1030 | ||||||||||||||||||||||||
478 | }; | - | ||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||
480 | Q_GLOBAL_STATIC(QEmptyItemModel, qEmptyModel) executed 46 times by 46 tests: end of block Executed by:
executed 46 times by 46 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 208548 times by 49 tests: return &holder.value; Executed by:
| 0-208548 | ||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||
482 | - | |||||||||||||||||||||||||
483 | QAbstractItemModelPrivate::~QAbstractItemModelPrivate() | - | ||||||||||||||||||||||||
484 | { | - | ||||||||||||||||||||||||
485 | } | - | ||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||
487 | QAbstractItemModel *QAbstractItemModelPrivate::staticEmptyModel() | - | ||||||||||||||||||||||||
488 | { | - | ||||||||||||||||||||||||
489 | return qEmptyModel(); executed 208548 times by 49 tests: return qEmptyModel(); Executed by:
| 208548 | ||||||||||||||||||||||||
490 | } | - | ||||||||||||||||||||||||
491 | - | |||||||||||||||||||||||||
492 | namespace { | - | ||||||||||||||||||||||||
493 | struct DefaultRoleNames : public QHash<int, QByteArray> | - | ||||||||||||||||||||||||
494 | { | - | ||||||||||||||||||||||||
495 | DefaultRoleNames() { | - | ||||||||||||||||||||||||
496 | (*this)[Qt::DisplayRole] = "display"; | - | ||||||||||||||||||||||||
497 | (*this)[Qt::DecorationRole] = "decoration"; | - | ||||||||||||||||||||||||
498 | (*this)[Qt::EditRole] = "edit"; | - | ||||||||||||||||||||||||
499 | (*this)[Qt::ToolTipRole] = "toolTip"; | - | ||||||||||||||||||||||||
500 | (*this)[Qt::StatusTipRole] = "statusTip"; | - | ||||||||||||||||||||||||
501 | (*this)[Qt::WhatsThisRole] = "whatsThis"; | - | ||||||||||||||||||||||||
502 | } executed 52 times by 52 tests: end of block Executed by:
| 52 | ||||||||||||||||||||||||
503 | }; | - | ||||||||||||||||||||||||
504 | } | - | ||||||||||||||||||||||||
505 | - | |||||||||||||||||||||||||
506 | Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames) executed 54 times by 54 tests: end of block Executed by:
executed 54 times by 54 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 5376 times by 54 tests: return &holder.value; Executed by:
| 0-5376 | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | const QHash<int,QByteArray> &QAbstractItemModelPrivate::defaultRoleNames() | - | ||||||||||||||||||||||||
509 | { | - | ||||||||||||||||||||||||
510 | return *qDefaultRoleNames(); executed 5376 times by 54 tests: return *qDefaultRoleNames(); Executed by:
| 5376 | ||||||||||||||||||||||||
511 | } | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||
514 | static uint typeOfVariant(const QVariant &value) | - | ||||||||||||||||||||||||
515 | { | - | ||||||||||||||||||||||||
516 | //return 0 for integer, 1 for floating point and 2 for other | - | ||||||||||||||||||||||||
517 | switch (value.userType()) { | - | ||||||||||||||||||||||||
518 | case QVariant::Bool: never executed: case QVariant::Bool: | 0 | ||||||||||||||||||||||||
519 | case QVariant::Int: executed 26 times by 2 tests: case QVariant::Int: Executed by:
| 26 | ||||||||||||||||||||||||
520 | case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||||||||||||||||||||
521 | case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||||||||||||||
522 | case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||||||||||||||
523 | case QVariant::Char: never executed: case QVariant::Char: | 0 | ||||||||||||||||||||||||
524 | case QMetaType::Short: never executed: case QMetaType::Short: | 0 | ||||||||||||||||||||||||
525 | case QMetaType::UShort: never executed: case QMetaType::UShort: | 0 | ||||||||||||||||||||||||
526 | case QMetaType::UChar: never executed: case QMetaType::UChar: | 0 | ||||||||||||||||||||||||
527 | case QMetaType::ULong: never executed: case QMetaType::ULong: | 0 | ||||||||||||||||||||||||
528 | case QMetaType::Long: never executed: case QMetaType::Long: | 0 | ||||||||||||||||||||||||
529 | return 0; executed 26 times by 2 tests: return 0; Executed by:
| 26 | ||||||||||||||||||||||||
530 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||
531 | case QMetaType::Float: never executed: case QMetaType::Float: | 0 | ||||||||||||||||||||||||
532 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
533 | default: executed 22804 times by 6 tests: default: Executed by:
| 22804 | ||||||||||||||||||||||||
534 | return 2; executed 22804 times by 6 tests: return 2; Executed by:
| 22804 | ||||||||||||||||||||||||
535 | } | - | ||||||||||||||||||||||||
536 | } | - | ||||||||||||||||||||||||
537 | - | |||||||||||||||||||||||||
538 | /*! | - | ||||||||||||||||||||||||
539 | \internal | - | ||||||||||||||||||||||||
540 | Return \c{true} if \a value contains a numerical type. | - | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort. | - | ||||||||||||||||||||||||
543 | */ | - | ||||||||||||||||||||||||
544 | bool QAbstractItemModelPrivate::variantLessThan(const QVariant &v1, const QVariant &v2) | - | ||||||||||||||||||||||||
545 | { | - | ||||||||||||||||||||||||
546 | switch(qMax(typeOfVariant(v1), typeOfVariant(v2))) | - | ||||||||||||||||||||||||
547 | { | - | ||||||||||||||||||||||||
548 | case 0: //integer type executed 13 times by 2 tests: case 0: Executed by:
| 13 | ||||||||||||||||||||||||
549 | return v1.toLongLong() < v2.toLongLong(); executed 13 times by 2 tests: return v1.toLongLong() < v2.toLongLong(); Executed by:
| 13 | ||||||||||||||||||||||||
550 | case 1: //floating point never executed: case 1: | 0 | ||||||||||||||||||||||||
551 | return v1.toReal() < v2.toReal(); never executed: return v1.toReal() < v2.toReal(); | 0 | ||||||||||||||||||||||||
552 | default: executed 11402 times by 6 tests: default: Executed by:
| 11402 | ||||||||||||||||||||||||
553 | return v1.toString().localeAwareCompare(v2.toString()) < 0; executed 11402 times by 6 tests: return v1.toString().localeAwareCompare(v2.toString()) < 0; Executed by:
| 11402 | ||||||||||||||||||||||||
554 | } | - | ||||||||||||||||||||||||
555 | } | - | ||||||||||||||||||||||||
556 | - | |||||||||||||||||||||||||
557 | void QAbstractItemModelPrivate::removePersistentIndexData(QPersistentModelIndexData *data) | - | ||||||||||||||||||||||||
558 | { | - | ||||||||||||||||||||||||
559 | if (data->index.isValid()) {
| 2-21150 | ||||||||||||||||||||||||
560 | int removed = persistent.indexes.remove(data->index); | - | ||||||||||||||||||||||||
561 | Q_ASSERT_X(removed == 1, "QPersistentModelIndex::~QPersistentModelIndex", | - | ||||||||||||||||||||||||
562 | "persistent model indexes corrupted"); //maybe the index was somewhat invalid? | - | ||||||||||||||||||||||||
563 | // This assert may happen if the model use changePersistentIndex in a way that could result on two | - | ||||||||||||||||||||||||
564 | // QPersistentModelIndex pointing to the same index. | - | ||||||||||||||||||||||||
565 | Q_UNUSED(removed); | - | ||||||||||||||||||||||||
566 | } executed 21150 times by 38 tests: end of block Executed by:
| 21150 | ||||||||||||||||||||||||
567 | // make sure our optimization still works | - | ||||||||||||||||||||||||
568 | for (int i = persistent.moved.count() - 1; i >= 0; --i) {
| 0-21152 | ||||||||||||||||||||||||
569 | int idx = persistent.moved[i].indexOf(data); | - | ||||||||||||||||||||||||
570 | if (idx >= 0)
| 0 | ||||||||||||||||||||||||
571 | persistent.moved[i].remove(idx); never executed: persistent.moved[i].remove(idx); | 0 | ||||||||||||||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||||||||||||||
573 | // update the references to invalidated persistent indexes | - | ||||||||||||||||||||||||
574 | for (int i = persistent.invalidated.count() - 1; i >= 0; --i) {
| 0-21152 | ||||||||||||||||||||||||
575 | int idx = persistent.invalidated[i].indexOf(data); | - | ||||||||||||||||||||||||
576 | if (idx >= 0)
| 0 | ||||||||||||||||||||||||
577 | persistent.invalidated[i].remove(idx); never executed: persistent.invalidated[i].remove(idx); | 0 | ||||||||||||||||||||||||
578 | } never executed: end of block | 0 | ||||||||||||||||||||||||
579 | - | |||||||||||||||||||||||||
580 | } executed 21152 times by 38 tests: end of block Executed by:
| 21152 | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex &parent, | - | ||||||||||||||||||||||||
583 | int first, int last) | - | ||||||||||||||||||||||||
584 | { | - | ||||||||||||||||||||||||
585 | Q_Q(QAbstractItemModel); | - | ||||||||||||||||||||||||
586 | Q_UNUSED(last); | - | ||||||||||||||||||||||||
587 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||||||||||||||
588 | if (first < q->rowCount(parent)) {
| 2725-118212 | ||||||||||||||||||||||||
589 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
590 | it != persistent.indexes.constEnd(); ++it) {
| 2725-7851 | ||||||||||||||||||||||||
591 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
592 | const QModelIndex &index = data->index; | - | ||||||||||||||||||||||||
593 | if (index.row() >= first && index.isValid() && index.parent() == parent) {
| 0-6497 | ||||||||||||||||||||||||
594 | persistent_moved.append(data); | - | ||||||||||||||||||||||||
595 | } executed 6163 times by 12 tests: end of block Executed by:
| 6163 | ||||||||||||||||||||||||
596 | } executed 7851 times by 15 tests: end of block Executed by:
| 7851 | ||||||||||||||||||||||||
597 | } executed 2725 times by 25 tests: end of block Executed by:
| 2725 | ||||||||||||||||||||||||
598 | persistent.moved.push(persistent_moved); | - | ||||||||||||||||||||||||
599 | } executed 120937 times by 45 tests: end of block Executed by:
| 120937 | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent, | - | ||||||||||||||||||||||||
602 | int first, int last) | - | ||||||||||||||||||||||||
603 | { | - | ||||||||||||||||||||||||
604 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||||||||||||||
605 | int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested | - | ||||||||||||||||||||||||
606 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||||||||||||||
607 | it != persistent_moved.constEnd(); ++it) {
| 6163-120937 | ||||||||||||||||||||||||
608 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
609 | QModelIndex old = data->index; | - | ||||||||||||||||||||||||
610 | persistent.indexes.erase(persistent.indexes.find(old)); | - | ||||||||||||||||||||||||
611 | data->index = q_func()->index(old.row() + count, old.column(), parent); | - | ||||||||||||||||||||||||
612 | if (data->index.isValid()) {
| 0-6163 | ||||||||||||||||||||||||
613 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
614 | } else { executed 6163 times by 12 tests: end of block Executed by:
| 6163 | ||||||||||||||||||||||||
615 | qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func(); | - | ||||||||||||||||||||||||
616 | } never executed: end of block | 0 | ||||||||||||||||||||||||
617 | } | - | ||||||||||||||||||||||||
618 | } executed 120937 times by 45 tests: end of block Executed by:
| 120937 | ||||||||||||||||||||||||
619 | - | |||||||||||||||||||||||||
620 | void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
621 | { | - | ||||||||||||||||||||||||
622 | QVector<QPersistentModelIndexData *> persistent_moved_explicitly; | - | ||||||||||||||||||||||||
623 | QVector<QPersistentModelIndexData *> persistent_moved_in_source; | - | ||||||||||||||||||||||||
624 | QVector<QPersistentModelIndexData *> persistent_moved_in_destination; | - | ||||||||||||||||||||||||
625 | - | |||||||||||||||||||||||||
626 | QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it; | - | ||||||||||||||||||||||||
627 | const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator begin = persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
628 | const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator end = persistent.indexes.constEnd(); | - | ||||||||||||||||||||||||
629 | - | |||||||||||||||||||||||||
630 | const bool sameParent = (srcParent == destinationParent); | - | ||||||||||||||||||||||||
631 | const bool movingUp = (srcFirst > destinationChild); | - | ||||||||||||||||||||||||
632 | - | |||||||||||||||||||||||||
633 | for ( it = begin; it != end; ++it) {
| 72-2617 | ||||||||||||||||||||||||
634 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
635 | const QModelIndex &index = data->index; | - | ||||||||||||||||||||||||
636 | const QModelIndex &parent = index.parent(); | - | ||||||||||||||||||||||||
637 | const bool isSourceIndex = (parent == srcParent); | - | ||||||||||||||||||||||||
638 | const bool isDestinationIndex = (parent == destinationParent); | - | ||||||||||||||||||||||||
639 | - | |||||||||||||||||||||||||
640 | int childPosition; | - | ||||||||||||||||||||||||
641 | if (orientation == Qt::Vertical)
| 0-2617 | ||||||||||||||||||||||||
642 | childPosition = index.row(); executed 2617 times by 3 tests: childPosition = index.row(); Executed by:
| 2617 | ||||||||||||||||||||||||
643 | else | - | ||||||||||||||||||||||||
644 | childPosition = index.column(); never executed: childPosition = index.column(); | 0 | ||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||
646 | if (!index.isValid() || !(isSourceIndex || isDestinationIndex ) )
| 0-2617 | ||||||||||||||||||||||||
647 | continue; executed 482 times by 2 tests: continue; Executed by:
| 482 | ||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||
649 | if (!sameParent && isDestinationIndex) {
| 480-1655 | ||||||||||||||||||||||||
650 | if (childPosition >= destinationChild)
| 376-447 | ||||||||||||||||||||||||
651 | persistent_moved_in_destination.append(data); executed 376 times by 1 test: persistent_moved_in_destination.append(data); Executed by:
| 376 | ||||||||||||||||||||||||
652 | continue; executed 823 times by 2 tests: continue; Executed by:
| 823 | ||||||||||||||||||||||||
653 | } | - | ||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||
655 | if (sameParent && movingUp && childPosition < destinationChild)
| 28-832 | ||||||||||||||||||||||||
656 | continue; executed 28 times by 1 test: continue; Executed by:
| 28 | ||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||
658 | if (sameParent && !movingUp && childPosition < srcFirst )
| 48-832 | ||||||||||||||||||||||||
659 | continue; executed 48 times by 1 test: continue; Executed by:
| 48 | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | if (!sameParent && childPosition < srcFirst)
| 386-832 | ||||||||||||||||||||||||
662 | continue; executed 386 times by 1 test: continue; Executed by:
| 386 | ||||||||||||||||||||||||
663 | - | |||||||||||||||||||||||||
664 | if (sameParent && (childPosition > srcLast) && (childPosition >= destinationChild ))
| 48-446 | ||||||||||||||||||||||||
665 | continue; executed 48 times by 1 test: continue; Executed by:
| 48 | ||||||||||||||||||||||||
666 | - | |||||||||||||||||||||||||
667 | if ((childPosition <= srcLast) && (childPosition >= srcFirst)) {
| 76-463 | ||||||||||||||||||||||||
668 | persistent_moved_explicitly.append(data); | - | ||||||||||||||||||||||||
669 | } else { executed 387 times by 2 tests: end of block Executed by:
| 387 | ||||||||||||||||||||||||
670 | persistent_moved_in_source.append(data); | - | ||||||||||||||||||||||||
671 | } executed 415 times by 2 tests: end of block Executed by:
| 415 | ||||||||||||||||||||||||
672 | } | - | ||||||||||||||||||||||||
673 | persistent.moved.push(persistent_moved_explicitly); | - | ||||||||||||||||||||||||
674 | persistent.moved.push(persistent_moved_in_source); | - | ||||||||||||||||||||||||
675 | persistent.moved.push(persistent_moved_in_destination); | - | ||||||||||||||||||||||||
676 | } executed 72 times by 5 tests: end of block Executed by:
| 72 | ||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||
678 | /*! | - | ||||||||||||||||||||||||
679 | \internal | - | ||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||
681 | Moves persistent indexes \a indexes by amount \a change. The change will be either a change in row value or a change in | - | ||||||||||||||||||||||||
682 | column value depending on the value of \a orientation. The indexes may also be moved to a different parent if \a parent | - | ||||||||||||||||||||||||
683 | differs from the existing parent for the index. | - | ||||||||||||||||||||||||
684 | */ | - | ||||||||||||||||||||||||
685 | void QAbstractItemModelPrivate::movePersistentIndexes(const QVector<QPersistentModelIndexData *> &indexes, int change, const QModelIndex &parent, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
686 | { | - | ||||||||||||||||||||||||
687 | QVector<QPersistentModelIndexData *>::const_iterator it; | - | ||||||||||||||||||||||||
688 | const QVector<QPersistentModelIndexData *>::const_iterator begin = indexes.constBegin(); | - | ||||||||||||||||||||||||
689 | const QVector<QPersistentModelIndexData *>::const_iterator end = indexes.constEnd(); | - | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | for (it = begin; it != end; ++it)
| 216-1178 | ||||||||||||||||||||||||
692 | { | - | ||||||||||||||||||||||||
693 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
694 | - | |||||||||||||||||||||||||
695 | int row = data->index.row(); | - | ||||||||||||||||||||||||
696 | int column = data->index.column(); | - | ||||||||||||||||||||||||
697 | - | |||||||||||||||||||||||||
698 | if (Qt::Vertical == orientation)
| 0-1178 | ||||||||||||||||||||||||
699 | row += change; executed 1178 times by 2 tests: row += change; Executed by:
| 1178 | ||||||||||||||||||||||||
700 | else | - | ||||||||||||||||||||||||
701 | column += change; never executed: column += change; | 0 | ||||||||||||||||||||||||
702 | - | |||||||||||||||||||||||||
703 | persistent.indexes.erase(persistent.indexes.find(data->index)); | - | ||||||||||||||||||||||||
704 | data->index = q_func()->index(row, column, parent); | - | ||||||||||||||||||||||||
705 | if (data->index.isValid()) {
| 0-1178 | ||||||||||||||||||||||||
706 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
707 | } else { executed 1178 times by 2 tests: end of block Executed by:
| 1178 | ||||||||||||||||||||||||
708 | qWarning() << "QAbstractItemModel::endMoveRows: Invalid index (" << row << "," << column << ") in model" << q_func(); | - | ||||||||||||||||||||||||
709 | } never executed: end of block | 0 | ||||||||||||||||||||||||
710 | } | - | ||||||||||||||||||||||||
711 | } executed 216 times by 5 tests: end of block Executed by:
| 216 | ||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | void QAbstractItemModelPrivate::itemsMoved(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
714 | { | - | ||||||||||||||||||||||||
715 | QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop(); | - | ||||||||||||||||||||||||
716 | QVector<QPersistentModelIndexData *> moved_in_source = persistent.moved.pop(); | - | ||||||||||||||||||||||||
717 | QVector<QPersistentModelIndexData *> moved_explicitly = persistent.moved.pop(); | - | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | const bool sameParent = (sourceParent == destinationParent); | - | ||||||||||||||||||||||||
720 | const bool movingUp = (sourceFirst > destinationChild); | - | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | const int explicit_change = (!sameParent || movingUp) ? destinationChild - sourceFirst : destinationChild - sourceLast - 1 ;
| 12-46 | ||||||||||||||||||||||||
723 | const int source_change = (!sameParent || !movingUp) ? -1*(sourceLast - sourceFirst + 1) : sourceLast - sourceFirst + 1 ;
| 12-46 | ||||||||||||||||||||||||
724 | const int destination_change = sourceLast - sourceFirst + 1; | - | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation); | - | ||||||||||||||||||||||||
727 | movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation); | - | ||||||||||||||||||||||||
728 | movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation); | - | ||||||||||||||||||||||||
729 | } executed 72 times by 5 tests: end of block Executed by:
| 72 | ||||||||||||||||||||||||
730 | - | |||||||||||||||||||||||||
731 | void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent, | - | ||||||||||||||||||||||||
732 | int first, int last) | - | ||||||||||||||||||||||||
733 | { | - | ||||||||||||||||||||||||
734 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||||||||||||||
735 | QVector<QPersistentModelIndexData *> persistent_invalidated; | - | ||||||||||||||||||||||||
736 | // find the persistent indexes that are affected by the change, either by being in the removed subtree | - | ||||||||||||||||||||||||
737 | // or by being on the same level and below the removed rows | - | ||||||||||||||||||||||||
738 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
739 | it != persistent.indexes.constEnd(); ++it) {
| 2687-3516 | ||||||||||||||||||||||||
740 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
741 | bool level_changed = false; | - | ||||||||||||||||||||||||
742 | QModelIndex current = data->index; | - | ||||||||||||||||||||||||
743 | while (current.isValid()) {
| 223-4337 | ||||||||||||||||||||||||
744 | QModelIndex current_parent = current.parent(); | - | ||||||||||||||||||||||||
745 | if (current_parent == parent) { // on the same level as the change
| 1044-3293 | ||||||||||||||||||||||||
746 | if (!level_changed && current.row() > last) // below the removed rows
| 316-2977 | ||||||||||||||||||||||||
747 | persistent_moved.append(data); executed 1097 times by 12 tests: persistent_moved.append(data); Executed by:
| 1097 | ||||||||||||||||||||||||
748 | else if (current.row() <= last && current.row() >= first) // in the removed subtree
| 115-2081 | ||||||||||||||||||||||||
749 | persistent_invalidated.append(data); executed 957 times by 15 tests: persistent_invalidated.append(data); Executed by:
| 957 | ||||||||||||||||||||||||
750 | break; executed 3293 times by 18 tests: break; Executed by:
| 3293 | ||||||||||||||||||||||||
751 | } | - | ||||||||||||||||||||||||
752 | current = current_parent; | - | ||||||||||||||||||||||||
753 | level_changed = true; | - | ||||||||||||||||||||||||
754 | } executed 1044 times by 9 tests: end of block Executed by:
| 1044 | ||||||||||||||||||||||||
755 | } executed 3516 times by 18 tests: end of block Executed by:
| 3516 | ||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||
757 | persistent.moved.push(persistent_moved); | - | ||||||||||||||||||||||||
758 | persistent.invalidated.push(persistent_invalidated); | - | ||||||||||||||||||||||||
759 | } executed 2687 times by 31 tests: end of block Executed by:
| 2687 | ||||||||||||||||||||||||
760 | - | |||||||||||||||||||||||||
761 | void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent, | - | ||||||||||||||||||||||||
762 | int first, int last) | - | ||||||||||||||||||||||||
763 | { | - | ||||||||||||||||||||||||
764 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||||||||||||||
765 | int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested | - | ||||||||||||||||||||||||
766 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||||||||||||||
767 | it != persistent_moved.constEnd(); ++it) {
| 1097-2687 | ||||||||||||||||||||||||
768 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
769 | QModelIndex old = data->index; | - | ||||||||||||||||||||||||
770 | persistent.indexes.erase(persistent.indexes.find(old)); | - | ||||||||||||||||||||||||
771 | data->index = q_func()->index(old.row() - count, old.column(), parent); | - | ||||||||||||||||||||||||
772 | if (data->index.isValid()) {
| 0-1097 | ||||||||||||||||||||||||
773 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
774 | } else { executed 1097 times by 12 tests: end of block Executed by:
| 1097 | ||||||||||||||||||||||||
775 | qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func(); | - | ||||||||||||||||||||||||
776 | } never executed: end of block | 0 | ||||||||||||||||||||||||
777 | } | - | ||||||||||||||||||||||||
778 | QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop(); | - | ||||||||||||||||||||||||
779 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); | - | ||||||||||||||||||||||||
780 | it != persistent_invalidated.constEnd(); ++it) {
| 957-2687 | ||||||||||||||||||||||||
781 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
782 | persistent.indexes.erase(persistent.indexes.find(data->index)); | - | ||||||||||||||||||||||||
783 | data->index = QModelIndex(); | - | ||||||||||||||||||||||||
784 | data->model = 0; | - | ||||||||||||||||||||||||
785 | } executed 957 times by 15 tests: end of block Executed by:
| 957 | ||||||||||||||||||||||||
786 | } executed 2687 times by 31 tests: end of block Executed by:
| 2687 | ||||||||||||||||||||||||
787 | - | |||||||||||||||||||||||||
788 | void QAbstractItemModelPrivate::columnsAboutToBeInserted(const QModelIndex &parent, | - | ||||||||||||||||||||||||
789 | int first, int last) | - | ||||||||||||||||||||||||
790 | { | - | ||||||||||||||||||||||||
791 | Q_Q(QAbstractItemModel); | - | ||||||||||||||||||||||||
792 | Q_UNUSED(last); | - | ||||||||||||||||||||||||
793 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||||||||||||||
794 | if (first < q->columnCount(parent)) {
| 336-13183 | ||||||||||||||||||||||||
795 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
796 | it != persistent.indexes.constEnd(); ++it) {
| 62-336 | ||||||||||||||||||||||||
797 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
798 | const QModelIndex &index = data->index; | - | ||||||||||||||||||||||||
799 | if (index.column() >= first && index.isValid() && index.parent() == parent)
| 0-32 | ||||||||||||||||||||||||
800 | persistent_moved.append(data); executed 15 times by 4 tests: persistent_moved.append(data); Executed by:
| 15 | ||||||||||||||||||||||||
801 | } executed 62 times by 5 tests: end of block Executed by:
| 62 | ||||||||||||||||||||||||
802 | } executed 336 times by 11 tests: end of block Executed by:
| 336 | ||||||||||||||||||||||||
803 | persistent.moved.push(persistent_moved); | - | ||||||||||||||||||||||||
804 | } executed 13519 times by 33 tests: end of block Executed by:
| 13519 | ||||||||||||||||||||||||
805 | - | |||||||||||||||||||||||||
806 | void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent, | - | ||||||||||||||||||||||||
807 | int first, int last) | - | ||||||||||||||||||||||||
808 | { | - | ||||||||||||||||||||||||
809 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||||||||||||||
810 | int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested | - | ||||||||||||||||||||||||
811 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||||||||||||||
812 | it != persistent_moved.constEnd(); ++it) {
| 15-13519 | ||||||||||||||||||||||||
813 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
814 | QModelIndex old = data->index; | - | ||||||||||||||||||||||||
815 | persistent.indexes.erase(persistent.indexes.find(old)); | - | ||||||||||||||||||||||||
816 | data->index = q_func()->index(old.row(), old.column() + count, parent); | - | ||||||||||||||||||||||||
817 | if (data->index.isValid()) {
| 0-15 | ||||||||||||||||||||||||
818 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
819 | } else { executed 15 times by 4 tests: end of block Executed by:
| 15 | ||||||||||||||||||||||||
820 | qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func(); | - | ||||||||||||||||||||||||
821 | } never executed: end of block | 0 | ||||||||||||||||||||||||
822 | } | - | ||||||||||||||||||||||||
823 | } executed 13519 times by 33 tests: end of block Executed by:
| 13519 | ||||||||||||||||||||||||
824 | - | |||||||||||||||||||||||||
825 | void QAbstractItemModelPrivate::columnsAboutToBeRemoved(const QModelIndex &parent, | - | ||||||||||||||||||||||||
826 | int first, int last) | - | ||||||||||||||||||||||||
827 | { | - | ||||||||||||||||||||||||
828 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||||||||||||||
829 | QVector<QPersistentModelIndexData *> persistent_invalidated; | - | ||||||||||||||||||||||||
830 | // find the persistent indexes that are affected by the change, either by being in the removed subtree | - | ||||||||||||||||||||||||
831 | // or by being on the same level and to the right of the removed columns | - | ||||||||||||||||||||||||
832 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
833 | it != persistent.indexes.constEnd(); ++it) {
| 98-204 | ||||||||||||||||||||||||
834 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
835 | bool level_changed = false; | - | ||||||||||||||||||||||||
836 | QModelIndex current = data->index; | - | ||||||||||||||||||||||||
837 | while (current.isValid()) {
| 35-99 | ||||||||||||||||||||||||
838 | QModelIndex current_parent = current.parent(); | - | ||||||||||||||||||||||||
839 | if (current_parent == parent) { // on the same level as the change
| 36-63 | ||||||||||||||||||||||||
840 | if (!level_changed && current.column() > last) // right of the removed columns
| 1-62 | ||||||||||||||||||||||||
841 | persistent_moved.append(data); executed 15 times by 6 tests: persistent_moved.append(data); Executed by:
| 15 | ||||||||||||||||||||||||
842 | else if (current.column() <= last && current.column() >= first) // in the removed subtree
| 0-48 | ||||||||||||||||||||||||
843 | persistent_invalidated.append(data); executed 26 times by 7 tests: persistent_invalidated.append(data); Executed by:
| 26 | ||||||||||||||||||||||||
844 | break; executed 63 times by 10 tests: break; Executed by:
| 63 | ||||||||||||||||||||||||
845 | } | - | ||||||||||||||||||||||||
846 | current = current_parent; | - | ||||||||||||||||||||||||
847 | level_changed = true; | - | ||||||||||||||||||||||||
848 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||||||||||||||
849 | } executed 98 times by 10 tests: end of block Executed by:
| 98 | ||||||||||||||||||||||||
850 | - | |||||||||||||||||||||||||
851 | persistent.moved.push(persistent_moved); | - | ||||||||||||||||||||||||
852 | persistent.invalidated.push(persistent_invalidated); | - | ||||||||||||||||||||||||
853 | - | |||||||||||||||||||||||||
854 | } executed 204 times by 16 tests: end of block Executed by:
| 204 | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, | - | ||||||||||||||||||||||||
857 | int first, int last) | - | ||||||||||||||||||||||||
858 | { | - | ||||||||||||||||||||||||
859 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||||||||||||||
860 | int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested | - | ||||||||||||||||||||||||
861 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||||||||||||||
862 | it != persistent_moved.constEnd(); ++it) {
| 15-204 | ||||||||||||||||||||||||
863 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
864 | QModelIndex old = data->index; | - | ||||||||||||||||||||||||
865 | persistent.indexes.erase(persistent.indexes.find(old)); | - | ||||||||||||||||||||||||
866 | data->index = q_func()->index(old.row(), old.column() - count, parent); | - | ||||||||||||||||||||||||
867 | if (data->index.isValid()) {
| 0-15 | ||||||||||||||||||||||||
868 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
869 | } else { executed 15 times by 6 tests: end of block Executed by:
| 15 | ||||||||||||||||||||||||
870 | qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func(); | - | ||||||||||||||||||||||||
871 | } never executed: end of block | 0 | ||||||||||||||||||||||||
872 | } | - | ||||||||||||||||||||||||
873 | QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop(); | - | ||||||||||||||||||||||||
874 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); | - | ||||||||||||||||||||||||
875 | it != persistent_invalidated.constEnd(); ++it) {
| 26-204 | ||||||||||||||||||||||||
876 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
877 | persistent.indexes.erase(persistent.indexes.find(data->index)); | - | ||||||||||||||||||||||||
878 | data->index = QModelIndex(); | - | ||||||||||||||||||||||||
879 | data->model = 0; | - | ||||||||||||||||||||||||
880 | } executed 26 times by 7 tests: end of block Executed by:
| 26 | ||||||||||||||||||||||||
881 | } executed 204 times by 16 tests: end of block Executed by:
| 204 | ||||||||||||||||||||||||
882 | - | |||||||||||||||||||||||||
883 | /*! | - | ||||||||||||||||||||||||
884 | \since 4.8 | - | ||||||||||||||||||||||||
885 | - | |||||||||||||||||||||||||
886 | This slot is called just after the internal data of a model is cleared | - | ||||||||||||||||||||||||
887 | while it is being reset. | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | This slot is provided the convenience of subclasses of concrete proxy | - | ||||||||||||||||||||||||
890 | models, such as subclasses of QSortFilterProxyModel which maintain extra | - | ||||||||||||||||||||||||
891 | data. | - | ||||||||||||||||||||||||
892 | - | |||||||||||||||||||||||||
893 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 12 | - | ||||||||||||||||||||||||
894 | - | |||||||||||||||||||||||||
895 | \note Due to a mistake, this slot is missing in Qt 5.0. | - | ||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||
897 | \sa modelAboutToBeReset(), modelReset() | - | ||||||||||||||||||||||||
898 | */ | - | ||||||||||||||||||||||||
899 | void QAbstractItemModel::resetInternalData() | - | ||||||||||||||||||||||||
900 | { | - | ||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||
902 | } | - | ||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||
904 | /*! | - | ||||||||||||||||||||||||
905 | \class QModelIndex | - | ||||||||||||||||||||||||
906 | \inmodule QtCore | - | ||||||||||||||||||||||||
907 | - | |||||||||||||||||||||||||
908 | \brief The QModelIndex class is used to locate data in a data model. | - | ||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||
910 | \ingroup model-view | - | ||||||||||||||||||||||||
911 | - | |||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | This class is used as an index into item models derived from | - | ||||||||||||||||||||||||
914 | QAbstractItemModel. The index is used by item views, delegates, and | - | ||||||||||||||||||||||||
915 | selection models to locate an item in the model. | - | ||||||||||||||||||||||||
916 | - | |||||||||||||||||||||||||
917 | New QModelIndex objects are created by the model using the | - | ||||||||||||||||||||||||
918 | QAbstractItemModel::createIndex() function. An \e invalid model index can | - | ||||||||||||||||||||||||
919 | be constructed with the QModelIndex constructor. Invalid indexes are often | - | ||||||||||||||||||||||||
920 | used as parent indexes when referring to top-level items in a model. | - | ||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||
922 | Model indexes refer to items in models, and contain all the information | - | ||||||||||||||||||||||||
923 | required to specify their locations in those models. Each index is located | - | ||||||||||||||||||||||||
924 | in a given row and column, and may have a parent index; use row(), | - | ||||||||||||||||||||||||
925 | column(), and parent() to obtain this information. Each top-level item in a | - | ||||||||||||||||||||||||
926 | model is represented by a model index that does not have a parent index - | - | ||||||||||||||||||||||||
927 | in this case, parent() will return an invalid model index, equivalent to an | - | ||||||||||||||||||||||||
928 | index constructed with the zero argument form of the QModelIndex() | - | ||||||||||||||||||||||||
929 | constructor. | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | To obtain a model index that refers to an existing item in a model, call | - | ||||||||||||||||||||||||
932 | QAbstractItemModel::index() with the required row and column values, and | - | ||||||||||||||||||||||||
933 | the model index of the parent. When referring to top-level items in a | - | ||||||||||||||||||||||||
934 | model, supply QModelIndex() as the parent index. | - | ||||||||||||||||||||||||
935 | - | |||||||||||||||||||||||||
936 | The model() function returns the model that the index references as a | - | ||||||||||||||||||||||||
937 | QAbstractItemModel. The child() function is used to examine items held | - | ||||||||||||||||||||||||
938 | under the index in the model. The sibling() function allows you to traverse | - | ||||||||||||||||||||||||
939 | items in the model on the same level as the index. | - | ||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||
941 | \note Model indexes should be used immediately and then discarded. You | - | ||||||||||||||||||||||||
942 | should not rely on indexes to remain valid after calling model functions | - | ||||||||||||||||||||||||
943 | that change the structure of the model or delete items. If you need to | - | ||||||||||||||||||||||||
944 | keep a model index over time use a QPersistentModelIndex. | - | ||||||||||||||||||||||||
945 | - | |||||||||||||||||||||||||
946 | \sa {Model/View Programming}, QPersistentModelIndex, QAbstractItemModel | - | ||||||||||||||||||||||||
947 | */ | - | ||||||||||||||||||||||||
948 | - | |||||||||||||||||||||||||
949 | /*! | - | ||||||||||||||||||||||||
950 | \fn QModelIndex::QModelIndex() | - | ||||||||||||||||||||||||
951 | - | |||||||||||||||||||||||||
952 | Creates a new empty model index. This type of model index is used to | - | ||||||||||||||||||||||||
953 | indicate that the position in the model is invalid. | - | ||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | \sa isValid(), QAbstractItemModel | - | ||||||||||||||||||||||||
956 | */ | - | ||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||
958 | /*! | - | ||||||||||||||||||||||||
959 | \fn QModelIndex::QModelIndex(int row, int column, void *data, const QAbstractItemModel *model) | - | ||||||||||||||||||||||||
960 | - | |||||||||||||||||||||||||
961 | \internal | - | ||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | Creates a new model index at the given \a row and \a column, | - | ||||||||||||||||||||||||
964 | pointing to some \a data. | - | ||||||||||||||||||||||||
965 | */ | - | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | /*! | - | ||||||||||||||||||||||||
968 | \fn int QModelIndex::row() const | - | ||||||||||||||||||||||||
969 | - | |||||||||||||||||||||||||
970 | Returns the row this model index refers to. | - | ||||||||||||||||||||||||
971 | */ | - | ||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | /*! | - | ||||||||||||||||||||||||
975 | \fn int QModelIndex::column() const | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | Returns the column this model index refers to. | - | ||||||||||||||||||||||||
978 | */ | - | ||||||||||||||||||||||||
979 | - | |||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | /*! | - | ||||||||||||||||||||||||
982 | \fn void *QModelIndex::internalPointer() const | - | ||||||||||||||||||||||||
983 | - | |||||||||||||||||||||||||
984 | Returns a \c{void} \c{*} pointer used by the model to associate | - | ||||||||||||||||||||||||
985 | the index with the internal data structure. | - | ||||||||||||||||||||||||
986 | - | |||||||||||||||||||||||||
987 | \sa QAbstractItemModel::createIndex() | - | ||||||||||||||||||||||||
988 | */ | - | ||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||
990 | /*! | - | ||||||||||||||||||||||||
991 | \fn quintptr QModelIndex::internalId() const | - | ||||||||||||||||||||||||
992 | - | |||||||||||||||||||||||||
993 | Returns a \c{quintptr} used by the model to associate | - | ||||||||||||||||||||||||
994 | the index with the internal data structure. | - | ||||||||||||||||||||||||
995 | - | |||||||||||||||||||||||||
996 | \sa QAbstractItemModel::createIndex() | - | ||||||||||||||||||||||||
997 | */ | - | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | /*! | - | ||||||||||||||||||||||||
1000 | \fn bool QModelIndex::isValid() const | - | ||||||||||||||||||||||||
1001 | - | |||||||||||||||||||||||||
1002 | Returns \c{true} if this model index is valid; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | A valid index belongs to a model, and has non-negative row and column | - | ||||||||||||||||||||||||
1005 | numbers. | - | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | \sa model(), row(), column() | - | ||||||||||||||||||||||||
1008 | */ | - | ||||||||||||||||||||||||
1009 | - | |||||||||||||||||||||||||
1010 | /*! | - | ||||||||||||||||||||||||
1011 | \fn const QAbstractItemModel *QModelIndex::model() const | - | ||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||
1013 | Returns a pointer to the model containing the item that this index | - | ||||||||||||||||||||||||
1014 | refers to. | - | ||||||||||||||||||||||||
1015 | - | |||||||||||||||||||||||||
1016 | A const pointer to the model is returned because calls to non-const | - | ||||||||||||||||||||||||
1017 | functions of the model might invalidate the model index and possibly | - | ||||||||||||||||||||||||
1018 | crash your application. | - | ||||||||||||||||||||||||
1019 | */ | - | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | /*! | - | ||||||||||||||||||||||||
1022 | \fn QModelIndex QModelIndex::sibling(int row, int column) const | - | ||||||||||||||||||||||||
1023 | - | |||||||||||||||||||||||||
1024 | Returns the sibling at \a row and \a column. If there is no sibling at this | - | ||||||||||||||||||||||||
1025 | position, an invalid QModelIndex is returned. | - | ||||||||||||||||||||||||
1026 | - | |||||||||||||||||||||||||
1027 | \sa parent(), child() | - | ||||||||||||||||||||||||
1028 | */ | - | ||||||||||||||||||||||||
1029 | - | |||||||||||||||||||||||||
1030 | /*! | - | ||||||||||||||||||||||||
1031 | \fn QModelIndex QModelIndex::child(int row, int column) const | - | ||||||||||||||||||||||||
1032 | - | |||||||||||||||||||||||||
1033 | Returns the child of the model index that is stored in the given \a row and | - | ||||||||||||||||||||||||
1034 | \a column. | - | ||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||
1036 | \note This function does not work for an invalid model index which is often | - | ||||||||||||||||||||||||
1037 | used as the root index. | - | ||||||||||||||||||||||||
1038 | - | |||||||||||||||||||||||||
1039 | \sa parent(), sibling() | - | ||||||||||||||||||||||||
1040 | */ | - | ||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||
1042 | /*! | - | ||||||||||||||||||||||||
1043 | \fn QVariant QModelIndex::data(int role) const | - | ||||||||||||||||||||||||
1044 | - | |||||||||||||||||||||||||
1045 | Returns the data for the given \a role for the item referred to by the | - | ||||||||||||||||||||||||
1046 | index. | - | ||||||||||||||||||||||||
1047 | */ | - | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | /*! | - | ||||||||||||||||||||||||
1050 | \fn Qt::ItemFlags QModelIndex::flags() const | - | ||||||||||||||||||||||||
1051 | \since 4.2 | - | ||||||||||||||||||||||||
1052 | - | |||||||||||||||||||||||||
1053 | Returns the flags for the item referred to by the index. | - | ||||||||||||||||||||||||
1054 | */ | - | ||||||||||||||||||||||||
1055 | - | |||||||||||||||||||||||||
1056 | /*! | - | ||||||||||||||||||||||||
1057 | \fn bool QModelIndex::operator==(const QModelIndex &other) const | - | ||||||||||||||||||||||||
1058 | - | |||||||||||||||||||||||||
1059 | Returns \c{true} if this model index refers to the same location as the | - | ||||||||||||||||||||||||
1060 | \a other model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1061 | - | |||||||||||||||||||||||||
1062 | All values in the model index are used when comparing with another model | - | ||||||||||||||||||||||||
1063 | index. | - | ||||||||||||||||||||||||
1064 | */ | - | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | - | |||||||||||||||||||||||||
1067 | /*! | - | ||||||||||||||||||||||||
1068 | \fn bool QModelIndex::operator!=(const QModelIndex &other) const | - | ||||||||||||||||||||||||
1069 | - | |||||||||||||||||||||||||
1070 | Returns \c{true} if this model index does not refer to the same location as | - | ||||||||||||||||||||||||
1071 | the \a other model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1072 | */ | - | ||||||||||||||||||||||||
1073 | - | |||||||||||||||||||||||||
1074 | - | |||||||||||||||||||||||||
1075 | /*! | - | ||||||||||||||||||||||||
1076 | \fn QModelIndex QModelIndex::parent() const | - | ||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||
1078 | Returns the parent of the model index, or QModelIndex() if it has no | - | ||||||||||||||||||||||||
1079 | parent. | - | ||||||||||||||||||||||||
1080 | - | |||||||||||||||||||||||||
1081 | \sa child(), sibling(), model() | - | ||||||||||||||||||||||||
1082 | */ | - | ||||||||||||||||||||||||
1083 | - | |||||||||||||||||||||||||
1084 | /*! | - | ||||||||||||||||||||||||
1085 | \class QAbstractItemModel | - | ||||||||||||||||||||||||
1086 | \inmodule QtCore | - | ||||||||||||||||||||||||
1087 | - | |||||||||||||||||||||||||
1088 | \brief The QAbstractItemModel class provides the abstract interface for | - | ||||||||||||||||||||||||
1089 | item model classes. | - | ||||||||||||||||||||||||
1090 | - | |||||||||||||||||||||||||
1091 | \ingroup model-view | - | ||||||||||||||||||||||||
1092 | - | |||||||||||||||||||||||||
1093 | - | |||||||||||||||||||||||||
1094 | The QAbstractItemModel class defines the standard interface that item | - | ||||||||||||||||||||||||
1095 | models must use to be able to interoperate with other components in the | - | ||||||||||||||||||||||||
1096 | model/view architecture. It is not supposed to be instantiated directly. | - | ||||||||||||||||||||||||
1097 | Instead, you should subclass it to create new models. | - | ||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||
1099 | The QAbstractItemModel class is one of the \l{Model/View Classes} | - | ||||||||||||||||||||||||
1100 | and is part of Qt's \l{Model/View Programming}{model/view framework}. It | - | ||||||||||||||||||||||||
1101 | can be used as the underlying data model for the item view elements in | - | ||||||||||||||||||||||||
1102 | QML or the item view classes in the Qt Widgets module. | - | ||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||
1104 | If you need a model to use with an item view such as QML's List View | - | ||||||||||||||||||||||||
1105 | element or the C++ widgets QListView or QTableView, you should consider | - | ||||||||||||||||||||||||
1106 | subclassing QAbstractListModel or QAbstractTableModel instead of this class. | - | ||||||||||||||||||||||||
1107 | - | |||||||||||||||||||||||||
1108 | The underlying data model is exposed to views and delegates as a hierarchy | - | ||||||||||||||||||||||||
1109 | of tables. If you do not make use of the hierarchy, then the model is a | - | ||||||||||||||||||||||||
1110 | simple table of rows and columns. Each item has a unique index specified by | - | ||||||||||||||||||||||||
1111 | a QModelIndex. | - | ||||||||||||||||||||||||
1112 | - | |||||||||||||||||||||||||
1113 | \image modelindex-no-parent.png | - | ||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||
1115 | Every item of data that can be accessed via a model has an associated model | - | ||||||||||||||||||||||||
1116 | index. You can obtain this model index using the index() function. Each | - | ||||||||||||||||||||||||
1117 | index may have a sibling() index; child items have a parent() index. | - | ||||||||||||||||||||||||
1118 | - | |||||||||||||||||||||||||
1119 | Each item has a number of data elements associated with it and they can be | - | ||||||||||||||||||||||||
1120 | retrieved by specifying a role (see \l Qt::ItemDataRole) to the model's | - | ||||||||||||||||||||||||
1121 | data() function. Data for all available roles can be obtained at the same | - | ||||||||||||||||||||||||
1122 | time using the itemData() function. | - | ||||||||||||||||||||||||
1123 | - | |||||||||||||||||||||||||
1124 | Data for each role is set using a particular \l Qt::ItemDataRole. Data for | - | ||||||||||||||||||||||||
1125 | individual roles are set individually with setData(), or they can be set | - | ||||||||||||||||||||||||
1126 | for all roles with setItemData(). | - | ||||||||||||||||||||||||
1127 | - | |||||||||||||||||||||||||
1128 | Items can be queried with flags() (see \l Qt::ItemFlag) to see if they can | - | ||||||||||||||||||||||||
1129 | be selected, dragged, or manipulated in other ways. | - | ||||||||||||||||||||||||
1130 | - | |||||||||||||||||||||||||
1131 | If an item has child objects, hasChildren() returns \c{true} for the | - | ||||||||||||||||||||||||
1132 | corresponding index. | - | ||||||||||||||||||||||||
1133 | - | |||||||||||||||||||||||||
1134 | The model has a rowCount() and a columnCount() for each level of the | - | ||||||||||||||||||||||||
1135 | hierarchy. Rows and columns can be inserted and removed with insertRows(), | - | ||||||||||||||||||||||||
1136 | insertColumns(), removeRows(), and removeColumns(). | - | ||||||||||||||||||||||||
1137 | - | |||||||||||||||||||||||||
1138 | The model emits signals to indicate changes. For example, dataChanged() is | - | ||||||||||||||||||||||||
1139 | emitted whenever items of data made available by the model are changed. | - | ||||||||||||||||||||||||
1140 | Changes to the headers supplied by the model cause headerDataChanged() to | - | ||||||||||||||||||||||||
1141 | be emitted. If the structure of the underlying data changes, the model can | - | ||||||||||||||||||||||||
1142 | emit layoutChanged() to indicate to any attached views that they should | - | ||||||||||||||||||||||||
1143 | redisplay any items shown, taking the new structure into account. | - | ||||||||||||||||||||||||
1144 | - | |||||||||||||||||||||||||
1145 | The items available through the model can be searched for particular data | - | ||||||||||||||||||||||||
1146 | using the match() function. | - | ||||||||||||||||||||||||
1147 | - | |||||||||||||||||||||||||
1148 | To sort the model, you can use sort(). | - | ||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||
1150 | - | |||||||||||||||||||||||||
1151 | \section1 Subclassing | - | ||||||||||||||||||||||||
1152 | - | |||||||||||||||||||||||||
1153 | \note Some general guidelines for subclassing models are available in the | - | ||||||||||||||||||||||||
1154 | \l{Model Subclassing Reference}. | - | ||||||||||||||||||||||||
1155 | - | |||||||||||||||||||||||||
1156 | When subclassing QAbstractItemModel, at the very least you must implement | - | ||||||||||||||||||||||||
1157 | index(), parent(), rowCount(), columnCount(), and data(). These functions | - | ||||||||||||||||||||||||
1158 | are used in all read-only models, and form the basis of editable models. | - | ||||||||||||||||||||||||
1159 | - | |||||||||||||||||||||||||
1160 | You can also reimplement hasChildren() to provide special behavior for | - | ||||||||||||||||||||||||
1161 | models where the implementation of rowCount() is expensive. This makes it | - | ||||||||||||||||||||||||
1162 | possible for models to restrict the amount of data requested by views, and | - | ||||||||||||||||||||||||
1163 | can be used as a way to implement lazy population of model data. | - | ||||||||||||||||||||||||
1164 | - | |||||||||||||||||||||||||
1165 | To enable editing in your model, you must also implement setData(), and | - | ||||||||||||||||||||||||
1166 | reimplement flags() to ensure that \c ItemIsEditable is returned. You can | - | ||||||||||||||||||||||||
1167 | also reimplement headerData() and setHeaderData() to control the way the | - | ||||||||||||||||||||||||
1168 | headers for your model are presented. | - | ||||||||||||||||||||||||
1169 | - | |||||||||||||||||||||||||
1170 | The dataChanged() and headerDataChanged() signals must be emitted | - | ||||||||||||||||||||||||
1171 | explicitly when reimplementing the setData() and setHeaderData() functions, | - | ||||||||||||||||||||||||
1172 | respectively. | - | ||||||||||||||||||||||||
1173 | - | |||||||||||||||||||||||||
1174 | Custom models need to create model indexes for other components to use. To | - | ||||||||||||||||||||||||
1175 | do this, call createIndex() with suitable row and column numbers for the | - | ||||||||||||||||||||||||
1176 | item, and an identifier for it, either as a pointer or as an integer value. | - | ||||||||||||||||||||||||
1177 | The combination of these values must be unique for each item. Custom models | - | ||||||||||||||||||||||||
1178 | typically use these unique identifiers in other reimplemented functions to | - | ||||||||||||||||||||||||
1179 | retrieve item data and access information about the item's parents and | - | ||||||||||||||||||||||||
1180 | children. See the \l{Simple Tree Model Example} for more information about | - | ||||||||||||||||||||||||
1181 | unique identifiers. | - | ||||||||||||||||||||||||
1182 | - | |||||||||||||||||||||||||
1183 | It is not necessary to support every role defined in Qt::ItemDataRole. | - | ||||||||||||||||||||||||
1184 | Depending on the type of data contained within a model, it may only be | - | ||||||||||||||||||||||||
1185 | useful to implement the data() function to return valid information for | - | ||||||||||||||||||||||||
1186 | some of the more common roles. Most models provide at least a textual | - | ||||||||||||||||||||||||
1187 | representation of item data for the Qt::DisplayRole, and well-behaved | - | ||||||||||||||||||||||||
1188 | models should also provide valid information for the Qt::ToolTipRole and | - | ||||||||||||||||||||||||
1189 | Qt::WhatsThisRole. Supporting these roles enables models to be used with | - | ||||||||||||||||||||||||
1190 | standard Qt views. However, for some models that handle highly-specialized | - | ||||||||||||||||||||||||
1191 | data, it may be appropriate to provide data only for user-defined roles. | - | ||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||
1193 | Models that provide interfaces to resizable data structures can provide | - | ||||||||||||||||||||||||
1194 | implementations of insertRows(), removeRows(), insertColumns(),and | - | ||||||||||||||||||||||||
1195 | removeColumns(). When implementing these functions, it is important to | - | ||||||||||||||||||||||||
1196 | notify any connected views about changes to the model's dimensions both | - | ||||||||||||||||||||||||
1197 | \e before and \e after they occur: | - | ||||||||||||||||||||||||
1198 | - | |||||||||||||||||||||||||
1199 | \list | - | ||||||||||||||||||||||||
1200 | \li An insertRows() implementation must call beginInsertRows() \e before | - | ||||||||||||||||||||||||
1201 | inserting new rows into the data structure, and endInsertRows() | - | ||||||||||||||||||||||||
1202 | \e{immediately afterwards}. | - | ||||||||||||||||||||||||
1203 | \li An insertColumns() implementation must call beginInsertColumns() | - | ||||||||||||||||||||||||
1204 | \e before inserting new columns into the data structure, and | - | ||||||||||||||||||||||||
1205 | endInsertColumns() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
1206 | \li A removeRows() implementation must call beginRemoveRows() \e before | - | ||||||||||||||||||||||||
1207 | the rows are removed from the data structure, and endRemoveRows() | - | ||||||||||||||||||||||||
1208 | \e{immediately afterwards}. | - | ||||||||||||||||||||||||
1209 | \li A removeColumns() implementation must call beginRemoveColumns() | - | ||||||||||||||||||||||||
1210 | \e before the columns are removed from the data structure, and | - | ||||||||||||||||||||||||
1211 | endRemoveColumns() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
1212 | \endlist | - | ||||||||||||||||||||||||
1213 | - | |||||||||||||||||||||||||
1214 | The \e private signals that these functions emit give attached components | - | ||||||||||||||||||||||||
1215 | the chance to take action before any data becomes unavailable. The | - | ||||||||||||||||||||||||
1216 | encapsulation of the insert and remove operations with these begin and end | - | ||||||||||||||||||||||||
1217 | functions also enables the model to manage \l{QPersistentModelIndex} | - | ||||||||||||||||||||||||
1218 | {persistent model indexes} correctly. \b{If you want selections to be | - | ||||||||||||||||||||||||
1219 | handled properly, you must ensure that you call these functions.} If you | - | ||||||||||||||||||||||||
1220 | insert or remove an item with children, you do not need to call these | - | ||||||||||||||||||||||||
1221 | functions for the child items. In other words, the parent item will take | - | ||||||||||||||||||||||||
1222 | care of its child items. | - | ||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||
1224 | To create models that populate incrementally, you can reimplement | - | ||||||||||||||||||||||||
1225 | fetchMore() and canFetchMore(). If the reimplementation of fetchMore() adds | - | ||||||||||||||||||||||||
1226 | rows to the model, \l{QAbstractItemModel::}{beginInsertRows()} and | - | ||||||||||||||||||||||||
1227 | \l{QAbstractItemModel::}{endInsertRows()} must be called. | - | ||||||||||||||||||||||||
1228 | - | |||||||||||||||||||||||||
1229 | \sa {Model Classes}, {Model Subclassing Reference}, QModelIndex, | - | ||||||||||||||||||||||||
1230 | QAbstractItemView, {Using drag and drop with item views}, | - | ||||||||||||||||||||||||
1231 | {Simple DOM Model Example}, {Simple Tree Model Example}, | - | ||||||||||||||||||||||||
1232 | {Editable Tree Model Example}, {Fetch More Example} | - | ||||||||||||||||||||||||
1233 | */ | - | ||||||||||||||||||||||||
1234 | - | |||||||||||||||||||||||||
1235 | /*! | - | ||||||||||||||||||||||||
1236 | \fn QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const = 0 | - | ||||||||||||||||||||||||
1237 | - | |||||||||||||||||||||||||
1238 | Returns the index of the item in the model specified by the given \a row, | - | ||||||||||||||||||||||||
1239 | \a column and \a parent index. | - | ||||||||||||||||||||||||
1240 | - | |||||||||||||||||||||||||
1241 | When reimplementing this function in a subclass, call createIndex() to | - | ||||||||||||||||||||||||
1242 | generate model indexes that other components can use to refer to items in | - | ||||||||||||||||||||||||
1243 | your model. | - | ||||||||||||||||||||||||
1244 | - | |||||||||||||||||||||||||
1245 | \sa createIndex() | - | ||||||||||||||||||||||||
1246 | */ | - | ||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||
1248 | /*! | - | ||||||||||||||||||||||||
1249 | \fn bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
1250 | - | |||||||||||||||||||||||||
1251 | Inserts a single column before the given \a column in the child items of | - | ||||||||||||||||||||||||
1252 | the \a parent specified. | - | ||||||||||||||||||||||||
1253 | - | |||||||||||||||||||||||||
1254 | Returns \c{true} if the column is inserted; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1255 | - | |||||||||||||||||||||||||
1256 | \sa insertColumns(), insertRow(), removeColumn() | - | ||||||||||||||||||||||||
1257 | */ | - | ||||||||||||||||||||||||
1258 | - | |||||||||||||||||||||||||
1259 | /*! | - | ||||||||||||||||||||||||
1260 | \fn bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent) | - | ||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | Inserts a single row before the given \a row in the child items of the | - | ||||||||||||||||||||||||
1263 | \a parent specified. | - | ||||||||||||||||||||||||
1264 | - | |||||||||||||||||||||||||
1265 | \note This function calls the virtual method insertRows. | - | ||||||||||||||||||||||||
1266 | - | |||||||||||||||||||||||||
1267 | Returns \c{true} if the row is inserted; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1268 | - | |||||||||||||||||||||||||
1269 | \sa insertRows(), insertColumn(), removeRow() | - | ||||||||||||||||||||||||
1270 | */ | - | ||||||||||||||||||||||||
1271 | - | |||||||||||||||||||||||||
1272 | /*! | - | ||||||||||||||||||||||||
1273 | \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 | - | ||||||||||||||||||||||||
1274 | - | |||||||||||||||||||||||||
1275 | Returns the parent of the model item with the given \a index. If the item | - | ||||||||||||||||||||||||
1276 | has no parent, an invalid QModelIndex is returned. | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | A common convention used in models that expose tree data structures is that | - | ||||||||||||||||||||||||
1279 | only items in the first column have children. For that case, when | - | ||||||||||||||||||||||||
1280 | reimplementing this function in a subclass the column of the returned | - | ||||||||||||||||||||||||
1281 | QModelIndex would be 0. | - | ||||||||||||||||||||||||
1282 | - | |||||||||||||||||||||||||
1283 | When reimplementing this function in a subclass, be careful to avoid | - | ||||||||||||||||||||||||
1284 | calling QModelIndex member functions, such as QModelIndex::parent(), since | - | ||||||||||||||||||||||||
1285 | indexes belonging to your model will simply call your implementation, | - | ||||||||||||||||||||||||
1286 | leading to infinite recursion. | - | ||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||
1288 | \sa createIndex() | - | ||||||||||||||||||||||||
1289 | */ | - | ||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||
1291 | /*! | - | ||||||||||||||||||||||||
1292 | \fn bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
1293 | - | |||||||||||||||||||||||||
1294 | Removes the given \a column from the child items of the \a parent | - | ||||||||||||||||||||||||
1295 | specified. | - | ||||||||||||||||||||||||
1296 | - | |||||||||||||||||||||||||
1297 | Returns \c{true} if the column is removed; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1298 | - | |||||||||||||||||||||||||
1299 | \sa removeColumns(), removeRow(), insertColumn() | - | ||||||||||||||||||||||||
1300 | */ | - | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | /*! | - | ||||||||||||||||||||||||
1303 | \fn bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent) | - | ||||||||||||||||||||||||
1304 | - | |||||||||||||||||||||||||
1305 | Removes the given \a row from the child items of the \a parent specified. | - | ||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||
1307 | Returns \c{true} if the row is removed; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1308 | - | |||||||||||||||||||||||||
1309 | This is a convenience function that calls removeRows(). The | - | ||||||||||||||||||||||||
1310 | QAbstractItemModel implementation of removeRows() does nothing. | - | ||||||||||||||||||||||||
1311 | - | |||||||||||||||||||||||||
1312 | \sa removeRows(), removeColumn(), insertRow() | - | ||||||||||||||||||||||||
1313 | */ | - | ||||||||||||||||||||||||
1314 | - | |||||||||||||||||||||||||
1315 | /*! | - | ||||||||||||||||||||||||
1316 | \fn bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||||||||||||||
1317 | - | |||||||||||||||||||||||||
1318 | On models that support this, moves \a sourceRow from \a sourceParent to \a destinationChild under | - | ||||||||||||||||||||||||
1319 | \a destinationParent. | - | ||||||||||||||||||||||||
1320 | - | |||||||||||||||||||||||||
1321 | Returns \c{true} if the rows were successfully moved; otherwise returns | - | ||||||||||||||||||||||||
1322 | \c{false}. | - | ||||||||||||||||||||||||
1323 | - | |||||||||||||||||||||||||
1324 | \sa moveRows(), moveColumn() | - | ||||||||||||||||||||||||
1325 | */ | - | ||||||||||||||||||||||||
1326 | - | |||||||||||||||||||||||||
1327 | /*! | - | ||||||||||||||||||||||||
1328 | \fn bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||
1330 | On models that support this, moves \a sourceColumn from \a sourceParent to \a destinationChild under | - | ||||||||||||||||||||||||
1331 | \a destinationParent. | - | ||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||
1333 | Returns \c{true} if the columns were successfully moved; otherwise returns | - | ||||||||||||||||||||||||
1334 | \c{false}. | - | ||||||||||||||||||||||||
1335 | - | |||||||||||||||||||||||||
1336 | \sa moveColumns(), moveRow() | - | ||||||||||||||||||||||||
1337 | */ | - | ||||||||||||||||||||||||
1338 | - | |||||||||||||||||||||||||
1339 | - | |||||||||||||||||||||||||
1340 | /*! | - | ||||||||||||||||||||||||
1341 | \fn void QAbstractItemModel::headerDataChanged(Qt::Orientation orientation, int first, int last) | - | ||||||||||||||||||||||||
1342 | - | |||||||||||||||||||||||||
1343 | This signal is emitted whenever a header is changed. The \a orientation | - | ||||||||||||||||||||||||
1344 | indicates whether the horizontal or vertical header has changed. The | - | ||||||||||||||||||||||||
1345 | sections in the header from the \a first to the \a last need to be updated. | - | ||||||||||||||||||||||||
1346 | - | |||||||||||||||||||||||||
1347 | When reimplementing the setHeaderData() function, this signal must be | - | ||||||||||||||||||||||||
1348 | emitted explicitly. | - | ||||||||||||||||||||||||
1349 | - | |||||||||||||||||||||||||
1350 | If you are changing the number of columns or rows you do not need to emit | - | ||||||||||||||||||||||||
1351 | this signal, but use the begin/end functions (refer to the section on | - | ||||||||||||||||||||||||
1352 | subclassing in the QAbstractItemModel class description for details). | - | ||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||
1354 | \sa headerData(), setHeaderData(), dataChanged() | - | ||||||||||||||||||||||||
1355 | */ | - | ||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||
1357 | - | |||||||||||||||||||||||||
1358 | /*! | - | ||||||||||||||||||||||||
1359 | \enum QAbstractItemModel::LayoutChangeHint | - | ||||||||||||||||||||||||
1360 | - | |||||||||||||||||||||||||
1361 | This enum describes the way the model changes layout. | - | ||||||||||||||||||||||||
1362 | - | |||||||||||||||||||||||||
1363 | \value NoLayoutChangeHint No hint is available. | - | ||||||||||||||||||||||||
1364 | \value VerticalSortHint Rows are being sorted. | - | ||||||||||||||||||||||||
1365 | \value HorizontalSortHint Columns are being sorted. | - | ||||||||||||||||||||||||
1366 | - | |||||||||||||||||||||||||
1367 | Note that VerticalSortHint and HorizontalSortHint carry the meaning that | - | ||||||||||||||||||||||||
1368 | items are being moved within the same parent, not moved to a different | - | ||||||||||||||||||||||||
1369 | parent in the model, and not filtered out or in. | - | ||||||||||||||||||||||||
1370 | */ | - | ||||||||||||||||||||||||
1371 | - | |||||||||||||||||||||||||
1372 | /*! | - | ||||||||||||||||||||||||
1373 | \fn void QAbstractItemModel::layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) | - | ||||||||||||||||||||||||
1374 | \since 5.0 | - | ||||||||||||||||||||||||
1375 | - | |||||||||||||||||||||||||
1376 | This signal is emitted just before the layout of a model is changed. | - | ||||||||||||||||||||||||
1377 | Components connected to this signal use it to adapt to changes in the | - | ||||||||||||||||||||||||
1378 | model's layout. | - | ||||||||||||||||||||||||
1379 | - | |||||||||||||||||||||||||
1380 | Subclasses should update any persistent model indexes after emitting | - | ||||||||||||||||||||||||
1381 | layoutAboutToBeChanged(). | - | ||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||
1383 | The optional \a parents parameter is used to give a more specific notification | - | ||||||||||||||||||||||||
1384 | about what parts of the layout of the model are changing. An empty list indicates | - | ||||||||||||||||||||||||
1385 | 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 | - | ||||||||||||||||||||||||
1386 | to give a hint about what is happening while the model is relayouting. | - | ||||||||||||||||||||||||
1387 | - | |||||||||||||||||||||||||
1388 | \sa layoutChanged(), changePersistentIndex() | - | ||||||||||||||||||||||||
1389 | */ | - | ||||||||||||||||||||||||
1390 | - | |||||||||||||||||||||||||
1391 | /*! | - | ||||||||||||||||||||||||
1392 | \fn void QAbstractItemModel::layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) | - | ||||||||||||||||||||||||
1393 | \since 5.0 | - | ||||||||||||||||||||||||
1394 | - | |||||||||||||||||||||||||
1395 | This signal is emitted whenever the layout of items exposed by the model | - | ||||||||||||||||||||||||
1396 | has changed; for example, when the model has been sorted. When this signal | - | ||||||||||||||||||||||||
1397 | is received by a view, it should update the layout of items to reflect this | - | ||||||||||||||||||||||||
1398 | change. | - | ||||||||||||||||||||||||
1399 | - | |||||||||||||||||||||||||
1400 | When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you | - | ||||||||||||||||||||||||
1401 | emit layoutAboutToBeChanged() before changing the order of items or | - | ||||||||||||||||||||||||
1402 | altering the structure of the data you expose to views, and emit | - | ||||||||||||||||||||||||
1403 | layoutChanged() after changing the layout. | - | ||||||||||||||||||||||||
1404 | - | |||||||||||||||||||||||||
1405 | The optional \a parents parameter is used to give a more specific notification | - | ||||||||||||||||||||||||
1406 | about what parts of the layout of the model are changing. An empty list indicates | - | ||||||||||||||||||||||||
1407 | 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 | - | ||||||||||||||||||||||||
1408 | to give a hint about what is happening while the model is relayouting. | - | ||||||||||||||||||||||||
1409 | - | |||||||||||||||||||||||||
1410 | Subclasses should update any persistent model indexes before emitting | - | ||||||||||||||||||||||||
1411 | layoutChanged(). In other words, when the structure changes: | - | ||||||||||||||||||||||||
1412 | - | |||||||||||||||||||||||||
1413 | \list | - | ||||||||||||||||||||||||
1414 | \li emit layoutAboutToBeChanged | - | ||||||||||||||||||||||||
1415 | \li Remember the QModelIndex that will change | - | ||||||||||||||||||||||||
1416 | \li Update your internal data | - | ||||||||||||||||||||||||
1417 | \li Call changePersistentIndex() | - | ||||||||||||||||||||||||
1418 | \li emit layoutChanged | - | ||||||||||||||||||||||||
1419 | \endlist | - | ||||||||||||||||||||||||
1420 | - | |||||||||||||||||||||||||
1421 | \sa layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), | - | ||||||||||||||||||||||||
1422 | changePersistentIndex() | - | ||||||||||||||||||||||||
1423 | */ | - | ||||||||||||||||||||||||
1424 | - | |||||||||||||||||||||||||
1425 | /*! | - | ||||||||||||||||||||||||
1426 | Constructs an abstract item model with the given \a parent. | - | ||||||||||||||||||||||||
1427 | */ | - | ||||||||||||||||||||||||
1428 | QAbstractItemModel::QAbstractItemModel(QObject *parent) | - | ||||||||||||||||||||||||
1429 | : QObject(*new QAbstractItemModelPrivate, parent) | - | ||||||||||||||||||||||||
1430 | { | - | ||||||||||||||||||||||||
1431 | } executed 1564 times by 48 tests: end of block Executed by:
| 1564 | ||||||||||||||||||||||||
1432 | - | |||||||||||||||||||||||||
1433 | /*! | - | ||||||||||||||||||||||||
1434 | \internal | - | ||||||||||||||||||||||||
1435 | */ | - | ||||||||||||||||||||||||
1436 | QAbstractItemModel::QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||||||||
1437 | : QObject(dd, parent) | - | ||||||||||||||||||||||||
1438 | { | - | ||||||||||||||||||||||||
1439 | } executed 3812 times by 44 tests: end of block Executed by:
| 3812 | ||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | /*! | - | ||||||||||||||||||||||||
1442 | Destroys the abstract item model. | - | ||||||||||||||||||||||||
1443 | */ | - | ||||||||||||||||||||||||
1444 | QAbstractItemModel::~QAbstractItemModel() | - | ||||||||||||||||||||||||
1445 | { | - | ||||||||||||||||||||||||
1446 | d_func()->invalidatePersistentIndexes(); | - | ||||||||||||||||||||||||
1447 | } executed 5209 times by 98 tests: end of block Executed by:
| 5209 | ||||||||||||||||||||||||
1448 | - | |||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||
1450 | /*! | - | ||||||||||||||||||||||||
1451 | \fn int QAbstractItemModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||
1453 | Returns the number of rows under the given \a parent. When the parent is | - | ||||||||||||||||||||||||
1454 | valid it means that rowCount is returning the number of children of parent. | - | ||||||||||||||||||||||||
1455 | - | |||||||||||||||||||||||||
1456 | \note When implementing a table based model, rowCount() should return 0 | - | ||||||||||||||||||||||||
1457 | when the parent is valid. | - | ||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||
1459 | \sa columnCount() | - | ||||||||||||||||||||||||
1460 | */ | - | ||||||||||||||||||||||||
1461 | - | |||||||||||||||||||||||||
1462 | /*! | - | ||||||||||||||||||||||||
1463 | \fn int QAbstractItemModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
1464 | - | |||||||||||||||||||||||||
1465 | Returns the number of columns for the children of the given \a parent. | - | ||||||||||||||||||||||||
1466 | - | |||||||||||||||||||||||||
1467 | In most subclasses, the number of columns is independent of the \a parent. | - | ||||||||||||||||||||||||
1468 | - | |||||||||||||||||||||||||
1469 | For example: | - | ||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||
1471 | \snippet ../widgets/itemviews/simpledommodel/dommodel.cpp 2 | - | ||||||||||||||||||||||||
1472 | - | |||||||||||||||||||||||||
1473 | \note When implementing a table based model, columnCount() should return 0 | - | ||||||||||||||||||||||||
1474 | when the parent is valid. | - | ||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||
1476 | \sa rowCount() | - | ||||||||||||||||||||||||
1477 | */ | - | ||||||||||||||||||||||||
1478 | - | |||||||||||||||||||||||||
1479 | /*! | - | ||||||||||||||||||||||||
1480 | \fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) | - | ||||||||||||||||||||||||
1481 | - | |||||||||||||||||||||||||
1482 | This signal is emitted whenever the data in an existing item changes. | - | ||||||||||||||||||||||||
1483 | - | |||||||||||||||||||||||||
1484 | If the items are of the same parent, the affected ones are those between | - | ||||||||||||||||||||||||
1485 | \a topLeft and \a bottomRight inclusive. If the items do not have the same | - | ||||||||||||||||||||||||
1486 | parent, the behavior is undefined. | - | ||||||||||||||||||||||||
1487 | - | |||||||||||||||||||||||||
1488 | When reimplementing the setData() function, this signal must be emitted | - | ||||||||||||||||||||||||
1489 | explicitly. | - | ||||||||||||||||||||||||
1490 | - | |||||||||||||||||||||||||
1491 | The optional \a roles argument can be used to specify which data roles have actually | - | ||||||||||||||||||||||||
1492 | been modified. An empty vector in the roles argument means that all roles should be | - | ||||||||||||||||||||||||
1493 | considered modified. The order of elements in the roles argument does not have any | - | ||||||||||||||||||||||||
1494 | relevance. | - | ||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||
1496 | \sa headerDataChanged(), setData(), layoutChanged() | - | ||||||||||||||||||||||||
1497 | */ | - | ||||||||||||||||||||||||
1498 | - | |||||||||||||||||||||||||
1499 | /*! | - | ||||||||||||||||||||||||
1500 | \fn void QAbstractItemModel::rowsInserted(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1501 | - | |||||||||||||||||||||||||
1502 | This signal is emitted after rows have been inserted into the | - | ||||||||||||||||||||||||
1503 | model. The new items are those between \a first and \a last | - | ||||||||||||||||||||||||
1504 | inclusive, under the given \a parent item. | - | ||||||||||||||||||||||||
1505 | - | |||||||||||||||||||||||||
1506 | \note Components connected to this signal use it to adapt to changes in the | - | ||||||||||||||||||||||||
1507 | model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1508 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||
1510 | \sa insertRows(), beginInsertRows() | - | ||||||||||||||||||||||||
1511 | */ | - | ||||||||||||||||||||||||
1512 | - | |||||||||||||||||||||||||
1513 | /*! | - | ||||||||||||||||||||||||
1514 | \fn void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | This signal is emitted just before rows are inserted into the model. The | - | ||||||||||||||||||||||||
1517 | new items will be positioned between \a start and \a end inclusive, under | - | ||||||||||||||||||||||||
1518 | the given \a parent item. | - | ||||||||||||||||||||||||
1519 | - | |||||||||||||||||||||||||
1520 | \note Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1521 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1522 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||
1524 | \sa insertRows(), beginInsertRows() | - | ||||||||||||||||||||||||
1525 | */ | - | ||||||||||||||||||||||||
1526 | - | |||||||||||||||||||||||||
1527 | /*! | - | ||||||||||||||||||||||||
1528 | \fn void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1529 | - | |||||||||||||||||||||||||
1530 | This signal is emitted after rows have been removed from the model. The | - | ||||||||||||||||||||||||
1531 | removed items are those between \a first and \a last inclusive, under the | - | ||||||||||||||||||||||||
1532 | given \a parent item. | - | ||||||||||||||||||||||||
1533 | - | |||||||||||||||||||||||||
1534 | \note Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1535 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1536 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1537 | - | |||||||||||||||||||||||||
1538 | \sa removeRows(), beginRemoveRows() | - | ||||||||||||||||||||||||
1539 | */ | - | ||||||||||||||||||||||||
1540 | - | |||||||||||||||||||||||||
1541 | /*! | - | ||||||||||||||||||||||||
1542 | \fn void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1543 | - | |||||||||||||||||||||||||
1544 | This signal is emitted just before rows are removed from the model. The | - | ||||||||||||||||||||||||
1545 | items that will be removed are those between \a first and \a last inclusive, | - | ||||||||||||||||||||||||
1546 | under the given \a parent item. | - | ||||||||||||||||||||||||
1547 | - | |||||||||||||||||||||||||
1548 | \note Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1549 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1550 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1551 | - | |||||||||||||||||||||||||
1552 | \sa removeRows(), beginRemoveRows() | - | ||||||||||||||||||||||||
1553 | */ | - | ||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||
1555 | /*! | - | ||||||||||||||||||||||||
1556 | \fn void QAbstractItemModel::rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) | - | ||||||||||||||||||||||||
1557 | \since 4.6 | - | ||||||||||||||||||||||||
1558 | - | |||||||||||||||||||||||||
1559 | This signal is emitted after rows have been moved within the | - | ||||||||||||||||||||||||
1560 | model. The items between \a start and \a end | - | ||||||||||||||||||||||||
1561 | inclusive, under the given \a parent item have been moved to \a destination | - | ||||||||||||||||||||||||
1562 | starting at the row \a row. | - | ||||||||||||||||||||||||
1563 | - | |||||||||||||||||||||||||
1564 | \b{Note:} Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1565 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1566 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1567 | - | |||||||||||||||||||||||||
1568 | \sa beginMoveRows() | - | ||||||||||||||||||||||||
1569 | */ | - | ||||||||||||||||||||||||
1570 | - | |||||||||||||||||||||||||
1571 | /*! | - | ||||||||||||||||||||||||
1572 | \fn void QAbstractItemModel::rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) | - | ||||||||||||||||||||||||
1573 | \since 4.6 | - | ||||||||||||||||||||||||
1574 | - | |||||||||||||||||||||||||
1575 | This signal is emitted just before rows are moved within the | - | ||||||||||||||||||||||||
1576 | model. The items that will be moved are those between \a sourceStart and \a sourceEnd | - | ||||||||||||||||||||||||
1577 | inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent | - | ||||||||||||||||||||||||
1578 | starting at the row \a destinationRow. | - | ||||||||||||||||||||||||
1579 | - | |||||||||||||||||||||||||
1580 | \b{Note:} Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1581 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1582 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1583 | - | |||||||||||||||||||||||||
1584 | \sa beginMoveRows() | - | ||||||||||||||||||||||||
1585 | */ | - | ||||||||||||||||||||||||
1586 | - | |||||||||||||||||||||||||
1587 | /*! | - | ||||||||||||||||||||||||
1588 | \fn void QAbstractItemModel::columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column) | - | ||||||||||||||||||||||||
1589 | \since 4.6 | - | ||||||||||||||||||||||||
1590 | - | |||||||||||||||||||||||||
1591 | This signal is emitted after columns have been moved within the | - | ||||||||||||||||||||||||
1592 | model. The items between \a start and \a end | - | ||||||||||||||||||||||||
1593 | inclusive, under the given \a parent item have been moved to \a destination | - | ||||||||||||||||||||||||
1594 | starting at the column \a column. | - | ||||||||||||||||||||||||
1595 | - | |||||||||||||||||||||||||
1596 | \b{Note:} Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1597 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1598 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1599 | - | |||||||||||||||||||||||||
1600 | \sa beginMoveRows() | - | ||||||||||||||||||||||||
1601 | */ | - | ||||||||||||||||||||||||
1602 | - | |||||||||||||||||||||||||
1603 | /*! | - | ||||||||||||||||||||||||
1604 | \fn void QAbstractItemModel::columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) | - | ||||||||||||||||||||||||
1605 | \since 4.6 | - | ||||||||||||||||||||||||
1606 | - | |||||||||||||||||||||||||
1607 | This signal is emitted just before columns are moved within the | - | ||||||||||||||||||||||||
1608 | model. The items that will be moved are those between \a sourceStart and \a sourceEnd | - | ||||||||||||||||||||||||
1609 | inclusive, under the given \a sourceParent item. They will be moved to \a destinationParent | - | ||||||||||||||||||||||||
1610 | starting at the column \a destinationColumn. | - | ||||||||||||||||||||||||
1611 | - | |||||||||||||||||||||||||
1612 | \b{Note:} Components connected to this signal use it to adapt to changes | - | ||||||||||||||||||||||||
1613 | in the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1614 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1615 | - | |||||||||||||||||||||||||
1616 | \sa beginMoveRows() | - | ||||||||||||||||||||||||
1617 | */ | - | ||||||||||||||||||||||||
1618 | - | |||||||||||||||||||||||||
1619 | /*! | - | ||||||||||||||||||||||||
1620 | \fn void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1621 | - | |||||||||||||||||||||||||
1622 | This signal is emitted after columns have been inserted into the model. The | - | ||||||||||||||||||||||||
1623 | new items are those between \a first and \a last inclusive, under the given | - | ||||||||||||||||||||||||
1624 | \a parent item. | - | ||||||||||||||||||||||||
1625 | - | |||||||||||||||||||||||||
1626 | \note Components connected to this signal use it to adapt to changes in the | - | ||||||||||||||||||||||||
1627 | model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1628 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||
1630 | \sa insertColumns(), beginInsertColumns() | - | ||||||||||||||||||||||||
1631 | */ | - | ||||||||||||||||||||||||
1632 | - | |||||||||||||||||||||||||
1633 | /*! | - | ||||||||||||||||||||||||
1634 | \fn void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1635 | - | |||||||||||||||||||||||||
1636 | This signal is emitted just before columns are inserted into the model. The | - | ||||||||||||||||||||||||
1637 | new items will be positioned between \a first and \a last inclusive, under | - | ||||||||||||||||||||||||
1638 | the given \a parent item. | - | ||||||||||||||||||||||||
1639 | - | |||||||||||||||||||||||||
1640 | \note Components connected to this signal use it to adapt to changes in the | - | ||||||||||||||||||||||||
1641 | model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1642 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1643 | - | |||||||||||||||||||||||||
1644 | \sa insertColumns(), beginInsertColumns() | - | ||||||||||||||||||||||||
1645 | */ | - | ||||||||||||||||||||||||
1646 | - | |||||||||||||||||||||||||
1647 | /*! | - | ||||||||||||||||||||||||
1648 | \fn void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1649 | - | |||||||||||||||||||||||||
1650 | This signal is emitted after columns have been removed from the model. | - | ||||||||||||||||||||||||
1651 | The removed items are those between \a first and \a last inclusive, | - | ||||||||||||||||||||||||
1652 | under the given \a parent item. | - | ||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||
1654 | \note Components connected to this signal use it to adapt to changes in | - | ||||||||||||||||||||||||
1655 | the model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1656 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1657 | - | |||||||||||||||||||||||||
1658 | \sa removeColumns(), beginRemoveColumns() | - | ||||||||||||||||||||||||
1659 | */ | - | ||||||||||||||||||||||||
1660 | - | |||||||||||||||||||||||||
1661 | /*! | - | ||||||||||||||||||||||||
1662 | \fn void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
1663 | - | |||||||||||||||||||||||||
1664 | This signal is emitted just before columns are removed from the model. The | - | ||||||||||||||||||||||||
1665 | items to be removed are those between \a first and \a last inclusive, under | - | ||||||||||||||||||||||||
1666 | the given \a parent item. | - | ||||||||||||||||||||||||
1667 | - | |||||||||||||||||||||||||
1668 | \note Components connected to this signal use it to adapt to changes in the | - | ||||||||||||||||||||||||
1669 | model's dimensions. It can only be emitted by the QAbstractItemModel | - | ||||||||||||||||||||||||
1670 | implementation, and cannot be explicitly emitted in subclass code. | - | ||||||||||||||||||||||||
1671 | - | |||||||||||||||||||||||||
1672 | \sa removeColumns(), beginRemoveColumns() | - | ||||||||||||||||||||||||
1673 | */ | - | ||||||||||||||||||||||||
1674 | - | |||||||||||||||||||||||||
1675 | /*! | - | ||||||||||||||||||||||||
1676 | Returns \c{true} if the model returns a valid QModelIndex for \a row and | - | ||||||||||||||||||||||||
1677 | \a column with \a parent, otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1678 | */ | - | ||||||||||||||||||||||||
1679 | bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
1680 | { | - | ||||||||||||||||||||||||
1681 | if (row < 0 || column < 0)
| 578-226490 | ||||||||||||||||||||||||
1682 | return false; executed 1916 times by 9 tests: return false; Executed by:
| 1916 | ||||||||||||||||||||||||
1683 | return row < rowCount(parent) && column < columnCount(parent); executed 225152 times by 32 tests: return row < rowCount(parent) && column < columnCount(parent); Executed by:
| 2667-225152 | ||||||||||||||||||||||||
1684 | } | - | ||||||||||||||||||||||||
1685 | - | |||||||||||||||||||||||||
1686 | - | |||||||||||||||||||||||||
1687 | /*! | - | ||||||||||||||||||||||||
1688 | Returns \c{true} if \a parent has any children; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1689 | - | |||||||||||||||||||||||||
1690 | Use rowCount() on the parent to find out the number of children. | - | ||||||||||||||||||||||||
1691 | - | |||||||||||||||||||||||||
1692 | Note that it is undefined behavior to report that a particular index hasChildren | - | ||||||||||||||||||||||||
1693 | with this method if the same index has the flag Qt::ItemNeverHasChildren set. | - | ||||||||||||||||||||||||
1694 | - | |||||||||||||||||||||||||
1695 | \sa parent(), index() | - | ||||||||||||||||||||||||
1696 | */ | - | ||||||||||||||||||||||||
1697 | bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
1698 | { | - | ||||||||||||||||||||||||
1699 | return (rowCount(parent) > 0) && (columnCount(parent) > 0); executed 2127 times by 5 tests: return (rowCount(parent) > 0) && (columnCount(parent) > 0); Executed by:
| 1-2127 | ||||||||||||||||||||||||
1700 | } | - | ||||||||||||||||||||||||
1701 | - | |||||||||||||||||||||||||
1702 | /*! | - | ||||||||||||||||||||||||
1703 | \fn QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const | - | ||||||||||||||||||||||||
1704 | - | |||||||||||||||||||||||||
1705 | Returns the sibling at \a row and \a column for the item at \a index, or an | - | ||||||||||||||||||||||||
1706 | invalid QModelIndex if there is no sibling at that location. | - | ||||||||||||||||||||||||
1707 | - | |||||||||||||||||||||||||
1708 | sibling() is just a convenience function that finds the item's parent, and | - | ||||||||||||||||||||||||
1709 | uses it to retrieve the index of the child item in the specified \a row and | - | ||||||||||||||||||||||||
1710 | \a column. | - | ||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||
1712 | This method can optionally be overridden for implementation-specific optimization. | - | ||||||||||||||||||||||||
1713 | - | |||||||||||||||||||||||||
1714 | \sa index(), QModelIndex::row(), QModelIndex::column() | - | ||||||||||||||||||||||||
1715 | */ | - | ||||||||||||||||||||||||
1716 | QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &idx) const | - | ||||||||||||||||||||||||
1717 | { | - | ||||||||||||||||||||||||
1718 | return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx)); executed 33300 times by 18 tests: return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx)); Executed by:
| 134-33300 | ||||||||||||||||||||||||
1719 | } | - | ||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||
1721 | - | |||||||||||||||||||||||||
1722 | /*! | - | ||||||||||||||||||||||||
1723 | Returns a map with values for all predefined roles in the model for the | - | ||||||||||||||||||||||||
1724 | item at the given \a index. | - | ||||||||||||||||||||||||
1725 | - | |||||||||||||||||||||||||
1726 | Reimplement this function if you want to extend the default behavior of | - | ||||||||||||||||||||||||
1727 | this function to include custom roles in the map. | - | ||||||||||||||||||||||||
1728 | - | |||||||||||||||||||||||||
1729 | \sa Qt::ItemDataRole, data() | - | ||||||||||||||||||||||||
1730 | */ | - | ||||||||||||||||||||||||
1731 | QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1732 | { | - | ||||||||||||||||||||||||
1733 | QMap<int, QVariant> roles; | - | ||||||||||||||||||||||||
1734 | for (int i = 0; i < Qt::UserRole; ++i) {
| 455-116480 | ||||||||||||||||||||||||
1735 | QVariant variantData = data(index, i); | - | ||||||||||||||||||||||||
1736 | if (variantData.isValid())
| 15335-101145 | ||||||||||||||||||||||||
1737 | roles.insert(i, variantData); executed 101145 times by 5 tests: roles.insert(i, variantData); Executed by:
| 101145 | ||||||||||||||||||||||||
1738 | } executed 116480 times by 6 tests: end of block Executed by:
| 116480 | ||||||||||||||||||||||||
1739 | return roles; executed 455 times by 6 tests: return roles; Executed by:
| 455 | ||||||||||||||||||||||||
1740 | } | - | ||||||||||||||||||||||||
1741 | - | |||||||||||||||||||||||||
1742 | /*! | - | ||||||||||||||||||||||||
1743 | Sets the \a role data for the item at \a index to \a value. | - | ||||||||||||||||||||||||
1744 | - | |||||||||||||||||||||||||
1745 | Returns \c{true} if successful; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1746 | - | |||||||||||||||||||||||||
1747 | The dataChanged() signal should be emitted if the data was successfully | - | ||||||||||||||||||||||||
1748 | set. | - | ||||||||||||||||||||||||
1749 | - | |||||||||||||||||||||||||
1750 | The base class implementation returns \c{false}. This function and data() must | - | ||||||||||||||||||||||||
1751 | be reimplemented for editable models. | - | ||||||||||||||||||||||||
1752 | - | |||||||||||||||||||||||||
1753 | \sa Qt::ItemDataRole, data(), itemData() | - | ||||||||||||||||||||||||
1754 | */ | - | ||||||||||||||||||||||||
1755 | bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||||||||
1756 | { | - | ||||||||||||||||||||||||
1757 | Q_UNUSED(index); | - | ||||||||||||||||||||||||
1758 | Q_UNUSED(value); | - | ||||||||||||||||||||||||
1759 | Q_UNUSED(role); | - | ||||||||||||||||||||||||
1760 | return false; executed 25 times by 3 tests: return false; Executed by:
| 25 | ||||||||||||||||||||||||
1761 | } | - | ||||||||||||||||||||||||
1762 | - | |||||||||||||||||||||||||
1763 | /*! | - | ||||||||||||||||||||||||
1764 | \fn QVariant QAbstractItemModel::data(const QModelIndex &index, int role) const = 0 | - | ||||||||||||||||||||||||
1765 | - | |||||||||||||||||||||||||
1766 | Returns the data stored under the given \a role for the item referred to | - | ||||||||||||||||||||||||
1767 | by the \a index. | - | ||||||||||||||||||||||||
1768 | - | |||||||||||||||||||||||||
1769 | \note If you do not have a value to return, return an \b invalid | - | ||||||||||||||||||||||||
1770 | QVariant instead of returning 0. | - | ||||||||||||||||||||||||
1771 | - | |||||||||||||||||||||||||
1772 | \sa Qt::ItemDataRole, setData(), headerData() | - | ||||||||||||||||||||||||
1773 | */ | - | ||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||
1775 | /*! | - | ||||||||||||||||||||||||
1776 | Sets the role data for the item at \a index to the associated value in | - | ||||||||||||||||||||||||
1777 | \a roles, for every Qt::ItemDataRole. | - | ||||||||||||||||||||||||
1778 | - | |||||||||||||||||||||||||
1779 | Returns \c{true} if successful; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
1780 | - | |||||||||||||||||||||||||
1781 | Roles that are not in \a roles will not be modified. | - | ||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||
1783 | \sa setData(), data(), itemData() | - | ||||||||||||||||||||||||
1784 | */ | - | ||||||||||||||||||||||||
1785 | bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) | - | ||||||||||||||||||||||||
1786 | { | - | ||||||||||||||||||||||||
1787 | bool b = true; | - | ||||||||||||||||||||||||
1788 | for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
| 59-11776 | ||||||||||||||||||||||||
1789 | b = b && setData(index, it.value(), it.key()); executed 11776 times by 1 test: b = b && setData(index, it.value(), it.key()); Executed by:
| 0-11776 | ||||||||||||||||||||||||
1790 | return b; executed 59 times by 2 tests: return b; Executed by:
| 59 | ||||||||||||||||||||||||
1791 | } | - | ||||||||||||||||||||||||
1792 | - | |||||||||||||||||||||||||
1793 | /*! | - | ||||||||||||||||||||||||
1794 | Returns the list of allowed MIME types. By default, the built-in | - | ||||||||||||||||||||||||
1795 | models and views use an internal MIME type: | - | ||||||||||||||||||||||||
1796 | \c{application/x-qabstractitemmodeldatalist}. | - | ||||||||||||||||||||||||
1797 | - | |||||||||||||||||||||||||
1798 | When implementing drag and drop support in a custom model, if you | - | ||||||||||||||||||||||||
1799 | will return data in formats other than the default internal MIME | - | ||||||||||||||||||||||||
1800 | type, reimplement this function to return your list of MIME types. | - | ||||||||||||||||||||||||
1801 | - | |||||||||||||||||||||||||
1802 | If you reimplement this function in your custom model, you must | - | ||||||||||||||||||||||||
1803 | also reimplement the member functions that call it: mimeData() and | - | ||||||||||||||||||||||||
1804 | dropMimeData(). | - | ||||||||||||||||||||||||
1805 | - | |||||||||||||||||||||||||
1806 | \sa mimeData(), dropMimeData() | - | ||||||||||||||||||||||||
1807 | */ | - | ||||||||||||||||||||||||
1808 | QStringList QAbstractItemModel::mimeTypes() const | - | ||||||||||||||||||||||||
1809 | { | - | ||||||||||||||||||||||||
1810 | QStringList types; | - | ||||||||||||||||||||||||
1811 | types << QLatin1String("application/x-qabstractitemmodeldatalist"); | - | ||||||||||||||||||||||||
1812 | return types; executed 172 times by 7 tests: return types; Executed by:
| 172 | ||||||||||||||||||||||||
1813 | } | - | ||||||||||||||||||||||||
1814 | - | |||||||||||||||||||||||||
1815 | /*! | - | ||||||||||||||||||||||||
1816 | Returns an object that contains serialized items of data corresponding to | - | ||||||||||||||||||||||||
1817 | the list of \a indexes specified. The format used to describe the encoded | - | ||||||||||||||||||||||||
1818 | data is obtained from the mimeTypes() function. This default implementation | - | ||||||||||||||||||||||||
1819 | uses the default MIME type returned by the default implementation of | - | ||||||||||||||||||||||||
1820 | mimeTypes(). If you reimplement mimeTypes() in your custom model to return | - | ||||||||||||||||||||||||
1821 | more MIME types, reimplement this function to make use of them. | - | ||||||||||||||||||||||||
1822 | - | |||||||||||||||||||||||||
1823 | If the list of \a indexes is empty, or there are no supported MIME types, 0 | - | ||||||||||||||||||||||||
1824 | is returned rather than a serialized empty list. | - | ||||||||||||||||||||||||
1825 | - | |||||||||||||||||||||||||
1826 | \sa mimeTypes(), dropMimeData() | - | ||||||||||||||||||||||||
1827 | */ | - | ||||||||||||||||||||||||
1828 | QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||||||||||||||
1829 | { | - | ||||||||||||||||||||||||
1830 | if (indexes.count() <= 0)
| 8-28 | ||||||||||||||||||||||||
1831 | return 0; executed 8 times by 2 tests: return 0; Executed by:
| 8 | ||||||||||||||||||||||||
1832 | QStringList types = mimeTypes(); | - | ||||||||||||||||||||||||
1833 | if (types.isEmpty())
| 0-28 | ||||||||||||||||||||||||
1834 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1835 | QMimeData *data = new QMimeData(); | - | ||||||||||||||||||||||||
1836 | QString format = types.at(0); | - | ||||||||||||||||||||||||
1837 | QByteArray encoded; | - | ||||||||||||||||||||||||
1838 | QDataStream stream(&encoded, QIODevice::WriteOnly); | - | ||||||||||||||||||||||||
1839 | encodeData(indexes, stream); | - | ||||||||||||||||||||||||
1840 | data->setData(format, encoded); | - | ||||||||||||||||||||||||
1841 | return data; executed 28 times by 4 tests: return data; Executed by:
| 28 | ||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||
1843 | - | |||||||||||||||||||||||||
1844 | /*! | - | ||||||||||||||||||||||||
1845 | Returns \c{true} if a model can accept a drop of the \a data. This | - | ||||||||||||||||||||||||
1846 | default implementation only checks if \a data has at least one format | - | ||||||||||||||||||||||||
1847 | in the list of mimeTypes() and if \a action is among the | - | ||||||||||||||||||||||||
1848 | model's supportedDropActions(). | - | ||||||||||||||||||||||||
1849 | - | |||||||||||||||||||||||||
1850 | Reimplement this function in your custom model, if you want to | - | ||||||||||||||||||||||||
1851 | test whether the \a data can be dropped at \a row, \a column, | - | ||||||||||||||||||||||||
1852 | \a parent with \a action. If you don't need that test, it is not | - | ||||||||||||||||||||||||
1853 | necessary to reimplement this function. | - | ||||||||||||||||||||||||
1854 | - | |||||||||||||||||||||||||
1855 | \sa dropMimeData(), {Using drag and drop with item views} | - | ||||||||||||||||||||||||
1856 | */ | - | ||||||||||||||||||||||||
1857 | bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
1858 | int row, int column, | - | ||||||||||||||||||||||||
1859 | const QModelIndex &parent) const | - | ||||||||||||||||||||||||
1860 | { | - | ||||||||||||||||||||||||
1861 | Q_UNUSED(row) | - | ||||||||||||||||||||||||
1862 | Q_UNUSED(column) | - | ||||||||||||||||||||||||
1863 | Q_UNUSED(parent) | - | ||||||||||||||||||||||||
1864 | - | |||||||||||||||||||||||||
1865 | if (!(action & supportedDropActions()))
| 0 | ||||||||||||||||||||||||
1866 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1867 | - | |||||||||||||||||||||||||
1868 | const QStringList modelTypes = mimeTypes(); | - | ||||||||||||||||||||||||
1869 | for (int i = 0; i < modelTypes.count(); ++i) {
| 0 | ||||||||||||||||||||||||
1870 | if (data->hasFormat(modelTypes.at(i)))
| 0 | ||||||||||||||||||||||||
1871 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1872 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1873 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1874 | } | - | ||||||||||||||||||||||||
1875 | - | |||||||||||||||||||||||||
1876 | /*! | - | ||||||||||||||||||||||||
1877 | Handles the \a data supplied by a drag and drop operation that ended with | - | ||||||||||||||||||||||||
1878 | the given \a action. | - | ||||||||||||||||||||||||
1879 | - | |||||||||||||||||||||||||
1880 | Returns \c{true} if the data and action were handled by the model; otherwise | - | ||||||||||||||||||||||||
1881 | returns \c{false}. | - | ||||||||||||||||||||||||
1882 | - | |||||||||||||||||||||||||
1883 | The specified \a row, \a column and \a parent indicate the location of an | - | ||||||||||||||||||||||||
1884 | item in the model where the operation ended. It is the responsibility of | - | ||||||||||||||||||||||||
1885 | the model to complete the action at the correct location. | - | ||||||||||||||||||||||||
1886 | - | |||||||||||||||||||||||||
1887 | For instance, a drop action on an item in a QTreeView can result in new | - | ||||||||||||||||||||||||
1888 | items either being inserted as children of the item specified by \a row, | - | ||||||||||||||||||||||||
1889 | \a column, and \a parent, or as siblings of the item. | - | ||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||
1891 | When \a row and \a column are -1 it means that the dropped data should be | - | ||||||||||||||||||||||||
1892 | considered as dropped directly on \a parent. Usually this will mean | - | ||||||||||||||||||||||||
1893 | appending the data as child items of \a parent. If \a row and \a column are | - | ||||||||||||||||||||||||
1894 | greater than or equal zero, it means that the drop occurred just before the | - | ||||||||||||||||||||||||
1895 | specified \a row and \a column in the specified \a parent. | - | ||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||
1897 | The mimeTypes() member is called to get the list of acceptable MIME types. | - | ||||||||||||||||||||||||
1898 | This default implementation assumes the default implementation of mimeTypes(), | - | ||||||||||||||||||||||||
1899 | which returns a single default MIME type. If you reimplement mimeTypes() in | - | ||||||||||||||||||||||||
1900 | your custom model to return multiple MIME types, you must reimplement this | - | ||||||||||||||||||||||||
1901 | function to make use of them. | - | ||||||||||||||||||||||||
1902 | - | |||||||||||||||||||||||||
1903 | \sa supportedDropActions(), canDropMimeData(), {Using drag and drop with item views} | - | ||||||||||||||||||||||||
1904 | */ | - | ||||||||||||||||||||||||
1905 | bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
1906 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
1907 | { | - | ||||||||||||||||||||||||
1908 | // check if the action is supported | - | ||||||||||||||||||||||||
1909 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
| 0-12 | ||||||||||||||||||||||||
1910 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1911 | // check if the format is supported | - | ||||||||||||||||||||||||
1912 | QStringList types = mimeTypes(); | - | ||||||||||||||||||||||||
1913 | if (types.isEmpty())
| 0-12 | ||||||||||||||||||||||||
1914 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1915 | QString format = types.at(0); | - | ||||||||||||||||||||||||
1916 | if (!data->hasFormat(format))
| 0-12 | ||||||||||||||||||||||||
1917 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1918 | if (row > rowCount(parent))
| 4-8 | ||||||||||||||||||||||||
1919 | row = rowCount(parent); executed 4 times by 1 test: row = rowCount(parent); Executed by:
| 4 | ||||||||||||||||||||||||
1920 | if (row == -1)
| 0-12 | ||||||||||||||||||||||||
1921 | row = rowCount(parent); never executed: row = rowCount(parent); | 0 | ||||||||||||||||||||||||
1922 | if (column == -1)
| 0-12 | ||||||||||||||||||||||||
1923 | column = 0; never executed: column = 0; | 0 | ||||||||||||||||||||||||
1924 | // decode and insert | - | ||||||||||||||||||||||||
1925 | QByteArray encoded = data->data(format); | - | ||||||||||||||||||||||||
1926 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||||||||||||||
1927 | return decodeData(row, column, parent, stream); executed 12 times by 1 test: return decodeData(row, column, parent, stream); Executed by:
| 12 | ||||||||||||||||||||||||
1928 | } | - | ||||||||||||||||||||||||
1929 | - | |||||||||||||||||||||||||
1930 | /*! | - | ||||||||||||||||||||||||
1931 | \since 4.2 | - | ||||||||||||||||||||||||
1932 | - | |||||||||||||||||||||||||
1933 | Returns the drop actions supported by this model. | - | ||||||||||||||||||||||||
1934 | - | |||||||||||||||||||||||||
1935 | The default implementation returns Qt::CopyAction. Reimplement this | - | ||||||||||||||||||||||||
1936 | function if you wish to support additional actions. You must also | - | ||||||||||||||||||||||||
1937 | reimplement the dropMimeData() function to handle the additional | - | ||||||||||||||||||||||||
1938 | operations. | - | ||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||
1940 | \sa dropMimeData(), Qt::DropActions, {Using drag and drop with item | - | ||||||||||||||||||||||||
1941 | views} | - | ||||||||||||||||||||||||
1942 | */ | - | ||||||||||||||||||||||||
1943 | Qt::DropActions QAbstractItemModel::supportedDropActions() const | - | ||||||||||||||||||||||||
1944 | { | - | ||||||||||||||||||||||||
1945 | return Qt::CopyAction; executed 91 times by 4 tests: return Qt::CopyAction; Executed by:
| 91 | ||||||||||||||||||||||||
1946 | } | - | ||||||||||||||||||||||||
1947 | - | |||||||||||||||||||||||||
1948 | /*! | - | ||||||||||||||||||||||||
1949 | Returns the actions supported by the data in this model. | - | ||||||||||||||||||||||||
1950 | - | |||||||||||||||||||||||||
1951 | The default implementation returns supportedDropActions(). Reimplement | - | ||||||||||||||||||||||||
1952 | this function if you wish to support additional actions. | - | ||||||||||||||||||||||||
1953 | - | |||||||||||||||||||||||||
1954 | supportedDragActions() is used by QAbstractItemView::startDrag() as the | - | ||||||||||||||||||||||||
1955 | default values when a drag occurs. | - | ||||||||||||||||||||||||
1956 | - | |||||||||||||||||||||||||
1957 | \sa Qt::DropActions, {Using drag and drop with item views} | - | ||||||||||||||||||||||||
1958 | */ | - | ||||||||||||||||||||||||
1959 | Qt::DropActions QAbstractItemModel::supportedDragActions() const | - | ||||||||||||||||||||||||
1960 | { | - | ||||||||||||||||||||||||
1961 | Q_D(const QAbstractItemModel); | - | ||||||||||||||||||||||||
1962 | if (d->supportedDragActions != -1)
| 0-1 | ||||||||||||||||||||||||
1963 | return d->supportedDragActions; never executed: return d->supportedDragActions; | 0 | ||||||||||||||||||||||||
1964 | return supportedDropActions(); executed 1 time by 1 test: return supportedDropActions(); Executed by:
| 1 | ||||||||||||||||||||||||
1965 | } | - | ||||||||||||||||||||||||
1966 | - | |||||||||||||||||||||||||
1967 | /*! | - | ||||||||||||||||||||||||
1968 | \internal | - | ||||||||||||||||||||||||
1969 | */ | - | ||||||||||||||||||||||||
1970 | void QAbstractItemModel::doSetSupportedDragActions(Qt::DropActions actions) | - | ||||||||||||||||||||||||
1971 | { | - | ||||||||||||||||||||||||
1972 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
1973 | d->supportedDragActions = actions; | - | ||||||||||||||||||||||||
1974 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1975 | - | |||||||||||||||||||||||||
1976 | /*! | - | ||||||||||||||||||||||||
1977 | \since 4.2 | - | ||||||||||||||||||||||||
1978 | \obsolete | - | ||||||||||||||||||||||||
1979 | \fn void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions) | - | ||||||||||||||||||||||||
1980 | - | |||||||||||||||||||||||||
1981 | This function is obsolete. Reimplement supportedDragActions() instead. | - | ||||||||||||||||||||||||
1982 | - | |||||||||||||||||||||||||
1983 | Sets the supported drag \a actions for the items in the model. | - | ||||||||||||||||||||||||
1984 | - | |||||||||||||||||||||||||
1985 | \sa supportedDragActions(), {Using drag and drop with item views} | - | ||||||||||||||||||||||||
1986 | */ | - | ||||||||||||||||||||||||
1987 | - | |||||||||||||||||||||||||
1988 | /*! | - | ||||||||||||||||||||||||
1989 | \note The base class implementation of this function does nothing and | - | ||||||||||||||||||||||||
1990 | returns \c{false}. | - | ||||||||||||||||||||||||
1991 | - | |||||||||||||||||||||||||
1992 | On models that support this, inserts \a count rows into the model before | - | ||||||||||||||||||||||||
1993 | the given \a row. Items in the new row will be children of the item | - | ||||||||||||||||||||||||
1994 | represented by the \a parent model index. | - | ||||||||||||||||||||||||
1995 | - | |||||||||||||||||||||||||
1996 | If \a row is 0, the rows are prepended to any existing rows in the parent. | - | ||||||||||||||||||||||||
1997 | - | |||||||||||||||||||||||||
1998 | If \a row is rowCount(), the rows are appended to any existing rows in the | - | ||||||||||||||||||||||||
1999 | parent. | - | ||||||||||||||||||||||||
2000 | - | |||||||||||||||||||||||||
2001 | If \a parent has no children, a single column with \a count rows is | - | ||||||||||||||||||||||||
2002 | inserted. | - | ||||||||||||||||||||||||
2003 | - | |||||||||||||||||||||||||
2004 | Returns \c{true} if the rows were successfully inserted; otherwise returns | - | ||||||||||||||||||||||||
2005 | \c{false}. | - | ||||||||||||||||||||||||
2006 | - | |||||||||||||||||||||||||
2007 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2008 | want to support insertions. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2009 | altering the data. In either case, you will need to call | - | ||||||||||||||||||||||||
2010 | beginInsertRows() and endInsertRows() to notify other components that the | - | ||||||||||||||||||||||||
2011 | model has changed. | - | ||||||||||||||||||||||||
2012 | - | |||||||||||||||||||||||||
2013 | \sa insertColumns(), removeRows(), beginInsertRows(), endInsertRows() | - | ||||||||||||||||||||||||
2014 | */ | - | ||||||||||||||||||||||||
2015 | bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) | - | ||||||||||||||||||||||||
2016 | { | - | ||||||||||||||||||||||||
2017 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2018 | } | - | ||||||||||||||||||||||||
2019 | - | |||||||||||||||||||||||||
2020 | /*! | - | ||||||||||||||||||||||||
2021 | On models that support this, inserts \a count new columns into the model | - | ||||||||||||||||||||||||
2022 | before the given \a column. The items in each new column will be children | - | ||||||||||||||||||||||||
2023 | of the item represented by the \a parent model index. | - | ||||||||||||||||||||||||
2024 | - | |||||||||||||||||||||||||
2025 | If \a column is 0, the columns are prepended to any existing columns. | - | ||||||||||||||||||||||||
2026 | - | |||||||||||||||||||||||||
2027 | If \a column is columnCount(), the columns are appended to any existing | - | ||||||||||||||||||||||||
2028 | columns. | - | ||||||||||||||||||||||||
2029 | - | |||||||||||||||||||||||||
2030 | If \a parent has no children, a single row with \a count columns is | - | ||||||||||||||||||||||||
2031 | inserted. | - | ||||||||||||||||||||||||
2032 | - | |||||||||||||||||||||||||
2033 | Returns \c{true} if the columns were successfully inserted; otherwise returns | - | ||||||||||||||||||||||||
2034 | \c{false}. | - | ||||||||||||||||||||||||
2035 | - | |||||||||||||||||||||||||
2036 | The base class implementation does nothing and returns \c{false}. | - | ||||||||||||||||||||||||
2037 | - | |||||||||||||||||||||||||
2038 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2039 | want to support insertions. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2040 | altering the data. | - | ||||||||||||||||||||||||
2041 | - | |||||||||||||||||||||||||
2042 | \sa insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns() | - | ||||||||||||||||||||||||
2043 | */ | - | ||||||||||||||||||||||||
2044 | bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) | - | ||||||||||||||||||||||||
2045 | { | - | ||||||||||||||||||||||||
2046 | return false; executed 76 times by 1 test: return false; Executed by:
| 76 | ||||||||||||||||||||||||
2047 | } | - | ||||||||||||||||||||||||
2048 | - | |||||||||||||||||||||||||
2049 | /*! | - | ||||||||||||||||||||||||
2050 | On models that support this, removes \a count rows starting with the given | - | ||||||||||||||||||||||||
2051 | \a row under parent \a parent from the model. | - | ||||||||||||||||||||||||
2052 | - | |||||||||||||||||||||||||
2053 | Returns \c{true} if the rows were successfully removed; otherwise returns | - | ||||||||||||||||||||||||
2054 | \c{false}. | - | ||||||||||||||||||||||||
2055 | - | |||||||||||||||||||||||||
2056 | The base class implementation does nothing and returns \c{false}. | - | ||||||||||||||||||||||||
2057 | - | |||||||||||||||||||||||||
2058 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2059 | want to support removing. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2060 | altering the data. | - | ||||||||||||||||||||||||
2061 | - | |||||||||||||||||||||||||
2062 | \sa removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), | - | ||||||||||||||||||||||||
2063 | endRemoveRows() | - | ||||||||||||||||||||||||
2064 | */ | - | ||||||||||||||||||||||||
2065 | bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) | - | ||||||||||||||||||||||||
2066 | { | - | ||||||||||||||||||||||||
2067 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2068 | } | - | ||||||||||||||||||||||||
2069 | - | |||||||||||||||||||||||||
2070 | /*! | - | ||||||||||||||||||||||||
2071 | On models that support this, removes \a count columns starting with the | - | ||||||||||||||||||||||||
2072 | given \a column under parent \a parent from the model. | - | ||||||||||||||||||||||||
2073 | - | |||||||||||||||||||||||||
2074 | Returns \c{true} if the columns were successfully removed; otherwise returns | - | ||||||||||||||||||||||||
2075 | \c{false}. | - | ||||||||||||||||||||||||
2076 | - | |||||||||||||||||||||||||
2077 | The base class implementation does nothing and returns \c{false}. | - | ||||||||||||||||||||||||
2078 | - | |||||||||||||||||||||||||
2079 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2080 | want to support removing. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2081 | altering the data. | - | ||||||||||||||||||||||||
2082 | - | |||||||||||||||||||||||||
2083 | \sa removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), | - | ||||||||||||||||||||||||
2084 | endRemoveColumns() | - | ||||||||||||||||||||||||
2085 | */ | - | ||||||||||||||||||||||||
2086 | bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &) | - | ||||||||||||||||||||||||
2087 | { | - | ||||||||||||||||||||||||
2088 | return false; executed 132 times by 1 test: return false; Executed by:
| 132 | ||||||||||||||||||||||||
2089 | } | - | ||||||||||||||||||||||||
2090 | - | |||||||||||||||||||||||||
2091 | /*! | - | ||||||||||||||||||||||||
2092 | On models that support this, moves \a count rows starting with the given | - | ||||||||||||||||||||||||
2093 | \a sourceRow under parent \a sourceParent to row \a destinationChild under | - | ||||||||||||||||||||||||
2094 | parent \a destinationParent. | - | ||||||||||||||||||||||||
2095 | - | |||||||||||||||||||||||||
2096 | Returns \c{true} if the rows were successfully moved; otherwise returns | - | ||||||||||||||||||||||||
2097 | \c{false}. | - | ||||||||||||||||||||||||
2098 | - | |||||||||||||||||||||||||
2099 | The base class implementation does nothing and returns \c{false}. | - | ||||||||||||||||||||||||
2100 | - | |||||||||||||||||||||||||
2101 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2102 | want to support moving. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2103 | altering the data. | - | ||||||||||||||||||||||||
2104 | - | |||||||||||||||||||||||||
2105 | \sa beginMoveRows(), endMoveRows() | - | ||||||||||||||||||||||||
2106 | */ | - | ||||||||||||||||||||||||
2107 | bool QAbstractItemModel::moveRows(const QModelIndex &, int , int , const QModelIndex &, int) | - | ||||||||||||||||||||||||
2108 | { | - | ||||||||||||||||||||||||
2109 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2110 | } | - | ||||||||||||||||||||||||
2111 | - | |||||||||||||||||||||||||
2112 | /*! | - | ||||||||||||||||||||||||
2113 | On models that support this, moves \a count columns starting with the given | - | ||||||||||||||||||||||||
2114 | \a sourceColumn under parent \a sourceParent to column \a destinationChild under | - | ||||||||||||||||||||||||
2115 | parent \a destinationParent. | - | ||||||||||||||||||||||||
2116 | - | |||||||||||||||||||||||||
2117 | Returns \c{true} if the columns were successfully moved; otherwise returns | - | ||||||||||||||||||||||||
2118 | \c{false}. | - | ||||||||||||||||||||||||
2119 | - | |||||||||||||||||||||||||
2120 | The base class implementation does nothing and returns \c{false}. | - | ||||||||||||||||||||||||
2121 | - | |||||||||||||||||||||||||
2122 | If you implement your own model, you can reimplement this function if you | - | ||||||||||||||||||||||||
2123 | want to support moving. Alternatively, you can provide your own API for | - | ||||||||||||||||||||||||
2124 | altering the data. | - | ||||||||||||||||||||||||
2125 | - | |||||||||||||||||||||||||
2126 | \sa beginMoveColumns(), endMoveColumns() | - | ||||||||||||||||||||||||
2127 | */ | - | ||||||||||||||||||||||||
2128 | bool QAbstractItemModel::moveColumns(const QModelIndex &, int , int , const QModelIndex &, int) | - | ||||||||||||||||||||||||
2129 | { | - | ||||||||||||||||||||||||
2130 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2131 | } | - | ||||||||||||||||||||||||
2132 | - | |||||||||||||||||||||||||
2133 | /*! | - | ||||||||||||||||||||||||
2134 | Fetches any available data for the items with the parent specified by the | - | ||||||||||||||||||||||||
2135 | \a parent index. | - | ||||||||||||||||||||||||
2136 | - | |||||||||||||||||||||||||
2137 | Reimplement this if you are populating your model incrementally. | - | ||||||||||||||||||||||||
2138 | - | |||||||||||||||||||||||||
2139 | The default implementation does nothing. | - | ||||||||||||||||||||||||
2140 | - | |||||||||||||||||||||||||
2141 | \sa canFetchMore() | - | ||||||||||||||||||||||||
2142 | */ | - | ||||||||||||||||||||||||
2143 | void QAbstractItemModel::fetchMore(const QModelIndex &) | - | ||||||||||||||||||||||||
2144 | { | - | ||||||||||||||||||||||||
2145 | // do nothing | - | ||||||||||||||||||||||||
2146 | } | - | ||||||||||||||||||||||||
2147 | - | |||||||||||||||||||||||||
2148 | /*! | - | ||||||||||||||||||||||||
2149 | Returns \c{true} if there is more data available for \a parent; otherwise | - | ||||||||||||||||||||||||
2150 | returns \c{false}. | - | ||||||||||||||||||||||||
2151 | - | |||||||||||||||||||||||||
2152 | The default implementation always returns \c{false}. | - | ||||||||||||||||||||||||
2153 | - | |||||||||||||||||||||||||
2154 | If canFetchMore() returns \c true, the fetchMore() function should | - | ||||||||||||||||||||||||
2155 | be called. This is the behavior of QAbstractItemView, for example. | - | ||||||||||||||||||||||||
2156 | - | |||||||||||||||||||||||||
2157 | \sa fetchMore() | - | ||||||||||||||||||||||||
2158 | */ | - | ||||||||||||||||||||||||
2159 | bool QAbstractItemModel::canFetchMore(const QModelIndex &) const | - | ||||||||||||||||||||||||
2160 | { | - | ||||||||||||||||||||||||
2161 | return false; executed 7866 times by 37 tests: return false; Executed by:
| 7866 | ||||||||||||||||||||||||
2162 | } | - | ||||||||||||||||||||||||
2163 | - | |||||||||||||||||||||||||
2164 | /*! | - | ||||||||||||||||||||||||
2165 | Returns the item flags for the given \a index. | - | ||||||||||||||||||||||||
2166 | - | |||||||||||||||||||||||||
2167 | The base class implementation returns a combination of flags that enables | - | ||||||||||||||||||||||||
2168 | the item (\c ItemIsEnabled) and allows it to be selected | - | ||||||||||||||||||||||||
2169 | (\c ItemIsSelectable). | - | ||||||||||||||||||||||||
2170 | - | |||||||||||||||||||||||||
2171 | \sa Qt::ItemFlags | - | ||||||||||||||||||||||||
2172 | */ | - | ||||||||||||||||||||||||
2173 | Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
2174 | { | - | ||||||||||||||||||||||||
2175 | Q_D(const QAbstractItemModel); | - | ||||||||||||||||||||||||
2176 | if (!d->indexValid(index))
| 38-45466 | ||||||||||||||||||||||||
2177 | return 0; executed 38 times by 5 tests: return 0; Executed by:
| 38 | ||||||||||||||||||||||||
2178 | - | |||||||||||||||||||||||||
2179 | return Qt::ItemIsSelectable|Qt::ItemIsEnabled; executed 45466 times by 26 tests: return Qt::ItemIsSelectable|Qt::ItemIsEnabled; Executed by:
| 45466 | ||||||||||||||||||||||||
2180 | } | - | ||||||||||||||||||||||||
2181 | - | |||||||||||||||||||||||||
2182 | /*! | - | ||||||||||||||||||||||||
2183 | Sorts the model by \a column in the given \a order. | - | ||||||||||||||||||||||||
2184 | - | |||||||||||||||||||||||||
2185 | The base class implementation does nothing. | - | ||||||||||||||||||||||||
2186 | */ | - | ||||||||||||||||||||||||
2187 | void QAbstractItemModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||
2188 | { | - | ||||||||||||||||||||||||
2189 | Q_UNUSED(column); | - | ||||||||||||||||||||||||
2190 | Q_UNUSED(order); | - | ||||||||||||||||||||||||
2191 | // do nothing | - | ||||||||||||||||||||||||
2192 | } executed 484 times by 9 tests: end of block Executed by:
| 484 | ||||||||||||||||||||||||
2193 | - | |||||||||||||||||||||||||
2194 | /*! | - | ||||||||||||||||||||||||
2195 | Returns a model index for the buddy of the item represented by \a index. | - | ||||||||||||||||||||||||
2196 | When the user wants to edit an item, the view will call this function to | - | ||||||||||||||||||||||||
2197 | check whether another item in the model should be edited instead. Then, the | - | ||||||||||||||||||||||||
2198 | view will construct a delegate using the model index returned by the buddy | - | ||||||||||||||||||||||||
2199 | item. | - | ||||||||||||||||||||||||
2200 | - | |||||||||||||||||||||||||
2201 | The default implementation of this function has each item as its own buddy. | - | ||||||||||||||||||||||||
2202 | */ | - | ||||||||||||||||||||||||
2203 | QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const | - | ||||||||||||||||||||||||
2204 | { | - | ||||||||||||||||||||||||
2205 | return index; executed 15166 times by 28 tests: return index; Executed by:
| 15166 | ||||||||||||||||||||||||
2206 | } | - | ||||||||||||||||||||||||
2207 | - | |||||||||||||||||||||||||
2208 | /*! | - | ||||||||||||||||||||||||
2209 | Returns a list of indexes for the items in the column of the \a start index | - | ||||||||||||||||||||||||
2210 | where data stored under the given \a role matches the specified \a value. | - | ||||||||||||||||||||||||
2211 | The way the search is performed is defined by the \a flags given. The list | - | ||||||||||||||||||||||||
2212 | that is returned may be empty. Note also that the order of results in the | - | ||||||||||||||||||||||||
2213 | list may not correspond to the order in the model, if for example a proxy | - | ||||||||||||||||||||||||
2214 | model is used. The order of the results can not be relied upon. | - | ||||||||||||||||||||||||
2215 | - | |||||||||||||||||||||||||
2216 | The search begins from the \a start index, and continues until the number | - | ||||||||||||||||||||||||
2217 | of matching data items equals \a hits, the search reaches the last row, or | - | ||||||||||||||||||||||||
2218 | the search reaches \a start again - depending on whether \c MatchWrap is | - | ||||||||||||||||||||||||
2219 | specified in \a flags. If you want to search for all matching items, use | - | ||||||||||||||||||||||||
2220 | \a hits = -1. | - | ||||||||||||||||||||||||
2221 | - | |||||||||||||||||||||||||
2222 | By default, this function will perform a wrapping, string-based comparison | - | ||||||||||||||||||||||||
2223 | on all items, searching for items that begin with the search term specified | - | ||||||||||||||||||||||||
2224 | by \a value. | - | ||||||||||||||||||||||||
2225 | - | |||||||||||||||||||||||||
2226 | \note The default implementation of this function only searches columns. | - | ||||||||||||||||||||||||
2227 | Reimplement this function to include a different search behavior. | - | ||||||||||||||||||||||||
2228 | */ | - | ||||||||||||||||||||||||
2229 | QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, | - | ||||||||||||||||||||||||
2230 | const QVariant &value, int hits, | - | ||||||||||||||||||||||||
2231 | Qt::MatchFlags flags) const | - | ||||||||||||||||||||||||
2232 | { | - | ||||||||||||||||||||||||
2233 | QModelIndexList result; | - | ||||||||||||||||||||||||
2234 | uint matchType = flags & 0x0F; | - | ||||||||||||||||||||||||
2235 | Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 277-359 | ||||||||||||||||||||||||
2236 | bool recurse = flags & Qt::MatchRecursive; | - | ||||||||||||||||||||||||
2237 | bool wrap = flags & Qt::MatchWrap; | - | ||||||||||||||||||||||||
2238 | bool allHits = (hits == -1); | - | ||||||||||||||||||||||||
2239 | QString text; // only convert to a string if it is needed | - | ||||||||||||||||||||||||
2240 | QModelIndex p = parent(start); | - | ||||||||||||||||||||||||
2241 | int from = start.row(); | - | ||||||||||||||||||||||||
2242 | int to = rowCount(p); | - | ||||||||||||||||||||||||
2243 | - | |||||||||||||||||||||||||
2244 | // iterates twice if wrapping | - | ||||||||||||||||||||||||
2245 | for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) {
| 193-886 | ||||||||||||||||||||||||
2246 | for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) {
| 111-3155 | ||||||||||||||||||||||||
2247 | QModelIndex idx = index(r, start.column(), p); | - | ||||||||||||||||||||||||
2248 | if (!idx.isValid())
| 925-2119 | ||||||||||||||||||||||||
2249 | continue; executed 2119 times by 12 tests: continue; Executed by:
| 2119 | ||||||||||||||||||||||||
2250 | QVariant v = data(idx, role); | - | ||||||||||||||||||||||||
2251 | // QVariant based matching | - | ||||||||||||||||||||||||
2252 | if (matchType == Qt::MatchExactly) {
| 204-721 | ||||||||||||||||||||||||
2253 | if (value == v)
| 46-158 | ||||||||||||||||||||||||
2254 | result.append(idx); executed 46 times by 10 tests: result.append(idx); Executed by:
| 46 | ||||||||||||||||||||||||
2255 | } else { // QString based matching executed 204 times by 10 tests: end of block Executed by:
| 204 | ||||||||||||||||||||||||
2256 | if (text.isEmpty()) // lazy conversion
| 261-460 | ||||||||||||||||||||||||
2257 | text = value.toString(); executed 261 times by 10 tests: text = value.toString(); Executed by:
| 261 | ||||||||||||||||||||||||
2258 | QString t = v.toString(); | - | ||||||||||||||||||||||||
2259 | switch (matchType) { | - | ||||||||||||||||||||||||
2260 | case Qt::MatchRegExp: executed 8 times by 1 test: case Qt::MatchRegExp: Executed by:
| 8 | ||||||||||||||||||||||||
2261 | if (QRegExp(text, cs).exactMatch(t))
| 2-6 | ||||||||||||||||||||||||
2262 | result.append(idx); executed 2 times by 1 test: result.append(idx); Executed by:
| 2 | ||||||||||||||||||||||||
2263 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||
2264 | case Qt::MatchWildcard: executed 4 times by 1 test: case Qt::MatchWildcard: Executed by:
| 4 | ||||||||||||||||||||||||
2265 | if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
| 1-3 | ||||||||||||||||||||||||
2266 | result.append(idx); executed 3 times by 1 test: result.append(idx); Executed by:
| 3 | ||||||||||||||||||||||||
2267 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
2268 | case Qt::MatchStartsWith: executed 341 times by 9 tests: case Qt::MatchStartsWith: Executed by:
| 341 | ||||||||||||||||||||||||
2269 | if (t.startsWith(text, cs))
| 47-294 | ||||||||||||||||||||||||
2270 | result.append(idx); executed 47 times by 7 tests: result.append(idx); Executed by:
| 47 | ||||||||||||||||||||||||
2271 | break; executed 341 times by 9 tests: break; Executed by:
| 341 | ||||||||||||||||||||||||
2272 | case Qt::MatchEndsWith: executed 4 times by 1 test: case Qt::MatchEndsWith: Executed by:
| 4 | ||||||||||||||||||||||||
2273 | if (t.endsWith(text, cs))
| 2 | ||||||||||||||||||||||||
2274 | result.append(idx); executed 2 times by 1 test: result.append(idx); Executed by:
| 2 | ||||||||||||||||||||||||
2275 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||
2276 | case Qt::MatchFixedString: executed 360 times by 4 tests: case Qt::MatchFixedString: Executed by:
| 360 | ||||||||||||||||||||||||
2277 | if (t.compare(text, cs) == 0)
| 66-294 | ||||||||||||||||||||||||
2278 | result.append(idx); executed 66 times by 3 tests: result.append(idx); Executed by:
| 66 | ||||||||||||||||||||||||
2279 | break; executed 360 times by 4 tests: break; Executed by:
| 360 | ||||||||||||||||||||||||
2280 | case Qt::MatchContains: executed 4 times by 1 test: case Qt::MatchContains: Executed by:
| 4 | ||||||||||||||||||||||||
2281 | default: never executed: default: | 0 | ||||||||||||||||||||||||
2282 | if (t.contains(text, cs))
| 1-3 | ||||||||||||||||||||||||
2283 | result.append(idx); executed 3 times by 1 test: result.append(idx); Executed by:
| 3 | ||||||||||||||||||||||||
2284 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
2285 | } | - | ||||||||||||||||||||||||
2286 | if (recurse && hasChildren(idx)) { // search the hierarchy
| 13-885 | ||||||||||||||||||||||||
2287 | result += match(index(0, idx.column(), idx), role, | - | ||||||||||||||||||||||||
2288 | (text.isEmpty() ? value : text), | - | ||||||||||||||||||||||||
2289 | (allHits ? -1 : hits - result.count()), flags); | - | ||||||||||||||||||||||||
2290 | } executed 13 times by 2 tests: end of block Executed by:
| 13 | ||||||||||||||||||||||||
2291 | } executed 925 times by 16 tests: end of block Executed by:
| 925 | ||||||||||||||||||||||||
2292 | // prepare for the next iteration | - | ||||||||||||||||||||||||
2293 | from = 0; | - | ||||||||||||||||||||||||
2294 | to = start.row(); | - | ||||||||||||||||||||||||
2295 | } executed 829 times by 20 tests: end of block Executed by:
| 829 | ||||||||||||||||||||||||
2296 | return result; executed 636 times by 20 tests: return result; Executed by:
| 636 | ||||||||||||||||||||||||
2297 | } | - | ||||||||||||||||||||||||
2298 | - | |||||||||||||||||||||||||
2299 | /*! | - | ||||||||||||||||||||||||
2300 | Returns the row and column span of the item represented by \a index. | - | ||||||||||||||||||||||||
2301 | - | |||||||||||||||||||||||||
2302 | \note Currently, span is not used. | - | ||||||||||||||||||||||||
2303 | */ | - | ||||||||||||||||||||||||
2304 | - | |||||||||||||||||||||||||
2305 | QSize QAbstractItemModel::span(const QModelIndex &) const | - | ||||||||||||||||||||||||
2306 | { | - | ||||||||||||||||||||||||
2307 | return QSize(1, 1); executed 129 times by 3 tests: return QSize(1, 1); Executed by:
| 129 | ||||||||||||||||||||||||
2308 | } | - | ||||||||||||||||||||||||
2309 | - | |||||||||||||||||||||||||
2310 | /*! | - | ||||||||||||||||||||||||
2311 | \fn void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames) | - | ||||||||||||||||||||||||
2312 | \since 4.6 | - | ||||||||||||||||||||||||
2313 | \obsolete | - | ||||||||||||||||||||||||
2314 | - | |||||||||||||||||||||||||
2315 | This function is obsolete. Reimplement roleNames() instead. | - | ||||||||||||||||||||||||
2316 | - | |||||||||||||||||||||||||
2317 | Sets the model's role names to \a roleNames. | - | ||||||||||||||||||||||||
2318 | - | |||||||||||||||||||||||||
2319 | This function allows mapping of role identifiers to role property names in | - | ||||||||||||||||||||||||
2320 | scripting languages. | - | ||||||||||||||||||||||||
2321 | - | |||||||||||||||||||||||||
2322 | \sa roleNames() | - | ||||||||||||||||||||||||
2323 | */ | - | ||||||||||||||||||||||||
2324 | - | |||||||||||||||||||||||||
2325 | /*! | - | ||||||||||||||||||||||||
2326 | \internal | - | ||||||||||||||||||||||||
2327 | */ | - | ||||||||||||||||||||||||
2328 | void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames) | - | ||||||||||||||||||||||||
2329 | { | - | ||||||||||||||||||||||||
2330 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2331 | d->roleNames = roleNames; | - | ||||||||||||||||||||||||
2332 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||||||||||||||
2333 | - | |||||||||||||||||||||||||
2334 | /*! | - | ||||||||||||||||||||||||
2335 | \since 4.6 | - | ||||||||||||||||||||||||
2336 | - | |||||||||||||||||||||||||
2337 | Returns the model's role names. | - | ||||||||||||||||||||||||
2338 | - | |||||||||||||||||||||||||
2339 | The default role names set by Qt are: | - | ||||||||||||||||||||||||
2340 | - | |||||||||||||||||||||||||
2341 | \table | - | ||||||||||||||||||||||||
2342 | \header | - | ||||||||||||||||||||||||
2343 | \li Qt Role | - | ||||||||||||||||||||||||
2344 | \li QML Role Name | - | ||||||||||||||||||||||||
2345 | \row | - | ||||||||||||||||||||||||
2346 | \li Qt::DisplayRole | - | ||||||||||||||||||||||||
2347 | \li display | - | ||||||||||||||||||||||||
2348 | \row | - | ||||||||||||||||||||||||
2349 | \li Qt::DecorationRole | - | ||||||||||||||||||||||||
2350 | \li decoration | - | ||||||||||||||||||||||||
2351 | \row | - | ||||||||||||||||||||||||
2352 | \li Qt::EditRole | - | ||||||||||||||||||||||||
2353 | \li edit | - | ||||||||||||||||||||||||
2354 | \row | - | ||||||||||||||||||||||||
2355 | \li Qt::ToolTipRole | - | ||||||||||||||||||||||||
2356 | \li toolTip | - | ||||||||||||||||||||||||
2357 | \row | - | ||||||||||||||||||||||||
2358 | \li Qt::StatusTipRole | - | ||||||||||||||||||||||||
2359 | \li statusTip | - | ||||||||||||||||||||||||
2360 | \row | - | ||||||||||||||||||||||||
2361 | \li Qt::WhatsThisRole | - | ||||||||||||||||||||||||
2362 | \li whatsThis | - | ||||||||||||||||||||||||
2363 | \endtable | - | ||||||||||||||||||||||||
2364 | */ | - | ||||||||||||||||||||||||
2365 | QHash<int,QByteArray> QAbstractItemModel::roleNames() const | - | ||||||||||||||||||||||||
2366 | { | - | ||||||||||||||||||||||||
2367 | Q_D(const QAbstractItemModel); | - | ||||||||||||||||||||||||
2368 | return d->roleNames; executed 8104 times by 31 tests: return d->roleNames; Executed by:
| 8104 | ||||||||||||||||||||||||
2369 | } | - | ||||||||||||||||||||||||
2370 | - | |||||||||||||||||||||||||
2371 | /*! | - | ||||||||||||||||||||||||
2372 | Lets the model know that it should submit cached information to permanent | - | ||||||||||||||||||||||||
2373 | storage. This function is typically used for row editing. | - | ||||||||||||||||||||||||
2374 | - | |||||||||||||||||||||||||
2375 | Returns \c{true} if there is no error; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
2376 | - | |||||||||||||||||||||||||
2377 | \sa revert() | - | ||||||||||||||||||||||||
2378 | */ | - | ||||||||||||||||||||||||
2379 | - | |||||||||||||||||||||||||
2380 | bool QAbstractItemModel::submit() | - | ||||||||||||||||||||||||
2381 | { | - | ||||||||||||||||||||||||
2382 | return true; executed 2970 times by 21 tests: return true; Executed by:
| 2970 | ||||||||||||||||||||||||
2383 | } | - | ||||||||||||||||||||||||
2384 | - | |||||||||||||||||||||||||
2385 | /*! | - | ||||||||||||||||||||||||
2386 | Lets the model know that it should discard cached information. This | - | ||||||||||||||||||||||||
2387 | function is typically used for row editing. | - | ||||||||||||||||||||||||
2388 | - | |||||||||||||||||||||||||
2389 | \sa submit() | - | ||||||||||||||||||||||||
2390 | */ | - | ||||||||||||||||||||||||
2391 | - | |||||||||||||||||||||||||
2392 | void QAbstractItemModel::revert() | - | ||||||||||||||||||||||||
2393 | { | - | ||||||||||||||||||||||||
2394 | // do nothing | - | ||||||||||||||||||||||||
2395 | } | - | ||||||||||||||||||||||||
2396 | - | |||||||||||||||||||||||||
2397 | /*! | - | ||||||||||||||||||||||||
2398 | Returns the data for the given \a role and \a section in the header with | - | ||||||||||||||||||||||||
2399 | the specified \a orientation. | - | ||||||||||||||||||||||||
2400 | - | |||||||||||||||||||||||||
2401 | For horizontal headers, the section number corresponds to the column | - | ||||||||||||||||||||||||
2402 | number. Similarly, for vertical headers, the section number corresponds to | - | ||||||||||||||||||||||||
2403 | the row number. | - | ||||||||||||||||||||||||
2404 | - | |||||||||||||||||||||||||
2405 | \sa Qt::ItemDataRole, setHeaderData(), QHeaderView | - | ||||||||||||||||||||||||
2406 | */ | - | ||||||||||||||||||||||||
2407 | - | |||||||||||||||||||||||||
2408 | QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||||||||
2409 | { | - | ||||||||||||||||||||||||
2410 | Q_UNUSED(orientation); | - | ||||||||||||||||||||||||
2411 | if (role == Qt::DisplayRole)
| 21648-75678 | ||||||||||||||||||||||||
2412 | return section + 1; executed 21648 times by 14 tests: return section + 1; Executed by:
| 21648 | ||||||||||||||||||||||||
2413 | return QVariant(); executed 75678 times by 18 tests: return QVariant(); Executed by:
| 75678 | ||||||||||||||||||||||||
2414 | } | - | ||||||||||||||||||||||||
2415 | - | |||||||||||||||||||||||||
2416 | /*! | - | ||||||||||||||||||||||||
2417 | Sets the data for the given \a role and \a section in the header with the | - | ||||||||||||||||||||||||
2418 | specified \a orientation to the \a value supplied. | - | ||||||||||||||||||||||||
2419 | - | |||||||||||||||||||||||||
2420 | Returns \c{true} if the header's data was updated; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
2421 | - | |||||||||||||||||||||||||
2422 | When reimplementing this function, the headerDataChanged() signal must be | - | ||||||||||||||||||||||||
2423 | emitted explicitly. | - | ||||||||||||||||||||||||
2424 | - | |||||||||||||||||||||||||
2425 | \sa Qt::ItemDataRole, headerData() | - | ||||||||||||||||||||||||
2426 | */ | - | ||||||||||||||||||||||||
2427 | - | |||||||||||||||||||||||||
2428 | bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||||||||||||||
2429 | const QVariant &value, int role) | - | ||||||||||||||||||||||||
2430 | { | - | ||||||||||||||||||||||||
2431 | Q_UNUSED(section); | - | ||||||||||||||||||||||||
2432 | Q_UNUSED(orientation); | - | ||||||||||||||||||||||||
2433 | Q_UNUSED(value); | - | ||||||||||||||||||||||||
2434 | Q_UNUSED(role); | - | ||||||||||||||||||||||||
2435 | return false; executed 84 times by 4 tests: return false; Executed by:
| 84 | ||||||||||||||||||||||||
2436 | } | - | ||||||||||||||||||||||||
2437 | - | |||||||||||||||||||||||||
2438 | /*! | - | ||||||||||||||||||||||||
2439 | \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const | - | ||||||||||||||||||||||||
2440 | - | |||||||||||||||||||||||||
2441 | Creates a model index for the given \a row and \a column with the internal | - | ||||||||||||||||||||||||
2442 | pointer \a ptr. | - | ||||||||||||||||||||||||
2443 | - | |||||||||||||||||||||||||
2444 | When using a QSortFilterProxyModel, its indexes have their own internal | - | ||||||||||||||||||||||||
2445 | pointer. It is not advisable to access this internal pointer outside of the | - | ||||||||||||||||||||||||
2446 | model. Use the data() function instead. | - | ||||||||||||||||||||||||
2447 | - | |||||||||||||||||||||||||
2448 | This function provides a consistent interface that model subclasses must | - | ||||||||||||||||||||||||
2449 | use to create model indexes. | - | ||||||||||||||||||||||||
2450 | */ | - | ||||||||||||||||||||||||
2451 | - | |||||||||||||||||||||||||
2452 | /*! | - | ||||||||||||||||||||||||
2453 | \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, quintptr id) const | - | ||||||||||||||||||||||||
2454 | - | |||||||||||||||||||||||||
2455 | Creates a model index for the given \a row and \a column with the internal | - | ||||||||||||||||||||||||
2456 | identifier, \a id. | - | ||||||||||||||||||||||||
2457 | - | |||||||||||||||||||||||||
2458 | This function provides a consistent interface that model subclasses must | - | ||||||||||||||||||||||||
2459 | use to create model indexes. | - | ||||||||||||||||||||||||
2460 | - | |||||||||||||||||||||||||
2461 | \sa QModelIndex::internalId() | - | ||||||||||||||||||||||||
2462 | */ | - | ||||||||||||||||||||||||
2463 | - | |||||||||||||||||||||||||
2464 | /*! | - | ||||||||||||||||||||||||
2465 | \internal | - | ||||||||||||||||||||||||
2466 | */ | - | ||||||||||||||||||||||||
2467 | void QAbstractItemModel::encodeData(const QModelIndexList &indexes, QDataStream &stream) const | - | ||||||||||||||||||||||||
2468 | { | - | ||||||||||||||||||||||||
2469 | QModelIndexList::ConstIterator it = indexes.begin(); | - | ||||||||||||||||||||||||
2470 | for (; it != indexes.end(); ++it)
| 28-77 | ||||||||||||||||||||||||
2471 | stream << (*it).row() << (*it).column() << itemData(*it); executed 77 times by 4 tests: stream << (*it).row() << (*it).column() << itemData(*it); Executed by:
| 77 | ||||||||||||||||||||||||
2472 | } executed 28 times by 4 tests: end of block Executed by:
| 28 | ||||||||||||||||||||||||
2473 | - | |||||||||||||||||||||||||
2474 | /*! | - | ||||||||||||||||||||||||
2475 | \internal | - | ||||||||||||||||||||||||
2476 | */ | - | ||||||||||||||||||||||||
2477 | bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &parent, | - | ||||||||||||||||||||||||
2478 | QDataStream &stream) | - | ||||||||||||||||||||||||
2479 | { | - | ||||||||||||||||||||||||
2480 | int top = INT_MAX; | - | ||||||||||||||||||||||||
2481 | int left = INT_MAX; | - | ||||||||||||||||||||||||
2482 | int bottom = 0; | - | ||||||||||||||||||||||||
2483 | int right = 0; | - | ||||||||||||||||||||||||
2484 | QVector<int> rows, columns; | - | ||||||||||||||||||||||||
2485 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||||||||||||||
2486 | - | |||||||||||||||||||||||||
2487 | while (!stream.atEnd()) {
| 12-46 | ||||||||||||||||||||||||
2488 | int r, c; | - | ||||||||||||||||||||||||
2489 | QMap<int, QVariant> v; | - | ||||||||||||||||||||||||
2490 | stream >> r >> c >> v; | - | ||||||||||||||||||||||||
2491 | rows.append(r); | - | ||||||||||||||||||||||||
2492 | columns.append(c); | - | ||||||||||||||||||||||||
2493 | data.append(v); | - | ||||||||||||||||||||||||
2494 | top = qMin(r, top); | - | ||||||||||||||||||||||||
2495 | left = qMin(c, left); | - | ||||||||||||||||||||||||
2496 | bottom = qMax(r, bottom); | - | ||||||||||||||||||||||||
2497 | right = qMax(c, right); | - | ||||||||||||||||||||||||
2498 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||
2499 | - | |||||||||||||||||||||||||
2500 | // insert the dragged items into the table, use a bit array to avoid overwriting items, | - | ||||||||||||||||||||||||
2501 | // since items from different tables can have the same row and column | - | ||||||||||||||||||||||||
2502 | int dragRowCount = 0; | - | ||||||||||||||||||||||||
2503 | int dragColumnCount = right - left + 1; | - | ||||||||||||||||||||||||
2504 | - | |||||||||||||||||||||||||
2505 | // Compute the number of continuous rows upon insertion and modify the rows to match | - | ||||||||||||||||||||||||
2506 | QVector<int> rowsToInsert(bottom + 1); | - | ||||||||||||||||||||||||
2507 | for (int i = 0; i < rows.count(); ++i)
| 12-46 | ||||||||||||||||||||||||
2508 | rowsToInsert[rows.at(i)] = 1; executed 46 times by 1 test: rowsToInsert[rows.at(i)] = 1; Executed by:
| 46 | ||||||||||||||||||||||||
2509 | for (int i = 0; i < rowsToInsert.count(); ++i) {
| 12-24 | ||||||||||||||||||||||||
2510 | if (rowsToInsert[i] == 1){
| 2-22 | ||||||||||||||||||||||||
2511 | rowsToInsert[i] = dragRowCount; | - | ||||||||||||||||||||||||
2512 | ++dragRowCount; | - | ||||||||||||||||||||||||
2513 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||
2514 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||
2515 | for (int i = 0; i < rows.count(); ++i)
| 12-46 | ||||||||||||||||||||||||
2516 | rows[i] = top + rowsToInsert[rows[i]]; executed 46 times by 1 test: rows[i] = top + rowsToInsert[rows[i]]; Executed by:
| 46 | ||||||||||||||||||||||||
2517 | - | |||||||||||||||||||||||||
2518 | QBitArray isWrittenTo(dragRowCount * dragColumnCount); | - | ||||||||||||||||||||||||
2519 | - | |||||||||||||||||||||||||
2520 | // make space in the table for the dropped data | - | ||||||||||||||||||||||||
2521 | int colCount = columnCount(parent); | - | ||||||||||||||||||||||||
2522 | if (colCount == 0) {
| 0-12 | ||||||||||||||||||||||||
2523 | insertColumns(colCount, dragColumnCount - colCount, parent); | - | ||||||||||||||||||||||||
2524 | colCount = columnCount(parent); | - | ||||||||||||||||||||||||
2525 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2526 | insertRows(row, dragRowCount, parent); | - | ||||||||||||||||||||||||
2527 | - | |||||||||||||||||||||||||
2528 | row = qMax(0, row); | - | ||||||||||||||||||||||||
2529 | column = qMax(0, column); | - | ||||||||||||||||||||||||
2530 | - | |||||||||||||||||||||||||
2531 | QVector<QPersistentModelIndex> newIndexes(data.size()); | - | ||||||||||||||||||||||||
2532 | // set the data in the table | - | ||||||||||||||||||||||||
2533 | for (int j = 0; j < data.size(); ++j) {
| 12-46 | ||||||||||||||||||||||||
2534 | int relativeRow = rows.at(j) - top; | - | ||||||||||||||||||||||||
2535 | int relativeColumn = columns.at(j) - left; | - | ||||||||||||||||||||||||
2536 | int destinationRow = relativeRow + row; | - | ||||||||||||||||||||||||
2537 | int destinationColumn = relativeColumn + column; | - | ||||||||||||||||||||||||
2538 | int flat = (relativeRow * dragColumnCount) + relativeColumn; | - | ||||||||||||||||||||||||
2539 | // if the item was already written to, or we just can't fit it in the table, create a new row | - | ||||||||||||||||||||||||
2540 | if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
| 3-37 | ||||||||||||||||||||||||
2541 | destinationColumn = qBound(column, destinationColumn, colCount - 1); | - | ||||||||||||||||||||||||
2542 | destinationRow = row + dragRowCount; | - | ||||||||||||||||||||||||
2543 | insertRows(row + dragRowCount, 1, parent); | - | ||||||||||||||||||||||||
2544 | flat = (dragRowCount * dragColumnCount) + relativeColumn; | - | ||||||||||||||||||||||||
2545 | isWrittenTo.resize(++dragRowCount * dragColumnCount); | - | ||||||||||||||||||||||||
2546 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
2547 | if (!isWrittenTo.testBit(flat)) {
| 0-46 | ||||||||||||||||||||||||
2548 | newIndexes[j] = index(destinationRow, destinationColumn, parent); | - | ||||||||||||||||||||||||
2549 | isWrittenTo.setBit(flat); | - | ||||||||||||||||||||||||
2550 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||
2551 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||
2552 | - | |||||||||||||||||||||||||
2553 | for(int k = 0; k < newIndexes.size(); k++) {
| 12-46 | ||||||||||||||||||||||||
2554 | if (newIndexes.at(k).isValid())
| 0-46 | ||||||||||||||||||||||||
2555 | setItemData(newIndexes.at(k), data.at(k)); executed 46 times by 1 test: setItemData(newIndexes.at(k), data.at(k)); Executed by:
| 46 | ||||||||||||||||||||||||
2556 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||
2557 | - | |||||||||||||||||||||||||
2558 | return true; executed 12 times by 1 test: return true; Executed by:
| 12 | ||||||||||||||||||||||||
2559 | } | - | ||||||||||||||||||||||||
2560 | - | |||||||||||||||||||||||||
2561 | /*! | - | ||||||||||||||||||||||||
2562 | Begins a row insertion operation. | - | ||||||||||||||||||||||||
2563 | - | |||||||||||||||||||||||||
2564 | When reimplementing insertRows() in a subclass, you must call this function | - | ||||||||||||||||||||||||
2565 | \e before inserting data into the model's underlying data store. | - | ||||||||||||||||||||||||
2566 | - | |||||||||||||||||||||||||
2567 | The \a parent index corresponds to the parent into which the new rows are | - | ||||||||||||||||||||||||
2568 | inserted; \a first and \a last are the row numbers that the new rows will | - | ||||||||||||||||||||||||
2569 | have after they have been inserted. | - | ||||||||||||||||||||||||
2570 | - | |||||||||||||||||||||||||
2571 | \table 80% | - | ||||||||||||||||||||||||
2572 | \row | - | ||||||||||||||||||||||||
2573 | \li \inlineimage modelview-begin-insert-rows.png Inserting rows | - | ||||||||||||||||||||||||
2574 | \li Specify the first and last row numbers for the span of rows you | - | ||||||||||||||||||||||||
2575 | want to insert into an item in a model. | - | ||||||||||||||||||||||||
2576 | - | |||||||||||||||||||||||||
2577 | For example, as shown in the diagram, we insert three rows before | - | ||||||||||||||||||||||||
2578 | row 2, so \a first is 2 and \a last is 4: | - | ||||||||||||||||||||||||
2579 | - | |||||||||||||||||||||||||
2580 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 0 | - | ||||||||||||||||||||||||
2581 | - | |||||||||||||||||||||||||
2582 | This inserts the three new rows as rows 2, 3, and 4. | - | ||||||||||||||||||||||||
2583 | \row | - | ||||||||||||||||||||||||
2584 | \li \inlineimage modelview-begin-append-rows.png Appending rows | - | ||||||||||||||||||||||||
2585 | \li To append rows, insert them after the last row. | - | ||||||||||||||||||||||||
2586 | - | |||||||||||||||||||||||||
2587 | For example, as shown in the diagram, we append two rows to a | - | ||||||||||||||||||||||||
2588 | collection of 4 existing rows (ending in row 3), so \a first is 4 | - | ||||||||||||||||||||||||
2589 | and \a last is 5: | - | ||||||||||||||||||||||||
2590 | - | |||||||||||||||||||||||||
2591 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1 | - | ||||||||||||||||||||||||
2592 | - | |||||||||||||||||||||||||
2593 | This appends the two new rows as rows 4 and 5. | - | ||||||||||||||||||||||||
2594 | \endtable | - | ||||||||||||||||||||||||
2595 | - | |||||||||||||||||||||||||
2596 | \note This function emits the rowsAboutToBeInserted() signal which | - | ||||||||||||||||||||||||
2597 | connected views (or proxies) must handle before the data is inserted. | - | ||||||||||||||||||||||||
2598 | Otherwise, the views may end up in an invalid state. | - | ||||||||||||||||||||||||
2599 | \sa endInsertRows() | - | ||||||||||||||||||||||||
2600 | */ | - | ||||||||||||||||||||||||
2601 | void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
2602 | { | - | ||||||||||||||||||||||||
2603 | Q_ASSERT(first >= 0); | - | ||||||||||||||||||||||||
2604 | Q_ASSERT(last >= first); | - | ||||||||||||||||||||||||
2605 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2606 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||||||||||||||
2607 | emit rowsAboutToBeInserted(parent, first, last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2608 | d->rowsAboutToBeInserted(parent, first, last); | - | ||||||||||||||||||||||||
2609 | } executed 120937 times by 45 tests: end of block Executed by:
| 120937 | ||||||||||||||||||||||||
2610 | - | |||||||||||||||||||||||||
2611 | /*! | - | ||||||||||||||||||||||||
2612 | Ends a row insertion operation. | - | ||||||||||||||||||||||||
2613 | - | |||||||||||||||||||||||||
2614 | When reimplementing insertRows() in a subclass, you must call this function | - | ||||||||||||||||||||||||
2615 | \e after inserting data into the model's underlying data store. | - | ||||||||||||||||||||||||
2616 | - | |||||||||||||||||||||||||
2617 | \sa beginInsertRows() | - | ||||||||||||||||||||||||
2618 | */ | - | ||||||||||||||||||||||||
2619 | void QAbstractItemModel::endInsertRows() | - | ||||||||||||||||||||||||
2620 | { | - | ||||||||||||||||||||||||
2621 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2622 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||||||||||||||
2623 | d->rowsInserted(change.parent, change.first, change.last); | - | ||||||||||||||||||||||||
2624 | emit rowsInserted(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2625 | } executed 120937 times by 45 tests: end of block Executed by:
| 120937 | ||||||||||||||||||||||||
2626 | - | |||||||||||||||||||||||||
2627 | /*! | - | ||||||||||||||||||||||||
2628 | Begins a row removal operation. | - | ||||||||||||||||||||||||
2629 | - | |||||||||||||||||||||||||
2630 | When reimplementing removeRows() in a subclass, you must call this | - | ||||||||||||||||||||||||
2631 | function \e before removing data from the model's underlying data store. | - | ||||||||||||||||||||||||
2632 | - | |||||||||||||||||||||||||
2633 | The \a parent index corresponds to the parent from which the new rows are | - | ||||||||||||||||||||||||
2634 | removed; \a first and \a last are the row numbers of the rows to be | - | ||||||||||||||||||||||||
2635 | removed. | - | ||||||||||||||||||||||||
2636 | - | |||||||||||||||||||||||||
2637 | \table 80% | - | ||||||||||||||||||||||||
2638 | \row | - | ||||||||||||||||||||||||
2639 | \li \inlineimage modelview-begin-remove-rows.png Removing rows | - | ||||||||||||||||||||||||
2640 | \li Specify the first and last row numbers for the span of rows you | - | ||||||||||||||||||||||||
2641 | want to remove from an item in a model. | - | ||||||||||||||||||||||||
2642 | - | |||||||||||||||||||||||||
2643 | For example, as shown in the diagram, we remove the two rows from | - | ||||||||||||||||||||||||
2644 | row 2 to row 3, so \a first is 2 and \a last is 3: | - | ||||||||||||||||||||||||
2645 | - | |||||||||||||||||||||||||
2646 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 2 | - | ||||||||||||||||||||||||
2647 | \endtable | - | ||||||||||||||||||||||||
2648 | - | |||||||||||||||||||||||||
2649 | \note This function emits the rowsAboutToBeRemoved() signal which connected | - | ||||||||||||||||||||||||
2650 | views (or proxies) must handle before the data is removed. Otherwise, the | - | ||||||||||||||||||||||||
2651 | views may end up in an invalid state. | - | ||||||||||||||||||||||||
2652 | - | |||||||||||||||||||||||||
2653 | \sa endRemoveRows() | - | ||||||||||||||||||||||||
2654 | */ | - | ||||||||||||||||||||||||
2655 | void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
2656 | { | - | ||||||||||||||||||||||||
2657 | Q_ASSERT(first >= 0); | - | ||||||||||||||||||||||||
2658 | Q_ASSERT(last >= first); | - | ||||||||||||||||||||||||
2659 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2660 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||||||||||||||
2661 | emit rowsAboutToBeRemoved(parent, first, last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2662 | d->rowsAboutToBeRemoved(parent, first, last); | - | ||||||||||||||||||||||||
2663 | } executed 2661 times by 30 tests: end of block Executed by:
| 2661 | ||||||||||||||||||||||||
2664 | - | |||||||||||||||||||||||||
2665 | /*! | - | ||||||||||||||||||||||||
2666 | Ends a row removal operation. | - | ||||||||||||||||||||||||
2667 | - | |||||||||||||||||||||||||
2668 | When reimplementing removeRows() in a subclass, you must call this function | - | ||||||||||||||||||||||||
2669 | \e after removing data from the model's underlying data store. | - | ||||||||||||||||||||||||
2670 | - | |||||||||||||||||||||||||
2671 | \sa beginRemoveRows() | - | ||||||||||||||||||||||||
2672 | */ | - | ||||||||||||||||||||||||
2673 | void QAbstractItemModel::endRemoveRows() | - | ||||||||||||||||||||||||
2674 | { | - | ||||||||||||||||||||||||
2675 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2676 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||||||||||||||
2677 | d->rowsRemoved(change.parent, change.first, change.last); | - | ||||||||||||||||||||||||
2678 | emit rowsRemoved(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2679 | } executed 2661 times by 30 tests: end of block Executed by:
| 2661 | ||||||||||||||||||||||||
2680 | - | |||||||||||||||||||||||||
2681 | /*! | - | ||||||||||||||||||||||||
2682 | Returns whether a move operation is valid. | - | ||||||||||||||||||||||||
2683 | - | |||||||||||||||||||||||||
2684 | A move operation is not allowed if it moves a continuous range of rows to a destination within | - | ||||||||||||||||||||||||
2685 | itself, or if it attempts to move a row to one of its own descendants. | - | ||||||||||||||||||||||||
2686 | - | |||||||||||||||||||||||||
2687 | \internal | - | ||||||||||||||||||||||||
2688 | */ | - | ||||||||||||||||||||||||
2689 | bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int start, int end, const QModelIndex &destinationParent, int destinationStart, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
2690 | { | - | ||||||||||||||||||||||||
2691 | // Don't move the range within itself. | - | ||||||||||||||||||||||||
2692 | if (destinationParent == srcParent)
| 53-106 | ||||||||||||||||||||||||
2693 | return !(destinationStart >= start && destinationStart <= end + 1); executed 53 times by 2 tests: return !(destinationStart >= start && destinationStart <= end + 1); Executed by:
| 12-53 | ||||||||||||||||||||||||
2694 | - | |||||||||||||||||||||||||
2695 | QModelIndex destinationAncestor = destinationParent; | - | ||||||||||||||||||||||||
2696 | int pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
| 0-106 | ||||||||||||||||||||||||
2697 | forever { | - | ||||||||||||||||||||||||
2698 | if (destinationAncestor == srcParent) {
| 75-270 | ||||||||||||||||||||||||
2699 | if (pos >= start && pos <= end)
| 7-67 | ||||||||||||||||||||||||
2700 | return false; executed 60 times by 1 test: return false; Executed by:
| 60 | ||||||||||||||||||||||||
2701 | break; executed 15 times by 2 tests: break; Executed by:
| 15 | ||||||||||||||||||||||||
2702 | } | - | ||||||||||||||||||||||||
2703 | - | |||||||||||||||||||||||||
2704 | if (!destinationAncestor.isValid())
| 31-239 | ||||||||||||||||||||||||
2705 | break; executed 31 times by 3 tests: break; Executed by:
| 31 | ||||||||||||||||||||||||
2706 | - | |||||||||||||||||||||||||
2707 | pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
| 0-239 | ||||||||||||||||||||||||
2708 | destinationAncestor = destinationAncestor.parent(); | - | ||||||||||||||||||||||||
2709 | } executed 239 times by 3 tests: end of block Executed by:
| 239 | ||||||||||||||||||||||||
2710 | - | |||||||||||||||||||||||||
2711 | return true; executed 46 times by 4 tests: return true; Executed by:
| 46 | ||||||||||||||||||||||||
2712 | } | - | ||||||||||||||||||||||||
2713 | - | |||||||||||||||||||||||||
2714 | /*! | - | ||||||||||||||||||||||||
2715 | \since 4.6 | - | ||||||||||||||||||||||||
2716 | - | |||||||||||||||||||||||||
2717 | Begins a row move operation. | - | ||||||||||||||||||||||||
2718 | - | |||||||||||||||||||||||||
2719 | When reimplementing a subclass, this method simplifies moving | - | ||||||||||||||||||||||||
2720 | entities in your model. This method is responsible for moving | - | ||||||||||||||||||||||||
2721 | persistent indexes in the model, which you would otherwise be | - | ||||||||||||||||||||||||
2722 | required to do yourself. Using beginMoveRows and endMoveRows | - | ||||||||||||||||||||||||
2723 | is an alternative to emitting layoutAboutToBeChanged and | - | ||||||||||||||||||||||||
2724 | layoutChanged directly along with changePersistentIndex. | - | ||||||||||||||||||||||||
2725 | - | |||||||||||||||||||||||||
2726 | The \a sourceParent index corresponds to the parent from which the | - | ||||||||||||||||||||||||
2727 | rows are moved; \a sourceFirst and \a sourceLast are the first and last | - | ||||||||||||||||||||||||
2728 | row numbers of the rows to be moved. The \a destinationParent index | - | ||||||||||||||||||||||||
2729 | corresponds to the parent into which those rows are moved. The \a | - | ||||||||||||||||||||||||
2730 | destinationChild is the row to which the rows will be moved. That | - | ||||||||||||||||||||||||
2731 | is, the index at row \a sourceFirst in \a sourceParent will become | - | ||||||||||||||||||||||||
2732 | row \a destinationChild in \a destinationParent, followed by all other | - | ||||||||||||||||||||||||
2733 | rows up to \a sourceLast. | - | ||||||||||||||||||||||||
2734 | - | |||||||||||||||||||||||||
2735 | However, when moving rows down in the same parent (\a sourceParent | - | ||||||||||||||||||||||||
2736 | and \a destinationParent are equal), the rows will be placed before the | - | ||||||||||||||||||||||||
2737 | \a destinationChild index. That is, if you wish to move rows 0 and 1 so | - | ||||||||||||||||||||||||
2738 | they will become rows 1 and 2, \a destinationChild should be 3. In this | - | ||||||||||||||||||||||||
2739 | case, the new index for the source row \c i (which is between | - | ||||||||||||||||||||||||
2740 | \a sourceFirst and \a sourceLast) is equal to | - | ||||||||||||||||||||||||
2741 | \c {(destinationChild-sourceLast-1+i)}. | - | ||||||||||||||||||||||||
2742 | - | |||||||||||||||||||||||||
2743 | Note that if \a sourceParent and \a destinationParent are the same, | - | ||||||||||||||||||||||||
2744 | you must ensure that the \a destinationChild is not within the range | - | ||||||||||||||||||||||||
2745 | of \a sourceFirst and \a sourceLast + 1. You must also ensure that you | - | ||||||||||||||||||||||||
2746 | do not attempt to move a row to one of its own children or ancestors. | - | ||||||||||||||||||||||||
2747 | This method returns \c{false} if either condition is true, in which case you | - | ||||||||||||||||||||||||
2748 | should abort your move operation. | - | ||||||||||||||||||||||||
2749 | - | |||||||||||||||||||||||||
2750 | \table 80% | - | ||||||||||||||||||||||||
2751 | \row | - | ||||||||||||||||||||||||
2752 | \li \inlineimage modelview-move-rows-1.png Moving rows to another parent | - | ||||||||||||||||||||||||
2753 | \li Specify the first and last row numbers for the span of rows in | - | ||||||||||||||||||||||||
2754 | the source parent you want to move in the model. Also specify | - | ||||||||||||||||||||||||
2755 | the row in the destination parent to move the span to. | - | ||||||||||||||||||||||||
2756 | - | |||||||||||||||||||||||||
2757 | For example, as shown in the diagram, we move three rows from | - | ||||||||||||||||||||||||
2758 | row 2 to 4 in the source, so \a sourceFirst is 2 and \a sourceLast is 4. | - | ||||||||||||||||||||||||
2759 | We move those items to above row 2 in the destination, so \a destinationChild is 2. | - | ||||||||||||||||||||||||
2760 | - | |||||||||||||||||||||||||
2761 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 6 | - | ||||||||||||||||||||||||
2762 | - | |||||||||||||||||||||||||
2763 | This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in | - | ||||||||||||||||||||||||
2764 | the destination. Other affected siblings are displaced accordingly. | - | ||||||||||||||||||||||||
2765 | \row | - | ||||||||||||||||||||||||
2766 | \li \inlineimage modelview-move-rows-2.png Moving rows to append to another parent | - | ||||||||||||||||||||||||
2767 | \li To append rows to another parent, move them to after the last row. | - | ||||||||||||||||||||||||
2768 | - | |||||||||||||||||||||||||
2769 | For example, as shown in the diagram, we move three rows to a | - | ||||||||||||||||||||||||
2770 | collection of 6 existing rows (ending in row 5), so \a destinationChild is 6: | - | ||||||||||||||||||||||||
2771 | - | |||||||||||||||||||||||||
2772 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7 | - | ||||||||||||||||||||||||
2773 | - | |||||||||||||||||||||||||
2774 | This moves the target rows to the end of the target parent as 6, 7 and 8. | - | ||||||||||||||||||||||||
2775 | \row | - | ||||||||||||||||||||||||
2776 | \li \inlineimage modelview-move-rows-3.png Moving rows in the same parent up | - | ||||||||||||||||||||||||
2777 | \li To move rows within the same parent, specify the row to move them to. | - | ||||||||||||||||||||||||
2778 | - | |||||||||||||||||||||||||
2779 | For example, as shown in the diagram, we move one item from row 2 to row 0, | - | ||||||||||||||||||||||||
2780 | so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0. | - | ||||||||||||||||||||||||
2781 | - | |||||||||||||||||||||||||
2782 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8 | - | ||||||||||||||||||||||||
2783 | - | |||||||||||||||||||||||||
2784 | Note that other rows may be displaced accordingly. Note also that when moving | - | ||||||||||||||||||||||||
2785 | items within the same parent you should not attempt invalid or no-op moves. In | - | ||||||||||||||||||||||||
2786 | the above example, item 2 is at row 2 before the move, so it can not be moved | - | ||||||||||||||||||||||||
2787 | to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where | - | ||||||||||||||||||||||||
2788 | it is already) | - | ||||||||||||||||||||||||
2789 | - | |||||||||||||||||||||||||
2790 | \row | - | ||||||||||||||||||||||||
2791 | \li \inlineimage modelview-move-rows-4.png Moving rows in the same parent down | - | ||||||||||||||||||||||||
2792 | \li To move rows within the same parent, specify the row to move them to. | - | ||||||||||||||||||||||||
2793 | - | |||||||||||||||||||||||||
2794 | For example, as shown in the diagram, we move one item from row 2 to row 4, | - | ||||||||||||||||||||||||
2795 | so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4. | - | ||||||||||||||||||||||||
2796 | - | |||||||||||||||||||||||||
2797 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9 | - | ||||||||||||||||||||||||
2798 | - | |||||||||||||||||||||||||
2799 | Note that other rows may be displaced accordingly. | - | ||||||||||||||||||||||||
2800 | \endtable | - | ||||||||||||||||||||||||
2801 | - | |||||||||||||||||||||||||
2802 | \sa endMoveRows() | - | ||||||||||||||||||||||||
2803 | */ | - | ||||||||||||||||||||||||
2804 | bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||||||||||||||
2805 | { | - | ||||||||||||||||||||||||
2806 | Q_ASSERT(sourceFirst >= 0); | - | ||||||||||||||||||||||||
2807 | Q_ASSERT(sourceLast >= sourceFirst); | - | ||||||||||||||||||||||||
2808 | Q_ASSERT(destinationChild >= 0); | - | ||||||||||||||||||||||||
2809 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2810 | - | |||||||||||||||||||||||||
2811 | if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)) {
| 70-87 | ||||||||||||||||||||||||
2812 | return false; executed 87 times by 2 tests: return false; Executed by:
| 87 | ||||||||||||||||||||||||
2813 | } | - | ||||||||||||||||||||||||
2814 | - | |||||||||||||||||||||||||
2815 | QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); | - | ||||||||||||||||||||||||
2816 | sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
| 10-39 | ||||||||||||||||||||||||
2817 | d->changes.push(sourceChange); | - | ||||||||||||||||||||||||
2818 | int destinationLast = destinationChild + (sourceLast - sourceFirst); | - | ||||||||||||||||||||||||
2819 | QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); | - | ||||||||||||||||||||||||
2820 | destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
| 7-37 | ||||||||||||||||||||||||
2821 | d->changes.push(destinationChange); | - | ||||||||||||||||||||||||
2822 | - | |||||||||||||||||||||||||
2823 | emit rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal()); | - | ||||||||||||||||||||||||
2824 | d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical); | - | ||||||||||||||||||||||||
2825 | return true; executed 70 times by 5 tests: return true; Executed by:
| 70 | ||||||||||||||||||||||||
2826 | } | - | ||||||||||||||||||||||||
2827 | - | |||||||||||||||||||||||||
2828 | /*! | - | ||||||||||||||||||||||||
2829 | Ends a row move operation. | - | ||||||||||||||||||||||||
2830 | - | |||||||||||||||||||||||||
2831 | When implementing a subclass, you must call this | - | ||||||||||||||||||||||||
2832 | function \e after moving data within the model's underlying data | - | ||||||||||||||||||||||||
2833 | store. | - | ||||||||||||||||||||||||
2834 | - | |||||||||||||||||||||||||
2835 | \sa beginMoveRows() | - | ||||||||||||||||||||||||
2836 | - | |||||||||||||||||||||||||
2837 | \since 4.6 | - | ||||||||||||||||||||||||
2838 | */ | - | ||||||||||||||||||||||||
2839 | void QAbstractItemModel::endMoveRows() | - | ||||||||||||||||||||||||
2840 | { | - | ||||||||||||||||||||||||
2841 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2842 | - | |||||||||||||||||||||||||
2843 | QAbstractItemModelPrivate::Change insertChange = d->changes.pop(); | - | ||||||||||||||||||||||||
2844 | QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); | - | ||||||||||||||||||||||||
2845 | - | |||||||||||||||||||||||||
2846 | QModelIndex adjustedSource = removeChange.parent; | - | ||||||||||||||||||||||||
2847 | QModelIndex adjustedDestination = insertChange.parent; | - | ||||||||||||||||||||||||
2848 | - | |||||||||||||||||||||||||
2849 | const int numMoved = removeChange.last - removeChange.first + 1; | - | ||||||||||||||||||||||||
2850 | if (insertChange.needsAdjust)
| 7-63 | ||||||||||||||||||||||||
2851 | adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer()); executed 7 times by 2 tests: adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer()); Executed by:
| 7 | ||||||||||||||||||||||||
2852 | - | |||||||||||||||||||||||||
2853 | if (removeChange.needsAdjust)
| 10-60 | ||||||||||||||||||||||||
2854 | adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer()); executed 10 times by 2 tests: adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer()); Executed by:
| 10 | ||||||||||||||||||||||||
2855 | - | |||||||||||||||||||||||||
2856 | d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical); | - | ||||||||||||||||||||||||
2857 | - | |||||||||||||||||||||||||
2858 | emit rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal()); | - | ||||||||||||||||||||||||
2859 | } executed 70 times by 5 tests: end of block Executed by:
| 70 | ||||||||||||||||||||||||
2860 | - | |||||||||||||||||||||||||
2861 | /*! | - | ||||||||||||||||||||||||
2862 | Begins a column insertion operation. | - | ||||||||||||||||||||||||
2863 | - | |||||||||||||||||||||||||
2864 | When reimplementing insertColumns() in a subclass, you must call this | - | ||||||||||||||||||||||||
2865 | function \e before inserting data into the model's underlying data store. | - | ||||||||||||||||||||||||
2866 | - | |||||||||||||||||||||||||
2867 | The \a parent index corresponds to the parent into which the new columns | - | ||||||||||||||||||||||||
2868 | are inserted; \a first and \a last are the column numbers of the new | - | ||||||||||||||||||||||||
2869 | columns will have after they have been inserted. | - | ||||||||||||||||||||||||
2870 | - | |||||||||||||||||||||||||
2871 | \table 80% | - | ||||||||||||||||||||||||
2872 | \row | - | ||||||||||||||||||||||||
2873 | \li \inlineimage modelview-begin-insert-columns.png Inserting columns | - | ||||||||||||||||||||||||
2874 | \li Specify the first and last column numbers for the span of columns | - | ||||||||||||||||||||||||
2875 | you want to insert into an item in a model. | - | ||||||||||||||||||||||||
2876 | - | |||||||||||||||||||||||||
2877 | For example, as shown in the diagram, we insert three columns | - | ||||||||||||||||||||||||
2878 | before column 4, so \a first is 4 and \a last is 6: | - | ||||||||||||||||||||||||
2879 | - | |||||||||||||||||||||||||
2880 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 3 | - | ||||||||||||||||||||||||
2881 | - | |||||||||||||||||||||||||
2882 | This inserts the three new columns as columns 4, 5, and 6. | - | ||||||||||||||||||||||||
2883 | \row | - | ||||||||||||||||||||||||
2884 | \li \inlineimage modelview-begin-append-columns.png Appending columns | - | ||||||||||||||||||||||||
2885 | \li To append columns, insert them after the last column. | - | ||||||||||||||||||||||||
2886 | - | |||||||||||||||||||||||||
2887 | For example, as shown in the diagram, we append three columns to a | - | ||||||||||||||||||||||||
2888 | collection of six existing columns (ending in column 5), so | - | ||||||||||||||||||||||||
2889 | \a first is 6 and \a last is 8: | - | ||||||||||||||||||||||||
2890 | - | |||||||||||||||||||||||||
2891 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4 | - | ||||||||||||||||||||||||
2892 | - | |||||||||||||||||||||||||
2893 | This appends the two new columns as columns 6, 7, and 8. | - | ||||||||||||||||||||||||
2894 | \endtable | - | ||||||||||||||||||||||||
2895 | - | |||||||||||||||||||||||||
2896 | \note This function emits the columnsAboutToBeInserted() signal which | - | ||||||||||||||||||||||||
2897 | connected views (or proxies) must handle before the data is inserted. | - | ||||||||||||||||||||||||
2898 | Otherwise, the views may end up in an invalid state. | - | ||||||||||||||||||||||||
2899 | - | |||||||||||||||||||||||||
2900 | \sa endInsertColumns() | - | ||||||||||||||||||||||||
2901 | */ | - | ||||||||||||||||||||||||
2902 | void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
2903 | { | - | ||||||||||||||||||||||||
2904 | Q_ASSERT(first >= 0); | - | ||||||||||||||||||||||||
2905 | Q_ASSERT(last >= first); | - | ||||||||||||||||||||||||
2906 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2907 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||||||||||||||
2908 | emit columnsAboutToBeInserted(parent, first, last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2909 | d->columnsAboutToBeInserted(parent, first, last); | - | ||||||||||||||||||||||||
2910 | } executed 13519 times by 33 tests: end of block Executed by:
| 13519 | ||||||||||||||||||||||||
2911 | - | |||||||||||||||||||||||||
2912 | /*! | - | ||||||||||||||||||||||||
2913 | Ends a column insertion operation. | - | ||||||||||||||||||||||||
2914 | - | |||||||||||||||||||||||||
2915 | When reimplementing insertColumns() in a subclass, you must call this | - | ||||||||||||||||||||||||
2916 | function \e after inserting data into the model's underlying data | - | ||||||||||||||||||||||||
2917 | store. | - | ||||||||||||||||||||||||
2918 | - | |||||||||||||||||||||||||
2919 | \sa beginInsertColumns() | - | ||||||||||||||||||||||||
2920 | */ | - | ||||||||||||||||||||||||
2921 | void QAbstractItemModel::endInsertColumns() | - | ||||||||||||||||||||||||
2922 | { | - | ||||||||||||||||||||||||
2923 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2924 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||||||||||||||
2925 | d->columnsInserted(change.parent, change.first, change.last); | - | ||||||||||||||||||||||||
2926 | emit columnsInserted(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2927 | } executed 13519 times by 33 tests: end of block Executed by:
| 13519 | ||||||||||||||||||||||||
2928 | - | |||||||||||||||||||||||||
2929 | /*! | - | ||||||||||||||||||||||||
2930 | Begins a column removal operation. | - | ||||||||||||||||||||||||
2931 | - | |||||||||||||||||||||||||
2932 | When reimplementing removeColumns() in a subclass, you must call this | - | ||||||||||||||||||||||||
2933 | function \e before removing data from the model's underlying data store. | - | ||||||||||||||||||||||||
2934 | - | |||||||||||||||||||||||||
2935 | The \a parent index corresponds to the parent from which the new columns | - | ||||||||||||||||||||||||
2936 | are removed; \a first and \a last are the column numbers of the first and | - | ||||||||||||||||||||||||
2937 | last columns to be removed. | - | ||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||
2939 | \table 80% | - | ||||||||||||||||||||||||
2940 | \row | - | ||||||||||||||||||||||||
2941 | \li \inlineimage modelview-begin-remove-columns.png Removing columns | - | ||||||||||||||||||||||||
2942 | \li Specify the first and last column numbers for the span of columns | - | ||||||||||||||||||||||||
2943 | you want to remove from an item in a model. | - | ||||||||||||||||||||||||
2944 | - | |||||||||||||||||||||||||
2945 | For example, as shown in the diagram, we remove the three columns | - | ||||||||||||||||||||||||
2946 | from column 4 to column 6, so \a first is 4 and \a last is 6: | - | ||||||||||||||||||||||||
2947 | - | |||||||||||||||||||||||||
2948 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 5 | - | ||||||||||||||||||||||||
2949 | \endtable | - | ||||||||||||||||||||||||
2950 | - | |||||||||||||||||||||||||
2951 | \note This function emits the columnsAboutToBeRemoved() signal which | - | ||||||||||||||||||||||||
2952 | connected views (or proxies) must handle before the data is removed. | - | ||||||||||||||||||||||||
2953 | Otherwise, the views may end up in an invalid state. | - | ||||||||||||||||||||||||
2954 | - | |||||||||||||||||||||||||
2955 | \sa endRemoveColumns() | - | ||||||||||||||||||||||||
2956 | */ | - | ||||||||||||||||||||||||
2957 | void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
2958 | { | - | ||||||||||||||||||||||||
2959 | Q_ASSERT(first >= 0); | - | ||||||||||||||||||||||||
2960 | Q_ASSERT(last >= first); | - | ||||||||||||||||||||||||
2961 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2962 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||||||||||||||
2963 | emit columnsAboutToBeRemoved(parent, first, last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2964 | d->columnsAboutToBeRemoved(parent, first, last); | - | ||||||||||||||||||||||||
2965 | } executed 204 times by 16 tests: end of block Executed by:
| 204 | ||||||||||||||||||||||||
2966 | - | |||||||||||||||||||||||||
2967 | /*! | - | ||||||||||||||||||||||||
2968 | Ends a column removal operation. | - | ||||||||||||||||||||||||
2969 | - | |||||||||||||||||||||||||
2970 | When reimplementing removeColumns() in a subclass, you must call this | - | ||||||||||||||||||||||||
2971 | function \e after removing data from the model's underlying data store. | - | ||||||||||||||||||||||||
2972 | - | |||||||||||||||||||||||||
2973 | \sa beginRemoveColumns() | - | ||||||||||||||||||||||||
2974 | */ | - | ||||||||||||||||||||||||
2975 | void QAbstractItemModel::endRemoveColumns() | - | ||||||||||||||||||||||||
2976 | { | - | ||||||||||||||||||||||||
2977 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
2978 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||||||||||||||
2979 | d->columnsRemoved(change.parent, change.first, change.last); | - | ||||||||||||||||||||||||
2980 | emit columnsRemoved(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||||||||||||||
2981 | } executed 204 times by 16 tests: end of block Executed by:
| 204 | ||||||||||||||||||||||||
2982 | - | |||||||||||||||||||||||||
2983 | /*! | - | ||||||||||||||||||||||||
2984 | Begins a column move operation. | - | ||||||||||||||||||||||||
2985 | - | |||||||||||||||||||||||||
2986 | When reimplementing a subclass, this method simplifies moving | - | ||||||||||||||||||||||||
2987 | entities in your model. This method is responsible for moving | - | ||||||||||||||||||||||||
2988 | persistent indexes in the model, which you would otherwise be | - | ||||||||||||||||||||||||
2989 | required to do yourself. Using beginMoveColumns and endMoveColumns | - | ||||||||||||||||||||||||
2990 | is an alternative to emitting layoutAboutToBeChanged and | - | ||||||||||||||||||||||||
2991 | layoutChanged directly along with changePersistentIndex. | - | ||||||||||||||||||||||||
2992 | - | |||||||||||||||||||||||||
2993 | The \a sourceParent index corresponds to the parent from which the | - | ||||||||||||||||||||||||
2994 | columns are moved; \a sourceFirst and \a sourceLast are the first and last | - | ||||||||||||||||||||||||
2995 | column numbers of the columns to be moved. The \a destinationParent index | - | ||||||||||||||||||||||||
2996 | corresponds to the parent into which those columns are moved. The \a | - | ||||||||||||||||||||||||
2997 | destinationChild is the column to which the columns will be moved. That | - | ||||||||||||||||||||||||
2998 | is, the index at column \a sourceFirst in \a sourceParent will become | - | ||||||||||||||||||||||||
2999 | column \a destinationChild in \a destinationParent, followed by all other | - | ||||||||||||||||||||||||
3000 | columns up to \a sourceLast. | - | ||||||||||||||||||||||||
3001 | - | |||||||||||||||||||||||||
3002 | However, when moving columns down in the same parent (\a sourceParent | - | ||||||||||||||||||||||||
3003 | and \a destinationParent are equal), the columns will be placed before the | - | ||||||||||||||||||||||||
3004 | \a destinationChild index. That is, if you wish to move columns 0 and 1 so | - | ||||||||||||||||||||||||
3005 | they will become columns 1 and 2, \a destinationChild should be 3. In this | - | ||||||||||||||||||||||||
3006 | case, the new index for the source column \c i (which is between | - | ||||||||||||||||||||||||
3007 | \a sourceFirst and \a sourceLast) is equal to | - | ||||||||||||||||||||||||
3008 | \c {(destinationChild-sourceLast-1+i)}. | - | ||||||||||||||||||||||||
3009 | - | |||||||||||||||||||||||||
3010 | Note that if \a sourceParent and \a destinationParent are the same, | - | ||||||||||||||||||||||||
3011 | you must ensure that the \a destinationChild is not within the range | - | ||||||||||||||||||||||||
3012 | of \a sourceFirst and \a sourceLast + 1. You must also ensure that you | - | ||||||||||||||||||||||||
3013 | do not attempt to move a column to one of its own children or ancestors. | - | ||||||||||||||||||||||||
3014 | This method returns \c{false} if either condition is true, in which case you | - | ||||||||||||||||||||||||
3015 | should abort your move operation. | - | ||||||||||||||||||||||||
3016 | - | |||||||||||||||||||||||||
3017 | \sa endMoveColumns() | - | ||||||||||||||||||||||||
3018 | - | |||||||||||||||||||||||||
3019 | \since 4.6 | - | ||||||||||||||||||||||||
3020 | */ | - | ||||||||||||||||||||||||
3021 | bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||||||||||||||
3022 | { | - | ||||||||||||||||||||||||
3023 | Q_ASSERT(sourceFirst >= 0); | - | ||||||||||||||||||||||||
3024 | Q_ASSERT(sourceLast >= sourceFirst); | - | ||||||||||||||||||||||||
3025 | Q_ASSERT(destinationChild >= 0); | - | ||||||||||||||||||||||||
3026 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
3027 | - | |||||||||||||||||||||||||
3028 | if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)) {
| 0-2 | ||||||||||||||||||||||||
3029 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3030 | } | - | ||||||||||||||||||||||||
3031 | - | |||||||||||||||||||||||||
3032 | QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); | - | ||||||||||||||||||||||||
3033 | sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent;
| 0-2 | ||||||||||||||||||||||||
3034 | d->changes.push(sourceChange); | - | ||||||||||||||||||||||||
3035 | int destinationLast = destinationChild + (sourceLast - sourceFirst); | - | ||||||||||||||||||||||||
3036 | QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); | - | ||||||||||||||||||||||||
3037 | destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent;
| 0-2 | ||||||||||||||||||||||||
3038 | d->changes.push(destinationChange); | - | ||||||||||||||||||||||||
3039 | - | |||||||||||||||||||||||||
3040 | d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal); | - | ||||||||||||||||||||||||
3041 | - | |||||||||||||||||||||||||
3042 | emit columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal()); | - | ||||||||||||||||||||||||
3043 | return true; executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||||||||||||||
3044 | } | - | ||||||||||||||||||||||||
3045 | - | |||||||||||||||||||||||||
3046 | /*! | - | ||||||||||||||||||||||||
3047 | Ends a column move operation. | - | ||||||||||||||||||||||||
3048 | - | |||||||||||||||||||||||||
3049 | When implementing a subclass, you must call this | - | ||||||||||||||||||||||||
3050 | function \e after moving data within the model's underlying data | - | ||||||||||||||||||||||||
3051 | store. | - | ||||||||||||||||||||||||
3052 | - | |||||||||||||||||||||||||
3053 | \sa beginMoveColumns() | - | ||||||||||||||||||||||||
3054 | - | |||||||||||||||||||||||||
3055 | \since 4.6 | - | ||||||||||||||||||||||||
3056 | */ | - | ||||||||||||||||||||||||
3057 | void QAbstractItemModel::endMoveColumns() | - | ||||||||||||||||||||||||
3058 | { | - | ||||||||||||||||||||||||
3059 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
3060 | - | |||||||||||||||||||||||||
3061 | QAbstractItemModelPrivate::Change insertChange = d->changes.pop(); | - | ||||||||||||||||||||||||
3062 | QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); | - | ||||||||||||||||||||||||
3063 | - | |||||||||||||||||||||||||
3064 | QModelIndex adjustedSource = removeChange.parent; | - | ||||||||||||||||||||||||
3065 | QModelIndex adjustedDestination = insertChange.parent; | - | ||||||||||||||||||||||||
3066 | - | |||||||||||||||||||||||||
3067 | const int numMoved = removeChange.last - removeChange.first + 1; | - | ||||||||||||||||||||||||
3068 | if (insertChange.needsAdjust)
| 0-2 | ||||||||||||||||||||||||
3069 | adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer()); never executed: adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer()); | 0 | ||||||||||||||||||||||||
3070 | - | |||||||||||||||||||||||||
3071 | if (removeChange.needsAdjust)
| 0-2 | ||||||||||||||||||||||||
3072 | adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer()); never executed: adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer()); | 0 | ||||||||||||||||||||||||
3073 | - | |||||||||||||||||||||||||
3074 | d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal); | - | ||||||||||||||||||||||||
3075 | - | |||||||||||||||||||||||||
3076 | emit columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal()); | - | ||||||||||||||||||||||||
3077 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
3078 | - | |||||||||||||||||||||||||
3079 | /*! | - | ||||||||||||||||||||||||
3080 | \fn void QAbstractItemModel::reset() | - | ||||||||||||||||||||||||
3081 | \obsolete | - | ||||||||||||||||||||||||
3082 | - | |||||||||||||||||||||||||
3083 | Resets the model to its original state in any attached views. | - | ||||||||||||||||||||||||
3084 | - | |||||||||||||||||||||||||
3085 | This function emits the signals modelAboutToBeReset() and modelReset(). | - | ||||||||||||||||||||||||
3086 | - | |||||||||||||||||||||||||
3087 | \note Use beginResetModel() and endResetModel() instead whenever possible. | - | ||||||||||||||||||||||||
3088 | Use this method only if there is no way to call beginResetModel() before invalidating the model. | - | ||||||||||||||||||||||||
3089 | Otherwise it could lead to unexpected behaviour, especially when used with proxy models. | - | ||||||||||||||||||||||||
3090 | - | |||||||||||||||||||||||||
3091 | For example, in this code both signals modelAboutToBeReset() and modelReset() | - | ||||||||||||||||||||||||
3092 | are emitted \e after the data changes: | - | ||||||||||||||||||||||||
3093 | - | |||||||||||||||||||||||||
3094 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 10 | - | ||||||||||||||||||||||||
3095 | - | |||||||||||||||||||||||||
3096 | Instead you should use: | - | ||||||||||||||||||||||||
3097 | - | |||||||||||||||||||||||||
3098 | \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 11 | - | ||||||||||||||||||||||||
3099 | */ | - | ||||||||||||||||||||||||
3100 | - | |||||||||||||||||||||||||
3101 | /*! | - | ||||||||||||||||||||||||
3102 | Begins a model reset operation. | - | ||||||||||||||||||||||||
3103 | - | |||||||||||||||||||||||||
3104 | A reset operation resets the model to its current state in any attached views. | - | ||||||||||||||||||||||||
3105 | - | |||||||||||||||||||||||||
3106 | \note Any views attached to this model will be reset as well. | - | ||||||||||||||||||||||||
3107 | - | |||||||||||||||||||||||||
3108 | When a model is reset it means that any previous data reported from the | - | ||||||||||||||||||||||||
3109 | model is now invalid and has to be queried for again. This also means that | - | ||||||||||||||||||||||||
3110 | the current item and any selected items will become invalid. | - | ||||||||||||||||||||||||
3111 | - | |||||||||||||||||||||||||
3112 | When a model radically changes its data it can sometimes be easier to just | - | ||||||||||||||||||||||||
3113 | call this function rather than emit dataChanged() to inform other | - | ||||||||||||||||||||||||
3114 | components when the underlying data source, or its structure, has changed. | - | ||||||||||||||||||||||||
3115 | - | |||||||||||||||||||||||||
3116 | You must call this function before resetting any internal data structures in your model | - | ||||||||||||||||||||||||
3117 | or proxy model. | - | ||||||||||||||||||||||||
3118 | - | |||||||||||||||||||||||||
3119 | This function emits the signal modelAboutToBeReset(). | - | ||||||||||||||||||||||||
3120 | - | |||||||||||||||||||||||||
3121 | \sa modelAboutToBeReset(), modelReset(), endResetModel() | - | ||||||||||||||||||||||||
3122 | \since 4.6 | - | ||||||||||||||||||||||||
3123 | */ | - | ||||||||||||||||||||||||
3124 | void QAbstractItemModel::beginResetModel() | - | ||||||||||||||||||||||||
3125 | { | - | ||||||||||||||||||||||||
3126 | emit modelAboutToBeReset(QPrivateSignal()); | - | ||||||||||||||||||||||||
3127 | } executed 8962 times by 41 tests: end of block Executed by:
| 8962 | ||||||||||||||||||||||||
3128 | - | |||||||||||||||||||||||||
3129 | /*! | - | ||||||||||||||||||||||||
3130 | Completes a model reset operation. | - | ||||||||||||||||||||||||
3131 | - | |||||||||||||||||||||||||
3132 | You must call this function after resetting any internal data structure in your model | - | ||||||||||||||||||||||||
3133 | or proxy model. | - | ||||||||||||||||||||||||
3134 | - | |||||||||||||||||||||||||
3135 | This function emits the signal modelReset(). | - | ||||||||||||||||||||||||
3136 | - | |||||||||||||||||||||||||
3137 | \sa beginResetModel() | - | ||||||||||||||||||||||||
3138 | \since 4.6 | - | ||||||||||||||||||||||||
3139 | */ | - | ||||||||||||||||||||||||
3140 | void QAbstractItemModel::endResetModel() | - | ||||||||||||||||||||||||
3141 | { | - | ||||||||||||||||||||||||
3142 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
3143 | d->invalidatePersistentIndexes(); | - | ||||||||||||||||||||||||
3144 | QMetaObject::invokeMethod(this, "resetInternalData"); | - | ||||||||||||||||||||||||
3145 | emit modelReset(QPrivateSignal()); | - | ||||||||||||||||||||||||
3146 | } executed 8961 times by 41 tests: end of block Executed by:
| 8961 | ||||||||||||||||||||||||
3147 | - | |||||||||||||||||||||||||
3148 | /*! | - | ||||||||||||||||||||||||
3149 | Changes the QPersistentModelIndex that is equal to the given \a from model | - | ||||||||||||||||||||||||
3150 | index to the given \a to model index. | - | ||||||||||||||||||||||||
3151 | - | |||||||||||||||||||||||||
3152 | If no persistent model index equal to the given \a from model index was | - | ||||||||||||||||||||||||
3153 | found, nothing is changed. | - | ||||||||||||||||||||||||
3154 | - | |||||||||||||||||||||||||
3155 | \sa persistentIndexList(), changePersistentIndexList() | - | ||||||||||||||||||||||||
3156 | */ | - | ||||||||||||||||||||||||
3157 | void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to) | - | ||||||||||||||||||||||||
3158 | { | - | ||||||||||||||||||||||||
3159 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
3160 | if (d->persistent.indexes.isEmpty())
| 0-12 | ||||||||||||||||||||||||
3161 | return; never executed: return; | 0 | ||||||||||||||||||||||||
3162 | // find the data and reinsert it sorted | - | ||||||||||||||||||||||||
3163 | const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from); | - | ||||||||||||||||||||||||
3164 | if (it != d->persistent.indexes.end()) {
| 0-12 | ||||||||||||||||||||||||
3165 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
3166 | d->persistent.indexes.erase(it); | - | ||||||||||||||||||||||||
3167 | data->index = to; | - | ||||||||||||||||||||||||
3168 | if (to.isValid())
| 0-12 | ||||||||||||||||||||||||
3169 | d->persistent.insertMultiAtEnd(to, data); executed 12 times by 1 test: d->persistent.insertMultiAtEnd(to, data); Executed by:
| 12 | ||||||||||||||||||||||||
3170 | else | - | ||||||||||||||||||||||||
3171 | data->model = 0; never executed: data->model = 0; | 0 | ||||||||||||||||||||||||
3172 | } | - | ||||||||||||||||||||||||
3173 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
3174 | - | |||||||||||||||||||||||||
3175 | /*! | - | ||||||||||||||||||||||||
3176 | \since 4.1 | - | ||||||||||||||||||||||||
3177 | - | |||||||||||||||||||||||||
3178 | Changes the {QPersistentModelIndex}es that are equal to the indexes in the | - | ||||||||||||||||||||||||
3179 | given \a from model index list to the given \a to model index list. | - | ||||||||||||||||||||||||
3180 | - | |||||||||||||||||||||||||
3181 | If no persistent model indexes equal to the indexes in the given \a from | - | ||||||||||||||||||||||||
3182 | model index list are found, nothing is changed. | - | ||||||||||||||||||||||||
3183 | - | |||||||||||||||||||||||||
3184 | \sa persistentIndexList(), changePersistentIndex() | - | ||||||||||||||||||||||||
3185 | */ | - | ||||||||||||||||||||||||
3186 | void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, | - | ||||||||||||||||||||||||
3187 | const QModelIndexList &to) | - | ||||||||||||||||||||||||
3188 | { | - | ||||||||||||||||||||||||
3189 | Q_D(QAbstractItemModel); | - | ||||||||||||||||||||||||
3190 | if (d->persistent.indexes.isEmpty())
| 734-4691 | ||||||||||||||||||||||||
3191 | return; executed 4691 times by 24 tests: return; Executed by:
| 4691 | ||||||||||||||||||||||||
3192 | QVector<QPersistentModelIndexData *> toBeReinserted; | - | ||||||||||||||||||||||||
3193 | toBeReinserted.reserve(to.count()); | - | ||||||||||||||||||||||||
3194 | for (int i = 0; i < from.count(); ++i) {
| 734-1639 | ||||||||||||||||||||||||
3195 | if (from.at(i) == to.at(i))
| 660-979 | ||||||||||||||||||||||||
3196 | continue; executed 979 times by 16 tests: continue; Executed by:
| 979 | ||||||||||||||||||||||||
3197 | const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i)); | - | ||||||||||||||||||||||||
3198 | if (it != d->persistent.indexes.end()) {
| 126-534 | ||||||||||||||||||||||||
3199 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
3200 | d->persistent.indexes.erase(it); | - | ||||||||||||||||||||||||
3201 | data->index = to.at(i); | - | ||||||||||||||||||||||||
3202 | if (data->index.isValid())
| 0-534 | ||||||||||||||||||||||||
3203 | toBeReinserted << data; executed 534 times by 13 tests: toBeReinserted << data; Executed by:
| 534 | ||||||||||||||||||||||||
3204 | else | - | ||||||||||||||||||||||||
3205 | data->model = 0; never executed: data->model = 0; | 0 | ||||||||||||||||||||||||
3206 | } | - | ||||||||||||||||||||||||
3207 | } executed 660 times by 13 tests: end of block Executed by:
| 660 | ||||||||||||||||||||||||
3208 | - | |||||||||||||||||||||||||
3209 | for (QVector<QPersistentModelIndexData *>::const_iterator it = toBeReinserted.constBegin(); | - | ||||||||||||||||||||||||
3210 | it != toBeReinserted.constEnd() ; ++it) {
| 534-734 | ||||||||||||||||||||||||
3211 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
3212 | d->persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||||||||||||||
3213 | } executed 534 times by 13 tests: end of block Executed by:
| 534 | ||||||||||||||||||||||||
3214 | } executed 734 times by 18 tests: end of block Executed by:
| 734 | ||||||||||||||||||||||||
3215 | - | |||||||||||||||||||||||||
3216 | /*! | - | ||||||||||||||||||||||||
3217 | \since 4.2 | - | ||||||||||||||||||||||||
3218 | - | |||||||||||||||||||||||||
3219 | Returns the list of indexes stored as persistent indexes in the model. | - | ||||||||||||||||||||||||
3220 | */ | - | ||||||||||||||||||||||||
3221 | QModelIndexList QAbstractItemModel::persistentIndexList() const | - | ||||||||||||||||||||||||
3222 | { | - | ||||||||||||||||||||||||
3223 | Q_D(const QAbstractItemModel); | - | ||||||||||||||||||||||||
3224 | QModelIndexList result; | - | ||||||||||||||||||||||||
3225 | result.reserve(d->persistent.indexes.count()); | - | ||||||||||||||||||||||||
3226 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin(); | - | ||||||||||||||||||||||||
3227 | it != d->persistent.indexes.constEnd(); ++it) {
| 975-1011 | ||||||||||||||||||||||||
3228 | QPersistentModelIndexData *data = *it; | - | ||||||||||||||||||||||||
3229 | result.append(data->index); | - | ||||||||||||||||||||||||
3230 | } executed 975 times by 11 tests: end of block Executed by:
| 975 | ||||||||||||||||||||||||
3231 | return result; executed 1011 times by 15 tests: return result; Executed by:
| 1011 | ||||||||||||||||||||||||
3232 | } | - | ||||||||||||||||||||||||
3233 | - | |||||||||||||||||||||||||
3234 | - | |||||||||||||||||||||||||
3235 | /*! | - | ||||||||||||||||||||||||
3236 | \class QAbstractTableModel | - | ||||||||||||||||||||||||
3237 | \inmodule QtCore | - | ||||||||||||||||||||||||
3238 | \brief The QAbstractTableModel class provides an abstract model that can be | - | ||||||||||||||||||||||||
3239 | subclassed to create table models. | - | ||||||||||||||||||||||||
3240 | - | |||||||||||||||||||||||||
3241 | \ingroup model-view | - | ||||||||||||||||||||||||
3242 | - | |||||||||||||||||||||||||
3243 | QAbstractTableModel provides a standard interface for models that represent | - | ||||||||||||||||||||||||
3244 | their data as a two-dimensional array of items. It is not used directly, | - | ||||||||||||||||||||||||
3245 | but must be subclassed. | - | ||||||||||||||||||||||||
3246 | - | |||||||||||||||||||||||||
3247 | Since the model provides a more specialized interface than | - | ||||||||||||||||||||||||
3248 | QAbstractItemModel, it is not suitable for use with tree views, although it | - | ||||||||||||||||||||||||
3249 | can be used to provide data to a QListView. If you need to represent a | - | ||||||||||||||||||||||||
3250 | simple list of items, and only need a model to contain a single column of | - | ||||||||||||||||||||||||
3251 | data, subclassing the QAbstractListModel may be more appropriate. | - | ||||||||||||||||||||||||
3252 | - | |||||||||||||||||||||||||
3253 | The rowCount() and columnCount() functions return the dimensions of the | - | ||||||||||||||||||||||||
3254 | table. To retrieve a model index corresponding to an item in the model, use | - | ||||||||||||||||||||||||
3255 | index() and provide only the row and column numbers. | - | ||||||||||||||||||||||||
3256 | - | |||||||||||||||||||||||||
3257 | \section1 Subclassing | - | ||||||||||||||||||||||||
3258 | - | |||||||||||||||||||||||||
3259 | When subclassing QAbstractTableModel, you must implement rowCount(), | - | ||||||||||||||||||||||||
3260 | columnCount(), and data(). Default implementations of the index() and | - | ||||||||||||||||||||||||
3261 | parent() functions are provided by QAbstractTableModel. | - | ||||||||||||||||||||||||
3262 | Well behaved models will also implement headerData(). | - | ||||||||||||||||||||||||
3263 | - | |||||||||||||||||||||||||
3264 | Editable models need to implement setData(), and implement flags() to | - | ||||||||||||||||||||||||
3265 | return a value containing | - | ||||||||||||||||||||||||
3266 | \l{Qt::ItemFlags}{Qt::ItemIsEditable}. | - | ||||||||||||||||||||||||
3267 | - | |||||||||||||||||||||||||
3268 | Models that provide interfaces to resizable data structures can | - | ||||||||||||||||||||||||
3269 | provide implementations of insertRows(), removeRows(), insertColumns(), | - | ||||||||||||||||||||||||
3270 | and removeColumns(). When implementing these functions, it is | - | ||||||||||||||||||||||||
3271 | important to call the appropriate functions so that all connected views | - | ||||||||||||||||||||||||
3272 | are aware of any changes: | - | ||||||||||||||||||||||||
3273 | - | |||||||||||||||||||||||||
3274 | \list | - | ||||||||||||||||||||||||
3275 | \li An insertRows() implementation must call beginInsertRows() | - | ||||||||||||||||||||||||
3276 | \e before inserting new rows into the data structure, and it must | - | ||||||||||||||||||||||||
3277 | call endInsertRows() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3278 | \li An insertColumns() implementation must call beginInsertColumns() | - | ||||||||||||||||||||||||
3279 | \e before inserting new columns into the data structure, and it must | - | ||||||||||||||||||||||||
3280 | call endInsertColumns() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3281 | \li A removeRows() implementation must call beginRemoveRows() | - | ||||||||||||||||||||||||
3282 | \e before the rows are removed from the data structure, and it must | - | ||||||||||||||||||||||||
3283 | call endRemoveRows() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3284 | \li A removeColumns() implementation must call beginRemoveColumns() | - | ||||||||||||||||||||||||
3285 | \e before the columns are removed from the data structure, and it must | - | ||||||||||||||||||||||||
3286 | call endRemoveColumns() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3287 | \endlist | - | ||||||||||||||||||||||||
3288 | - | |||||||||||||||||||||||||
3289 | \note Some general guidelines for subclassing models are available in the | - | ||||||||||||||||||||||||
3290 | \l{Model Subclassing Reference}. | - | ||||||||||||||||||||||||
3291 | - | |||||||||||||||||||||||||
3292 | \note | - | ||||||||||||||||||||||||
3293 | - | |||||||||||||||||||||||||
3294 | \sa {Model Classes}, QAbstractItemModel, QAbstractListModel, | - | ||||||||||||||||||||||||
3295 | {Pixelator Example} | - | ||||||||||||||||||||||||
3296 | */ | - | ||||||||||||||||||||||||
3297 | - | |||||||||||||||||||||||||
3298 | /*! | - | ||||||||||||||||||||||||
3299 | Constructs an abstract table model for the given \a parent. | - | ||||||||||||||||||||||||
3300 | */ | - | ||||||||||||||||||||||||
3301 | - | |||||||||||||||||||||||||
3302 | QAbstractTableModel::QAbstractTableModel(QObject *parent) | - | ||||||||||||||||||||||||
3303 | : QAbstractItemModel(parent) | - | ||||||||||||||||||||||||
3304 | { | - | ||||||||||||||||||||||||
3305 | - | |||||||||||||||||||||||||
3306 | } executed 430 times by 14 tests: end of block Executed by:
| 430 | ||||||||||||||||||||||||
3307 | - | |||||||||||||||||||||||||
3308 | /*! | - | ||||||||||||||||||||||||
3309 | \internal | - | ||||||||||||||||||||||||
3310 | - | |||||||||||||||||||||||||
3311 | Constructs an abstract table model with \a dd and the given \a parent. | - | ||||||||||||||||||||||||
3312 | */ | - | ||||||||||||||||||||||||
3313 | - | |||||||||||||||||||||||||
3314 | QAbstractTableModel::QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||||||||
3315 | : QAbstractItemModel(dd, parent) | - | ||||||||||||||||||||||||
3316 | { | - | ||||||||||||||||||||||||
3317 | - | |||||||||||||||||||||||||
3318 | } executed 287 times by 4 tests: end of block Executed by:
| 287 | ||||||||||||||||||||||||
3319 | - | |||||||||||||||||||||||||
3320 | /*! | - | ||||||||||||||||||||||||
3321 | Destroys the abstract table model. | - | ||||||||||||||||||||||||
3322 | */ | - | ||||||||||||||||||||||||
3323 | - | |||||||||||||||||||||||||
3324 | QAbstractTableModel::~QAbstractTableModel() | - | ||||||||||||||||||||||||
3325 | { | - | ||||||||||||||||||||||||
3326 | - | |||||||||||||||||||||||||
3327 | } | - | ||||||||||||||||||||||||
3328 | - | |||||||||||||||||||||||||
3329 | /*! | - | ||||||||||||||||||||||||
3330 | \fn QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const | - | ||||||||||||||||||||||||
3331 | - | |||||||||||||||||||||||||
3332 | Returns the index of the data in \a row and \a column with \a parent. | - | ||||||||||||||||||||||||
3333 | - | |||||||||||||||||||||||||
3334 | \sa parent() | - | ||||||||||||||||||||||||
3335 | */ | - | ||||||||||||||||||||||||
3336 | - | |||||||||||||||||||||||||
3337 | QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
3338 | { | - | ||||||||||||||||||||||||
3339 | return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); executed 61784 times by 16 tests: return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); Executed by:
| 2284-61784 | ||||||||||||||||||||||||
3340 | } | - | ||||||||||||||||||||||||
3341 | - | |||||||||||||||||||||||||
3342 | /*! | - | ||||||||||||||||||||||||
3343 | \fn QModelIndex QAbstractTableModel::parent(const QModelIndex &index) const | - | ||||||||||||||||||||||||
3344 | - | |||||||||||||||||||||||||
3345 | Returns the parent of the model item with the given \a index. | - | ||||||||||||||||||||||||
3346 | - | |||||||||||||||||||||||||
3347 | \sa index(), hasChildren() | - | ||||||||||||||||||||||||
3348 | */ | - | ||||||||||||||||||||||||
3349 | - | |||||||||||||||||||||||||
3350 | QModelIndex QAbstractTableModel::parent(const QModelIndex &) const | - | ||||||||||||||||||||||||
3351 | { | - | ||||||||||||||||||||||||
3352 | return QModelIndex(); executed 41542 times by 13 tests: return QModelIndex(); Executed by:
| 41542 | ||||||||||||||||||||||||
3353 | } | - | ||||||||||||||||||||||||
3354 | - | |||||||||||||||||||||||||
3355 | /*! | - | ||||||||||||||||||||||||
3356 | \reimp | - | ||||||||||||||||||||||||
3357 | */ | - | ||||||||||||||||||||||||
3358 | QModelIndex QAbstractTableModel::sibling(int row, int column, const QModelIndex &) const | - | ||||||||||||||||||||||||
3359 | { | - | ||||||||||||||||||||||||
3360 | return index(row, column); executed 7902 times by 5 tests: return index(row, column); Executed by:
| 7902 | ||||||||||||||||||||||||
3361 | } | - | ||||||||||||||||||||||||
3362 | - | |||||||||||||||||||||||||
3363 | bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
3364 | { | - | ||||||||||||||||||||||||
3365 | if (parent.model() == this || !parent.isValid())
| 0-2459 | ||||||||||||||||||||||||
3366 | return rowCount(parent) > 0 && columnCount(parent) > 0; executed 2713 times by 3 tests: return rowCount(parent) > 0 && columnCount(parent) > 0; Executed by:
| 0-2713 | ||||||||||||||||||||||||
3367 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3368 | } | - | ||||||||||||||||||||||||
3369 | - | |||||||||||||||||||||||||
3370 | /*! | - | ||||||||||||||||||||||||
3371 | \reimp | - | ||||||||||||||||||||||||
3372 | */ | - | ||||||||||||||||||||||||
3373 | Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
3374 | { | - | ||||||||||||||||||||||||
3375 | Qt::ItemFlags f = QAbstractItemModel::flags(index); | - | ||||||||||||||||||||||||
3376 | if (index.isValid())
| 2-10749 | ||||||||||||||||||||||||
3377 | f |= Qt::ItemNeverHasChildren; executed 10749 times by 8 tests: f |= Qt::ItemNeverHasChildren; Executed by:
| 10749 | ||||||||||||||||||||||||
3378 | return f; executed 10751 times by 9 tests: return f; Executed by:
| 10751 | ||||||||||||||||||||||||
3379 | } | - | ||||||||||||||||||||||||
3380 | - | |||||||||||||||||||||||||
3381 | /*! | - | ||||||||||||||||||||||||
3382 | \class QAbstractListModel | - | ||||||||||||||||||||||||
3383 | \inmodule QtCore | - | ||||||||||||||||||||||||
3384 | \brief The QAbstractListModel class provides an abstract model that can be | - | ||||||||||||||||||||||||
3385 | subclassed to create one-dimensional list models. | - | ||||||||||||||||||||||||
3386 | - | |||||||||||||||||||||||||
3387 | \ingroup model-view | - | ||||||||||||||||||||||||
3388 | - | |||||||||||||||||||||||||
3389 | QAbstractListModel provides a standard interface for models that represent | - | ||||||||||||||||||||||||
3390 | their data as a simple non-hierarchical sequence of items. It is not used | - | ||||||||||||||||||||||||
3391 | directly, but must be subclassed. | - | ||||||||||||||||||||||||
3392 | - | |||||||||||||||||||||||||
3393 | Since the model provides a more specialized interface than | - | ||||||||||||||||||||||||
3394 | QAbstractItemModel, it is not suitable for use with tree views; you will | - | ||||||||||||||||||||||||
3395 | need to subclass QAbstractItemModel if you want to provide a model for | - | ||||||||||||||||||||||||
3396 | that purpose. If you need to use a number of list models to manage data, | - | ||||||||||||||||||||||||
3397 | it may be more appropriate to subclass QAbstractTableModel instead. | - | ||||||||||||||||||||||||
3398 | - | |||||||||||||||||||||||||
3399 | Simple models can be created by subclassing this class and implementing | - | ||||||||||||||||||||||||
3400 | the minimum number of required functions. For example, we could implement | - | ||||||||||||||||||||||||
3401 | a simple read-only QStringList-based model that provides a list of strings | - | ||||||||||||||||||||||||
3402 | to a QListView widget. In such a case, we only need to implement the | - | ||||||||||||||||||||||||
3403 | rowCount() function to return the number of items in the list, and the | - | ||||||||||||||||||||||||
3404 | data() function to retrieve items from the list. | - | ||||||||||||||||||||||||
3405 | - | |||||||||||||||||||||||||
3406 | Since the model represents a one-dimensional structure, the rowCount() | - | ||||||||||||||||||||||||
3407 | function returns the total number of items in the model. The columnCount() | - | ||||||||||||||||||||||||
3408 | function is implemented for interoperability with all kinds of views, but | - | ||||||||||||||||||||||||
3409 | by default informs views that the model contains only one column. | - | ||||||||||||||||||||||||
3410 | - | |||||||||||||||||||||||||
3411 | \section1 Subclassing | - | ||||||||||||||||||||||||
3412 | - | |||||||||||||||||||||||||
3413 | When subclassing QAbstractListModel, you must provide implementations | - | ||||||||||||||||||||||||
3414 | of the rowCount() and data() functions. Well behaved models also provide | - | ||||||||||||||||||||||||
3415 | a headerData() implementation. | - | ||||||||||||||||||||||||
3416 | - | |||||||||||||||||||||||||
3417 | If your model is used within QML and requires roles other than the | - | ||||||||||||||||||||||||
3418 | default ones provided by the roleNames() function, you must override it. | - | ||||||||||||||||||||||||
3419 | - | |||||||||||||||||||||||||
3420 | For editable list models, you must also provide an implementation of | - | ||||||||||||||||||||||||
3421 | setData(), and implement the flags() function so that it returns a value | - | ||||||||||||||||||||||||
3422 | containing \l{Qt::ItemFlags}{Qt::ItemIsEditable}. | - | ||||||||||||||||||||||||
3423 | - | |||||||||||||||||||||||||
3424 | Note that QAbstractListModel provides a default implementation of | - | ||||||||||||||||||||||||
3425 | columnCount() that informs views that there is only a single column | - | ||||||||||||||||||||||||
3426 | of items in this model. | - | ||||||||||||||||||||||||
3427 | - | |||||||||||||||||||||||||
3428 | Models that provide interfaces to resizable list-like data structures | - | ||||||||||||||||||||||||
3429 | can provide implementations of insertRows() and removeRows(). When | - | ||||||||||||||||||||||||
3430 | implementing these functions, it is important to call the appropriate | - | ||||||||||||||||||||||||
3431 | functions so that all connected views are aware of any changes: | - | ||||||||||||||||||||||||
3432 | - | |||||||||||||||||||||||||
3433 | \list | - | ||||||||||||||||||||||||
3434 | \li An insertRows() implementation must call beginInsertRows() | - | ||||||||||||||||||||||||
3435 | \e before inserting new rows into the data structure, and it must | - | ||||||||||||||||||||||||
3436 | call endInsertRows() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3437 | \li A removeRows() implementation must call beginRemoveRows() | - | ||||||||||||||||||||||||
3438 | \e before the rows are removed from the data structure, and it must | - | ||||||||||||||||||||||||
3439 | call endRemoveRows() \e{immediately afterwards}. | - | ||||||||||||||||||||||||
3440 | \endlist | - | ||||||||||||||||||||||||
3441 | - | |||||||||||||||||||||||||
3442 | \note Some general guidelines for subclassing models are available in the | - | ||||||||||||||||||||||||
3443 | \l{Model Subclassing Reference}. | - | ||||||||||||||||||||||||
3444 | - | |||||||||||||||||||||||||
3445 | \sa {Model Classes}, {Model Subclassing Reference}, QAbstractItemView, | - | ||||||||||||||||||||||||
3446 | QAbstractTableModel, {Item Views Puzzle Example} | - | ||||||||||||||||||||||||
3447 | */ | - | ||||||||||||||||||||||||
3448 | - | |||||||||||||||||||||||||
3449 | /*! | - | ||||||||||||||||||||||||
3450 | Constructs an abstract list model with the given \a parent. | - | ||||||||||||||||||||||||
3451 | */ | - | ||||||||||||||||||||||||
3452 | - | |||||||||||||||||||||||||
3453 | QAbstractListModel::QAbstractListModel(QObject *parent) | - | ||||||||||||||||||||||||
3454 | : QAbstractItemModel(parent) | - | ||||||||||||||||||||||||
3455 | { | - | ||||||||||||||||||||||||
3456 | - | |||||||||||||||||||||||||
3457 | } executed 591 times by 23 tests: end of block Executed by:
| 591 | ||||||||||||||||||||||||
3458 | - | |||||||||||||||||||||||||
3459 | /*! | - | ||||||||||||||||||||||||
3460 | \internal | - | ||||||||||||||||||||||||
3461 | - | |||||||||||||||||||||||||
3462 | Constructs an abstract list model with \a dd and the given \a parent. | - | ||||||||||||||||||||||||
3463 | */ | - | ||||||||||||||||||||||||
3464 | - | |||||||||||||||||||||||||
3465 | QAbstractListModel::QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||||||||
3466 | : QAbstractItemModel(dd, parent) | - | ||||||||||||||||||||||||
3467 | { | - | ||||||||||||||||||||||||
3468 | - | |||||||||||||||||||||||||
3469 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3470 | - | |||||||||||||||||||||||||
3471 | /*! | - | ||||||||||||||||||||||||
3472 | Destroys the abstract list model. | - | ||||||||||||||||||||||||
3473 | */ | - | ||||||||||||||||||||||||
3474 | - | |||||||||||||||||||||||||
3475 | QAbstractListModel::~QAbstractListModel() | - | ||||||||||||||||||||||||
3476 | { | - | ||||||||||||||||||||||||
3477 | - | |||||||||||||||||||||||||
3478 | } | - | ||||||||||||||||||||||||
3479 | - | |||||||||||||||||||||||||
3480 | /*! | - | ||||||||||||||||||||||||
3481 | \fn QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const | - | ||||||||||||||||||||||||
3482 | - | |||||||||||||||||||||||||
3483 | Returns the index of the data in \a row and \a column with \a parent. | - | ||||||||||||||||||||||||
3484 | - | |||||||||||||||||||||||||
3485 | \sa parent() | - | ||||||||||||||||||||||||
3486 | */ | - | ||||||||||||||||||||||||
3487 | - | |||||||||||||||||||||||||
3488 | QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||||||||||||||
3489 | { | - | ||||||||||||||||||||||||
3490 | return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); executed 99747 times by 20 tests: return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); Executed by:
| 646-99747 | ||||||||||||||||||||||||
3491 | } | - | ||||||||||||||||||||||||
3492 | - | |||||||||||||||||||||||||
3493 | /*! | - | ||||||||||||||||||||||||
3494 | Returns the parent of the model item with the given \a index. | - | ||||||||||||||||||||||||
3495 | - | |||||||||||||||||||||||||
3496 | \sa index(), hasChildren() | - | ||||||||||||||||||||||||
3497 | */ | - | ||||||||||||||||||||||||
3498 | - | |||||||||||||||||||||||||
3499 | QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const | - | ||||||||||||||||||||||||
3500 | { | - | ||||||||||||||||||||||||
3501 | return QModelIndex(); executed 33511 times by 17 tests: return QModelIndex(); Executed by:
| 33511 | ||||||||||||||||||||||||
3502 | } | - | ||||||||||||||||||||||||
3503 | - | |||||||||||||||||||||||||
3504 | /*! | - | ||||||||||||||||||||||||
3505 | \reimp | - | ||||||||||||||||||||||||
3506 | */ | - | ||||||||||||||||||||||||
3507 | QModelIndex QAbstractListModel::sibling(int row, int column, const QModelIndex &) const | - | ||||||||||||||||||||||||
3508 | { | - | ||||||||||||||||||||||||
3509 | return index(row, column); executed 261 times by 5 tests: return index(row, column); Executed by:
| 261 | ||||||||||||||||||||||||
3510 | } | - | ||||||||||||||||||||||||
3511 | - | |||||||||||||||||||||||||
3512 | /*! | - | ||||||||||||||||||||||||
3513 | \reimp | - | ||||||||||||||||||||||||
3514 | */ | - | ||||||||||||||||||||||||
3515 | Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||
3516 | { | - | ||||||||||||||||||||||||
3517 | Qt::ItemFlags f = QAbstractItemModel::flags(index); | - | ||||||||||||||||||||||||
3518 | if (index.isValid())
| 18-12064 | ||||||||||||||||||||||||
3519 | f |= Qt::ItemNeverHasChildren; executed 12064 times by 14 tests: f |= Qt::ItemNeverHasChildren; Executed by:
| 12064 | ||||||||||||||||||||||||
3520 | return f; executed 12082 times by 16 tests: return f; Executed by:
| 12082 | ||||||||||||||||||||||||
3521 | } | - | ||||||||||||||||||||||||
3522 | - | |||||||||||||||||||||||||
3523 | /*! | - | ||||||||||||||||||||||||
3524 | \internal | - | ||||||||||||||||||||||||
3525 | - | |||||||||||||||||||||||||
3526 | Returns the number of columns in the list with the given \a parent. | - | ||||||||||||||||||||||||
3527 | - | |||||||||||||||||||||||||
3528 | \sa rowCount() | - | ||||||||||||||||||||||||
3529 | */ | - | ||||||||||||||||||||||||
3530 | - | |||||||||||||||||||||||||
3531 | int QAbstractListModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
3532 | { | - | ||||||||||||||||||||||||
3533 | return parent.isValid() ? 0 : 1; executed 134423 times by 22 tests: return parent.isValid() ? 0 : 1; Executed by:
| 7-134423 | ||||||||||||||||||||||||
3534 | } | - | ||||||||||||||||||||||||
3535 | - | |||||||||||||||||||||||||
3536 | bool QAbstractListModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
3537 | { | - | ||||||||||||||||||||||||
3538 | return parent.isValid() ? false : (rowCount() > 0); executed 1661 times by 7 tests: return parent.isValid() ? false : (rowCount() > 0); Executed by:
| 296-1661 | ||||||||||||||||||||||||
3539 | } | - | ||||||||||||||||||||||||
3540 | - | |||||||||||||||||||||||||
3541 | /*! | - | ||||||||||||||||||||||||
3542 | \typedef QModelIndexList | - | ||||||||||||||||||||||||
3543 | \relates QModelIndex | - | ||||||||||||||||||||||||
3544 | - | |||||||||||||||||||||||||
3545 | Synonym for QList<QModelIndex>. | - | ||||||||||||||||||||||||
3546 | */ | - | ||||||||||||||||||||||||
3547 | - | |||||||||||||||||||||||||
3548 | /*! | - | ||||||||||||||||||||||||
3549 | \reimp | - | ||||||||||||||||||||||||
3550 | */ | - | ||||||||||||||||||||||||
3551 | bool QAbstractTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
3552 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
3553 | { | - | ||||||||||||||||||||||||
3554 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
| 0 | ||||||||||||||||||||||||
3555 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3556 | - | |||||||||||||||||||||||||
3557 | QStringList types = mimeTypes(); | - | ||||||||||||||||||||||||
3558 | if (types.isEmpty())
| 0 | ||||||||||||||||||||||||
3559 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3560 | QString format = types.at(0); | - | ||||||||||||||||||||||||
3561 | if (!data->hasFormat(format))
| 0 | ||||||||||||||||||||||||
3562 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3563 | - | |||||||||||||||||||||||||
3564 | QByteArray encoded = data->data(format); | - | ||||||||||||||||||||||||
3565 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||||||||||||||
3566 | - | |||||||||||||||||||||||||
3567 | // if the drop is on an item, replace the data in the items | - | ||||||||||||||||||||||||
3568 | if (parent.isValid() && row == -1 && column == -1) {
| 0 | ||||||||||||||||||||||||
3569 | int top = INT_MAX; | - | ||||||||||||||||||||||||
3570 | int left = INT_MAX; | - | ||||||||||||||||||||||||
3571 | QVector<int> rows, columns; | - | ||||||||||||||||||||||||
3572 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||||||||||||||
3573 | - | |||||||||||||||||||||||||
3574 | while (!stream.atEnd()) {
| 0 | ||||||||||||||||||||||||
3575 | int r, c; | - | ||||||||||||||||||||||||
3576 | QMap<int, QVariant> v; | - | ||||||||||||||||||||||||
3577 | stream >> r >> c >> v; | - | ||||||||||||||||||||||||
3578 | rows.append(r); | - | ||||||||||||||||||||||||
3579 | columns.append(c); | - | ||||||||||||||||||||||||
3580 | data.append(v); | - | ||||||||||||||||||||||||
3581 | top = qMin(r, top); | - | ||||||||||||||||||||||||
3582 | left = qMin(c, left); | - | ||||||||||||||||||||||||
3583 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3584 | - | |||||||||||||||||||||||||
3585 | for (int i = 0; i < data.size(); ++i) {
| 0 | ||||||||||||||||||||||||
3586 | int r = (rows.at(i) - top) + parent.row(); | - | ||||||||||||||||||||||||
3587 | int c = (columns.at(i) - left) + parent.column(); | - | ||||||||||||||||||||||||
3588 | if (hasIndex(r, c))
| 0 | ||||||||||||||||||||||||
3589 | setItemData(index(r, c), data.at(i)); never executed: setItemData(index(r, c), data.at(i)); | 0 | ||||||||||||||||||||||||
3590 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3591 | - | |||||||||||||||||||||||||
3592 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
3593 | } | - | ||||||||||||||||||||||||
3594 | - | |||||||||||||||||||||||||
3595 | // otherwise insert new rows for the data | - | ||||||||||||||||||||||||
3596 | return decodeData(row, column, parent, stream); never executed: return decodeData(row, column, parent, stream); | 0 | ||||||||||||||||||||||||
3597 | } | - | ||||||||||||||||||||||||
3598 | - | |||||||||||||||||||||||||
3599 | /*! | - | ||||||||||||||||||||||||
3600 | \reimp | - | ||||||||||||||||||||||||
3601 | */ | - | ||||||||||||||||||||||||
3602 | bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||||||||||||||
3603 | int row, int column, const QModelIndex &parent) | - | ||||||||||||||||||||||||
3604 | { | - | ||||||||||||||||||||||||
3605 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
| 0 | ||||||||||||||||||||||||
3606 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3607 | - | |||||||||||||||||||||||||
3608 | QStringList types = mimeTypes(); | - | ||||||||||||||||||||||||
3609 | if (types.isEmpty())
| 0 | ||||||||||||||||||||||||
3610 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3611 | QString format = types.at(0); | - | ||||||||||||||||||||||||
3612 | if (!data->hasFormat(format))
| 0 | ||||||||||||||||||||||||
3613 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
3614 | - | |||||||||||||||||||||||||
3615 | QByteArray encoded = data->data(format); | - | ||||||||||||||||||||||||
3616 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||||||||||||||
3617 | - | |||||||||||||||||||||||||
3618 | // if the drop is on an item, replace the data in the items | - | ||||||||||||||||||||||||
3619 | if (parent.isValid() && row == -1 && column == -1) {
| 0 | ||||||||||||||||||||||||
3620 | int top = INT_MAX; | - | ||||||||||||||||||||||||
3621 | int left = INT_MAX; | - | ||||||||||||||||||||||||
3622 | QVector<int> rows, columns; | - | ||||||||||||||||||||||||
3623 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||||||||||||||
3624 | - | |||||||||||||||||||||||||
3625 | while (!stream.atEnd()) {
| 0 | ||||||||||||||||||||||||
3626 | int r, c; | - | ||||||||||||||||||||||||
3627 | QMap<int, QVariant> v; | - | ||||||||||||||||||||||||
3628 | stream >> r >> c >> v; | - | ||||||||||||||||||||||||
3629 | rows.append(r); | - | ||||||||||||||||||||||||
3630 | columns.append(c); | - | ||||||||||||||||||||||||
3631 | data.append(v); | - | ||||||||||||||||||||||||
3632 | top = qMin(r, top); | - | ||||||||||||||||||||||||
3633 | left = qMin(c, left); | - | ||||||||||||||||||||||||
3634 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3635 | - | |||||||||||||||||||||||||
3636 | for (int i = 0; i < data.size(); ++i) {
| 0 | ||||||||||||||||||||||||
3637 | int r = (rows.at(i) - top) + parent.row(); | - | ||||||||||||||||||||||||
3638 | if (columns.at(i) == left && hasIndex(r, 0))
| 0 | ||||||||||||||||||||||||
3639 | setItemData(index(r), data.at(i)); never executed: setItemData(index(r), data.at(i)); | 0 | ||||||||||||||||||||||||
3640 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3641 | - | |||||||||||||||||||||||||
3642 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
3643 | } | - | ||||||||||||||||||||||||
3644 | - | |||||||||||||||||||||||||
3645 | if (row == -1)
| 0 | ||||||||||||||||||||||||
3646 | row = rowCount(parent); never executed: row = rowCount(parent); | 0 | ||||||||||||||||||||||||
3647 | - | |||||||||||||||||||||||||
3648 | // otherwise insert new rows for the data | - | ||||||||||||||||||||||||
3649 | return decodeData(row, column, parent, stream); never executed: return decodeData(row, column, parent, stream); | 0 | ||||||||||||||||||||||||
3650 | } | - | ||||||||||||||||||||||||
3651 | - | |||||||||||||||||||||||||
3652 | /*! | - | ||||||||||||||||||||||||
3653 | \fn QAbstractItemModel::modelAboutToBeReset() | - | ||||||||||||||||||||||||
3654 | \since 4.2 | - | ||||||||||||||||||||||||
3655 | - | |||||||||||||||||||||||||
3656 | This signal is emitted when beginResetModel() is called, before the model's internal | - | ||||||||||||||||||||||||
3657 | state (e.g. persistent model indexes) has been invalidated. | - | ||||||||||||||||||||||||
3658 | - | |||||||||||||||||||||||||
3659 | \sa beginResetModel(), modelReset() | - | ||||||||||||||||||||||||
3660 | */ | - | ||||||||||||||||||||||||
3661 | - | |||||||||||||||||||||||||
3662 | /*! | - | ||||||||||||||||||||||||
3663 | \fn QAbstractItemModel::modelReset() | - | ||||||||||||||||||||||||
3664 | \since 4.1 | - | ||||||||||||||||||||||||
3665 | - | |||||||||||||||||||||||||
3666 | This signal is emitted when endResetModel() is called, after the | - | ||||||||||||||||||||||||
3667 | model's internal state (e.g. persistent model indexes) has been invalidated. | - | ||||||||||||||||||||||||
3668 | - | |||||||||||||||||||||||||
3669 | Note that if a model is reset it should be considered that all information | - | ||||||||||||||||||||||||
3670 | previously retrieved from it is invalid. This includes but is not limited | - | ||||||||||||||||||||||||
3671 | to the rowCount() and columnCount(), flags(), data retrieved through data(), | - | ||||||||||||||||||||||||
3672 | and roleNames(). | - | ||||||||||||||||||||||||
3673 | - | |||||||||||||||||||||||||
3674 | \sa endResetModel(), modelAboutToBeReset() | - | ||||||||||||||||||||||||
3675 | */ | - | ||||||||||||||||||||||||
3676 | - | |||||||||||||||||||||||||
3677 | /*! | - | ||||||||||||||||||||||||
3678 | \fn bool QModelIndex::operator<(const QModelIndex &other) const | - | ||||||||||||||||||||||||
3679 | \since 4.1 | - | ||||||||||||||||||||||||
3680 | - | |||||||||||||||||||||||||
3681 | Returns \c{true} if this model index is smaller than the \a other | - | ||||||||||||||||||||||||
3682 | model index; otherwise returns \c{false}. | - | ||||||||||||||||||||||||
3683 | - | |||||||||||||||||||||||||
3684 | The less than calculation is not directly useful to developers - the way that indexes | - | ||||||||||||||||||||||||
3685 | with different parents compare is not defined. This operator only exists so that the | - | ||||||||||||||||||||||||
3686 | class can be used with QMap. | - | ||||||||||||||||||||||||
3687 | */ | - | ||||||||||||||||||||||||
3688 | - | |||||||||||||||||||||||||
3689 | /*! | - | ||||||||||||||||||||||||
3690 | \fn uint qHash(const QPersistentModelIndex &index, uint seed = 0) | - | ||||||||||||||||||||||||
3691 | \since 5.0 | - | ||||||||||||||||||||||||
3692 | \relates QPersistentModelIndex | - | ||||||||||||||||||||||||
3693 | - | |||||||||||||||||||||||||
3694 | Returns a hash of the QPersistentModelIndex \a index, using \a seed to | - | ||||||||||||||||||||||||
3695 | seed the calculation. | - | ||||||||||||||||||||||||
3696 | */ | - | ||||||||||||||||||||||||
3697 | - | |||||||||||||||||||||||||
3698 | - | |||||||||||||||||||||||||
3699 | /*! | - | ||||||||||||||||||||||||
3700 | \internal | - | ||||||||||||||||||||||||
3701 | QHash::insertMulti insert the value before the old value. and find() return the new value. | - | ||||||||||||||||||||||||
3702 | We need insertMultiAtEnd because we don't want to overwrite the old one, which should be removed later | - | ||||||||||||||||||||||||
3703 | - | |||||||||||||||||||||||||
3704 | There should be only one instance QPersistentModelIndexData per index, but in some intermediate state there may be | - | ||||||||||||||||||||||||
3705 | severals of PersistantModelIndex pointing to the same index, but one is already updated, and the other one is not. | - | ||||||||||||||||||||||||
3706 | This make sure than when updating the first one we don't overwrite the second one in the hash, and the second one | - | ||||||||||||||||||||||||
3707 | will be updated right later. | - | ||||||||||||||||||||||||
3708 | */ | - | ||||||||||||||||||||||||
3709 | void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& key, QPersistentModelIndexData *data) | - | ||||||||||||||||||||||||
3710 | { | - | ||||||||||||||||||||||||
3711 | QHash<QModelIndex,QPersistentModelIndexData *>::iterator newIt = | - | ||||||||||||||||||||||||
3712 | indexes.insertMulti(key, data); | - | ||||||||||||||||||||||||
3713 | QHash<QModelIndex,QPersistentModelIndexData *>::iterator it = newIt + 1; | - | ||||||||||||||||||||||||
3714 | while (it != indexes.end() && it.key() == key) {
| 29-8524 | ||||||||||||||||||||||||
3715 | qSwap(*newIt,*it); | - | ||||||||||||||||||||||||
3716 | newIt = it; | - | ||||||||||||||||||||||||
3717 | ++it; | - | ||||||||||||||||||||||||
3718 | } executed 29 times by 4 tests: end of block Executed by:
| 29 | ||||||||||||||||||||||||
3719 | } executed 9014 times by 21 tests: end of block Executed by:
| 9014 | ||||||||||||||||||||||||
3720 | - | |||||||||||||||||||||||||
3721 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |