Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | ((!(index.isValid())) ? qt_assert("index.isValid()",__FILE__,5157) : qt_noop()); | - | ||||||||||||
8 | QPersistentModelIndexData *d = 0; | - | ||||||||||||
9 | QAbstractItemModel *model = const_cast<QAbstractItemModel *>(index.model()); | - | ||||||||||||
10 | QHash<QModelIndex, QPersistentModelIndexData *> &indexes = model->d_func()->persistent.indexes; | - | ||||||||||||
11 | const QHash<QModelIndex, QPersistentModelIndexData *>::iteratorauto it = indexes.findconstFind(index); | - | ||||||||||||
12 | if (it != indexes.endcend()
| 26745-77648 | ||||||||||||
13 | d = (*it); | - | ||||||||||||
14 | } executed 77648 times by 34 tests: else {end of block Executed by:
| 77648 | ||||||||||||
15 | d = new QPersistentModelIndexData(index); | - | ||||||||||||
16 | indexes.insert(index, d); | - | ||||||||||||
17 | } executed 26745 times by 41 tests: end of block Executed by:
| 26745 | ||||||||||||
18 | ((!(d)) ? qt_assert("d",__FILE__,6268) : qt_noop()); | - | ||||||||||||
19 | return executed 104393 times by 41 tests: d;return d; Executed by:
executed 104393 times by 41 tests: return d; Executed by:
| 104393 | ||||||||||||
20 | } | - | ||||||||||||
21 | - | |||||||||||||
22 | void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | ((!(data)) ? qt_assert("data",__FILE__,6874) : qt_noop()); | - | ||||||||||||
25 | ((!(data->ref.load() == 0)) ? qt_assert("data->ref.load() == 0",__FILE__,6975) : qt_noop()); | - | ||||||||||||
26 | QAbstractItemModel *model = const_cast<QAbstractItemModel *>(data->model); | - | ||||||||||||
27 | - | |||||||||||||
28 | if (model) { | - | ||||||||||||
29 | QAbstractItemModelPrivate *p = model->d_func(); | - | ||||||||||||
30 | ((!(p)) ? qt_assert("p",__FILE__,7480) : qt_noop()); | - | ||||||||||||
31 | p->removePersistentIndexData(data); | - | ||||||||||||
32 | } | - | ||||||||||||
33 | delete data; | - | ||||||||||||
34 | } | - | ||||||||||||
35 | QPersistentModelIndex::QPersistentModelIndex() | - | ||||||||||||
36 | : d(0) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | } | - | ||||||||||||
39 | QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other) | - | ||||||||||||
40 | : d(other.d) | - | ||||||||||||
41 | { | - | ||||||||||||
42 | if (d) d->ref.ref(); | - | ||||||||||||
43 | } | - | ||||||||||||
44 | - | |||||||||||||
45 | - | |||||||||||||
46 | - | |||||||||||||
47 | - | |||||||||||||
48 | - | |||||||||||||
49 | QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index) | - | ||||||||||||
50 | : d(0) | - | ||||||||||||
51 | { | - | ||||||||||||
52 | if (index.isValid()) { | - | ||||||||||||
53 | d = QPersistentModelIndexData::create(index); | - | ||||||||||||
54 | d->ref.ref(); | - | ||||||||||||
55 | } | - | ||||||||||||
56 | } | - | ||||||||||||
57 | - | |||||||||||||
58 | - | |||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | - | |||||||||||||
62 | - | |||||||||||||
63 | - | |||||||||||||
64 | QPersistentModelIndex::~QPersistentModelIndex() | - | ||||||||||||
65 | { | - | ||||||||||||
66 | if (d && !d->ref.deref()) { | - | ||||||||||||
67 | QPersistentModelIndexData::destroy(d); | - | ||||||||||||
68 | d = 0; | - | ||||||||||||
69 | } | - | ||||||||||||
70 | } | - | ||||||||||||
71 | bool QPersistentModelIndex::operator==(const QPersistentModelIndex &other) const | - | ||||||||||||
72 | { | - | ||||||||||||
73 | if (d && other.d) | - | ||||||||||||
74 | return d->index == other.d->index; | - | ||||||||||||
75 | return d == other.d; | - | ||||||||||||
76 | } | - | ||||||||||||
77 | bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const | - | ||||||||||||
78 | { | - | ||||||||||||
79 | if (d && other.d) | - | ||||||||||||
80 | return d->index < other.d->index; | - | ||||||||||||
81 | - | |||||||||||||
82 | return d < other.d; | - | ||||||||||||
83 | } | - | ||||||||||||
84 | QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIndex &other) | - | ||||||||||||
85 | { | - | ||||||||||||
86 | if (d == other.d) | - | ||||||||||||
87 | return *this; | - | ||||||||||||
88 | if (d && !d->ref.deref()) | - | ||||||||||||
89 | QPersistentModelIndexData::destroy(d); | - | ||||||||||||
90 | d = other.d; | - | ||||||||||||
91 | if (d) d->ref.ref(); | - | ||||||||||||
92 | return *this; | - | ||||||||||||
93 | } | - | ||||||||||||
94 | QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | if (d && !d->ref.deref()) | - | ||||||||||||
97 | QPersistentModelIndexData::destroy(d); | - | ||||||||||||
98 | if (other.isValid()) { | - | ||||||||||||
99 | d = QPersistentModelIndexData::create(other); | - | ||||||||||||
100 | if (d) d->ref.ref(); | - | ||||||||||||
101 | } else { | - | ||||||||||||
102 | d = 0; | - | ||||||||||||
103 | } | - | ||||||||||||
104 | return *this; | - | ||||||||||||
105 | } | - | ||||||||||||
106 | - | |||||||||||||
107 | - | |||||||||||||
108 | - | |||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | QPersistentModelIndex::operator const QModelIndex&() const | - | ||||||||||||
114 | { | - | ||||||||||||
115 | static const QModelIndex invalid; | - | ||||||||||||
116 | if (d) | - | ||||||||||||
117 | return d->index; | - | ||||||||||||
118 | return invalid; | - | ||||||||||||
119 | } | - | ||||||||||||
120 | bool QPersistentModelIndex::operator==(const QModelIndex &other) const | - | ||||||||||||
121 | { | - | ||||||||||||
122 | if (d) | - | ||||||||||||
123 | return d->index == other; | - | ||||||||||||
124 | return !other.isValid(); | - | ||||||||||||
125 | } | - | ||||||||||||
126 | bool QPersistentModelIndex::operator!=(const QModelIndex &other) const | - | ||||||||||||
127 | { | - | ||||||||||||
128 | if (d) | - | ||||||||||||
129 | return d->index != other; | - | ||||||||||||
130 | return other.isValid(); | - | ||||||||||||
131 | } | - | ||||||||||||
132 | - | |||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | int QPersistentModelIndex::row() const | - | ||||||||||||
140 | { | - | ||||||||||||
141 | if (d) | - | ||||||||||||
142 | return d->index.row(); | - | ||||||||||||
143 | return -1; | - | ||||||||||||
144 | } | - | ||||||||||||
145 | - | |||||||||||||
146 | - | |||||||||||||
147 | - | |||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | - | |||||||||||||
151 | - | |||||||||||||
152 | int QPersistentModelIndex::column() const | - | ||||||||||||
153 | { | - | ||||||||||||
154 | if (d) | - | ||||||||||||
155 | return d->index.column(); | - | ||||||||||||
156 | return -1; | - | ||||||||||||
157 | } | - | ||||||||||||
158 | void *QPersistentModelIndex::internalPointer() const | - | ||||||||||||
159 | { | - | ||||||||||||
160 | if (d) | - | ||||||||||||
161 | return d->index.internalPointer(); | - | ||||||||||||
162 | return 0; | - | ||||||||||||
163 | } | - | ||||||||||||
164 | quintptr QPersistentModelIndex::internalId() const | - | ||||||||||||
165 | { | - | ||||||||||||
166 | if (d) | - | ||||||||||||
167 | return d->index.internalId(); | - | ||||||||||||
168 | return 0; | - | ||||||||||||
169 | } | - | ||||||||||||
170 | - | |||||||||||||
171 | - | |||||||||||||
172 | - | |||||||||||||
173 | - | |||||||||||||
174 | - | |||||||||||||
175 | - | |||||||||||||
176 | - | |||||||||||||
177 | QModelIndex QPersistentModelIndex::parent() const | - | ||||||||||||
178 | { | - | ||||||||||||
179 | if (d) | - | ||||||||||||
180 | return d->index.parent(); | - | ||||||||||||
181 | return QModelIndex(); | - | ||||||||||||
182 | } | - | ||||||||||||
183 | QModelIndex QPersistentModelIndex::sibling(int row, int column) const | - | ||||||||||||
184 | { | - | ||||||||||||
185 | if (d) | - | ||||||||||||
186 | return d->index.sibling(row, column); | - | ||||||||||||
187 | return QModelIndex(); | - | ||||||||||||
188 | } | - | ||||||||||||
189 | QModelIndex QPersistentModelIndex::child(int row, int column) const | - | ||||||||||||
190 | { | - | ||||||||||||
191 | if (d) | - | ||||||||||||
192 | return d->index.child(row, column); | - | ||||||||||||
193 | return QModelIndex(); | - | ||||||||||||
194 | } | - | ||||||||||||
195 | - | |||||||||||||
196 | - | |||||||||||||
197 | - | |||||||||||||
198 | - | |||||||||||||
199 | - | |||||||||||||
200 | - | |||||||||||||
201 | - | |||||||||||||
202 | QVariant QPersistentModelIndex::data(int role) const | - | ||||||||||||
203 | { | - | ||||||||||||
204 | if (d) | - | ||||||||||||
205 | return d->index.data(role); | - | ||||||||||||
206 | return QVariant(); | - | ||||||||||||
207 | } | - | ||||||||||||
208 | - | |||||||||||||
209 | - | |||||||||||||
210 | - | |||||||||||||
211 | - | |||||||||||||
212 | - | |||||||||||||
213 | - | |||||||||||||
214 | Qt::ItemFlags QPersistentModelIndex::flags() const | - | ||||||||||||
215 | { | - | ||||||||||||
216 | if (d) | - | ||||||||||||
217 | return d->index.flags(); | - | ||||||||||||
218 | return 0; | - | ||||||||||||
219 | } | - | ||||||||||||
220 | - | |||||||||||||
221 | - | |||||||||||||
222 | - | |||||||||||||
223 | - | |||||||||||||
224 | const QAbstractItemModel *QPersistentModelIndex::model() const | - | ||||||||||||
225 | { | - | ||||||||||||
226 | if (d) | - | ||||||||||||
227 | return d->index.model(); | - | ||||||||||||
228 | return 0; | - | ||||||||||||
229 | } | - | ||||||||||||
230 | bool QPersistentModelIndex::isValid() const | - | ||||||||||||
231 | { | - | ||||||||||||
232 | return d && d->index.isValid(); | - | ||||||||||||
233 | } | - | ||||||||||||
234 | - | |||||||||||||
235 | - | |||||||||||||
236 | QDebug operator<<(QDebug dbg, const QModelIndex &idx) | - | ||||||||||||
237 | { | - | ||||||||||||
238 | QDebugStateSaver saver(dbg); | - | ||||||||||||
239 | dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column() | - | ||||||||||||
240 | << ',' << idx.internalPointer() << ',' << idx.model() << ')'; | - | ||||||||||||
241 | return dbg; | - | ||||||||||||
242 | } | - | ||||||||||||
243 | - | |||||||||||||
244 | QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) | - | ||||||||||||
245 | { | - | ||||||||||||
246 | if (idx.d) | - | ||||||||||||
247 | dbg << idx.d->index; | - | ||||||||||||
248 | else | - | ||||||||||||
249 | dbg << QModelIndex(); | - | ||||||||||||
250 | return dbg; | - | ||||||||||||
251 | } | - | ||||||||||||
252 | - | |||||||||||||
253 | - | |||||||||||||
254 | class QEmptyItemModel : public QAbstractItemModel | - | ||||||||||||
255 | { | - | ||||||||||||
256 | public: | - | ||||||||||||
257 | explicit QEmptyItemModel(QObject *parent = 0) : QAbstractItemModel(parent) {} | - | ||||||||||||
258 | QModelIndex index(int, int, const QModelIndex &) const override { return QModelIndex(); } | - | ||||||||||||
259 | QModelIndex parent(const QModelIndex &) const override { return QModelIndex(); } | - | ||||||||||||
260 | int rowCount(const QModelIndex &) const override { return 0; } | - | ||||||||||||
261 | int columnCount(const QModelIndex &) const override { return 0; } | - | ||||||||||||
262 | bool hasChildren(const QModelIndex &) const override { return false; } | - | ||||||||||||
263 | QVariant data(const QModelIndex &, int) const override { return QVariant(); } | - | ||||||||||||
264 | }; | - | ||||||||||||
265 | - | |||||||||||||
266 | namespace { namespace Q_QGS_qEmptyModel { typedef QEmptyItemModel Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QEmptyItemModel, Q_QGS_qEmptyModel::innerFunction, Q_QGS_qEmptyModel::guard> qEmptyModel; | - | ||||||||||||
267 | - | |||||||||||||
268 | - | |||||||||||||
269 | QAbstractItemModelPrivate::QAbstractItemModelPrivate() | - | ||||||||||||
270 | : QObjectPrivate(), | - | ||||||||||||
271 | supportedDragActions(-1), | - | ||||||||||||
272 | roleNames(defaultRoleNames()) | - | ||||||||||||
273 | { | - | ||||||||||||
274 | } executed 5394 times by 54 tests: end of block Executed by:
| 5394 | ||||||||||||
275 | - | |||||||||||||
276 | QAbstractItemModelPrivate::~QAbstractItemModelPrivate() | - | ||||||||||||
277 | { | - | ||||||||||||
278 | } | - | ||||||||||||
279 | - | |||||||||||||
280 | QAbstractItemModel *QAbstractItemModelPrivate::staticEmptyModel() | - | ||||||||||||
281 | { | - | ||||||||||||
282 | return qEmptyModel(); | - | ||||||||||||
283 | } | - | ||||||||||||
284 | - | |||||||||||||
285 | void QAbstractItemModelPrivate::invalidatePersistentIndexes() | - | ||||||||||||
286 | { | - | ||||||||||||
287 | for (QPersistentModelIndexData *data : qAsConst(persistent.indexes)) { | - | ||||||||||||
288 | data->index = QModelIndex(); | - | ||||||||||||
289 | data->model = 0; | - | ||||||||||||
290 | } executed 4404 times by 38 tests: end of block Executed by:
| 4404 | ||||||||||||
291 | persistent.indexes.clear(); | - | ||||||||||||
292 | } executed 14712 times by 98 tests: end of block Executed by:
| 14712 | ||||||||||||
293 | - | |||||||||||||
294 | - | |||||||||||||
295 | - | |||||||||||||
296 | - | |||||||||||||
297 | - | |||||||||||||
298 | - | |||||||||||||
299 | void QAbstractItemModelPrivate::invalidatePersistentIndex(const QModelIndex &index) { | - | ||||||||||||
300 | const auto it = persistent.indexes.constFind(index); | - | ||||||||||||
301 | if (it != persistent.indexes.cend()
| 1130-3496222 | ||||||||||||
302 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
303 | persistent.indexes.erase(it); | - | ||||||||||||
304 | data->index = QModelIndex(); | - | ||||||||||||
305 | data->model = 0; | - | ||||||||||||
306 | } executed 1130 times by 11 tests: end of block Executed by:
| 1130 | ||||||||||||
307 | } executed 3497352 times by 37 tests: end of block Executed by:
| 3497352 | ||||||||||||
308 | - | |||||||||||||
309 | namespace { | - | ||||||||||||
310 | struct DefaultRoleNames : public QHash<int, QByteArray> | - | ||||||||||||
311 | { | - | ||||||||||||
312 | DefaultRoleNames() { | - | ||||||||||||
313 | (*this)[Qt::DisplayRole] = "display"; | - | ||||||||||||
314 | (*this)[Qt::DecorationRole] = "decoration"; | - | ||||||||||||
315 | (*this)[Qt::EditRole] = "edit"; | - | ||||||||||||
316 | (*this)[Qt::ToolTipRole] = "toolTip"; | - | ||||||||||||
317 | (*this)[Qt::StatusTipRole] = "statusTip"; | - | ||||||||||||
318 | (*this)[Qt::WhatsThisRole] = "whatsThis"; | - | ||||||||||||
319 | } | - | ||||||||||||
320 | }; | - | ||||||||||||
321 | } | - | ||||||||||||
322 | - | |||||||||||||
323 | namespace { namespace Q_QGS_qDefaultRoleNames { typedef DefaultRoleNames Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<DefaultRoleNames, Q_QGS_qDefaultRoleNames::innerFunction, Q_QGS_qDefaultRoleNames::guard> qDefaultRoleNames; | - | ||||||||||||
324 | - | |||||||||||||
325 | const QHash<int,QByteArray> &QAbstractItemModelPrivate::defaultRoleNames() | - | ||||||||||||
326 | { | - | ||||||||||||
327 | return *qDefaultRoleNames(); | - | ||||||||||||
328 | } | - | ||||||||||||
329 | - | |||||||||||||
330 | - | |||||||||||||
331 | static uint typeOfVariant(const QVariant &value) | - | ||||||||||||
332 | { | - | ||||||||||||
333 | - | |||||||||||||
334 | switch (value.userType()) { | - | ||||||||||||
335 | case QVariant::Bool: | - | ||||||||||||
336 | case QVariant::Int: | - | ||||||||||||
337 | case QVariant::UInt: | - | ||||||||||||
338 | case QVariant::LongLong: | - | ||||||||||||
339 | case QVariant::ULongLong: | - | ||||||||||||
340 | case QVariant::Char: | - | ||||||||||||
341 | case QMetaType::Short: | - | ||||||||||||
342 | case QMetaType::UShort: | - | ||||||||||||
343 | case QMetaType::UChar: | - | ||||||||||||
344 | case QMetaType::ULong: | - | ||||||||||||
345 | case QMetaType::Long: | - | ||||||||||||
346 | return 0; | - | ||||||||||||
347 | case QVariant::Double: | - | ||||||||||||
348 | case QMetaType::Float: | - | ||||||||||||
349 | return 1; | - | ||||||||||||
350 | default: | - | ||||||||||||
351 | return 2; | - | ||||||||||||
352 | } | - | ||||||||||||
353 | } | - | ||||||||||||
354 | - | |||||||||||||
355 | - | |||||||||||||
356 | - | |||||||||||||
357 | - | |||||||||||||
358 | - | |||||||||||||
359 | - | |||||||||||||
360 | - | |||||||||||||
361 | bool QAbstractItemModelPrivate::variantLessThan(const QVariant &v1, const QVariant &v2) | - | ||||||||||||
362 | { | - | ||||||||||||
363 | switch(qMax(typeOfVariant(v1), typeOfVariant(v2))) | - | ||||||||||||
364 | { | - | ||||||||||||
365 | case 0: | - | ||||||||||||
366 | return v1.toLongLong() < v2.toLongLong(); | - | ||||||||||||
367 | case 1: | - | ||||||||||||
368 | return v1.toReal() < v2.toReal(); | - | ||||||||||||
369 | default: | - | ||||||||||||
370 | return v1.toString().localeAwareCompare(v2.toString()) < 0; | - | ||||||||||||
371 | } | - | ||||||||||||
372 | } | - | ||||||||||||
373 | - | |||||||||||||
374 | void QAbstractItemModelPrivate::removePersistentIndexData(QPersistentModelIndexData *data) | - | ||||||||||||
375 | { | - | ||||||||||||
376 | if (data->index.isValid()
| 2-21134 | ||||||||||||
377 | int removed = persistent.indexes.remove(data->index); | - | ||||||||||||
378 | ((!(removed == 1)) ? qt_assert_x("QPersistentModelIndex::~QPersistentModelIndex", "persistent model indexes corrupted", | - | ||||||||||||
379 | __FILE__ | - | ||||||||||||
380 | , | - | ||||||||||||
381 | 562599 | - | ||||||||||||
382 | ) : qt_noop()) | - | ||||||||||||
383 | ; | - | ||||||||||||
384 | - | |||||||||||||
385 | - | |||||||||||||
386 | (void)removed;; | - | ||||||||||||
387 | } executed 21134 times by 38 tests: end of block Executed by:
| 21134 | ||||||||||||
388 | - | |||||||||||||
389 | for (int i = persistent.moved.count() - 1; i >= 0
| 0-21136 | ||||||||||||
390 | int idx = persistent.moved[.at(i].).indexOf(data); | - | ||||||||||||
391 | if (idx >= 0
| 0 | ||||||||||||
392 | persistent.moved[i].remove(idx); never executed: persistent.moved[i].remove(idx); | 0 | ||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||
394 | - | |||||||||||||
395 | for (int i = persistent.invalidated.count() - 1; i >= 0
| 0-21136 | ||||||||||||
396 | int idx = persistent.invalidated[.at(i].).indexOf(data); | - | ||||||||||||
397 | if (idx >= 0
| 0 | ||||||||||||
398 | persistent.invalidated[i].remove(idx); never executed: persistent.invalidated[i].remove(idx); | 0 | ||||||||||||
399 | } never executed: end of block | 0 | ||||||||||||
400 | - | |||||||||||||
401 | } executed 21136 times by 38 tests: end of block Executed by:
| 21136 | ||||||||||||
402 | - | |||||||||||||
403 | void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex &parent, | - | ||||||||||||
404 | int first, int last) | - | ||||||||||||
405 | { | - | ||||||||||||
406 | QAbstractItemModel * const q = q_func(); | - | ||||||||||||
407 | (void)last;; | - | ||||||||||||
408 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||
409 | if (first < q->rowCount(parent)) { | - | ||||||||||||
410 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||
411 | it != persistent.indexes.constEnd(); ++it) { | - | ||||||||||||
412 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
413 | const QModelIndex &index = data->index; | - | ||||||||||||
414 | if (index.row() >= first && index.isValid() && index.parent() == parent) { | - | ||||||||||||
415 | persistent_moved.append(data); | - | ||||||||||||
416 | } | - | ||||||||||||
417 | } | - | ||||||||||||
418 | } | - | ||||||||||||
419 | persistent.moved.push(persistent_moved); | - | ||||||||||||
420 | } | - | ||||||||||||
421 | - | |||||||||||||
422 | void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent, | - | ||||||||||||
423 | int first, int last) | - | ||||||||||||
424 | { | - | ||||||||||||
425 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||
426 | int count = (last - first) + 1; | - | ||||||||||||
427 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||
428 | it != persistent_moved.constEnd()
| 6164-121996 | ||||||||||||
429 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
430 | QModelIndex old = data->index; | - | ||||||||||||
431 | persistent.indexes.erase(persistent.indexes.findconstFind(old)); | - | ||||||||||||
432 | data->index = q_func()->index(old.row() + count, old.column(), parent); | - | ||||||||||||
433 | if (data->index.isValid()
| 0-6164 | ||||||||||||
434 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
435 | } executed 6164 times by 12 tests: else {end of block Executed by:
| 6164 | ||||||||||||
436 | QMessageLogger(__FILE__, 615652, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func(); | - | ||||||||||||
437 | } never executed: end of block | 0 | ||||||||||||
438 | } | - | ||||||||||||
439 | } executed 121996 times by 45 tests: end of block Executed by:
| 121996 | ||||||||||||
440 | - | |||||||||||||
441 | void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) | - | ||||||||||||
442 | { | - | ||||||||||||
443 | QVector<QPersistentModelIndexData *> persistent_moved_explicitly; | - | ||||||||||||
444 | QVector<QPersistentModelIndexData *> persistent_moved_in_source; | - | ||||||||||||
445 | QVector<QPersistentModelIndexData *> persistent_moved_in_destination; | - | ||||||||||||
446 | - | |||||||||||||
447 | QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it; | - | ||||||||||||
448 | const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator begin = persistent.indexes.constBegin(); | - | ||||||||||||
449 | const QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator end = persistent.indexes.constEnd(); | - | ||||||||||||
450 | - | |||||||||||||
451 | const bool sameParent = (srcParent == destinationParent); | - | ||||||||||||
452 | const bool movingUp = (srcFirst > destinationChild); | - | ||||||||||||
453 | - | |||||||||||||
454 | for ( it = begin; it != end; ++it) { | - | ||||||||||||
455 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
456 | const QModelIndex &index = data->index; | - | ||||||||||||
457 | const QModelIndex &parent = index.parent(); | - | ||||||||||||
458 | const bool isSourceIndex = (parent == srcParent); | - | ||||||||||||
459 | const bool isDestinationIndex = (parent == destinationParent); | - | ||||||||||||
460 | - | |||||||||||||
461 | int childPosition; | - | ||||||||||||
462 | if (orientation == Qt::Vertical) | - | ||||||||||||
463 | childPosition = index.row(); | - | ||||||||||||
464 | else | - | ||||||||||||
465 | childPosition = index.column(); | - | ||||||||||||
466 | - | |||||||||||||
467 | if (!index.isValid() || !(isSourceIndex || isDestinationIndex ) ) | - | ||||||||||||
468 | continue; | - | ||||||||||||
469 | - | |||||||||||||
470 | if (!sameParent && isDestinationIndex) { | - | ||||||||||||
471 | if (childPosition >= destinationChild) | - | ||||||||||||
472 | persistent_moved_in_destination.append(data); | - | ||||||||||||
473 | continue; | - | ||||||||||||
474 | } | - | ||||||||||||
475 | - | |||||||||||||
476 | if (sameParent && movingUp && childPosition < destinationChild) | - | ||||||||||||
477 | continue; | - | ||||||||||||
478 | - | |||||||||||||
479 | if (sameParent && !movingUp && childPosition < srcFirst ) | - | ||||||||||||
480 | continue; | - | ||||||||||||
481 | - | |||||||||||||
482 | if (!sameParent && childPosition < srcFirst) | - | ||||||||||||
483 | continue; | - | ||||||||||||
484 | - | |||||||||||||
485 | if (sameParent && (childPosition > srcLast) && (childPosition >= destinationChild )) | - | ||||||||||||
486 | continue; | - | ||||||||||||
487 | - | |||||||||||||
488 | if ((childPosition <= srcLast) && (childPosition >= srcFirst)) { | - | ||||||||||||
489 | persistent_moved_explicitly.append(data); | - | ||||||||||||
490 | } else { | - | ||||||||||||
491 | persistent_moved_in_source.append(data); | - | ||||||||||||
492 | } | - | ||||||||||||
493 | } | - | ||||||||||||
494 | persistent.moved.push(persistent_moved_explicitly); | - | ||||||||||||
495 | persistent.moved.push(persistent_moved_in_source); | - | ||||||||||||
496 | persistent.moved.push(persistent_moved_in_destination); | - | ||||||||||||
497 | } | - | ||||||||||||
498 | void QAbstractItemModelPrivate::movePersistentIndexes(const QVector<QPersistentModelIndexData *> &indexes, int change, const QModelIndex &parent, Qt::Orientation orientation) | - | ||||||||||||
499 | { | - | ||||||||||||
500 | QVector<QPersistentModelIndexData *>::const_iterator it; | - | ||||||||||||
501 | const QVector<QPersistentModelIndexData *>::const_iterator begin = indexes.constBegin(); | - | ||||||||||||
502 | const QVector<QPersistentModelIndexData *>::const_iterator end = indexes.constEnd(); | - | ||||||||||||
503 | - | |||||||||||||
504 | for (it = begin; it != end
| 216-1178 | ||||||||||||
505 | { | - | ||||||||||||
506 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
507 | - | |||||||||||||
508 | int row = data->index.row(); | - | ||||||||||||
509 | int column = data->index.column(); | - | ||||||||||||
510 | - | |||||||||||||
511 | if (Qt::Vertical == orientation
| 0-1178 | ||||||||||||
512 | row += change; executed 1178 times by 2 tests: row += change; Executed by:
| 1178 | ||||||||||||
513 | else | - | ||||||||||||
514 | column += change; never executed: column += change; | 0 | ||||||||||||
515 | - | |||||||||||||
516 | persistent.indexes.erase(persistent.indexes.findconstFind(data->index)); | - | ||||||||||||
517 | data->index = q_func()->index(row, column, parent); | - | ||||||||||||
518 | if (data->index.isValid()
| 0-1178 | ||||||||||||
519 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
520 | } executed 1178 times by 2 tests: else {end of block Executed by:
| 1178 | ||||||||||||
521 | QMessageLogger(__FILE__, 708745, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endMoveRows: Invalid index (" << row << "," << column << ") in model" << q_func(); | - | ||||||||||||
522 | } never executed: end of block | 0 | ||||||||||||
523 | } | - | ||||||||||||
524 | } executed 216 times by 5 tests: end of block Executed by:
| 216 | ||||||||||||
525 | - | |||||||||||||
526 | void QAbstractItemModelPrivate::itemsMoved(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation) | - | ||||||||||||
527 | { | - | ||||||||||||
528 | QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop(); | - | ||||||||||||
529 | QVector<QPersistentModelIndexData *> moved_in_source = persistent.moved.pop(); | - | ||||||||||||
530 | QVector<QPersistentModelIndexData *> moved_explicitly = persistent.moved.pop(); | - | ||||||||||||
531 | - | |||||||||||||
532 | const bool sameParent = (sourceParent == destinationParent); | - | ||||||||||||
533 | const bool movingUp = (sourceFirst > destinationChild); | - | ||||||||||||
534 | - | |||||||||||||
535 | const int explicit_change = (!sameParent || movingUp) ? destinationChild - sourceFirst : destinationChild - sourceLast - 1 ; | - | ||||||||||||
536 | const int source_change = (!sameParent || !movingUp) ? -1*(sourceLast - sourceFirst + 1) : sourceLast - sourceFirst + 1 ; | - | ||||||||||||
537 | const int destination_change = sourceLast - sourceFirst + 1; | - | ||||||||||||
538 | - | |||||||||||||
539 | movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation); | - | ||||||||||||
540 | movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation); | - | ||||||||||||
541 | movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation); | - | ||||||||||||
542 | } | - | ||||||||||||
543 | - | |||||||||||||
544 | void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent, | - | ||||||||||||
545 | int first, int last) | - | ||||||||||||
546 | { | - | ||||||||||||
547 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||
548 | QVector<QPersistentModelIndexData *> persistent_invalidated; | - | ||||||||||||
549 | - | |||||||||||||
550 | - | |||||||||||||
551 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||
552 | it != persistent.indexes.constEnd(); ++it) { | - | ||||||||||||
553 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
554 | bool level_changed = false; | - | ||||||||||||
555 | QModelIndex current = data->index; | - | ||||||||||||
556 | while (current.isValid()) { | - | ||||||||||||
557 | QModelIndex current_parent = current.parent(); | - | ||||||||||||
558 | if (current_parent == parent) { | - | ||||||||||||
559 | if (!level_changed && current.row() > last) | - | ||||||||||||
560 | persistent_moved.append(data); | - | ||||||||||||
561 | else if (current.row() <= last && current.row() >= first) | - | ||||||||||||
562 | persistent_invalidated.append(data); | - | ||||||||||||
563 | break; | - | ||||||||||||
564 | } | - | ||||||||||||
565 | current = current_parent; | - | ||||||||||||
566 | level_changed = true; | - | ||||||||||||
567 | } | - | ||||||||||||
568 | } | - | ||||||||||||
569 | - | |||||||||||||
570 | persistent.moved.push(persistent_moved); | - | ||||||||||||
571 | persistent.invalidated.push(persistent_invalidated); | - | ||||||||||||
572 | } | - | ||||||||||||
573 | - | |||||||||||||
574 | void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent, | - | ||||||||||||
575 | int first, int last) | - | ||||||||||||
576 | { | - | ||||||||||||
577 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||
578 | int count = (last - first) + 1; | - | ||||||||||||
579 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||
580 | it != persistent_moved.constEnd()
| 1097-2919 | ||||||||||||
581 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
582 | QModelIndex old = data->index; | - | ||||||||||||
583 | persistent.indexes.erase(persistent.indexes.findconstFind(old)); | - | ||||||||||||
584 | data->index = q_func()->index(old.row() - count, old.column(), parent); | - | ||||||||||||
585 | if (data->index.isValid()
| 0-1097 | ||||||||||||
586 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
587 | } executed 1097 times by 12 tests: else {end of block Executed by:
| 1097 | ||||||||||||
588 | QMessageLogger(__FILE__, 775812, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func(); | - | ||||||||||||
589 | } never executed: end of block | 0 | ||||||||||||
590 | } | - | ||||||||||||
591 | QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop(); | - | ||||||||||||
592 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); | - | ||||||||||||
593 | it != persistent_invalidated.constEnd()
| 1191-2919 | ||||||||||||
594 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
595 | persistent.indexes.erase(persistent.indexes.findconstFind(data->index)); | - | ||||||||||||
596 | data->index = QModelIndex(); | - | ||||||||||||
597 | data->model = 0; | - | ||||||||||||
598 | } executed 1191 times by 15 tests: end of block Executed by:
| 1191 | ||||||||||||
599 | } executed 2919 times by 31 tests: end of block Executed by:
| 2919 | ||||||||||||
600 | - | |||||||||||||
601 | void QAbstractItemModelPrivate::columnsAboutToBeInserted(const QModelIndex &parent, | - | ||||||||||||
602 | int first, int last) | - | ||||||||||||
603 | { | - | ||||||||||||
604 | QAbstractItemModel * const q = q_func(); | - | ||||||||||||
605 | (void)last;; | - | ||||||||||||
606 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||
607 | if (first < q->columnCount(parent)) { | - | ||||||||||||
608 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||
609 | it != persistent.indexes.constEnd(); ++it) { | - | ||||||||||||
610 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
611 | const QModelIndex &index = data->index; | - | ||||||||||||
612 | if (index.column() >= first && index.isValid() && index.parent() == parent) | - | ||||||||||||
613 | persistent_moved.append(data); | - | ||||||||||||
614 | } | - | ||||||||||||
615 | } | - | ||||||||||||
616 | persistent.moved.push(persistent_moved); | - | ||||||||||||
617 | } | - | ||||||||||||
618 | - | |||||||||||||
619 | void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent, | - | ||||||||||||
620 | int first, int last) | - | ||||||||||||
621 | { | - | ||||||||||||
622 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||
623 | int count = (last - first) + 1; | - | ||||||||||||
624 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||
625 | it != persistent_moved.constEnd()
| 15-13532 | ||||||||||||
626 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
627 | QModelIndex old = data->index; | - | ||||||||||||
628 | persistent.indexes.erase(persistent.indexes.findconstFind(old)); | - | ||||||||||||
629 | data->index = q_func()->index(old.row(), old.column() + count, parent); | - | ||||||||||||
630 | if (data->index.isValid()
| 0-15 | ||||||||||||
631 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
632 | } executed 15 times by 4 tests: else {end of block Executed by:
| 15 | ||||||||||||
633 | QMessageLogger(__FILE__, 820857, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func(); | - | ||||||||||||
634 | } never executed: end of block | 0 | ||||||||||||
635 | } | - | ||||||||||||
636 | } executed 13532 times by 33 tests: end of block Executed by:
| 13532 | ||||||||||||
637 | - | |||||||||||||
638 | void QAbstractItemModelPrivate::columnsAboutToBeRemoved(const QModelIndex &parent, | - | ||||||||||||
639 | int first, int last) | - | ||||||||||||
640 | { | - | ||||||||||||
641 | QVector<QPersistentModelIndexData *> persistent_moved; | - | ||||||||||||
642 | QVector<QPersistentModelIndexData *> persistent_invalidated; | - | ||||||||||||
643 | - | |||||||||||||
644 | - | |||||||||||||
645 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = persistent.indexes.constBegin(); | - | ||||||||||||
646 | it != persistent.indexes.constEnd(); ++it) { | - | ||||||||||||
647 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
648 | bool level_changed = false; | - | ||||||||||||
649 | QModelIndex current = data->index; | - | ||||||||||||
650 | while (current.isValid()) { | - | ||||||||||||
651 | QModelIndex current_parent = current.parent(); | - | ||||||||||||
652 | if (current_parent == parent) { | - | ||||||||||||
653 | if (!level_changed && current.column() > last) | - | ||||||||||||
654 | persistent_moved.append(data); | - | ||||||||||||
655 | else if (current.column() <= last && current.column() >= first) | - | ||||||||||||
656 | persistent_invalidated.append(data); | - | ||||||||||||
657 | break; | - | ||||||||||||
658 | } | - | ||||||||||||
659 | current = current_parent; | - | ||||||||||||
660 | level_changed = true; | - | ||||||||||||
661 | } | - | ||||||||||||
662 | } | - | ||||||||||||
663 | - | |||||||||||||
664 | persistent.moved.push(persistent_moved); | - | ||||||||||||
665 | persistent.invalidated.push(persistent_invalidated); | - | ||||||||||||
666 | - | |||||||||||||
667 | } | - | ||||||||||||
668 | - | |||||||||||||
669 | void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, | - | ||||||||||||
670 | int first, int last) | - | ||||||||||||
671 | { | - | ||||||||||||
672 | QVector<QPersistentModelIndexData *> persistent_moved = persistent.moved.pop(); | - | ||||||||||||
673 | int count = (last - first) + 1; | - | ||||||||||||
674 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_moved.constBegin(); | - | ||||||||||||
675 | it != persistent_moved.constEnd()
| 15-210 | ||||||||||||
676 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
677 | QModelIndex old = data->index; | - | ||||||||||||
678 | persistent.indexes.erase(persistent.indexes.findconstFind(old)); | - | ||||||||||||
679 | data->index = q_func()->index(old.row(), old.column() - count, parent); | - | ||||||||||||
680 | if (data->index.isValid()
| 0-15 | ||||||||||||
681 | persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
682 | } executed 15 times by 6 tests: else {end of block Executed by:
| 15 | ||||||||||||
683 | QMessageLogger(__FILE__, 870907, __PRETTY_FUNCTION__).warning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func(); | - | ||||||||||||
684 | } never executed: end of block | 0 | ||||||||||||
685 | } | - | ||||||||||||
686 | QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop(); | - | ||||||||||||
687 | for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); | - | ||||||||||||
688 | it != persistent_invalidated.constEnd()
| 26-210 | ||||||||||||
689 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
690 | persistent.indexes.erase(persistent.indexes.findconstFind(data->index)); | - | ||||||||||||
691 | data->index = QModelIndex(); | - | ||||||||||||
692 | data->model = 0; | - | ||||||||||||
693 | } executed 26 times by 7 tests: end of block Executed by:
| 26 | ||||||||||||
694 | } executed 210 times by 16 tests: end of block Executed by:
| 210 | ||||||||||||
695 | void QAbstractItemModel::resetInternalData() | - | ||||||||||||
696 | { | - | ||||||||||||
697 | - | |||||||||||||
698 | } | - | ||||||||||||
699 | QAbstractItemModel::QAbstractItemModel(QObject *parent) | - | ||||||||||||
700 | : QObject(*new QAbstractItemModelPrivate, parent) | - | ||||||||||||
701 | { | - | ||||||||||||
702 | } | - | ||||||||||||
703 | - | |||||||||||||
704 | - | |||||||||||||
705 | - | |||||||||||||
706 | - | |||||||||||||
707 | QAbstractItemModel::QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||
708 | : QObject(dd, parent) | - | ||||||||||||
709 | { | - | ||||||||||||
710 | } | - | ||||||||||||
711 | - | |||||||||||||
712 | - | |||||||||||||
713 | - | |||||||||||||
714 | - | |||||||||||||
715 | QAbstractItemModel::~QAbstractItemModel() | - | ||||||||||||
716 | { | - | ||||||||||||
717 | d_func()->invalidatePersistentIndexes(); | - | ||||||||||||
718 | } | - | ||||||||||||
719 | bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent) const | - | ||||||||||||
720 | { | - | ||||||||||||
721 | if (row < 0 || column < 0) | - | ||||||||||||
722 | return false; | - | ||||||||||||
723 | return row < rowCount(parent) && column < columnCount(parent); | - | ||||||||||||
724 | } | - | ||||||||||||
725 | bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||
726 | { | - | ||||||||||||
727 | return (rowCount(parent) > 0) && (columnCount(parent) > 0); | - | ||||||||||||
728 | } | - | ||||||||||||
729 | QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &idx) const | - | ||||||||||||
730 | { | - | ||||||||||||
731 | return (row == idx.row() && column == idx.column()) ? idx : index(row, column, parent(idx)); | - | ||||||||||||
732 | } | - | ||||||||||||
733 | QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const | - | ||||||||||||
734 | { | - | ||||||||||||
735 | QMap<int, QVariant> roles; | - | ||||||||||||
736 | for (int i = 0; i < Qt::UserRole; ++i) { | - | ||||||||||||
737 | QVariant variantData = data(index, i); | - | ||||||||||||
738 | if (variantData.isValid()) | - | ||||||||||||
739 | roles.insert(i, variantData); | - | ||||||||||||
740 | } | - | ||||||||||||
741 | return roles; | - | ||||||||||||
742 | } | - | ||||||||||||
743 | bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||
744 | { | - | ||||||||||||
745 | (void)index;; | - | ||||||||||||
746 | (void)value;; | - | ||||||||||||
747 | (void)role;; | - | ||||||||||||
748 | return false; | - | ||||||||||||
749 | } | - | ||||||||||||
750 | bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) | - | ||||||||||||
751 | { | - | ||||||||||||
752 | bool b = true; | - | ||||||||||||
753 | for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it) | - | ||||||||||||
754 | b = b && setData(index, it.value(), it.key()); | - | ||||||||||||
755 | return b; | - | ||||||||||||
756 | } | - | ||||||||||||
757 | QStringList QAbstractItemModel::mimeTypes() const | - | ||||||||||||
758 | { | - | ||||||||||||
759 | QStringList types; | - | ||||||||||||
760 | types << QLatin1String([]() -> QString { enum { Size = sizeof(u"" "application/x-qabstractitemmodeldatalist")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "application/x-qabstractitemmodeldatalist" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 174 times by 7 tests: return qstring_literal_temp; Executed by:
executed 174 times by 7 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 174 times by 7 tests: }());return qstring_literal_temp; Executed by:
| 174 | ||||||||||||
761 | return executed 174 times by 7 tests: types;return types; Executed by:
executed 174 times by 7 tests: return types; Executed by:
| 174 | ||||||||||||
762 | } | - | ||||||||||||
763 | QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const | - | ||||||||||||
764 | { | - | ||||||||||||
765 | if (indexes.count() <= 0) | - | ||||||||||||
766 | return 0; | - | ||||||||||||
767 | QStringList types = mimeTypes(); | - | ||||||||||||
768 | if (types.isEmpty()) | - | ||||||||||||
769 | return 0; | - | ||||||||||||
770 | QMimeData *data = new QMimeData(); | - | ||||||||||||
771 | QString format = types.at(0); | - | ||||||||||||
772 | QByteArray encoded; | - | ||||||||||||
773 | QDataStream stream(&encoded, QIODevice::WriteOnly); | - | ||||||||||||
774 | encodeData(indexes, stream); | - | ||||||||||||
775 | data->setData(format, encoded); | - | ||||||||||||
776 | return data; | - | ||||||||||||
777 | } | - | ||||||||||||
778 | bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||
779 | int row, int column, | - | ||||||||||||
780 | const QModelIndex &parent) const | - | ||||||||||||
781 | { | - | ||||||||||||
782 | (void)row; | - | ||||||||||||
783 | (void)column; | - | ||||||||||||
784 | (void)parent; | - | ||||||||||||
785 | - | |||||||||||||
786 | if (!(action & supportedDropActions())) | - | ||||||||||||
787 | return false; | - | ||||||||||||
788 | - | |||||||||||||
789 | const QStringList modelTypes = mimeTypes(); | - | ||||||||||||
790 | for (int i = 0; i < modelTypes.count(); ++i) { | - | ||||||||||||
791 | if (data->hasFormat(modelTypes.at(i))) | - | ||||||||||||
792 | return true; | - | ||||||||||||
793 | } | - | ||||||||||||
794 | return false; | - | ||||||||||||
795 | } | - | ||||||||||||
796 | bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||
797 | int row, int column, const QModelIndex &parent) | - | ||||||||||||
798 | { | - | ||||||||||||
799 | - | |||||||||||||
800 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction)) | - | ||||||||||||
801 | return false; | - | ||||||||||||
802 | - | |||||||||||||
803 | QStringList types = mimeTypes(); | - | ||||||||||||
804 | if (types.isEmpty()) | - | ||||||||||||
805 | return false; | - | ||||||||||||
806 | QString format = types.at(0); | - | ||||||||||||
807 | if (!data->hasFormat(format)) | - | ||||||||||||
808 | return false; | - | ||||||||||||
809 | if (row > rowCount(parent)) | - | ||||||||||||
810 | row = rowCount(parent); | - | ||||||||||||
811 | if (row == -1) | - | ||||||||||||
812 | row = rowCount(parent); | - | ||||||||||||
813 | if (column == -1) | - | ||||||||||||
814 | column = 0; | - | ||||||||||||
815 | - | |||||||||||||
816 | QByteArray encoded = data->data(format); | - | ||||||||||||
817 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||
818 | return decodeData(row, column, parent, stream); | - | ||||||||||||
819 | } | - | ||||||||||||
820 | Qt::DropActions QAbstractItemModel::supportedDropActions() const | - | ||||||||||||
821 | { | - | ||||||||||||
822 | return Qt::CopyAction; | - | ||||||||||||
823 | } | - | ||||||||||||
824 | Qt::DropActions QAbstractItemModel::supportedDragActions() const | - | ||||||||||||
825 | { | - | ||||||||||||
826 | const QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
827 | if (d->supportedDragActions != -1) | - | ||||||||||||
828 | return d->supportedDragActions; | - | ||||||||||||
829 | return supportedDropActions(); | - | ||||||||||||
830 | } | - | ||||||||||||
831 | - | |||||||||||||
832 | - | |||||||||||||
833 | - | |||||||||||||
834 | - | |||||||||||||
835 | void QAbstractItemModel::doSetSupportedDragActions(Qt::DropActions actions) | - | ||||||||||||
836 | { | - | ||||||||||||
837 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
838 | d->supportedDragActions = actions; | - | ||||||||||||
839 | } | - | ||||||||||||
840 | bool QAbstractItemModel::insertRows(int, int, const QModelIndex &) | - | ||||||||||||
841 | { | - | ||||||||||||
842 | return false; | - | ||||||||||||
843 | } | - | ||||||||||||
844 | bool QAbstractItemModel::insertColumns(int, int, const QModelIndex &) | - | ||||||||||||
845 | { | - | ||||||||||||
846 | return false; | - | ||||||||||||
847 | } | - | ||||||||||||
848 | bool QAbstractItemModel::removeRows(int, int, const QModelIndex &) | - | ||||||||||||
849 | { | - | ||||||||||||
850 | return false; | - | ||||||||||||
851 | } | - | ||||||||||||
852 | bool QAbstractItemModel::removeColumns(int, int, const QModelIndex &) | - | ||||||||||||
853 | { | - | ||||||||||||
854 | return false; | - | ||||||||||||
855 | } | - | ||||||||||||
856 | bool QAbstractItemModel::moveRows(const QModelIndex &, int , int , const QModelIndex &, int) | - | ||||||||||||
857 | { | - | ||||||||||||
858 | return false; | - | ||||||||||||
859 | } | - | ||||||||||||
860 | bool QAbstractItemModel::moveColumns(const QModelIndex &, int , int , const QModelIndex &, int) | - | ||||||||||||
861 | { | - | ||||||||||||
862 | return false; | - | ||||||||||||
863 | } | - | ||||||||||||
864 | void QAbstractItemModel::fetchMore(const QModelIndex &) | - | ||||||||||||
865 | { | - | ||||||||||||
866 | - | |||||||||||||
867 | } | - | ||||||||||||
868 | bool QAbstractItemModel::canFetchMore(const QModelIndex &) const | - | ||||||||||||
869 | { | - | ||||||||||||
870 | return false; | - | ||||||||||||
871 | } | - | ||||||||||||
872 | Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const | - | ||||||||||||
873 | { | - | ||||||||||||
874 | const QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
875 | if (!d->indexValid(index)) | - | ||||||||||||
876 | return 0; | - | ||||||||||||
877 | - | |||||||||||||
878 | return Qt::ItemIsSelectable|Qt::ItemIsEnabled; | - | ||||||||||||
879 | } | - | ||||||||||||
880 | - | |||||||||||||
881 | - | |||||||||||||
882 | - | |||||||||||||
883 | - | |||||||||||||
884 | - | |||||||||||||
885 | - | |||||||||||||
886 | void QAbstractItemModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||
887 | { | - | ||||||||||||
888 | (void)column;; | - | ||||||||||||
889 | (void)order;; | - | ||||||||||||
890 | - | |||||||||||||
891 | } | - | ||||||||||||
892 | QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const | - | ||||||||||||
893 | { | - | ||||||||||||
894 | return index; | - | ||||||||||||
895 | } | - | ||||||||||||
896 | QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, | - | ||||||||||||
897 | const QVariant &value, int hits, | - | ||||||||||||
898 | Qt::MatchFlags flags) const | - | ||||||||||||
899 | { | - | ||||||||||||
900 | QModelIndexList result; | - | ||||||||||||
901 | uint matchType = flags & 0x0F; | - | ||||||||||||
902 | Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; | - | ||||||||||||
903 | bool recurse = flags & Qt::MatchRecursive; | - | ||||||||||||
904 | bool wrap = flags & Qt::MatchWrap; | - | ||||||||||||
905 | bool allHits = (hits == -1); | - | ||||||||||||
906 | QString text; | - | ||||||||||||
907 | QModelIndex p = parent(start); | - | ||||||||||||
908 | int from = start.row(); | - | ||||||||||||
909 | int to = rowCount(p); | - | ||||||||||||
910 | - | |||||||||||||
911 | - | |||||||||||||
912 | for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { | - | ||||||||||||
913 | for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) { | - | ||||||||||||
914 | QModelIndex idx = index(r, start.column(), p); | - | ||||||||||||
915 | if (!idx.isValid()) | - | ||||||||||||
916 | continue; | - | ||||||||||||
917 | QVariant v = data(idx, role); | - | ||||||||||||
918 | - | |||||||||||||
919 | if (matchType == Qt::MatchExactly) { | - | ||||||||||||
920 | if (value == v) | - | ||||||||||||
921 | result.append(idx); | - | ||||||||||||
922 | } else { | - | ||||||||||||
923 | if (text.isEmpty()) | - | ||||||||||||
924 | text = value.toString(); | - | ||||||||||||
925 | QString t = v.toString(); | - | ||||||||||||
926 | switch (matchType) { | - | ||||||||||||
927 | case Qt::MatchRegExp: | - | ||||||||||||
928 | if (QRegExp(text, cs).exactMatch(t)) | - | ||||||||||||
929 | result.append(idx); | - | ||||||||||||
930 | break; | - | ||||||||||||
931 | case Qt::MatchWildcard: | - | ||||||||||||
932 | if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) | - | ||||||||||||
933 | result.append(idx); | - | ||||||||||||
934 | break; | - | ||||||||||||
935 | case Qt::MatchStartsWith: | - | ||||||||||||
936 | if (t.startsWith(text, cs)) | - | ||||||||||||
937 | result.append(idx); | - | ||||||||||||
938 | break; | - | ||||||||||||
939 | case Qt::MatchEndsWith: | - | ||||||||||||
940 | if (t.endsWith(text, cs)) | - | ||||||||||||
941 | result.append(idx); | - | ||||||||||||
942 | break; | - | ||||||||||||
943 | case Qt::MatchFixedString: | - | ||||||||||||
944 | if (t.compare(text, cs) == 0) | - | ||||||||||||
945 | result.append(idx); | - | ||||||||||||
946 | break; | - | ||||||||||||
947 | case Qt::MatchContains: | - | ||||||||||||
948 | default: | - | ||||||||||||
949 | if (t.contains(text, cs)) | - | ||||||||||||
950 | result.append(idx); | - | ||||||||||||
951 | } | - | ||||||||||||
952 | } | - | ||||||||||||
953 | if (recurse && hasChildren(idx)) { | - | ||||||||||||
954 | result += match(index(0, idx.column(), idx), role, | - | ||||||||||||
955 | (text.isEmpty() ? value : text), | - | ||||||||||||
956 | (allHits ? -1 : hits - result.count()), flags); | - | ||||||||||||
957 | } | - | ||||||||||||
958 | } | - | ||||||||||||
959 | - | |||||||||||||
960 | from = 0; | - | ||||||||||||
961 | to = start.row(); | - | ||||||||||||
962 | } | - | ||||||||||||
963 | return result; | - | ||||||||||||
964 | } | - | ||||||||||||
965 | - | |||||||||||||
966 | - | |||||||||||||
967 | - | |||||||||||||
968 | - | |||||||||||||
969 | - | |||||||||||||
970 | - | |||||||||||||
971 | - | |||||||||||||
972 | QSize QAbstractItemModel::span(const QModelIndex &) const | - | ||||||||||||
973 | { | - | ||||||||||||
974 | return QSize(1, 1); | - | ||||||||||||
975 | } | - | ||||||||||||
976 | void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames) | - | ||||||||||||
977 | { | - | ||||||||||||
978 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
979 | d->roleNames = roleNames; | - | ||||||||||||
980 | } | - | ||||||||||||
981 | QHash<int,QByteArray> QAbstractItemModel::roleNames() const | - | ||||||||||||
982 | { | - | ||||||||||||
983 | const QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
984 | return d->roleNames; | - | ||||||||||||
985 | } | - | ||||||||||||
986 | bool QAbstractItemModel::submit() | - | ||||||||||||
987 | { | - | ||||||||||||
988 | return true; | - | ||||||||||||
989 | } | - | ||||||||||||
990 | void QAbstractItemModel::revert() | - | ||||||||||||
991 | { | - | ||||||||||||
992 | - | |||||||||||||
993 | } | - | ||||||||||||
994 | QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||
995 | { | - | ||||||||||||
996 | (void)orientation;; | - | ||||||||||||
997 | if (role == Qt::DisplayRole) | - | ||||||||||||
998 | return section + 1; | - | ||||||||||||
999 | return QVariant(); | - | ||||||||||||
1000 | } | - | ||||||||||||
1001 | bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||
1002 | const QVariant &value, int role) | - | ||||||||||||
1003 | { | - | ||||||||||||
1004 | (void)section;; | - | ||||||||||||
1005 | (void)orientation;; | - | ||||||||||||
1006 | (void)value;; | - | ||||||||||||
1007 | (void)role;; | - | ||||||||||||
1008 | return false; | - | ||||||||||||
1009 | } | - | ||||||||||||
1010 | void QAbstractItemModel::encodeData(const QModelIndexList &indexes, QDataStream &stream) const | - | ||||||||||||
1011 | { | - | ||||||||||||
1012 | QModelIndexList::ConstIterator it = indexes.begin(); | - | ||||||||||||
1013 | for (; it != indexes.end(); ++it) | - | ||||||||||||
1014 | stream << (*it).row() << (*it).column() << itemData(*it); | - | ||||||||||||
1015 | } | - | ||||||||||||
1016 | - | |||||||||||||
1017 | - | |||||||||||||
1018 | - | |||||||||||||
1019 | - | |||||||||||||
1020 | bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &parent, | - | ||||||||||||
1021 | QDataStream &stream) | - | ||||||||||||
1022 | { | - | ||||||||||||
1023 | int top = 2147483647; | - | ||||||||||||
1024 | int left = 2147483647; | - | ||||||||||||
1025 | int bottom = 0; | - | ||||||||||||
1026 | int right = 0; | - | ||||||||||||
1027 | QVector<int> rows, columns; | - | ||||||||||||
1028 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||
1029 | - | |||||||||||||
1030 | while (!stream.atEnd()
| 12-46 | ||||||||||||
1031 | int r, c; | - | ||||||||||||
1032 | QMap<int, QVariant> v; | - | ||||||||||||
1033 | stream >> r >> c >> v; | - | ||||||||||||
1034 | rows.append(r); | - | ||||||||||||
1035 | columns.append(c); | - | ||||||||||||
1036 | data.append(v); | - | ||||||||||||
1037 | top = qMin(r, top); | - | ||||||||||||
1038 | left = qMin(c, left); | - | ||||||||||||
1039 | bottom = qMax(r, bottom); | - | ||||||||||||
1040 | right = qMax(c, right); | - | ||||||||||||
1041 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||
1042 | - | |||||||||||||
1043 | - | |||||||||||||
1044 | - | |||||||||||||
1045 | int dragRowCount = 0; | - | ||||||||||||
1046 | int dragColumnCount = right - left + 1; | - | ||||||||||||
1047 | - | |||||||||||||
1048 | - | |||||||||||||
1049 | QVector<int> rowsToInsert(bottom + 1); | - | ||||||||||||
1050 | for (int i = 0; i < rows.count()
| 12-46 | ||||||||||||
1051 | rowsToInsert[rows.at(i)] = 1; executed 46 times by 1 test: rowsToInsert[rows.at(i)] = 1; Executed by:
| 46 | ||||||||||||
1052 | for (int i = 0; i < rowsToInsert.count()
| 12-24 | ||||||||||||
1053 | if (rowsToInsert[.at(i]) == 1
| 2-22 | ||||||||||||
1054 | rowsToInsert[i] = dragRowCount; | - | ||||||||||||
1055 | ++dragRowCount; | - | ||||||||||||
1056 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||
1057 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||
1058 | for (int i = 0; i < rows.count()
| 12-46 | ||||||||||||
1059 | rows[i] = top + rowsToInsert[.at(rows[.at(i]];)); executed 46 times by 1 test: rows[i] = top + rowsToInsert.at(rows.at(i)); Executed by:
| 46 | ||||||||||||
1060 | - | |||||||||||||
1061 | QBitArray isWrittenTo(dragRowCount * dragColumnCount); | - | ||||||||||||
1062 | - | |||||||||||||
1063 | - | |||||||||||||
1064 | int colCount = columnCount(parent); | - | ||||||||||||
1065 | if (colCount == 0
| 0-12 | ||||||||||||
1066 | insertColumns(colCount, dragColumnCount - colCount, parent); | - | ||||||||||||
1067 | colCount = columnCount(parent); | - | ||||||||||||
1068 | } never executed: end of block | 0 | ||||||||||||
1069 | insertRows(row, dragRowCount, parent); | - | ||||||||||||
1070 | - | |||||||||||||
1071 | row = qMax(0, row); | - | ||||||||||||
1072 | column = qMax(0, column); | - | ||||||||||||
1073 | - | |||||||||||||
1074 | QVector<QPersistentModelIndex> newIndexes(data.size()); | - | ||||||||||||
1075 | - | |||||||||||||
1076 | for (int j = 0; j < data.size()
| 12-46 | ||||||||||||
1077 | int relativeRow = rows.at(j) - top; | - | ||||||||||||
1078 | int relativeColumn = columns.at(j) - left; | - | ||||||||||||
1079 | int destinationRow = relativeRow + row; | - | ||||||||||||
1080 | int destinationColumn = relativeColumn + column; | - | ||||||||||||
1081 | int flat = (relativeRow * dragColumnCount) + relativeColumn; | - | ||||||||||||
1082 | - | |||||||||||||
1083 | if (destinationColumn >= colCount
| 3-37 | ||||||||||||
1084 | destinationColumn = qBound(column, destinationColumn, colCount - 1); | - | ||||||||||||
1085 | destinationRow = row + dragRowCount; | - | ||||||||||||
1086 | insertRows(row + dragRowCount, 1, parent); | - | ||||||||||||
1087 | flat = (dragRowCount * dragColumnCount) + relativeColumn; | - | ||||||||||||
1088 | isWrittenTo.resize(++dragRowCount * dragColumnCount); | - | ||||||||||||
1089 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
1090 | if (!isWrittenTo.testBit(flat)
| 0-46 | ||||||||||||
1091 | newIndexes[j] = index(destinationRow, destinationColumn, parent); | - | ||||||||||||
1092 | isWrittenTo.setBit(flat); | - | ||||||||||||
1093 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||
1094 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||
1095 | - | |||||||||||||
1096 | for(int k = 0; k < newIndexes.size()
| 12-46 | ||||||||||||
1097 | if (newIndexes.at(k).isValid()
| 0-46 | ||||||||||||
1098 | setItemData(newIndexes.at(k), data.at(k)); executed 46 times by 1 test: setItemData(newIndexes.at(k), data.at(k)); Executed by:
| 46 | ||||||||||||
1099 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||
1100 | - | |||||||||||||
1101 | return executed 12 times by 1 test: true;return true; Executed by:
executed 12 times by 1 test: return true; Executed by:
| 12 | ||||||||||||
1102 | } | - | ||||||||||||
1103 | void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||
1104 | { | - | ||||||||||||
1105 | ((!(first >= 0)) ? qt_assert("first >= 0",__FILE__,26032640) : qt_noop()); | - | ||||||||||||
1106 | ((!(last >= first)) ? qt_assert("last >= first",__FILE__,26042641) : qt_noop()); | - | ||||||||||||
1107 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1108 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||
1109 | rowsAboutToBeInserted(parent, first, last, QPrivateSignal()); | - | ||||||||||||
1110 | d->rowsAboutToBeInserted(parent, first, last); | - | ||||||||||||
1111 | } | - | ||||||||||||
1112 | void QAbstractItemModel::endInsertRows() | - | ||||||||||||
1113 | { | - | ||||||||||||
1114 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1115 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||
1116 | d->rowsInserted(change.parent, change.first, change.last); | - | ||||||||||||
1117 | rowsInserted(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||
1118 | } | - | ||||||||||||
1119 | void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||
1120 | { | - | ||||||||||||
1121 | ((!(first >= 0)) ? qt_assert("first >= 0",__FILE__,26572694) : qt_noop()); | - | ||||||||||||
1122 | ((!(last >= first)) ? qt_assert("last >= first",__FILE__,26582695) : qt_noop()); | - | ||||||||||||
1123 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1124 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||
1125 | rowsAboutToBeRemoved(parent, first, last, QPrivateSignal()); | - | ||||||||||||
1126 | d->rowsAboutToBeRemoved(parent, first, last); | - | ||||||||||||
1127 | } | - | ||||||||||||
1128 | void QAbstractItemModel::endRemoveRows() | - | ||||||||||||
1129 | { | - | ||||||||||||
1130 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1131 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||
1132 | d->rowsRemoved(change.parent, change.first, change.last); | - | ||||||||||||
1133 | rowsRemoved(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||
1134 | } | - | ||||||||||||
1135 | bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int start, int end, const QModelIndex &destinationParent, int destinationStart, Qt::Orientation orientation) | - | ||||||||||||
1136 | { | - | ||||||||||||
1137 | - | |||||||||||||
1138 | if (destinationParent == srcParent) | - | ||||||||||||
1139 | return !(destinationStart >= start && destinationStart <= end + 1); | - | ||||||||||||
1140 | - | |||||||||||||
1141 | QModelIndex destinationAncestor = destinationParent; | - | ||||||||||||
1142 | int pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column(); | - | ||||||||||||
1143 | for(;;) { | - | ||||||||||||
1144 | if (destinationAncestor == srcParent) { | - | ||||||||||||
1145 | if (pos >= start && pos <= end) | - | ||||||||||||
1146 | return false; | - | ||||||||||||
1147 | break; | - | ||||||||||||
1148 | } | - | ||||||||||||
1149 | - | |||||||||||||
1150 | if (!destinationAncestor.isValid()) | - | ||||||||||||
1151 | break; | - | ||||||||||||
1152 | - | |||||||||||||
1153 | pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column(); | - | ||||||||||||
1154 | destinationAncestor = destinationAncestor.parent(); | - | ||||||||||||
1155 | } | - | ||||||||||||
1156 | - | |||||||||||||
1157 | return true; | - | ||||||||||||
1158 | } | - | ||||||||||||
1159 | bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||
1160 | { | - | ||||||||||||
1161 | ((!(sourceFirst >= 0)) ? qt_assert("sourceFirst >= 0",__FILE__,28062843) : qt_noop()); | - | ||||||||||||
1162 | ((!(sourceLast >= sourceFirst)) ? qt_assert("sourceLast >= sourceFirst",__FILE__,28072844) : qt_noop()); | - | ||||||||||||
1163 | ((!(destinationChild >= 0)) ? qt_assert("destinationChild >= 0",__FILE__,28082845) : qt_noop()); | - | ||||||||||||
1164 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1165 | - | |||||||||||||
1166 | if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical)) { | - | ||||||||||||
1167 | return false; | - | ||||||||||||
1168 | } | - | ||||||||||||
1169 | - | |||||||||||||
1170 | QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); | - | ||||||||||||
1171 | sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent; | - | ||||||||||||
1172 | d->changes.push(sourceChange); | - | ||||||||||||
1173 | int destinationLast = destinationChild + (sourceLast - sourceFirst); | - | ||||||||||||
1174 | QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); | - | ||||||||||||
1175 | destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent; | - | ||||||||||||
1176 | d->changes.push(destinationChange); | - | ||||||||||||
1177 | - | |||||||||||||
1178 | rowsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal()); | - | ||||||||||||
1179 | d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Vertical); | - | ||||||||||||
1180 | return true; | - | ||||||||||||
1181 | } | - | ||||||||||||
1182 | void QAbstractItemModel::endMoveRows() | - | ||||||||||||
1183 | { | - | ||||||||||||
1184 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1185 | - | |||||||||||||
1186 | QAbstractItemModelPrivate::Change insertChange = d->changes.pop(); | - | ||||||||||||
1187 | QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); | - | ||||||||||||
1188 | - | |||||||||||||
1189 | QModelIndex adjustedSource = removeChange.parent; | - | ||||||||||||
1190 | QModelIndex adjustedDestination = insertChange.parent; | - | ||||||||||||
1191 | - | |||||||||||||
1192 | const int numMoved = removeChange.last - removeChange.first + 1; | - | ||||||||||||
1193 | if (insertChange.needsAdjust) | - | ||||||||||||
1194 | adjustedDestination = createIndex(adjustedDestination.row() - numMoved, adjustedDestination.column(), adjustedDestination.internalPointer()); | - | ||||||||||||
1195 | - | |||||||||||||
1196 | if (removeChange.needsAdjust) | - | ||||||||||||
1197 | adjustedSource = createIndex(adjustedSource.row() + numMoved, adjustedSource.column(), adjustedSource.internalPointer()); | - | ||||||||||||
1198 | - | |||||||||||||
1199 | d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Vertical); | - | ||||||||||||
1200 | - | |||||||||||||
1201 | rowsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal()); | - | ||||||||||||
1202 | } | - | ||||||||||||
1203 | void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||
1204 | { | - | ||||||||||||
1205 | ((!(first >= 0)) ? qt_assert("first >= 0",__FILE__,29042941) : qt_noop()); | - | ||||||||||||
1206 | ((!(last >= first)) ? qt_assert("last >= first",__FILE__,29052942) : qt_noop()); | - | ||||||||||||
1207 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1208 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||
1209 | columnsAboutToBeInserted(parent, first, last, QPrivateSignal()); | - | ||||||||||||
1210 | d->columnsAboutToBeInserted(parent, first, last); | - | ||||||||||||
1211 | } | - | ||||||||||||
1212 | void QAbstractItemModel::endInsertColumns() | - | ||||||||||||
1213 | { | - | ||||||||||||
1214 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1215 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||
1216 | d->columnsInserted(change.parent, change.first, change.last); | - | ||||||||||||
1217 | columnsInserted(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||
1218 | } | - | ||||||||||||
1219 | void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||
1220 | { | - | ||||||||||||
1221 | ((!(first >= 0)) ? qt_assert("first >= 0",__FILE__,29592996) : qt_noop()); | - | ||||||||||||
1222 | ((!(last >= first)) ? qt_assert("last >= first",__FILE__,29602997) : qt_noop()); | - | ||||||||||||
1223 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1224 | d->changes.push(QAbstractItemModelPrivate::Change(parent, first, last)); | - | ||||||||||||
1225 | columnsAboutToBeRemoved(parent, first, last, QPrivateSignal()); | - | ||||||||||||
1226 | d->columnsAboutToBeRemoved(parent, first, last); | - | ||||||||||||
1227 | } | - | ||||||||||||
1228 | void QAbstractItemModel::endRemoveColumns() | - | ||||||||||||
1229 | { | - | ||||||||||||
1230 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1231 | QAbstractItemModelPrivate::Change change = d->changes.pop(); | - | ||||||||||||
1232 | d->columnsRemoved(change.parent, change.first, change.last); | - | ||||||||||||
1233 | columnsRemoved(change.parent, change.first, change.last, QPrivateSignal()); | - | ||||||||||||
1234 | } | - | ||||||||||||
1235 | bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) | - | ||||||||||||
1236 | { | - | ||||||||||||
1237 | ((!(sourceFirst >= 0)) ? qt_assert("sourceFirst >= 0",__FILE__,30233060) : qt_noop()); | - | ||||||||||||
1238 | ((!(sourceLast >= sourceFirst)) ? qt_assert("sourceLast >= sourceFirst",__FILE__,30243061) : qt_noop()); | - | ||||||||||||
1239 | ((!(destinationChild >= 0)) ? qt_assert("destinationChild >= 0",__FILE__,30253062) : qt_noop()); | - | ||||||||||||
1240 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1241 | - | |||||||||||||
1242 | if (!d->allowMove(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal)) { | - | ||||||||||||
1243 | return false; | - | ||||||||||||
1244 | } | - | ||||||||||||
1245 | - | |||||||||||||
1246 | QAbstractItemModelPrivate::Change sourceChange(sourceParent, sourceFirst, sourceLast); | - | ||||||||||||
1247 | sourceChange.needsAdjust = sourceParent.isValid() && sourceParent.row() >= destinationChild && sourceParent.parent() == destinationParent; | - | ||||||||||||
1248 | d->changes.push(sourceChange); | - | ||||||||||||
1249 | int destinationLast = destinationChild + (sourceLast - sourceFirst); | - | ||||||||||||
1250 | QAbstractItemModelPrivate::Change destinationChange(destinationParent, destinationChild, destinationLast); | - | ||||||||||||
1251 | destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent; | - | ||||||||||||
1252 | d->changes.push(destinationChange); | - | ||||||||||||
1253 | - | |||||||||||||
1254 | d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal); | - | ||||||||||||
1255 | - | |||||||||||||
1256 | columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal()); | - | ||||||||||||
1257 | return true; | - | ||||||||||||
1258 | } | - | ||||||||||||
1259 | void QAbstractItemModel::endMoveColumns() | - | ||||||||||||
1260 | { | - | ||||||||||||
1261 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1262 | - | |||||||||||||
1263 | QAbstractItemModelPrivate::Change insertChange = d->changes.pop(); | - | ||||||||||||
1264 | QAbstractItemModelPrivate::Change removeChange = d->changes.pop(); | - | ||||||||||||
1265 | - | |||||||||||||
1266 | QModelIndex adjustedSource = removeChange.parent; | - | ||||||||||||
1267 | QModelIndex adjustedDestination = insertChange.parent; | - | ||||||||||||
1268 | - | |||||||||||||
1269 | const int numMoved = removeChange.last - removeChange.first + 1; | - | ||||||||||||
1270 | if (insertChange.needsAdjust) | - | ||||||||||||
1271 | adjustedDestination = createIndex(adjustedDestination.row(), adjustedDestination.column() - numMoved, adjustedDestination.internalPointer()); | - | ||||||||||||
1272 | - | |||||||||||||
1273 | if (removeChange.needsAdjust) | - | ||||||||||||
1274 | adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer()); | - | ||||||||||||
1275 | - | |||||||||||||
1276 | d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal); | - | ||||||||||||
1277 | - | |||||||||||||
1278 | columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal()); | - | ||||||||||||
1279 | } | - | ||||||||||||
1280 | void QAbstractItemModel::beginResetModel() | - | ||||||||||||
1281 | { | - | ||||||||||||
1282 | modelAboutToBeReset(QPrivateSignal()); | - | ||||||||||||
1283 | } | - | ||||||||||||
1284 | void QAbstractItemModel::endResetModel() | - | ||||||||||||
1285 | { | - | ||||||||||||
1286 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1287 | d->invalidatePersistentIndexes(); | - | ||||||||||||
1288 | QMetaObject::invokeMethod(this, "resetInternalData"); | - | ||||||||||||
1289 | modelReset(QPrivateSignal()); | - | ||||||||||||
1290 | } | - | ||||||||||||
1291 | void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to) | - | ||||||||||||
1292 | { | - | ||||||||||||
1293 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1294 | if (d->persistent.indexes.isEmpty()
| 0-12 | ||||||||||||
1295 | return; never executed: return; | 0 | ||||||||||||
1296 | - | |||||||||||||
1297 | const QHash<QModelIndex, QPersistentModelIndexData *>::iteratorauto it = d->persistent.indexes.findconstFind(from); | - | ||||||||||||
1298 | if (it != d->persistent.indexes.endcend()
| 0-12 | ||||||||||||
1299 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
1300 | d->persistent.indexes.erase(it); | - | ||||||||||||
1301 | data->index = to; | - | ||||||||||||
1302 | if (to.isValid()
| 0-12 | ||||||||||||
1303 | d->persistent.insertMultiAtEnd(to, data); executed 12 times by 1 test: d->persistent.insertMultiAtEnd(to, data); Executed by:
| 12 | ||||||||||||
1304 | else | - | ||||||||||||
1305 | data->model = 0; never executed: data->model = 0; | 0 | ||||||||||||
1306 | } | - | ||||||||||||
1307 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||
1308 | void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, | - | ||||||||||||
1309 | const QModelIndexList &to) | - | ||||||||||||
1310 | { | - | ||||||||||||
1311 | QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1312 | if (d->persistent.indexes.isEmpty()
| 735-4679 | ||||||||||||
1313 | return; executed 4679 times by 24 tests: return; Executed by:
| 4679 | ||||||||||||
1314 | QVector<QPersistentModelIndexData *> toBeReinserted; | - | ||||||||||||
1315 | toBeReinserted.reserve(to.count()); | - | ||||||||||||
1316 | for (int i = 0; i < from.count()
| 735-1672 | ||||||||||||
1317 | if (from.at(i) == to.at(i)
| 660-1012 | ||||||||||||
1318 | continue; executed 1012 times by 16 tests: continue; Executed by:
| 1012 | ||||||||||||
1319 | const QHash<QModelIndex, QPersistentModelIndexData *>::iteratorauto it = d->persistent.indexes.findconstFind(from.at(i)); | - | ||||||||||||
1320 | if (it != d->persistent.indexes.endcend()
| 126-534 | ||||||||||||
1321 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
1322 | d->persistent.indexes.erase(it); | - | ||||||||||||
1323 | data->index = to.at(i); | - | ||||||||||||
1324 | if (data->index.isValid()
| 0-534 | ||||||||||||
1325 | toBeReinserted << data; executed 534 times by 13 tests: toBeReinserted << data; Executed by:
| 534 | ||||||||||||
1326 | else | - | ||||||||||||
1327 | data->model = 0; never executed: data->model = 0; | 0 | ||||||||||||
1328 | } | - | ||||||||||||
1329 | } executed 660 times by 13 tests: end of block Executed by:
| 660 | ||||||||||||
1330 | - | |||||||||||||
1331 | for (QVector<QPersistentModelIndexData *>::const_iterator it = toBeReinserted.constBegin(); | - | ||||||||||||
1332 | it != toBeReinserted.constEnd()
| 534-735 | ||||||||||||
1333 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
1334 | d->persistent.insertMultiAtEnd(data->index, data); | - | ||||||||||||
1335 | } executed 534 times by 13 tests: end of block Executed by:
| 534 | ||||||||||||
1336 | } executed 735 times by 18 tests: end of block Executed by:
| 735 | ||||||||||||
1337 | - | |||||||||||||
1338 | - | |||||||||||||
1339 | - | |||||||||||||
1340 | - | |||||||||||||
1341 | - | |||||||||||||
1342 | - | |||||||||||||
1343 | QModelIndexList QAbstractItemModel::persistentIndexList() const | - | ||||||||||||
1344 | { | - | ||||||||||||
1345 | const QAbstractItemModelPrivate * const d = d_func(); | - | ||||||||||||
1346 | QModelIndexList result; | - | ||||||||||||
1347 | result.reserve(d->persistent.indexes.count()); | - | ||||||||||||
1348 | for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin(); | - | ||||||||||||
1349 | it != d->persistent.indexes.constEnd(); ++it) { | - | ||||||||||||
1350 | QPersistentModelIndexData *data = *it; | - | ||||||||||||
1351 | result.append(data->index); | - | ||||||||||||
1352 | } | - | ||||||||||||
1353 | return result; | - | ||||||||||||
1354 | } | - | ||||||||||||
1355 | QAbstractTableModel::QAbstractTableModel(QObject *parent) | - | ||||||||||||
1356 | : QAbstractItemModel(parent) | - | ||||||||||||
1357 | { | - | ||||||||||||
1358 | - | |||||||||||||
1359 | } | - | ||||||||||||
1360 | - | |||||||||||||
1361 | - | |||||||||||||
1362 | - | |||||||||||||
1363 | - | |||||||||||||
1364 | - | |||||||||||||
1365 | - | |||||||||||||
1366 | - | |||||||||||||
1367 | QAbstractTableModel::QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||
1368 | : QAbstractItemModel(dd, parent) | - | ||||||||||||
1369 | { | - | ||||||||||||
1370 | - | |||||||||||||
1371 | } | - | ||||||||||||
1372 | - | |||||||||||||
1373 | - | |||||||||||||
1374 | - | |||||||||||||
1375 | - | |||||||||||||
1376 | - | |||||||||||||
1377 | QAbstractTableModel::~QAbstractTableModel() | - | ||||||||||||
1378 | { | - | ||||||||||||
1379 | - | |||||||||||||
1380 | } | - | ||||||||||||
1381 | QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||
1382 | { | - | ||||||||||||
1383 | return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); | - | ||||||||||||
1384 | } | - | ||||||||||||
1385 | QModelIndex QAbstractTableModel::parent(const QModelIndex &) const | - | ||||||||||||
1386 | { | - | ||||||||||||
1387 | return QModelIndex(); | - | ||||||||||||
1388 | } | - | ||||||||||||
1389 | - | |||||||||||||
1390 | - | |||||||||||||
1391 | - | |||||||||||||
1392 | - | |||||||||||||
1393 | QModelIndex QAbstractTableModel::sibling(int row, int column, const QModelIndex &) const | - | ||||||||||||
1394 | { | - | ||||||||||||
1395 | return index(row, column); | - | ||||||||||||
1396 | } | - | ||||||||||||
1397 | - | |||||||||||||
1398 | bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||
1399 | { | - | ||||||||||||
1400 | if (parent.model() == this || !parent.isValid()) | - | ||||||||||||
1401 | return rowCount(parent) > 0 && columnCount(parent) > 0; | - | ||||||||||||
1402 | return false; | - | ||||||||||||
1403 | } | - | ||||||||||||
1404 | - | |||||||||||||
1405 | - | |||||||||||||
1406 | - | |||||||||||||
1407 | - | |||||||||||||
1408 | Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const | - | ||||||||||||
1409 | { | - | ||||||||||||
1410 | Qt::ItemFlags f = QAbstractItemModel::flags(index); | - | ||||||||||||
1411 | if (index.isValid()) | - | ||||||||||||
1412 | f |= Qt::ItemNeverHasChildren; | - | ||||||||||||
1413 | return f; | - | ||||||||||||
1414 | } | - | ||||||||||||
1415 | QAbstractListModel::QAbstractListModel(QObject *parent) | - | ||||||||||||
1416 | : QAbstractItemModel(parent) | - | ||||||||||||
1417 | { | - | ||||||||||||
1418 | - | |||||||||||||
1419 | } | - | ||||||||||||
1420 | - | |||||||||||||
1421 | - | |||||||||||||
1422 | - | |||||||||||||
1423 | - | |||||||||||||
1424 | - | |||||||||||||
1425 | - | |||||||||||||
1426 | - | |||||||||||||
1427 | QAbstractListModel::QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent) | - | ||||||||||||
1428 | : QAbstractItemModel(dd, parent) | - | ||||||||||||
1429 | { | - | ||||||||||||
1430 | - | |||||||||||||
1431 | } | - | ||||||||||||
1432 | - | |||||||||||||
1433 | - | |||||||||||||
1434 | - | |||||||||||||
1435 | - | |||||||||||||
1436 | - | |||||||||||||
1437 | QAbstractListModel::~QAbstractListModel() | - | ||||||||||||
1438 | { | - | ||||||||||||
1439 | - | |||||||||||||
1440 | } | - | ||||||||||||
1441 | QModelIndex QAbstractListModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||
1442 | { | - | ||||||||||||
1443 | return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); | - | ||||||||||||
1444 | } | - | ||||||||||||
1445 | - | |||||||||||||
1446 | - | |||||||||||||
1447 | - | |||||||||||||
1448 | - | |||||||||||||
1449 | - | |||||||||||||
1450 | - | |||||||||||||
1451 | - | |||||||||||||
1452 | QModelIndex QAbstractListModel::parent(const QModelIndex & ) const | - | ||||||||||||
1453 | { | - | ||||||||||||
1454 | return QModelIndex(); | - | ||||||||||||
1455 | } | - | ||||||||||||
1456 | - | |||||||||||||
1457 | - | |||||||||||||
1458 | - | |||||||||||||
1459 | - | |||||||||||||
1460 | QModelIndex QAbstractListModel::sibling(int row, int column, const QModelIndex &) const | - | ||||||||||||
1461 | { | - | ||||||||||||
1462 | return index(row, column); | - | ||||||||||||
1463 | } | - | ||||||||||||
1464 | - | |||||||||||||
1465 | - | |||||||||||||
1466 | - | |||||||||||||
1467 | - | |||||||||||||
1468 | Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const | - | ||||||||||||
1469 | { | - | ||||||||||||
1470 | Qt::ItemFlags f = QAbstractItemModel::flags(index); | - | ||||||||||||
1471 | if (index.isValid()) | - | ||||||||||||
1472 | f |= Qt::ItemNeverHasChildren; | - | ||||||||||||
1473 | return f; | - | ||||||||||||
1474 | } | - | ||||||||||||
1475 | int QAbstractListModel::columnCount(const QModelIndex &parent) const | - | ||||||||||||
1476 | { | - | ||||||||||||
1477 | return parent.isValid() ? 0 : 1; | - | ||||||||||||
1478 | } | - | ||||||||||||
1479 | - | |||||||||||||
1480 | bool QAbstractListModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||
1481 | { | - | ||||||||||||
1482 | return parent.isValid() ? false : (rowCount() > 0); | - | ||||||||||||
1483 | } | - | ||||||||||||
1484 | bool QAbstractTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||
1485 | int row, int column, const QModelIndex &parent) | - | ||||||||||||
1486 | { | - | ||||||||||||
1487 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction)) | - | ||||||||||||
1488 | return false; | - | ||||||||||||
1489 | - | |||||||||||||
1490 | QStringList types = mimeTypes(); | - | ||||||||||||
1491 | if (types.isEmpty()) | - | ||||||||||||
1492 | return false; | - | ||||||||||||
1493 | QString format = types.at(0); | - | ||||||||||||
1494 | if (!data->hasFormat(format)) | - | ||||||||||||
1495 | return false; | - | ||||||||||||
1496 | - | |||||||||||||
1497 | QByteArray encoded = data->data(format); | - | ||||||||||||
1498 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||
1499 | - | |||||||||||||
1500 | - | |||||||||||||
1501 | if (parent.isValid() && row == -1 && column == -1) { | - | ||||||||||||
1502 | int top = 2147483647; | - | ||||||||||||
1503 | int left = 2147483647; | - | ||||||||||||
1504 | QVector<int> rows, columns; | - | ||||||||||||
1505 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||
1506 | - | |||||||||||||
1507 | while (!stream.atEnd()) { | - | ||||||||||||
1508 | int r, c; | - | ||||||||||||
1509 | QMap<int, QVariant> v; | - | ||||||||||||
1510 | stream >> r >> c >> v; | - | ||||||||||||
1511 | rows.append(r); | - | ||||||||||||
1512 | columns.append(c); | - | ||||||||||||
1513 | data.append(v); | - | ||||||||||||
1514 | top = qMin(r, top); | - | ||||||||||||
1515 | left = qMin(c, left); | - | ||||||||||||
1516 | } | - | ||||||||||||
1517 | - | |||||||||||||
1518 | for (int i = 0; i < data.size(); ++i) { | - | ||||||||||||
1519 | int r = (rows.at(i) - top) + parent.row(); | - | ||||||||||||
1520 | int c = (columns.at(i) - left) + parent.column(); | - | ||||||||||||
1521 | if (hasIndex(r, c)) | - | ||||||||||||
1522 | setItemData(index(r, c), data.at(i)); | - | ||||||||||||
1523 | } | - | ||||||||||||
1524 | - | |||||||||||||
1525 | return true; | - | ||||||||||||
1526 | } | - | ||||||||||||
1527 | - | |||||||||||||
1528 | - | |||||||||||||
1529 | return decodeData(row, column, parent, stream); | - | ||||||||||||
1530 | } | - | ||||||||||||
1531 | - | |||||||||||||
1532 | - | |||||||||||||
1533 | - | |||||||||||||
1534 | - | |||||||||||||
1535 | bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, | - | ||||||||||||
1536 | int row, int column, const QModelIndex &parent) | - | ||||||||||||
1537 | { | - | ||||||||||||
1538 | if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction)) | - | ||||||||||||
1539 | return false; | - | ||||||||||||
1540 | - | |||||||||||||
1541 | QStringList types = mimeTypes(); | - | ||||||||||||
1542 | if (types.isEmpty()) | - | ||||||||||||
1543 | return false; | - | ||||||||||||
1544 | QString format = types.at(0); | - | ||||||||||||
1545 | if (!data->hasFormat(format)) | - | ||||||||||||
1546 | return false; | - | ||||||||||||
1547 | - | |||||||||||||
1548 | QByteArray encoded = data->data(format); | - | ||||||||||||
1549 | QDataStream stream(&encoded, QIODevice::ReadOnly); | - | ||||||||||||
1550 | - | |||||||||||||
1551 | - | |||||||||||||
1552 | if (parent.isValid() && row == -1 && column == -1) { | - | ||||||||||||
1553 | int top = 2147483647; | - | ||||||||||||
1554 | int left = 2147483647; | - | ||||||||||||
1555 | QVector<int> rows, columns; | - | ||||||||||||
1556 | QVector<QMap<int, QVariant> > data; | - | ||||||||||||
1557 | - | |||||||||||||
1558 | while (!stream.atEnd()) { | - | ||||||||||||
1559 | int r, c; | - | ||||||||||||
1560 | QMap<int, QVariant> v; | - | ||||||||||||
1561 | stream >> r >> c >> v; | - | ||||||||||||
1562 | rows.append(r); | - | ||||||||||||
1563 | columns.append(c); | - | ||||||||||||
1564 | data.append(v); | - | ||||||||||||
1565 | top = qMin(r, top); | - | ||||||||||||
1566 | left = qMin(c, left); | - | ||||||||||||
1567 | } | - | ||||||||||||
1568 | - | |||||||||||||
1569 | for (int i = 0; i < data.size(); ++i) { | - | ||||||||||||
1570 | int r = (rows.at(i) - top) + parent.row(); | - | ||||||||||||
1571 | if (columns.at(i) == left && hasIndex(r, 0)) | - | ||||||||||||
1572 | setItemData(index(r), data.at(i)); | - | ||||||||||||
1573 | } | - | ||||||||||||
1574 | - | |||||||||||||
1575 | return true; | - | ||||||||||||
1576 | } | - | ||||||||||||
1577 | - | |||||||||||||
1578 | if (row == -1) | - | ||||||||||||
1579 | row = rowCount(parent); | - | ||||||||||||
1580 | - | |||||||||||||
1581 | - | |||||||||||||
1582 | return decodeData(row, column, parent, stream); | - | ||||||||||||
1583 | } | - | ||||||||||||
1584 | void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& key, QPersistentModelIndexData *data) | - | ||||||||||||
1585 | { | - | ||||||||||||
1586 | QHash<QModelIndex,QPersistentModelIndexData *>::iterator newIt = | - | ||||||||||||
1587 | indexes.insertMulti(key, data); | - | ||||||||||||
1588 | QHash<QModelIndex,QPersistentModelIndexData *>::iterator it = newIt + 1; | - | ||||||||||||
1589 | while (it != indexes.end() && it.key() == key) { | - | ||||||||||||
1590 | qSwap(*newIt,*it); | - | ||||||||||||
1591 | newIt = it; | - | ||||||||||||
1592 | ++it; | - | ||||||||||||
1593 | } | - | ||||||||||||
1594 | } | - | ||||||||||||
1595 | - | |||||||||||||
1596 | - | |||||||||||||
Switch to Source code | Preprocessed file |