qstandarditemmodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/itemmodels/qstandarditemmodel.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static inline QString qStandardItemModelDataListMimeType()-
10{-
11 return
never executed: return ([]() -> QString { enum { Size = sizeof(u"" "application/x-qstandarditemmodeldatalist")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "application/x-qstandarditemmodeldatalist" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());
([]() -> QString { enum { Size = sizeof(u"" "application/x-qstandarditemmodeldatalist")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "application/x-qstandarditemmodeldatalist" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}());
never executed: return ([]() -> QString { enum { Size = sizeof(u"" "application/x-qstandarditemmodeldatalist")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "application/x-qstandarditemmodeldatalist" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());
0
12}-
13-
14class QStandardItemModelLessThan-
15{-
16public:-
17 inline QStandardItemModelLessThan()-
18 { }-
19-
20 inline bool operator()(const QPair<QStandardItem*, int> &l,-
21 const QPair<QStandardItem*, int> &r) const-
22 {-
23 return *(l.first) < *(r.first);-
24 }-
25};-
26-
27class QStandardItemModelGreaterThan-
28{-
29public:-
30 inline QStandardItemModelGreaterThan()-
31 { }-
32-
33 inline bool operator()(const QPair<QStandardItem*, int> &l,-
34 const QPair<QStandardItem*, int> &r) const-
35 {-
36 return *(r.first) < *(l.first);-
37 }-
38};-
39-
40-
41-
42-
43QStandardItemPrivate::~QStandardItemPrivate()-
44{-
45 QVector<QStandardItem*>::const_iterator it;-
46 for (it = children.constBegin(); it != children.constEnd(); ++it) {-
47 QStandardItem *child = *it;-
48 if (child)-
49 child->d_func()->setModel(0);-
50 delete child;-
51 }-
52 children.clear();-
53 if (parent && model)-
54 parent->d_func()->childDeleted(q_func());-
55}-
56-
57-
58-
59-
60QPair<int, int> QStandardItemPrivate::position() const-
61{-
62 if (QStandardItem *par = parent) {-
63 int idx = par->d_func()->childIndex(q_func());-
64 if (idx == -1)-
65 return QPair<int, int>(-1, -1);-
66 return QPair<int, int>(idx / par->columnCount(), idx % par->columnCount());-
67 }-
68-
69 return QPair<int, int>(-1, -1);-
70}-
71-
72-
73-
74-
75void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item,-
76 bool emitChanged)-
77{-
78 QStandardItem * const q = q_func();-
79 if (item == q) {-
80 QMessageLogger(__FILE__, 120131, __PRETTY_FUNCTION__).warning("QStandardItem::setChild: Can't make an item a child of itself %p",-
81 item);-
82 return;-
83 }-
84 if ((row < 0) || (column < 0))-
85 return;-
86 if (rows <= row)-
87 q->setRowCount(row + 1);-
88 if (columns <= column)-
89 q->setColumnCount(column + 1);-
90 int index = childIndex(row, column);-
91 ((!(index != -1)) ? qt_assert("index != -1",__FILE__,131142) : qt_noop());-
92 QStandardItem *oldItem = children.at(index);-
93 if (item == oldItem)-
94 return;-
95-
96 if (model && emitChanged) {-
97 model->layoutAboutToBeChanged();-
98 }-
99-
100 if (item) {-
101 if (item->d_func()->parent == 0) {-
102 item->d_func()->setParentAndModel(q, model);-
103 } else {-
104 QMessageLogger(__FILE__, 144155, __PRETTY_FUNCTION__).warning("QStandardItem::setChild: Ignoring duplicate insertion of item %p",-
105 item);-
106 return;-
107 }-
108 }-
109 if (oldItem)-
110 oldItem->d_func()->setModel(0);-
111 delete oldItem;-
112 children.replace(index, item);-
113-
114 if (model && emitChanged)-
115 model->layoutChanged();-
116-
117 if (emitChanged && model)-
118 model->d_func()->itemChanged(item);-
119}-
120-
121-
122-
123-
124-
125void QStandardItemPrivate::changeFlags(bool enable, Qt::ItemFlags f)-
126{-
127 QStandardItem * const q = q_func();-
128 Qt::ItemFlags flags = q->flags();-
129 if (enable)-
130 flags |= f;-
131 else-
132 flags &= ~f;-
133 q->setFlags(flags);-
134}-
135-
136-
137-
138-
139void QStandardItemPrivate::childDeleted(QStandardItem *child)-
140{-
141 int index = childIndex(child);-
142 ((!(index != -1)) ? qt_assert("index != -1",__FILE__,182193) : qt_noop());-
143 children.replace(index, 0);-
144}-
145-
146-
147-
148-
149void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles)-
150{-
151 QStandardItem * const q = q_func();-
152-
153-
154 QVector<QStandardItemData> newValues;-
QMap<int, QVariant>::const_iterator it;
155 for (auto it = roles.begin(); it !=(), end = roles.end(); it != end
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
;
++it) {
0
156 const QVariant value&value = it.value();-
157 if (value.isValid()
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
158 int role = it.key();-
159 role = (
(role == Qt::EditRole)Description
TRUEnever evaluated
FALSEnever evaluated
role == Qt::EditRole)
(role == Qt::EditRole)Description
TRUEnever evaluated
FALSEnever evaluated
? Qt::DisplayRole : role;
0
160 newValues.append(QStandardItemDatawid(role, it.value());-
newValues.append(wid);));
161 }
never executed: end of block
0
162 }
never executed: end of block
0
163-
164 if (values!=newValues
values!=newValuesDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
165 values=.swap(newValues;);-
166 if (model
modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
167 model->d_func()->itemChanged(q);
never executed: model->d_func()->itemChanged(q);
0
168 }
never executed: end of block
0
169}
never executed: end of block
0
170-
171-
172-
173-
174const QMap<int, QVariant> QStandardItemPrivate::itemData() const-
175{-
176 QMap<int, QVariant> result;-
177 QVector<QStandardItemData>::const_iterator it;-
178 for (it = values.begin(); it != values.end(); ++it)-
179 result.insert((*it).role, (*it).value);-
180 return result;-
181}-
182-
183-
184-
185-
186void QStandardItemPrivate::sortChildren(int column, Qt::SortOrder order)-
187{-
188 QStandardItem * const q = q_func();-
189 if (column >= columnCount())-
190 return;-
191-
192 QVector<QPair<QStandardItem*, int> > sortable;-
193 QVector<int> unsortable;-
194-
195 sortable.reserve(rowCount());-
196 unsortable.reserve(rowCount());-
197-
198 for (int row = 0; row < rowCount(); ++row) {-
199 QStandardItem *itm = q->child(row, column);-
200 if (itm)-
201 sortable.append(QPair<QStandardItem*,int>(itm, row));-
202 else-
203 unsortable.append(row);-
204 }-
205-
206 if (order == Qt::AscendingOrder) {-
207 QStandardItemModelLessThan lt;-
208 std::stable_sort(sortable.begin(), sortable.end(), lt);-
209 } else {-
210 QStandardItemModelGreaterThan gt;-
211 std::stable_sort(sortable.begin(), sortable.end(), gt);-
212 }-
213-
214 QModelIndexList changedPersistentIndexesFrom, changedPersistentIndexesTo;-
215 QVector<QStandardItem*> sorted_children(children.count());-
216 for (int i = 0; i < rowCount(); ++i) {-
217 int r = (i < sortable.count()-
218 ? sortable.at(i).second-
219 : unsortable.at(i - sortable.count()));-
220 for (int c = 0; c < columnCount(); ++c) {-
221 QStandardItem *itm = q->child(r, c);-
222 sorted_children[childIndex(i, c)] = itm;-
223 if (model) {-
224 QModelIndex from = model->createIndex(r, c, q);-
225 if (model->d_func()->persistent.indexes.contains(from)) {-
226 QModelIndex to = model->createIndex(i, c, q);-
227 changedPersistentIndexesFrom.append(from);-
228 changedPersistentIndexesTo.append(to);-
229 }-
230 }-
231 }-
232 }-
233-
234 children = sorted_children;-
235-
236 if (model) {-
237 model->changePersistentIndexList(changedPersistentIndexesFrom, changedPersistentIndexesTo);-
238 }-
239-
240 QVector<QStandardItem*>::iterator it;-
241 for (it = children.begin(); it != children.end(); ++it) {-
242 if (*it)-
243 (*it)->d_func()->sortChildren(column, order);-
244 }-
245}-
246-
247-
248-
249-
250-
251void QStandardItemPrivate::setModel(QStandardItemModel *mod)-
252{-
253 if (children.isEmpty()) {-
254 if (model)-
255 model->d_func()->invalidatePersistentIndex(model->indexFromItem(q_ptr));-
256 model = mod;-
257 } else {-
258 QStack<QStandardItem*> stack;-
259 stack.push(q_ptr);-
260 while (!stack.isEmpty()) {-
261 QStandardItem *itm = stack.pop();-
262 if (itm->d_func()->model) {-
263 itm->d_func()->model->d_func()->invalidatePersistentIndex(itm->d_func()->model->indexFromItem(itm));-
264 }-
265 itm->d_func()->model = mod;-
266 const QVector<QStandardItem*> &childList = itm->d_func()->children;-
267 for (int i = 0; i < childList.count(); ++i) {-
268 QStandardItem *chi = childList.at(i);-
269 if (chi)-
270 stack.push(chi);-
271 }-
272 }-
273 }-
274}-
275-
276-
277-
278-
279QStandardItemModelPrivate::QStandardItemModelPrivate()-
280 : root(new QStandardItem),-
281 itemPrototype(0),-
282 sortRole(Qt::DisplayRole)-
283{-
284 root->setFlags(Qt::ItemIsDropEnabled);-
285}-
286-
287-
288-
289-
290QStandardItemModelPrivate::~QStandardItemModelPrivate()-
291{-
292 delete itemPrototype;-
293 qDeleteAll(columnHeaderItems);-
294 qDeleteAll(rowHeaderItems);-
295}-
296-
297-
298-
299-
300void QStandardItemModelPrivate::init()-
301{-
302 QStandardItemModel * const q = q_func();-
303 QObject::connect(q, qFlagLocation("2""dataChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "345""354"),-
304 q, qFlagLocation("1""_q_emitItemChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "346""355"));-
305}-
306-
307-
308-
309-
310void QStandardItemModelPrivate::_q_emitItemChanged(const QModelIndex &topLeft,-
311 const QModelIndex &bottomRight)-
312{-
313 QStandardItemModel * const q = q_func();-
314 QModelIndex parent = topLeft.parent();-
315 for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {-
316 for (int column = topLeft.column(); column <= bottomRight.column(); ++column) {-
317 QModelIndex index = q->index(row, column, parent);-
318 if (QStandardItem *item = itemFromIndex(index))-
319 q->itemChanged(item);-
320 }-
321 }-
322}-
323-
324-
325-
326-
327bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &items)-
328{-
329 QStandardItem * const q = q_func();-
330 if ((row < 0) || (row > rowCount()))-
331 return false;-
332 int count = items.count();-
333 if (model)-
334 model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);-
335 if (rowCount() == 0) {-
336 if (columnCount() == 0)-
337 q->setColumnCount(1);-
338 children.resize(columnCount() * count);-
339 rows = count;-
340 } else {-
341 rows += count;-
342 int index = childIndex(row, 0);-
343 if (index != -1)-
344 children.insert(index, columnCount() * count, 0);-
345 }-
346 for (int i = 0; i < items.count(); ++i) {-
347 QStandardItem *item = items.at(i);-
348 item->d_func()->model = model;-
349 item->d_func()->parent = q;-
350 int index = childIndex(i + row, 0);-
351 children.replace(index, item);-
352 }-
353 if (model)-
354 model->d_func()->rowsInserted(q, row, count);-
355 return true;-
356}-
357-
358bool QStandardItemPrivate::insertRows(int row, int count, const QList<QStandardItem*> &items)-
359{-
360 QStandardItem * const q = q_func();-
361 if ((count < 1) || (row < 0) || (row > rowCount()))-
362 return false;-
363 if (model)-
364 model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);-
365 if (rowCount() == 0) {-
366 children.resize(columnCount() * count);-
367 rows = count;-
368 } else {-
369 rows += count;-
370 int index = childIndex(row, 0);-
371 if (index != -1)-
372 children.insert(index, columnCount() * count, 0);-
373 }-
374 if (!items.isEmpty()) {-
375 int index = childIndex(row, 0);-
376 int limit = qMin(items.count(), columnCount() * count);-
377 for (int i = 0; i < limit; ++i) {-
378 QStandardItem *item = items.at(i);-
379 if (item) {-
380 if (item->d_func()->parent == 0) {-
381 item->d_func()->setParentAndModel(q, model);-
382 } else {-
383 QMessageLogger(__FILE__, 425434, __PRETTY_FUNCTION__).warning("QStandardItem::insertRows: Ignoring duplicate insertion of item %p",-
384 item);-
385 item = 0;-
386 }-
387 }-
388 children.replace(index, item);-
389 ++index;-
390 }-
391 }-
392 if (model)-
393 model->d_func()->rowsInserted(q, row, count);-
394 return true;-
395}-
396-
397-
398-
399-
400bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QStandardItem*> &items)-
401{-
402 QStandardItem * const q = q_func();-
403 if ((count < 1) || (column < 0) || (column > columnCount()))-
404 return false;-
405 if (model)-
406 model->d_func()->columnsAboutToBeInserted(q, column, column + count - 1);-
407 if (columnCount() == 0) {-
408 children.resize(rowCount() * count);-
409 columns = count;-
410 } else {-
411 columns += count;-
412 int index = childIndex(0, column);-
413 for (int row = 0; row < rowCount(); ++row) {-
414 children.insert(index, count, 0);-
415 index += columnCount();-
416 }-
417 }-
418 if (!items.isEmpty()) {-
419 int limit = qMin(items.count(), rowCount() * count);-
420 for (int i = 0; i < limit; ++i) {-
421 QStandardItem *item = items.at(i);-
422 if (item) {-
423 if (item->d_func()->parent == 0) {-
424 item->d_func()->setParentAndModel(q, model);-
425 } else {-
426 QMessageLogger(__FILE__, 468477, __PRETTY_FUNCTION__).warning("QStandardItem::insertColumns: Ignoring duplicate insertion of item %p",-
427 item);-
428 item = 0;-
429 }-
430 }-
431 int r = i / count;-
432 int c = column + (i % count);-
433 int index = childIndex(r, c);-
434 children.replace(index, item);-
435 }-
436 }-
437 if (model)-
438 model->d_func()->columnsInserted(q, column, count);-
439 return true;-
440}-
441-
442-
443-
444-
445void QStandardItemModelPrivate::itemChanged(QStandardItem *item)-
446{-
447 QStandardItemModel * const q = q_func();-
448 if (item->d_func()->parent == 0) {-
449-
450 int idx = columnHeaderItems.indexOf(item);-
451 if (idx != -1) {-
452 q->headerDataChanged(Qt::Horizontal, idx, idx);-
453 } else {-
454 idx = rowHeaderItems.indexOf(item);-
455 if (idx != -1)-
456 q->headerDataChanged(Qt::Vertical, idx, idx);-
457 }-
458 } else {-
459-
460 QModelIndex index = q->indexFromItem(item);-
461 q->dataChanged(index, index);-
462 }-
463}-
464-
465-
466-
467-
468void QStandardItemModelPrivate::rowsAboutToBeInserted(QStandardItem *parent,-
469 int start, int end)-
470{-
471 QStandardItemModel * const q = q_func();-
472 QModelIndex index = q->indexFromItem(parent);-
473 q->beginInsertRows(index, start, end);-
474}-
475-
476-
477-
478-
479void QStandardItemModelPrivate::columnsAboutToBeInserted(QStandardItem *parent,-
480 int start, int end)-
481{-
482 QStandardItemModel * const q = q_func();-
483 QModelIndex index = q->indexFromItem(parent);-
484 q->beginInsertColumns(index, start, end);-
485}-
486-
487-
488-
489-
490void QStandardItemModelPrivate::rowsAboutToBeRemoved(QStandardItem *parent,-
491 int start, int end)-
492{-
493 QStandardItemModel * const q = q_func();-
494 QModelIndex index = q->indexFromItem(parent);-
495 q->beginRemoveRows(index, start, end);-
496}-
497-
498-
499-
500-
501void QStandardItemModelPrivate::columnsAboutToBeRemoved(QStandardItem *parent,-
502 int start, int end)-
503{-
504 QStandardItemModel * const q = q_func();-
505 QModelIndex index = q->indexFromItem(parent);-
506 q->beginRemoveColumns(index, start, end);-
507}-
508-
509-
510-
511-
512void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent,-
513 int row, int count)-
514{-
515 QStandardItemModel * const q = q_func();-
516 if (parent == root.data())-
517 rowHeaderItems.insert(row, count, 0);-
518 q->endInsertRows();-
519}-
520-
521-
522-
523-
524void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent,-
525 int column, int count)-
526{-
527 QStandardItemModel * const q = q_func();-
528 if (parent == root.data())-
529 columnHeaderItems.insert(column, count, 0);-
530 q->endInsertColumns();-
531}-
532-
533-
534-
535-
536void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent,-
537 int row, int count)-
538{-
539 QStandardItemModel * const q = q_func();-
540 if (parent == root.data()) {-
541 for (int i = row; i < row + count; ++i) {-
542 QStandardItem *oldItem = rowHeaderItems.at(i);-
543 if (oldItem)-
544 oldItem->d_func()->setModel(0);-
545 delete oldItem;-
546 }-
547 rowHeaderItems.remove(row, count);-
548 }-
549 q->endRemoveRows();-
550}-
551-
552-
553-
554-
555void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent,-
556 int column, int count)-
557{-
558 QStandardItemModel * const q = q_func();-
559 if (parent == root.data()) {-
560 for (int i = column; i < column + count; ++i) {-
561 QStandardItem *oldItem = columnHeaderItems.at(i);-
562 if (oldItem)-
563 oldItem->d_func()->setModel(0);-
564 delete oldItem;-
565 }-
566 columnHeaderItems.remove(column, count);-
567 }-
568 q->endRemoveColumns();-
569}-
570QStandardItem::QStandardItem()-
571 : d_ptr(new QStandardItemPrivate)-
572{-
573 QStandardItemPrivate * const d = d_func();-
574 d->q_ptr = this;-
575}-
576-
577-
578-
579-
580QStandardItem::QStandardItem(const QString &text)-
581 : d_ptr(new QStandardItemPrivate)-
582{-
583 QStandardItemPrivate * const d = d_func();-
584 d->q_ptr = this;-
585 setText(text);-
586}-
587-
588-
589-
590-
591QStandardItem::QStandardItem(const QIcon &icon, const QString &text)-
592 : d_ptr(new QStandardItemPrivate)-
593{-
594 QStandardItemPrivate * const d = d_func();-
595 d->q_ptr = this;-
596 setIcon(icon);-
597 setText(text);-
598}-
599-
600-
601-
602-
603QStandardItem::QStandardItem(int rows, int columns)-
604 : d_ptr(new QStandardItemPrivate)-
605{-
606 QStandardItemPrivate * const d = d_func();-
607 d->q_ptr = this;-
608 setRowCount(rows);-
609 setColumnCount(columns);-
610}-
611-
612-
613-
614-
615QStandardItem::QStandardItem(QStandardItemPrivate &dd)-
616 : d_ptr(&dd)-
617{-
618 QStandardItemPrivate * const d = d_func();-
619 d->q_ptr = this;-
620}-
621-
622-
623-
624-
625-
626-
627-
628QStandardItem::QStandardItem(const QStandardItem &other)-
629 : d_ptr(new QStandardItemPrivate)-
630{-
631 QStandardItemPrivate * const d = d_func();-
632 d->q_ptr = this;-
633 operator=(other);-
634}-
635-
636-
637-
638-
639-
640-
641-
642QStandardItem &QStandardItem::operator=(const QStandardItem &other)-
643{-
644 QStandardItemPrivate * const d = d_func();-
645 d->values = other.d_func()->values;-
646 return *this;-
647}-
648-
649-
650-
651-
652-
653QStandardItem::~QStandardItem()-
654{-
655}-
656QStandardItem *QStandardItem::parent() const-
657{-
658 const QStandardItemPrivate * const d = d_func();-
659 if (!d->model || (d->model->d_func()->root.data() != d->parent))-
660 return d->parent;-
661 return 0;-
662}-
663void QStandardItem::setData(const QVariant &value, int role)-
664{-
665 QStandardItemPrivate * const d = d_func();-
666 role = (role == Qt::EditRole) ? Qt::DisplayRole : role;-
667 QVector<QStandardItemData>::iterator it;-
668 for (it = d->values.begin(); it != d->values.end(); ++it) {-
669 if ((*it).role == role) {-
670 if (value.isValid()) {-
671 if ((*it).value.type() == value.type() && (*it).value == value)-
672 return;-
673 (*it).value = value;-
674 } else {-
675 d->values.erase(it);-
676 }-
677 if (d->model)-
678 d->model->d_func()->itemChanged(this);-
679 return;-
680 }-
681 }-
682 d->values.append(QStandardItemData(role, value));-
683 if (d->model)-
684 d->model->d_func()->itemChanged(this);-
685}-
686QVariant QStandardItem::data(int role) const-
687{-
688 const QStandardItemPrivate * const d = d_func();-
689 role = (role == Qt::EditRole) ? Qt::DisplayRole : role;-
690 QVector<QStandardItemData>::const_iterator it;-
691 for (it = d->values.begin(); it != d->values.end(); ++it) {-
692 if ((*it).role == role)-
693 return (*it).value;-
694 }-
695 return QVariant();-
696}-
697void QStandardItem::emitDataChanged()-
698{-
699 QStandardItemPrivate * const d = d_func();-
700 if (d->model)-
701 d->model->d_func()->itemChanged(this);-
702}-
703void QStandardItem::setFlags(Qt::ItemFlags flags)-
704{-
705 setData((int)flags, Qt::UserRole - 1);-
706}-
707Qt::ItemFlags QStandardItem::flags() const-
708{-
709 QVariant v = data(Qt::UserRole - 1);-
710 if (!v.isValid())-
711 return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable-
712 |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);-
713 return Qt::ItemFlags(v.toInt());-
714}-
715void QStandardItem::setEnabled(bool enabled)-
716{-
717 QStandardItemPrivate * const d = d_func();-
718 d->changeFlags(enabled, Qt::ItemIsEnabled);-
719}-
720void QStandardItem::setEditable(bool editable)-
721{-
722 QStandardItemPrivate * const d = d_func();-
723 d->changeFlags(editable, Qt::ItemIsEditable);-
724}-
725void QStandardItem::setSelectable(bool selectable)-
726{-
727 QStandardItemPrivate * const d = d_func();-
728 d->changeFlags(selectable, Qt::ItemIsSelectable);-
729}-
730void QStandardItem::setCheckable(bool checkable)-
731{-
732 QStandardItemPrivate * const d = d_func();-
733 if (checkable && !isCheckable()) {-
734-
735 if (!data(Qt::CheckStateRole).isValid())-
736 setData(Qt::Unchecked, Qt::CheckStateRole);-
737 }-
738 d->changeFlags(checkable, Qt::ItemIsUserCheckable);-
739}-
740void QStandardItem::setAutoTristate(bool tristate)-
741{-
742 QStandardItemPrivate * const d = d_func();-
743 d->changeFlags(tristate, Qt::ItemIsAutoTristate);-
744}-
745void QStandardItem::setUserTristate(bool tristate)-
746{-
747 QStandardItemPrivate * const d = d_func();-
748 d->changeFlags(tristate, Qt::ItemIsUserTristate);-
749}-
750void QStandardItem::setTristate(bool tristate)-
751{-
752 setAutoTristate(tristate);-
753}-
754void QStandardItem::setDragEnabled(bool dragEnabled)-
755{-
756 QStandardItemPrivate * const d = d_func();-
757 d->changeFlags(dragEnabled, Qt::ItemIsDragEnabled);-
758}-
759void QStandardItem::setDropEnabled(bool dropEnabled)-
760{-
761 QStandardItemPrivate * const d = d_func();-
762 d->changeFlags(dropEnabled, Qt::ItemIsDropEnabled);-
763}-
764int QStandardItem::row() const-
765{-
766 const QStandardItemPrivate * const d = d_func();-
767 QPair<int, int> pos = d->position();-
768 return pos.first;-
769}-
770-
771-
772-
773-
774-
775-
776-
777int QStandardItem::column() const-
778{-
779 const QStandardItemPrivate * const d = d_func();-
780 QPair<int, int> pos = d->position();-
781 return pos.second;-
782}-
783QModelIndex QStandardItem::index() const-
784{-
785 const QStandardItemPrivate * const d = d_func();-
786 return d->model ? d->model->indexFromItem(this) : QModelIndex();-
787}-
788QStandardItemModel *QStandardItem::model() const-
789{-
790 const QStandardItemPrivate * const d = d_func();-
791 return d->model;-
792}-
793-
794-
795-
796-
797-
798-
799-
800void QStandardItem::setRowCount(int rows)-
801{-
802 int rc = rowCount();-
803 if (rc == rows)-
804 return;-
805 if (rc < rows)-
806 insertRows(qMax(rc, 0), rows - rc);-
807 else-
808 removeRows(qMax(rows, 0), rc - rows);-
809}-
810-
811-
812-
813-
814-
815-
816int QStandardItem::rowCount() const-
817{-
818 const QStandardItemPrivate * const d = d_func();-
819 return d->rowCount();-
820}-
821-
822-
823-
824-
825-
826-
827-
828void QStandardItem::setColumnCount(int columns)-
829{-
830 int cc = columnCount();-
831 if (cc == columns)-
832 return;-
833 if (cc < columns)-
834 insertColumns(qMax(cc, 0), columns - cc);-
835 else-
836 removeColumns(qMax(columns, 0), cc - columns);-
837}-
838-
839-
840-
841-
842-
843-
844int QStandardItem::columnCount() const-
845{-
846 const QStandardItemPrivate * const d = d_func();-
847 return d->columnCount();-
848}-
849-
850-
851-
852-
853-
854-
855-
856void QStandardItem::insertRow(int row, const QList<QStandardItem*> &items)-
857{-
858 QStandardItemPrivate * const d = d_func();-
859 if (row < 0)-
860 return;-
861 if (columnCount() < items.count())-
862 setColumnCount(items.count());-
863 d->insertRows(row, 1, items);-
864}-
865-
866-
867-
868-
869-
870-
871void QStandardItem::insertRows(int row, const QList<QStandardItem*> &items)-
872{-
873 QStandardItemPrivate * const d = d_func();-
874 if (row < 0)-
875 return;-
876 d->insertRows(row, items);-
877}-
878-
879-
880-
881-
882-
883-
884-
885void QStandardItem::insertColumn(int column, const QList<QStandardItem*> &items)-
886{-
887 QStandardItemPrivate * const d = d_func();-
888 if (column < 0)-
889 return;-
890 if (rowCount() < items.count())-
891 setRowCount(items.count());-
892 d->insertColumns(column, 1, items);-
893}-
894-
895-
896-
897-
898-
899-
900void QStandardItem::insertRows(int row, int count)-
901{-
902 QStandardItemPrivate * const d = d_func();-
903 if (rowCount() < row) {-
904 count += row - rowCount();-
905 row = rowCount();-
906 }-
907 d->insertRows(row, count, QList<QStandardItem*>());-
908}-
909-
910-
911-
912-
913-
914-
915void QStandardItem::insertColumns(int column, int count)-
916{-
917 QStandardItemPrivate * const d = d_func();-
918 if (columnCount() < column) {-
919 count += column - columnCount();-
920 column = columnCount();-
921 }-
922 d->insertColumns(column, count, QList<QStandardItem*>());-
923}-
924void QStandardItem::removeRow(int row)-
925{-
926 removeRows(row, 1);-
927}-
928-
929-
930-
931-
932-
933-
934-
935void QStandardItem::removeColumn(int column)-
936{-
937 removeColumns(column, 1);-
938}-
939-
940-
941-
942-
943-
944-
945-
946void QStandardItem::removeRows(int row, int count)-
947{-
948 QStandardItemPrivate * const d = d_func();-
949 if ((count < 1) || (row < 0) || ((row + count) > rowCount()))-
950 return;-
951 if (d->model)-
952 d->model->d_func()->rowsAboutToBeRemoved(this, row, row + count - 1);-
953 int i = d->childIndex(row, 0);-
954 int n = count * d->columnCount();-
955 for (int j = i; j < n+i; ++j) {-
956 QStandardItem *oldItem = d->children.at(j);-
957 if (oldItem)-
958 oldItem->d_func()->setModel(0);-
959 delete oldItem;-
960 }-
961 d->children.remove(qMax(i, 0), n);-
962 d->rows -= count;-
963 if (d->model)-
964 d->model->d_func()->rowsRemoved(this, row, count);-
965}-
966-
967-
968-
969-
970-
971-
972-
973void QStandardItem::removeColumns(int column, int count)-
974{-
975 QStandardItemPrivate * const d = d_func();-
976 if ((count < 1) || (column < 0) || ((column + count) > columnCount()))-
977 return;-
978 if (d->model)-
979 d->model->d_func()->columnsAboutToBeRemoved(this, column, column + count - 1);-
980 for (int row = d->rowCount() - 1; row >= 0; --row) {-
981 int i = d->childIndex(row, column);-
982 for (int j=i; j<i+count; ++j) {-
983 QStandardItem *oldItem = d->children.at(j);-
984 if (oldItem)-
985 oldItem->d_func()->setModel(0);-
986 delete oldItem;-
987 }-
988 d->children.remove(i, count);-
989 }-
990 d->columns -= count;-
991 if (d->model)-
992 d->model->d_func()->columnsRemoved(this, column, count);-
993}-
994-
995-
996-
997-
998-
999-
1000bool QStandardItem::hasChildren() const-
1001{-
1002 return (rowCount() > 0) && (columnCount() > 0);-
1003}-
1004void QStandardItem::setChild(int row, int column, QStandardItem *item)-
1005{-
1006 QStandardItemPrivate * const d = d_func();-
1007 d->setChild(row, column, item, true);-
1008}-
1009QStandardItem *QStandardItem::child(int row, int column) const-
1010{-
1011 const QStandardItemPrivate * const d = d_func();-
1012 int index = d->childIndex(row, column);-
1013 if (index == -1)-
1014 return 0;-
1015 return d->children.at(index);-
1016}-
1017QStandardItem *QStandardItem::takeChild(int row, int column)-
1018{-
1019 QStandardItemPrivate * const d = d_func();-
1020 QStandardItem *item = 0;-
1021 int index = d->childIndex(row, column);-
1022 if (index != -1) {-
1023 item = d->children.at(index);-
1024 if (item)-
1025 item->d_func()->setParentAndModel(0, 0);-
1026 d->children.replace(index, 0);-
1027 }-
1028 return item;-
1029}-
1030QList<QStandardItem*> QStandardItem::takeRow(int row)-
1031{-
1032 QStandardItemPrivate * const d = d_func();-
1033 QList<QStandardItem*> items;-
1034 if ((
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
row < 0)
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(row >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
row >= rowCount())
(row >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1035 return
never executed: return items;
QList<QStandardItem*>();items;
never executed: return items;
0
1036 if (d->model
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1037 d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
never executed: d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
0
1038-
1039 QList<QStandardItem*> items;int index = d->childIndex(row, 0);-
1040 if (index != -1
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1041 int col_count = d->columnCount();-
1042 items.reserve(col_count);-
1043 for (int column = 0; column < col_count
column < col_countDescription
TRUEnever evaluated
FALSEnever evaluated
; ++column) {
0
1044 QStandardItem *ch = d->children.at(index + column);-
1045 if (ch
chDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1046 ch->d_func()->setParentAndModel(0, 0);
never executed: ch->d_func()->setParentAndModel(0, 0);
0
1047 items.append(ch);-
1048 }
never executed: end of block
0
1049 d->children.remove(index, col_count);-
1050 }
never executed: end of block
0
1051 d->rows--;-
1052 if (d->model
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1053 d->model->d_func()->rowsRemoved(this, row, 1);
never executed: d->model->d_func()->rowsRemoved(this, row, 1);
0
1054 return
never executed: return items;
items;
never executed: return items;
0
1055}-
1056QList<QStandardItem*> QStandardItem::takeColumn(int column)-
1057{-
1058 QStandardItemPrivate * const d = d_func();-
1059 QList<QStandardItem*> items;-
1060 if ((
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
column < 0)
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(column >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
column >= columnCount())
(column >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1061 return
never executed: return items;
QList<QStandardItem*>();items;
never executed: return items;
0
1062 if (d->model
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1063 d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
never executed: d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
0
1064-
1065 QList<QStandardItem*>const int rowCount = d->rowCount();-
1066 items;.reserve(rowCount);-
1067 for (int row = d->rowCount ()- 1; row >= 0
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
; --row) {
0
1068 int index = d->childIndex(row, column);-
1069 QStandardItem *ch = d->children.at(index);-
1070 if (ch
chDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1071 ch->d_func()->setParentAndModel(0, 0);
never executed: ch->d_func()->setParentAndModel(0, 0);
0
1072 d->children.remove(index);-
1073 items.prepend(ch);-
1074 }
never executed: end of block
0
1075 d->columns--;-
1076 if (d->model
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1077 d->model->d_func()->columnsRemoved(this, column, 1);
never executed: d->model->d_func()->columnsRemoved(this, column, 1);
0
1078 return
never executed: return items;
items;
never executed: return items;
0
1079}-
1080bool QStandardItem::operator<(const QStandardItem &other) const-
1081{-
1082 const int role = model() ? model()->sortRole() : Qt::DisplayRole;-
1083 const QVariant l = data(role), r = other.data(role);-
1084-
1085 if (l.userType() == QVariant::Invalid)-
1086 return false;-
1087 if (r.userType() == QVariant::Invalid)-
1088 return true;-
1089 switch (l.userType()) {-
1090 case QVariant::Int:-
1091 return l.toInt() < r.toInt();-
1092 case QVariant::UInt:-
1093 return l.toUInt() < r.toUInt();-
1094 case QVariant::LongLong:-
1095 return l.toLongLong() < r.toLongLong();-
1096 case QVariant::ULongLong:-
1097 return l.toULongLong() < r.toULongLong();-
1098 case QMetaType::Float:-
1099 return l.toFloat() < r.toFloat();-
1100 case QVariant::Double:-
1101 return l.toDouble() < r.toDouble();-
1102 case QVariant::Char:-
1103 return l.toChar() < r.toChar();-
1104 case QVariant::Date:-
1105 return l.toDate() < r.toDate();-
1106 case QVariant::Time:-
1107 return l.toTime() < r.toTime();-
1108 case QVariant::DateTime:-
1109 return l.toDateTime() < r.toDateTime();-
1110 case QVariant::String:-
1111 default:-
1112 return l.toString().compare(r.toString()) < 0;-
1113 }-
1114}-
1115void QStandardItem::sortChildren(int column, Qt::SortOrder order)-
1116{-
1117 QStandardItemPrivate * const d = d_func();-
1118 if ((column < 0) || (rowCount() == 0))-
1119 return;-
1120-
1121 QList<QPersistentModelIndex> parents;-
1122 if (d->model) {-
1123 parents << index();-
1124 d->model->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint);-
1125 }-
1126 d->sortChildren(column, order);-
1127 if (d->model)-
1128 d->model->layoutChanged(parents, QAbstractItemModel::VerticalSortHint);-
1129}-
1130QStandardItem *QStandardItem::clone() const-
1131{-
1132 return new QStandardItem(*this);-
1133}-
1134int QStandardItem::type() const-
1135{-
1136 return Type;-
1137}-
1138void QStandardItem::read(QDataStream &in)-
1139{-
1140 QStandardItemPrivate * const d = d_func();-
1141 in >> d->values;-
1142 qint32 flags;-
1143 in >> flags;-
1144 setFlags(Qt::ItemFlags(flags));-
1145}-
1146-
1147-
1148-
1149-
1150-
1151-
1152-
1153void QStandardItem::write(QDataStream &out) const-
1154{-
1155 const QStandardItemPrivate * const d = d_func();-
1156 out << d->values;-
1157 out << flags();-
1158}-
1159QDataStream &operator>>(QDataStream &in, QStandardItem &item)-
1160{-
1161 item.read(in);-
1162 return in;-
1163}-
1164QDataStream &operator<<(QDataStream &out, const QStandardItem &item)-
1165{-
1166 item.write(out);-
1167 return out;-
1168}-
1169QStandardItemModel::QStandardItemModel(QObject *parent)-
1170 : QAbstractItemModel(*new QStandardItemModelPrivate, parent)-
1171{-
1172 QStandardItemModelPrivate * const d = d_func();-
1173 d->init();-
1174 d->root->d_func()->setModel(this);-
1175}-
1176-
1177-
1178-
1179-
1180-
1181QStandardItemModel::QStandardItemModel(int rows, int columns, QObject *parent)-
1182 : QAbstractItemModel(*new QStandardItemModelPrivate, parent)-
1183{-
1184 QStandardItemModelPrivate * const d = d_func();-
1185 d->init();-
1186 d->root->insertColumns(0, columns);-
1187 d->columnHeaderItems.insert(0, columns, 0);-
1188 d->root->insertRows(0, rows);-
1189 d->rowHeaderItems.insert(0, rows, 0);-
1190 d->root->d_func()->setModel(this);-
1191}-
1192-
1193-
1194-
1195-
1196QStandardItemModel::QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent)-
1197 : QAbstractItemModel(dd, parent)-
1198{-
1199 QStandardItemModelPrivate * const d = d_func();-
1200 d->init();-
1201}-
1202-
1203-
1204-
1205-
1206QStandardItemModel::~QStandardItemModel()-
1207{-
1208}-
1209-
1210-
1211-
1212-
1213void QStandardItemModel::setItemRoleNames(const QHash<int,QByteArray> &roleNames)-
1214{-
1215 QStandardItemModelPrivate * const d = d_func();-
1216 d->roleNames = roleNames;-
1217}-
1218-
1219-
1220-
1221-
1222-
1223-
1224-
1225void QStandardItemModel::clear()-
1226{-
1227 QStandardItemModelPrivate * const d = d_func();-
1228 beginResetModel();-
1229 d->root.reset(new QStandardItem);-
1230 d->root->setFlags(Qt::ItemIsDropEnabled);-
1231 d->root->d_func()->setModel(this);-
1232 qDeleteAll(d->columnHeaderItems);-
1233 d->columnHeaderItems.clear();-
1234 qDeleteAll(d->rowHeaderItems);-
1235 d->rowHeaderItems.clear();-
1236 endResetModel();-
1237}
never executed: end of block
0
1238QStandardItem *QStandardItemModel::itemFromIndex(const QModelIndex &index) const-
1239{-
1240 const QStandardItemModelPrivate * const d = d_func();-
1241 if ((index.row() < 0) || (index.column() < 0) || (index.model() != this))-
1242 return 0;-
1243 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());-
1244 if (parent == 0)-
1245 return 0;-
1246 QStandardItem *item = parent->child(index.row(), index.column());-
1247-
1248 if (item == 0) {-
1249 item = d->createItem();-
1250 parent->d_func()->setChild(index.row(), index.column(), item);-
1251 }-
1252 return item;-
1253}-
1254QModelIndex QStandardItemModel::indexFromItem(const QStandardItem *item) const-
1255{-
1256 if (item && item->d_func()->parent) {-
1257 QPair<int, int> pos = item->d_func()->position();-
1258 return createIndex(pos.first, pos.second, item->d_func()->parent);-
1259 }-
1260 return QModelIndex();-
1261}-
1262void QStandardItemModel::setRowCount(int rows)-
1263{-
1264 QStandardItemModelPrivate * const d = d_func();-
1265 d->root->setRowCount(rows);-
1266}-
1267void QStandardItemModel::setColumnCount(int columns)-
1268{-
1269 QStandardItemModelPrivate * const d = d_func();-
1270 d->root->setColumnCount(columns);-
1271}-
1272void QStandardItemModel::setItem(int row, int column, QStandardItem *item)-
1273{-
1274 QStandardItemModelPrivate * const d = d_func();-
1275 d->root->d_func()->setChild(row, column, item, true);-
1276}-
1277QStandardItem *QStandardItemModel::item(int row, int column) const-
1278{-
1279 const QStandardItemModelPrivate * const d = d_func();-
1280 return d->root->child(row, column);-
1281}-
1282QStandardItem *QStandardItemModel::invisibleRootItem() const-
1283{-
1284 const QStandardItemModelPrivate * const d = d_func();-
1285 return d->root.data();-
1286}-
1287void QStandardItemModel::setHorizontalHeaderItem(int column, QStandardItem *item)-
1288{-
1289 QStandardItemModelPrivate * const d = d_func();-
1290 if (column < 0)-
1291 return;-
1292 if (columnCount() <= column)-
1293 setColumnCount(column + 1);-
1294-
1295 QStandardItem *oldItem = d->columnHeaderItems.at(column);-
1296 if (item == oldItem)-
1297 return;-
1298-
1299 if (item) {-
1300 if (item->model() == 0) {-
1301 item->d_func()->setModel(this);-
1302 } else {-
1303 QMessageLogger(__FILE__, 23422355, __PRETTY_FUNCTION__).warning("QStandardItem::setHorizontalHeaderItem: Ignoring duplicate insertion of item %p",-
1304 item);-
1305 return;-
1306 }-
1307 }-
1308-
1309 if (oldItem)-
1310 oldItem->d_func()->setModel(0);-
1311 delete oldItem;-
1312-
1313 d->columnHeaderItems.replace(column, item);-
1314 headerDataChanged(Qt::Horizontal, column, column);-
1315}-
1316QStandardItem *QStandardItemModel::horizontalHeaderItem(int column) const-
1317{-
1318 const QStandardItemModelPrivate * const d = d_func();-
1319 if ((column < 0) || (column >= columnCount()))-
1320 return 0;-
1321 return d->columnHeaderItems.at(column);-
1322}-
1323void QStandardItemModel::setVerticalHeaderItem(int row, QStandardItem *item)-
1324{-
1325 QStandardItemModelPrivate * const d = d_func();-
1326 if (row < 0)-
1327 return;-
1328 if (rowCount() <= row)-
1329 setRowCount(row + 1);-
1330-
1331 QStandardItem *oldItem = d->rowHeaderItems.at(row);-
1332 if (item == oldItem)-
1333 return;-
1334-
1335 if (item) {-
1336 if (item->model() == 0) {-
1337 item->d_func()->setModel(this);-
1338 } else {-
1339 QMessageLogger(__FILE__, 23982411, __PRETTY_FUNCTION__).warning("QStandardItem::setVerticalHeaderItem: Ignoring duplicate insertion of item %p",-
1340 item);-
1341 return;-
1342 }-
1343 }-
1344-
1345 if (oldItem)-
1346 oldItem->d_func()->setModel(0);-
1347 delete oldItem;-
1348-
1349 d->rowHeaderItems.replace(row, item);-
1350 headerDataChanged(Qt::Vertical, row, row);-
1351}-
1352QStandardItem *QStandardItemModel::verticalHeaderItem(int row) const-
1353{-
1354 const QStandardItemModelPrivate * const d = d_func();-
1355 if ((row < 0) || (row >= rowCount()))-
1356 return 0;-
1357 return d->rowHeaderItems.at(row);-
1358}-
1359void QStandardItemModel::setHorizontalHeaderLabels(const QStringList &labels)-
1360{-
1361 QStandardItemModelPrivate * const d = d_func();-
1362 if (columnCount() < labels.count())-
1363 setColumnCount(labels.count());-
1364 for (int i = 0; i < labels.count(); ++i) {-
1365 QStandardItem *item = horizontalHeaderItem(i);-
1366 if (!item) {-
1367 item = d->createItem();-
1368 setHorizontalHeaderItem(i, item);-
1369 }-
1370 item->setText(labels.at(i));-
1371 }-
1372}-
1373void QStandardItemModel::setVerticalHeaderLabels(const QStringList &labels)-
1374{-
1375 QStandardItemModelPrivate * const d = d_func();-
1376 if (rowCount() < labels.count())-
1377 setRowCount(labels.count());-
1378 for (int i = 0; i < labels.count(); ++i) {-
1379 QStandardItem *item = verticalHeaderItem(i);-
1380 if (!item) {-
1381 item = d->createItem();-
1382 setVerticalHeaderItem(i, item);-
1383 }-
1384 item->setText(labels.at(i));-
1385 }-
1386}-
1387void QStandardItemModel::setItemPrototype(const QStandardItem *item)-
1388{-
1389 QStandardItemModelPrivate * const d = d_func();-
1390 if (d->itemPrototype != item) {-
1391 delete d->itemPrototype;-
1392 d->itemPrototype = item;-
1393 }-
1394}-
1395const QStandardItem *QStandardItemModel::itemPrototype() const-
1396{-
1397 const QStandardItemModelPrivate * const d = d_func();-
1398 return d->itemPrototype;-
1399}-
1400-
1401-
1402-
1403-
1404-
1405-
1406-
1407QList<QStandardItem*> QStandardItemModel::findItems(const QString &text,-
1408 Qt::MatchFlags flags, int column) const-
1409{-
1410 QModelIndexList indexes = match(index(0, column, QModelIndex()),-
1411 Qt::DisplayRole, text, -1, flags);-
1412 QList<QStandardItem*> items;-
1413 const int numIndexes = indexes.size();-
1414 items.reserve(numIndexes);-
1415 for (int i = 0; i < numIndexes; ++i)-
1416 items.append(itemFromIndex(indexes.at(i)));-
1417 return items;-
1418}-
1419void QStandardItemModel::appendRow(const QList<QStandardItem*> &items)-
1420{-
1421 invisibleRootItem()->appendRow(items);-
1422}-
1423void QStandardItemModel::appendColumn(const QList<QStandardItem*> &items)-
1424{-
1425 invisibleRootItem()->appendColumn(items);-
1426}-
1427void QStandardItemModel::insertRow(int row, const QList<QStandardItem*> &items)-
1428{-
1429 invisibleRootItem()->insertRow(row, items);-
1430}-
1431void QStandardItemModel::insertColumn(int column, const QList<QStandardItem*> &items)-
1432{-
1433 invisibleRootItem()->insertColumn(column, items);-
1434}-
1435QStandardItem *QStandardItemModel::takeItem(int row, int column)-
1436{-
1437 QStandardItemModelPrivate * const d = d_func();-
1438 return d->root->takeChild(row, column);-
1439}-
1440QList<QStandardItem*> QStandardItemModel::takeRow(int row)-
1441{-
1442 QStandardItemModelPrivate * const d = d_func();-
1443 return d->root->takeRow(row);-
1444}-
1445QList<QStandardItem*> QStandardItemModel::takeColumn(int column)-
1446{-
1447 QStandardItemModelPrivate * const d = d_func();-
1448 return d->root->takeColumn(column);-
1449}-
1450QStandardItem *QStandardItemModel::takeHorizontalHeaderItem(int column)-
1451{-
1452 QStandardItemModelPrivate * const d = d_func();-
1453 if ((column < 0) || (column >= columnCount()))-
1454 return 0;-
1455 QStandardItem *headerItem = d->columnHeaderItems.at(column);-
1456 if (headerItem) {-
1457 headerItem->d_func()->setParentAndModel(0, 0);-
1458 d->columnHeaderItems.replace(column, 0);-
1459 }-
1460 return headerItem;-
1461}-
1462QStandardItem *QStandardItemModel::takeVerticalHeaderItem(int row)-
1463{-
1464 QStandardItemModelPrivate * const d = d_func();-
1465 if ((row < 0) || (row >= rowCount()))-
1466 return 0;-
1467 QStandardItem *headerItem = d->rowHeaderItems.at(row);-
1468 if (headerItem) {-
1469 headerItem->d_func()->setParentAndModel(0, 0);-
1470 d->rowHeaderItems.replace(row, 0);-
1471 }-
1472 return headerItem;-
1473}-
1474int QStandardItemModel::sortRole() const-
1475{-
1476 const QStandardItemModelPrivate * const d = d_func();-
1477 return d->sortRole;-
1478}-
1479-
1480void QStandardItemModel::setSortRole(int role)-
1481{-
1482 QStandardItemModelPrivate * const d = d_func();-
1483 d->sortRole = role;-
1484}-
1485-
1486-
1487-
1488-
1489int QStandardItemModel::columnCount(const QModelIndex &parent) const-
1490{-
1491 const QStandardItemModelPrivate * const d = d_func();-
1492 QStandardItem *item = d->itemFromIndex(parent);-
1493 return item ? item->columnCount() : 0;-
1494}-
1495-
1496-
1497-
1498-
1499QVariant QStandardItemModel::data(const QModelIndex &index, int role) const-
1500{-
1501 const QStandardItemModelPrivate * const d = d_func();-
1502 QStandardItem *item = d->itemFromIndex(index);-
1503 return item ? item->data(role) : QVariant();-
1504}-
1505-
1506-
1507-
1508-
1509Qt::ItemFlags QStandardItemModel::flags(const QModelIndex &index) const-
1510{-
1511 const QStandardItemModelPrivate * const d = d_func();-
1512 if (!d->indexValid(index))-
1513 return d->root->flags();-
1514 QStandardItem *item = d->itemFromIndex(index);-
1515 if (item)-
1516 return item->flags();-
1517 return Qt::ItemIsSelectable-
1518 |Qt::ItemIsEnabled-
1519 |Qt::ItemIsEditable-
1520 |Qt::ItemIsDragEnabled-
1521 |Qt::ItemIsDropEnabled;-
1522}-
1523-
1524-
1525-
1526-
1527bool QStandardItemModel::hasChildren(const QModelIndex &parent) const-
1528{-
1529 const QStandardItemModelPrivate * const d = d_func();-
1530 QStandardItem *item = d->itemFromIndex(parent);-
1531 return item ? item->hasChildren() : false;-
1532}-
1533-
1534-
1535-
1536-
1537QModelIndex QStandardItemModel::sibling(int row, int column, const QModelIndex &idx) const-
1538{-
1539 return QAbstractItemModel::sibling(row, column, idx);-
1540}-
1541-
1542-
1543-
1544-
1545QVariant QStandardItemModel::headerData(int section, Qt::Orientation orientation, int role) const-
1546{-
1547 const QStandardItemModelPrivate * const d = d_func();-
1548 if ((section < 0)-
1549 || ((orientation == Qt::Horizontal) && (section >= columnCount()))-
1550 || ((orientation == Qt::Vertical) && (section >= rowCount()))) {-
1551 return QVariant();-
1552 }-
1553 QStandardItem *headerItem = 0;-
1554 if (orientation == Qt::Horizontal)-
1555 headerItem = d->columnHeaderItems.at(section);-
1556 else if (orientation == Qt::Vertical)-
1557 headerItem = d->rowHeaderItems.at(section);-
1558 return headerItem ? headerItem->data(role)-
1559 : QAbstractItemModel::headerData(section, orientation, role);-
1560}-
1561-
1562-
1563-
1564-
1565-
1566-
1567Qt::DropActions QStandardItemModel::supportedDropActions () const-
1568{-
1569 return Qt::CopyAction | Qt::MoveAction;-
1570}-
1571-
1572-
1573-
1574-
1575QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex &parent) const-
1576{-
1577 const QStandardItemModelPrivate * const d = d_func();-
1578 QStandardItem *parentItem = d->itemFromIndex(parent);-
1579 if ((parentItem == 0)-
1580 || (row < 0)-
1581 || (column < 0)-
1582 || (row >= parentItem->rowCount())-
1583 || (column >= parentItem->columnCount())) {-
1584 return QModelIndex();-
1585 }-
1586 return createIndex(row, column, parentItem);-
1587}-
1588-
1589-
1590-
1591-
1592bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent)-
1593{-
1594 QStandardItemModelPrivate * const d = d_func();-
1595 QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();-
1596 if (item == 0)-
1597 return false;-
1598 return item->d_func()->insertColumns(column, count, QList<QStandardItem*>());-
1599}-
1600-
1601-
1602-
1603-
1604bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent)-
1605{-
1606 QStandardItemModelPrivate * const d = d_func();-
1607 QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();-
1608 if (item == 0)-
1609 return false;-
1610 return item->d_func()->insertRows(row, count, QList<QStandardItem*>());-
1611}-
1612-
1613-
1614-
1615-
1616QMap<int, QVariant> QStandardItemModel::itemData(const QModelIndex &index) const-
1617{-
1618 const QStandardItemModelPrivate * const d = d_func();-
1619 QStandardItem *item = d->itemFromIndex(index);-
1620 return item ? item->d_func()->itemData() : QMap<int, QVariant>();-
1621}-
1622-
1623-
1624-
1625-
1626QModelIndex QStandardItemModel::parent(const QModelIndex &child) const-
1627{-
1628 const QStandardItemModelPrivate * const d = d_func();-
1629 if (!d->indexValid(child))-
1630 return QModelIndex();-
1631 QStandardItem *parentItem = static_cast<QStandardItem*>(child.internalPointer());-
1632 return indexFromItem(parentItem);-
1633}-
1634-
1635-
1636-
1637-
1638bool QStandardItemModel::removeColumns(int column, int count, const QModelIndex &parent)-
1639{-
1640 QStandardItemModelPrivate * const d = d_func();-
1641 QStandardItem *item = d->itemFromIndex(parent);-
1642 if ((item == 0) || (count < 1) || (column < 0) || ((column + count) > item->columnCount()))-
1643 return false;-
1644 item->removeColumns(column, count);-
1645 return true;-
1646}-
1647-
1648-
1649-
1650-
1651bool QStandardItemModel::removeRows(int row, int count, const QModelIndex &parent)-
1652{-
1653 QStandardItemModelPrivate * const d = d_func();-
1654 QStandardItem *item = d->itemFromIndex(parent);-
1655 if ((item == 0) || (count < 1) || (row < 0) || ((row + count) > item->rowCount()))-
1656 return false;-
1657 item->removeRows(row, count);-
1658 return true;-
1659}-
1660-
1661-
1662-
1663-
1664int QStandardItemModel::rowCount(const QModelIndex &parent) const-
1665{-
1666 const QStandardItemModelPrivate * const d = d_func();-
1667 QStandardItem *item = d->itemFromIndex(parent);-
1668 return item ? item->rowCount() : 0;-
1669}-
1670-
1671-
1672-
1673-
1674bool QStandardItemModel::setData(const QModelIndex &index, const QVariant &value, int role)-
1675{-
1676 if (!index.isValid())-
1677 return false;-
1678 QStandardItem *item = itemFromIndex(index);-
1679 if (item == 0)-
1680 return false;-
1681 item->setData(value, role);-
1682 return true;-
1683}-
1684-
1685-
1686-
1687-
1688bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)-
1689{-
1690 QStandardItemModelPrivate * const d = d_func();-
1691 if ((section < 0)-
1692 || ((orientation == Qt::Horizontal) && (section >= columnCount()))-
1693 || ((orientation == Qt::Vertical) && (section >= rowCount()))) {-
1694 return false;-
1695 }-
1696 QStandardItem *headerItem = 0;-
1697 if (orientation == Qt::Horizontal) {-
1698 headerItem = d->columnHeaderItems.at(section);-
1699 if (headerItem == 0) {-
1700 headerItem = d->createItem();-
1701 headerItem->d_func()->setModel(this);-
1702 d->columnHeaderItems.replace(section, headerItem);-
1703 }-
1704 } else if (orientation == Qt::Vertical) {-
1705 headerItem = d->rowHeaderItems.at(section);-
1706 if (headerItem == 0) {-
1707 headerItem = d->createItem();-
1708 headerItem->d_func()->setModel(this);-
1709 d->rowHeaderItems.replace(section, headerItem);-
1710 }-
1711 }-
1712 if (headerItem) {-
1713 headerItem->setData(value, role);-
1714 return true;-
1715 }-
1716 return false;-
1717}-
1718-
1719-
1720-
1721-
1722bool QStandardItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)-
1723{-
1724 QStandardItem *item = itemFromIndex(index);-
1725 if (item == 0)-
1726 return false;-
1727 item->d_func()->setItemData(roles);-
1728 return true;-
1729}-
1730-
1731-
1732-
1733-
1734void QStandardItemModel::sort(int column, Qt::SortOrder order)-
1735{-
1736 QStandardItemModelPrivate * const d = d_func();-
1737 d->root->sortChildren(column, order);-
1738}-
1739-
1740-
1741-
1742-
1743QStringList QStandardItemModel::mimeTypes() const-
1744{-
1745 return
never executed: return QAbstractItemModel::mimeTypes() << qStandardItemModelDataListMimeType();
QAbstractItemModel::mimeTypes() << QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType();
never executed: return QAbstractItemModel::mimeTypes() << qStandardItemModelDataListMimeType();
0
1746}-
1747-
1748-
1749-
1750-
1751QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const-
1752{-
1753 QMimeData *data = QAbstractItemModel::mimeData(indexes);-
1754 if(!data
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1755 return
never executed: return 0;
0;
never executed: return 0;
0
1756-
1757 const QString format = QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType();-
1758 if (!mimeTypes().contains(format)
!mimeTypes().contains(format)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1759 return
never executed: return data;
data;
never executed: return data;
0
1760 QByteArray encoded;-
1761 QDataStream stream(&encoded, QIODevice::WriteOnly);-
1762-
1763 QSet<QStandardItem*> itemsSet;-
1764 QStack<QStandardItem*> stack;-
1765 itemsSet.reserve(indexes.count());-
1766 stack.reserve(indexes.count());-
1767 for (int i = 0; i < indexes.count()
i < indexes.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1768 if (QStandardItem *item = itemFromIndex(indexes.at(i))
QStandardItem ...indexes.at(i))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1769 itemsSet << item;-
1770 stack.push(item);-
1771 }
never executed: end of block
else {
0
1772 QMessageLogger(__FILE__, 30023015, __PRETTY_FUNCTION__).warning() << ("QStandardItemModel::mimeData: No item associated with invalid index";);-
1773 return
never executed: return 0;
0;
never executed: return 0;
0
1774 }-
1775 }-
1776-
1777-
1778 {-
1779 QSet<QStandardItem *> seen;-
1780 while (!stack.isEmpty()
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1781 QStandardItem *itm = stack.pop();-
1782 if (seen.contains(itm)
seen.contains(itm)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1783 continue;
never executed: continue;
0
1784 seen.insert(itm);-
1785-
1786 const QVector<QStandardItem*> &childList = itm->d_func()->children;-
1787 for (int i = 0; i < childList.count()
i < childList.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1788 QStandardItem *chi = childList.at(i);-
1789 if (chi
chiDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1790 QSet<QStandardItem *>::iterator it =itemsSet.find(chi);-
iferase(it != itemsSet.end()) {itemsSet.eraseconstFind(it);
}chi));
1791 stack.push(chi);-
1792 }
never executed: end of block
0
1793 }
never executed: end of block
0
1794 }
never executed: end of block
0
1795 }-
1796-
1797 stack.reserve(itemsSet.count());-
1798 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(itemsSet)>::type> _container_((itemsSet)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QStandardItem *item = *_container_.i; _container_.control; _container_.control = 0) {: qAsConst(itemsSet))-
1799 stack.push(item);
never executed: stack.push(item);
0
1800-
1801-
1802 }while (!stack.isEmpty()
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1803 QStandardItem *item = stack.pop();-
1804 if (itemsSet.contains(item)
itemsSet.contains(item)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1805 stream << item->row() << item->column();
never executed: stream << item->row() << item->column();
0
1806-
1807 stream << *item << item->columnCount() << item->d_ptr->children.count();-
1808 stack += item->d_ptr->children;-
1809 }
never executed: end of block
0
1810-
1811 data->setData(format, encoded);-
1812 return
never executed: return data;
data;
never executed: return data;
0
1813}-
1814-
1815-
1816-
1817-
1818-
1819-
1820void QStandardItemModelPrivate::decodeDataRecursive(QDataStream &stream, QStandardItem *item)-
1821{-
1822 int colCount, childCount;-
1823 stream >> *item;-
1824 stream >> colCount >> childCount;-
1825 item->setColumnCount(colCount);-
1826-
1827 int childPos = childCount;-
1828-
1829 while(childPos > 0) {-
1830 childPos--;-
1831 QStandardItem *child = createItem();-
1832 decodeDataRecursive(stream, child);-
1833 item->setChild( childPos / colCount, childPos % colCount, child);-
1834 }-
1835}-
1836-
1837-
1838-
1839-
1840-
1841bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action,-
1842 int row, int column, const QModelIndex &parent)-
1843{-
1844 QStandardItemModelPrivate * const d = d_func();-
1845-
1846 if (!data
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
|| !(action == Qt::CopyAction
action == Qt::CopyActionDescription
TRUEnever evaluated
FALSEnever evaluated
|| action == Qt::MoveAction
action == Qt::MoveActionDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
1847 return
never executed: return false;
false;
never executed: return false;
0
1848-
1849 const QString format = QLatin1String("application/x-qstandarditemmodeldatalist");qStandardItemModelDataListMimeType();-
1850 if (!data->hasFormat(format)
!data->hasFormat(format)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1851 return
never executed: return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
QAbstractItemModel::dropMimeData(data, action, row, column, parent);
never executed: return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
0
1852-
1853 if (row > rowCount(parent)
row > rowCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1854 row = rowCount(parent);
never executed: row = rowCount(parent);
0
1855 if (row == -1
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1856 row = rowCount(parent);
never executed: row = rowCount(parent);
0
1857 if (column == -1
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1858 column = 0;
never executed: column = 0;
0
1859-
1860-
1861 QByteArray encoded = data->data(format);-
1862 QDataStream stream(&encoded, QIODevice::ReadOnly);-
1863-
1864-
1865-
1866-
1867 int top = 2147483647;-
1868 int left = 2147483647;-
1869 int bottom = 0;-
1870 int right = 0;-
1871 QVector<int> rows, columns;-
1872 QVector<QStandardItem *> items;-
1873-
1874 while (!stream.atEnd()
!stream.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1875 int r, c;-
1876 QStandardItem *item = d->createItem();-
1877 stream >> r >> c;-
1878 d->decodeDataRecursive(stream, item);-
1879-
1880 rows.append(r);-
1881 columns.append(c);-
1882 items.append(item);-
1883 top = qMin(r, top);-
1884 left = qMin(c, left);-
1885 bottom = qMax(r, bottom);-
1886 right = qMax(c, right);-
1887 }
never executed: end of block
0
1888-
1889-
1890-
1891 int dragRowCount = 0;-
1892 int dragColumnCount = right - left + 1;-
1893-
1894-
1895 QVector<int> rowsToInsert(bottom + 1);-
1896 for (int i = 0; i < rows.count()
i < rows.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1897 rowsToInsert[rows.at(i)] = 1;
never executed: rowsToInsert[rows.at(i)] = 1;
0
1898 for (int i = 0; i < rowsToInsert.count()
i < rowsToInsert.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1899 if (rowsToInsert[.at(i]) == 1
rowsToInsert.at(i) == 1Description
TRUEnever evaluated
FALSEnever evaluated
){
0
1900 rowsToInsert[i] = dragRowCount;-
1901 ++dragRowCount;-
1902 }
never executed: end of block
0
1903 }
never executed: end of block
0
1904 for (int i = 0; i < rows.count()
i < rows.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
1905 rows[i] = top + rowsToInsert[.at(rows[.at(i]];));
never executed: rows[i] = top + rowsToInsert.at(rows.at(i));
0
1906-
1907 QBitArray isWrittenTo(dragRowCount * dragColumnCount);-
1908-
1909-
1910 int colCount = columnCount(parent);-
1911 if (colCount < dragColumnCount + column
colCount < dra...Count + columnDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1912 insertColumns(colCount, dragColumnCount + column - colCount, parent);-
1913 colCount = columnCount(parent);-
1914 }
never executed: end of block
0
1915 insertRows(row, dragRowCount, parent);-
1916-
1917 row = qMax(0, row);-
1918 column = qMax(0, column);-
1919-
1920 QStandardItem *parentItem = itemFromIndex (parent);-
1921 if (!parentItem
!parentItemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1922 parentItem = invisibleRootItem();
never executed: parentItem = invisibleRootItem();
0
1923-
1924 QVector<QPersistentModelIndex> newIndexes(items.size());-
1925-
1926 for (int j = 0; j < items.size()
j < items.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++j) {
0
1927 int relativeRow = rows.at(j) - top;-
1928 int relativeColumn = columns.at(j) - left;-
1929 int destinationRow = relativeRow + row;-
1930 int destinationColumn = relativeColumn + column;-
1931 int flat = (relativeRow * dragColumnCount) + relativeColumn;-
1932-
1933 if (destinationColumn >= colCount
destinationColumn >= colCountDescription
TRUEnever evaluated
FALSEnever evaluated
|| isWrittenTo.testBit(flat)
isWrittenTo.testBit(flat)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1934 destinationColumn = qBound(column, destinationColumn, colCount - 1);-
1935 destinationRow = row + dragRowCount;-
1936 insertRows(row + dragRowCount, 1, parent);-
1937 flat = (dragRowCount * dragColumnCount) + relativeColumn;-
1938 isWrittenTo.resize(++dragRowCount * dragColumnCount);-
1939 }
never executed: end of block
0
1940 if (!isWrittenTo.testBit(flat)
!isWrittenTo.testBit(flat)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1941 newIndexes[j] = index(destinationRow, destinationColumn, parentItem->index());-
1942 isWrittenTo.setBit(flat);-
1943 }
never executed: end of block
0
1944 }
never executed: end of block
0
1945-
1946 for(int k = 0; k < newIndexes.size()
k < newIndexes.size()Description
TRUEnever evaluated
FALSEnever evaluated
; k++) {
0
1947 if (newIndexes.at(k).isValid()
newIndexes.at(k).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1948 parentItem->setChild(newIndexes.at(k).row(), newIndexes.at(k).column(), items.at(k));-
1949 }
never executed: end of block
else {
0
1950 delete items.at(k);-
1951 }
never executed: end of block
0
1952 }-
1953-
1954 return
never executed: return true;
true;
never executed: return true;
0
1955}-
1956-
1957-
1958-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9