qstandarditemmodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/itemmodels/qstandarditemmodel.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qstandarditemmodel.h"-
35-
36#ifndef QT_NO_STANDARDITEMMODEL-
37-
38#include <QtCore/qdatetime.h>-
39#include <QtCore/qlist.h>-
40#include <QtCore/qmap.h>-
41#include <QtCore/qpair.h>-
42#include <QtCore/qvariant.h>-
43#include <QtCore/qvector.h>-
44#include <QtCore/qstringlist.h>-
45#include <QtCore/qbitarray.h>-
46#include <QtCore/qmimedata.h>-
47-
48#include <private/qstandarditemmodel_p.h>-
49#include <qdebug.h>-
50#include <algorithm>-
51-
52QT_BEGIN_NAMESPACE-
53-
54class QStandardItemModelLessThan-
55{-
56public:-
57 inline QStandardItemModelLessThan()-
58 { }-
59-
60 inline bool operator()(const QPair<QStandardItem*, int> &l,-
61 const QPair<QStandardItem*, int> &r) const-
62 {-
63 return *(l.first) < *(r.first);
never executed: return *(l.first) < *(r.first);
0
64 }-
65};-
66-
67class QStandardItemModelGreaterThan-
68{-
69public:-
70 inline QStandardItemModelGreaterThan()-
71 { }-
72-
73 inline bool operator()(const QPair<QStandardItem*, int> &l,-
74 const QPair<QStandardItem*, int> &r) const-
75 {-
76 return *(r.first) < *(l.first);
never executed: return *(r.first) < *(l.first);
0
77 }-
78};-
79-
80/*!-
81 \internal-
82*/-
83QStandardItemPrivate::~QStandardItemPrivate()-
84{-
85 QVector<QStandardItem*>::const_iterator it;-
86 for (it = children.constBegin(); it != children.constEnd(); ++it) {
it != children.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
87 QStandardItem *child = *it;-
88 if (child)
childDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 child->d_func()->setModel(0);
never executed: child->d_func()->setModel(0);
0
90 delete child;-
91 }
never executed: end of block
0
92 children.clear();-
93 if (parent && model)
parentDescription
TRUEnever evaluated
FALSEnever evaluated
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
94 parent->d_func()->childDeleted(q_func());
never executed: parent->d_func()->childDeleted(q_func());
0
95}
never executed: end of block
0
96-
97/*!-
98 \internal-
99*/-
100QPair<int, int> QStandardItemPrivate::position() const-
101{-
102 if (QStandardItem *par = parent) {
QStandardItem *par = parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
103 int idx = par->d_func()->childIndex(q_func());-
104 if (idx == -1)
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
105 return QPair<int, int>(-1, -1);
never executed: return QPair<int, int>(-1, -1);
0
106 return QPair<int, int>(idx / par->columnCount(), idx % par->columnCount());
never executed: return QPair<int, int>(idx / par->columnCount(), idx % par->columnCount());
0
107 }-
108 // ### support header items?-
109 return QPair<int, int>(-1, -1);
never executed: return QPair<int, int>(-1, -1);
0
110}-
111-
112/*!-
113 \internal-
114*/-
115void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item,-
116 bool emitChanged)-
117{-
118 Q_Q(QStandardItem);-
119 if (item == q) {
item == qDescription
TRUEnever evaluated
FALSEnever evaluated
0
120 qWarning("QStandardItem::setChild: Can't make an item a child of itself %p",-
121 item);-
122 return;
never executed: return;
0
123 }-
124 if ((row < 0) || (column < 0))
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
125 return;
never executed: return;
0
126 if (rows <= row)
rows <= rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
127 q->setRowCount(row + 1);
never executed: q->setRowCount(row + 1);
0
128 if (columns <= column)
columns <= columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 q->setColumnCount(column + 1);
never executed: q->setColumnCount(column + 1);
0
130 int index = childIndex(row, column);-
131 Q_ASSERT(index != -1);-
132 QStandardItem *oldItem = children.at(index);-
133 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 return;
never executed: return;
0
135-
136 if (model && emitChanged) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
emitChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
137 emit model->layoutAboutToBeChanged();-
138 }
never executed: end of block
0
139-
140 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
141 if (item->d_func()->parent == 0) {
item->d_func()->parent == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
142 item->d_func()->setParentAndModel(q, model);-
143 } else {
never executed: end of block
0
144 qWarning("QStandardItem::setChild: Ignoring duplicate insertion of item %p",-
145 item);-
146 return;
never executed: return;
0
147 }-
148 }-
149 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
150 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
151 delete oldItem;-
152 children.replace(index, item);-
153-
154 if (model && emitChanged)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
emitChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
155 emit model->layoutChanged();
never executed: model->layoutChanged();
0
156-
157 if (emitChanged && model)
emitChangedDescription
TRUEnever evaluated
FALSEnever evaluated
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
158 model->d_func()->itemChanged(item);
never executed: model->d_func()->itemChanged(item);
0
159}
never executed: end of block
0
160-
161-
162/*!-
163 \internal-
164*/-
165void QStandardItemPrivate::changeFlags(bool enable, Qt::ItemFlags f)-
166{-
167 Q_Q(QStandardItem);-
168 Qt::ItemFlags flags = q->flags();-
169 if (enable)
enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 flags |= f;
never executed: flags |= f;
0
171 else-
172 flags &= ~f;
never executed: flags &= ~f;
0
173 q->setFlags(flags);-
174}
never executed: end of block
0
175-
176/*!-
177 \internal-
178*/-
179void QStandardItemPrivate::childDeleted(QStandardItem *child)-
180{-
181 int index = childIndex(child);-
182 Q_ASSERT(index != -1);-
183 children.replace(index, 0);-
184}
never executed: end of block
0
185-
186/*!-
187 \internal-
188*/-
189void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles)-
190{-
191 Q_Q(QStandardItem);-
192-
193 //let's build the vector of new values-
194 QVector<QStandardItemData> newValues;-
195 QMap<int, QVariant>::const_iterator it;-
196 for (it = roles.begin(); it != roles.end(); ++it) {
it != roles.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
197 QVariant value = it.value();-
198 if (value.isValid()) {
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
199 int role = it.key();-
200 role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
(role == Qt::EditRole)Description
TRUEnever evaluated
FALSEnever evaluated
0
201 QStandardItemData wid(role,it.value());-
202 newValues.append(wid);-
203 }
never executed: end of block
0
204 }
never executed: end of block
0
205-
206 if (values!=newValues) {
values!=newValuesDescription
TRUEnever evaluated
FALSEnever evaluated
0
207 values=newValues;-
208 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
209 model->d_func()->itemChanged(q);
never executed: model->d_func()->itemChanged(q);
0
210 }
never executed: end of block
0
211}
never executed: end of block
0
212-
213/*!-
214 \internal-
215*/-
216const QMap<int, QVariant> QStandardItemPrivate::itemData() const-
217{-
218 QMap<int, QVariant> result;-
219 QVector<QStandardItemData>::const_iterator it;-
220 for (it = values.begin(); it != values.end(); ++it)
it != values.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
221 result.insert((*it).role, (*it).value);
never executed: result.insert((*it).role, (*it).value);
0
222 return result;
never executed: return result;
0
223}-
224-
225/*!-
226 \internal-
227*/-
228void QStandardItemPrivate::sortChildren(int column, Qt::SortOrder order)-
229{-
230 Q_Q(QStandardItem);-
231 if (column >= columnCount())
column >= columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
232 return;
never executed: return;
0
233-
234 QVector<QPair<QStandardItem*, int> > sortable;-
235 QVector<int> unsortable;-
236-
237 sortable.reserve(rowCount());-
238 unsortable.reserve(rowCount());-
239-
240 for (int row = 0; row < rowCount(); ++row) {
row < rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
241 QStandardItem *itm = q->child(row, column);-
242 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
243 sortable.append(QPair<QStandardItem*,int>(itm, row));
never executed: sortable.append(QPair<QStandardItem*,int>(itm, row));
0
244 else-
245 unsortable.append(row);
never executed: unsortable.append(row);
0
246 }-
247-
248 if (order == Qt::AscendingOrder) {
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
249 QStandardItemModelLessThan lt;-
250 std::stable_sort(sortable.begin(), sortable.end(), lt);-
251 } else {
never executed: end of block
0
252 QStandardItemModelGreaterThan gt;-
253 std::stable_sort(sortable.begin(), sortable.end(), gt);-
254 }
never executed: end of block
0
255-
256 QModelIndexList changedPersistentIndexesFrom, changedPersistentIndexesTo;-
257 QVector<QStandardItem*> sorted_children(children.count());-
258 for (int i = 0; i < rowCount(); ++i) {
i < rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
259 int r = (i < sortable.count()
i < sortable.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
260 ? sortable.at(i).second-
261 : unsortable.at(i - sortable.count()));-
262 for (int c = 0; c < columnCount(); ++c) {
c < columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
263 QStandardItem *itm = q->child(r, c);-
264 sorted_children[childIndex(i, c)] = itm;-
265 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
266 QModelIndex from = model->createIndex(r, c, q);-
267 if (model->d_func()->persistent.indexes.contains(from)) {
model->d_func(...contains(from)Description
TRUEnever evaluated
FALSEnever evaluated
0
268 QModelIndex to = model->createIndex(i, c, q);-
269 changedPersistentIndexesFrom.append(from);-
270 changedPersistentIndexesTo.append(to);-
271 }
never executed: end of block
0
272 }
never executed: end of block
0
273 }
never executed: end of block
0
274 }
never executed: end of block
0
275-
276 children = sorted_children;-
277-
278 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
279 model->changePersistentIndexList(changedPersistentIndexesFrom, changedPersistentIndexesTo);-
280 }
never executed: end of block
0
281-
282 QVector<QStandardItem*>::iterator it;-
283 for (it = children.begin(); it != children.end(); ++it) {
it != children.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
284 if (*it)
*itDescription
TRUEnever evaluated
FALSEnever evaluated
0
285 (*it)->d_func()->sortChildren(column, order);
never executed: (*it)->d_func()->sortChildren(column, order);
0
286 }
never executed: end of block
0
287}
never executed: end of block
0
288-
289/*!-
290 \internal-
291 set the model of this item and all its children-
292 */-
293void QStandardItemPrivate::setModel(QStandardItemModel *mod)-
294{-
295 if (children.isEmpty()) {
children.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
296 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
297 model->d_func()->invalidatePersistentIndex(model->indexFromItem(q_ptr));
never executed: model->d_func()->invalidatePersistentIndex(model->indexFromItem(q_ptr));
0
298 model = mod;-
299 } else {
never executed: end of block
0
300 QStack<QStandardItem*> stack;-
301 stack.push(q_ptr);-
302 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
303 QStandardItem *itm = stack.pop();-
304 if (itm->d_func()->model) {
itm->d_func()->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
305 itm->d_func()->model->d_func()->invalidatePersistentIndex(itm->d_func()->model->indexFromItem(itm));-
306 }
never executed: end of block
0
307 itm->d_func()->model = mod;-
308 const QVector<QStandardItem*> &childList = itm->d_func()->children;-
309 for (int i = 0; i < childList.count(); ++i) {
i < childList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
310 QStandardItem *chi = childList.at(i);-
311 if (chi)
chiDescription
TRUEnever evaluated
FALSEnever evaluated
0
312 stack.push(chi);
never executed: stack.push(chi);
0
313 }
never executed: end of block
0
314 }
never executed: end of block
0
315 }
never executed: end of block
0
316}-
317-
318/*!-
319 \internal-
320*/-
321QStandardItemModelPrivate::QStandardItemModelPrivate()-
322 : root(new QStandardItem),-
323 itemPrototype(0),-
324 sortRole(Qt::DisplayRole)-
325{-
326 root->setFlags(Qt::ItemIsDropEnabled);-
327}
never executed: end of block
0
328-
329/*!-
330 \internal-
331*/-
332QStandardItemModelPrivate::~QStandardItemModelPrivate()-
333{-
334 delete itemPrototype;-
335 qDeleteAll(columnHeaderItems);-
336 qDeleteAll(rowHeaderItems);-
337}
never executed: end of block
0
338-
339/*!-
340 \internal-
341*/-
342void QStandardItemModelPrivate::init()-
343{-
344 Q_Q(QStandardItemModel);-
345 QObject::connect(q, SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
346 q, SLOT(_q_emitItemChanged(QModelIndex,QModelIndex)));-
347}
never executed: end of block
0
348-
349/*!-
350 \internal-
351*/-
352void QStandardItemModelPrivate::_q_emitItemChanged(const QModelIndex &topLeft,-
353 const QModelIndex &bottomRight)-
354{-
355 Q_Q(QStandardItemModel);-
356 QModelIndex parent = topLeft.parent();-
357 for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
row <= bottomRight.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
358 for (int column = topLeft.column(); column <= bottomRight.column(); ++column) {
column <= bottomRight.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
359 QModelIndex index = q->index(row, column, parent);-
360 if (QStandardItem *item = itemFromIndex(index))
QStandardItem ...omIndex(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
361 emit q->itemChanged(item);
never executed: q->itemChanged(item);
0
362 }
never executed: end of block
0
363 }
never executed: end of block
0
364}
never executed: end of block
0
365-
366/*!-
367 \internal-
368*/-
369bool QStandardItemPrivate::insertRows(int row, const QList<QStandardItem*> &items)-
370{-
371 Q_Q(QStandardItem);-
372 if ((row < 0) || (row > rowCount()))
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(row > rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
373 return false;
never executed: return false;
0
374 int count = items.count();-
375 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
376 model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);
never executed: model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);
0
377 if (rowCount() == 0) {
rowCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
378 if (columnCount() == 0)
columnCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
379 q->setColumnCount(1);
never executed: q->setColumnCount(1);
0
380 children.resize(columnCount() * count);-
381 rows = count;-
382 } else {
never executed: end of block
0
383 rows += count;-
384 int index = childIndex(row, 0);-
385 if (index != -1)
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
386 children.insert(index, columnCount() * count, 0);
never executed: children.insert(index, columnCount() * count, 0);
0
387 }
never executed: end of block
0
388 for (int i = 0; i < items.count(); ++i) {
i < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
389 QStandardItem *item = items.at(i);-
390 item->d_func()->model = model;-
391 item->d_func()->parent = q;-
392 int index = childIndex(i + row, 0);-
393 children.replace(index, item);-
394 }
never executed: end of block
0
395 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
396 model->d_func()->rowsInserted(q, row, count);
never executed: model->d_func()->rowsInserted(q, row, count);
0
397 return true;
never executed: return true;
0
398}-
399-
400bool QStandardItemPrivate::insertRows(int row, int count, const QList<QStandardItem*> &items)-
401{-
402 Q_Q(QStandardItem);-
403 if ((count < 1) || (row < 0) || (row > rowCount()))
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(row > rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
404 return false;
never executed: return false;
0
405 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
406 model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);
never executed: model->d_func()->rowsAboutToBeInserted(q, row, row + count - 1);
0
407 if (rowCount() == 0) {
rowCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
408 children.resize(columnCount() * count);-
409 rows = count;-
410 } else {
never executed: end of block
0
411 rows += count;-
412 int index = childIndex(row, 0);-
413 if (index != -1)
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
414 children.insert(index, columnCount() * count, 0);
never executed: children.insert(index, columnCount() * count, 0);
0
415 }
never executed: end of block
0
416 if (!items.isEmpty()) {
!items.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
417 int index = childIndex(row, 0);-
418 int limit = qMin(items.count(), columnCount() * count);-
419 for (int i = 0; i < limit; ++i) {
i < limitDescription
TRUEnever evaluated
FALSEnever evaluated
0
420 QStandardItem *item = items.at(i);-
421 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
422 if (item->d_func()->parent == 0) {
item->d_func()->parent == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
423 item->d_func()->setParentAndModel(q, model);-
424 } else {
never executed: end of block
0
425 qWarning("QStandardItem::insertRows: Ignoring duplicate insertion of item %p",-
426 item);-
427 item = 0;-
428 }
never executed: end of block
0
429 }-
430 children.replace(index, item);-
431 ++index;-
432 }
never executed: end of block
0
433 }
never executed: end of block
0
434 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
435 model->d_func()->rowsInserted(q, row, count);
never executed: model->d_func()->rowsInserted(q, row, count);
0
436 return true;
never executed: return true;
0
437}-
438-
439/*!-
440 \internal-
441*/-
442bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QStandardItem*> &items)-
443{-
444 Q_Q(QStandardItem);-
445 if ((count < 1) || (column < 0) || (column > columnCount()))
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(column > columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
446 return false;
never executed: return false;
0
447 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 model->d_func()->columnsAboutToBeInserted(q, column, column + count - 1);
never executed: model->d_func()->columnsAboutToBeInserted(q, column, column + count - 1);
0
449 if (columnCount() == 0) {
columnCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
450 children.resize(rowCount() * count);-
451 columns = count;-
452 } else {
never executed: end of block
0
453 columns += count;-
454 int index = childIndex(0, column);-
455 for (int row = 0; row < rowCount(); ++row) {
row < rowCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
456 children.insert(index, count, 0);-
457 index += columnCount();-
458 }
never executed: end of block
0
459 }
never executed: end of block
0
460 if (!items.isEmpty()) {
!items.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
461 int limit = qMin(items.count(), rowCount() * count);-
462 for (int i = 0; i < limit; ++i) {
i < limitDescription
TRUEnever evaluated
FALSEnever evaluated
0
463 QStandardItem *item = items.at(i);-
464 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
465 if (item->d_func()->parent == 0) {
item->d_func()->parent == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
466 item->d_func()->setParentAndModel(q, model);-
467 } else {
never executed: end of block
0
468 qWarning("QStandardItem::insertColumns: Ignoring duplicate insertion of item %p",-
469 item);-
470 item = 0;-
471 }
never executed: end of block
0
472 }-
473 int r = i / count;-
474 int c = column + (i % count);-
475 int index = childIndex(r, c);-
476 children.replace(index, item);-
477 }
never executed: end of block
0
478 }
never executed: end of block
0
479 if (model)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
480 model->d_func()->columnsInserted(q, column, count);
never executed: model->d_func()->columnsInserted(q, column, count);
0
481 return true;
never executed: return true;
0
482}-
483-
484/*!-
485 \internal-
486*/-
487void QStandardItemModelPrivate::itemChanged(QStandardItem *item)-
488{-
489 Q_Q(QStandardItemModel);-
490 if (item->d_func()->parent == 0) {
item->d_func()->parent == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
491 // Header item-
492 int idx = columnHeaderItems.indexOf(item);-
493 if (idx != -1) {
idx != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
494 emit q->headerDataChanged(Qt::Horizontal, idx, idx);-
495 } else {
never executed: end of block
0
496 idx = rowHeaderItems.indexOf(item);-
497 if (idx != -1)
idx != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
498 emit q->headerDataChanged(Qt::Vertical, idx, idx);
never executed: q->headerDataChanged(Qt::Vertical, idx, idx);
0
499 }
never executed: end of block
0
500 } else {-
501 // Normal item-
502 QModelIndex index = q->indexFromItem(item);-
503 emit q->dataChanged(index, index);-
504 }
never executed: end of block
0
505}-
506-
507/*!-
508 \internal-
509*/-
510void QStandardItemModelPrivate::rowsAboutToBeInserted(QStandardItem *parent,-
511 int start, int end)-
512{-
513 Q_Q(QStandardItemModel);-
514 QModelIndex index = q->indexFromItem(parent);-
515 q->beginInsertRows(index, start, end);-
516}
never executed: end of block
0
517-
518/*!-
519 \internal-
520*/-
521void QStandardItemModelPrivate::columnsAboutToBeInserted(QStandardItem *parent,-
522 int start, int end)-
523{-
524 Q_Q(QStandardItemModel);-
525 QModelIndex index = q->indexFromItem(parent);-
526 q->beginInsertColumns(index, start, end);-
527}
never executed: end of block
0
528-
529/*!-
530 \internal-
531*/-
532void QStandardItemModelPrivate::rowsAboutToBeRemoved(QStandardItem *parent,-
533 int start, int end)-
534{-
535 Q_Q(QStandardItemModel);-
536 QModelIndex index = q->indexFromItem(parent);-
537 q->beginRemoveRows(index, start, end);-
538}
never executed: end of block
0
539-
540/*!-
541 \internal-
542*/-
543void QStandardItemModelPrivate::columnsAboutToBeRemoved(QStandardItem *parent,-
544 int start, int end)-
545{-
546 Q_Q(QStandardItemModel);-
547 QModelIndex index = q->indexFromItem(parent);-
548 q->beginRemoveColumns(index, start, end);-
549}
never executed: end of block
0
550-
551/*!-
552 \internal-
553*/-
554void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent,-
555 int row, int count)-
556{-
557 Q_Q(QStandardItemModel);-
558 if (parent == root.data())
parent == root.data()Description
TRUEnever evaluated
FALSEnever evaluated
0
559 rowHeaderItems.insert(row, count, 0);
never executed: rowHeaderItems.insert(row, count, 0);
0
560 q->endInsertRows();-
561}
never executed: end of block
0
562-
563/*!-
564 \internal-
565*/-
566void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent,-
567 int column, int count)-
568{-
569 Q_Q(QStandardItemModel);-
570 if (parent == root.data())
parent == root.data()Description
TRUEnever evaluated
FALSEnever evaluated
0
571 columnHeaderItems.insert(column, count, 0);
never executed: columnHeaderItems.insert(column, count, 0);
0
572 q->endInsertColumns();-
573}
never executed: end of block
0
574-
575/*!-
576 \internal-
577*/-
578void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent,-
579 int row, int count)-
580{-
581 Q_Q(QStandardItemModel);-
582 if (parent == root.data()) {
parent == root.data()Description
TRUEnever evaluated
FALSEnever evaluated
0
583 for (int i = row; i < row + count; ++i) {
i < row + countDescription
TRUEnever evaluated
FALSEnever evaluated
0
584 QStandardItem *oldItem = rowHeaderItems.at(i);-
585 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
586 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
587 delete oldItem;-
588 }
never executed: end of block
0
589 rowHeaderItems.remove(row, count);-
590 }
never executed: end of block
0
591 q->endRemoveRows();-
592}
never executed: end of block
0
593-
594/*!-
595 \internal-
596*/-
597void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent,-
598 int column, int count)-
599{-
600 Q_Q(QStandardItemModel);-
601 if (parent == root.data()) {
parent == root.data()Description
TRUEnever evaluated
FALSEnever evaluated
0
602 for (int i = column; i < column + count; ++i) {
i < column + countDescription
TRUEnever evaluated
FALSEnever evaluated
0
603 QStandardItem *oldItem = columnHeaderItems.at(i);-
604 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
605 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
606 delete oldItem;-
607 }
never executed: end of block
0
608 columnHeaderItems.remove(column, count);-
609 }
never executed: end of block
0
610 q->endRemoveColumns();-
611}
never executed: end of block
0
612-
613/*!-
614 \class QStandardItem-
615 \brief The QStandardItem class provides an item for use with the-
616 QStandardItemModel class.-
617 \since 4.2-
618 \ingroup model-view-
619 \inmodule QtGui-
620-
621 Items usually contain text, icons, or checkboxes.-
622-
623 Each item can have its own background brush which is set with the-
624 setBackground() function. The current background brush can be found with-
625 background(). The text label for each item can be rendered with its own-
626 font and brush. These are specified with the setFont() and setForeground()-
627 functions, and read with font() and foreground().-
628-
629 By default, items are enabled, editable, selectable, checkable, and can be-
630 used both as the source of a drag and drop operation and as a drop target.-
631 Each item's flags can be changed by calling setFlags(). Checkable items-
632 can be checked and unchecked with the setCheckState() function. The-
633 corresponding checkState() function indicates whether the item is-
634 currently checked.-
635-
636 You can store application-specific data in an item by calling setData().-
637-
638 Each item can have a two-dimensional table of child items. This makes it-
639 possible to build hierarchies of items. The typical hierarchy is the tree,-
640 in which case the child table is a table with a single column (a list).-
641-
642 The dimensions of the child table can be set with setRowCount() and-
643 setColumnCount(). Items can be positioned in the child table with-
644 setChild(). Get a pointer to a child item with child(). New rows and-
645 columns of children can also be inserted with insertRow() and-
646 insertColumn(), or appended with appendRow() and appendColumn(). When-
647 using the append and insert functions, the dimensions of the child table-
648 will grow as needed.-
649-
650 An existing row of children can be removed with removeRow() or takeRow();-
651 correspondingly, a column can be removed with removeColumn() or-
652 takeColumn().-
653-
654 An item's children can be sorted by calling sortChildren().-
655-
656 \section1 Subclassing-
657-
658 When subclassing QStandardItem to provide custom items, it is possible to-
659 define new types for them so that they can be distinguished from the base-
660 class. The type() function should be reimplemented to return a new type-
661 value equal to or greater than \l UserType.-
662-
663 Reimplement data() and setData() if you want to perform custom handling of-
664 data queries and/or control how an item's data is represented.-
665-
666 Reimplement clone() if you want QStandardItemModel to be able to create-
667 instances of your custom item class on demand (see-
668 QStandardItemModel::setItemPrototype()).-
669-
670 Reimplement read() and write() if you want to control how items are-
671 represented in their serialized form.-
672-
673 Reimplement \l{operator<()} if you want to control the semantics of item-
674 comparison. \l{operator<()} determines the sorted order when sorting items-
675 with sortChildren() or with QStandardItemModel::sort().-
676-
677 \sa QStandardItemModel, {Item View Convenience Classes}, {Model/View Programming}-
678*/-
679-
680/*!-
681 \enum QStandardItem::ItemType-
682-
683 This enum describes the types that are used to describe standard items.-
684-
685 \value Type The default type for standard items.-
686 \value UserType The minimum value for custom types. Values below UserType are-
687 reserved by Qt.-
688-
689 You can define new user types in QStandardItem subclasses to ensure that-
690 custom items are treated specially; for example, when items are sorted.-
691-
692 \sa type()-
693*/-
694-
695/*!-
696 Constructs an item.-
697*/-
698QStandardItem::QStandardItem()-
699 : d_ptr(new QStandardItemPrivate)-
700{-
701 Q_D(QStandardItem);-
702 d->q_ptr = this;-
703}
never executed: end of block
0
704-
705/*!-
706 Constructs an item with the given \a text.-
707*/-
708QStandardItem::QStandardItem(const QString &text)-
709 : d_ptr(new QStandardItemPrivate)-
710{-
711 Q_D(QStandardItem);-
712 d->q_ptr = this;-
713 setText(text);-
714}
never executed: end of block
0
715-
716/*!-
717 Constructs an item with the given \a icon and \a text.-
718*/-
719QStandardItem::QStandardItem(const QIcon &icon, const QString &text)-
720 : d_ptr(new QStandardItemPrivate)-
721{-
722 Q_D(QStandardItem);-
723 d->q_ptr = this;-
724 setIcon(icon);-
725 setText(text);-
726}
never executed: end of block
0
727-
728/*!-
729 Constructs an item with \a rows rows and \a columns columns of child items.-
730*/-
731QStandardItem::QStandardItem(int rows, int columns)-
732 : d_ptr(new QStandardItemPrivate)-
733{-
734 Q_D(QStandardItem);-
735 d->q_ptr = this;-
736 setRowCount(rows);-
737 setColumnCount(columns);-
738}
never executed: end of block
0
739-
740/*!-
741 \internal-
742*/-
743QStandardItem::QStandardItem(QStandardItemPrivate &dd)-
744 : d_ptr(&dd)-
745{-
746 Q_D(QStandardItem);-
747 d->q_ptr = this;-
748}
never executed: end of block
0
749-
750/*!-
751 Constructs a copy of \a other. Note that model() is-
752 not copied.-
753-
754 This function is useful when reimplementing clone().-
755*/-
756QStandardItem::QStandardItem(const QStandardItem &other)-
757 : d_ptr(new QStandardItemPrivate)-
758{-
759 Q_D(QStandardItem);-
760 d->q_ptr = this;-
761 operator=(other);-
762}
never executed: end of block
0
763-
764/*!-
765 Assigns \a other's data and flags to this item. Note that-
766 type() and model() are not copied.-
767-
768 This function is useful when reimplementing clone().-
769*/-
770QStandardItem &QStandardItem::operator=(const QStandardItem &other)-
771{-
772 Q_D(QStandardItem);-
773 d->values = other.d_func()->values;-
774 return *this;
never executed: return *this;
0
775}-
776-
777/*!-
778 Destructs the item.-
779 This causes the item's children to be destructed as well.-
780*/-
781QStandardItem::~QStandardItem()-
782{-
783}-
784-
785/*!-
786 Returns the item's parent item, or 0 if the item has no parent.-
787 \note For toplevel items parent() returns 0. To receive toplevel-
788 item's parent use QStandardItemModel::invisibleRootItem() instead.-
789-
790 \sa child(), QStandardItemModel::invisibleRootItem()-
791*/-
792QStandardItem *QStandardItem::parent() const-
793{-
794 Q_D(const QStandardItem);-
795 if (!d->model || (d->model->d_func()->root.data() != d->parent))
!d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
(d->model->d_f... != d->parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
796 return d->parent;
never executed: return d->parent;
0
797 return 0;
never executed: return 0;
0
798}-
799-
800/*!-
801 Sets the item's data for the given \a role to the specified \a value.-
802-
803 If you subclass QStandardItem and reimplement this function, your-
804 reimplementation should call emitDataChanged() if you do not call-
805 the base implementation of setData(). This will ensure that e.g.-
806 views using the model are notified of the changes.-
807-
808 \note The default implementation treats Qt::EditRole and Qt::DisplayRole-
809 as referring to the same data.-
810-
811 \sa Qt::ItemDataRole, data(), setFlags()-
812*/-
813void QStandardItem::setData(const QVariant &value, int role)-
814{-
815 Q_D(QStandardItem);-
816 role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
(role == Qt::EditRole)Description
TRUEnever evaluated
FALSEnever evaluated
0
817 QVector<QStandardItemData>::iterator it;-
818 for (it = d->values.begin(); it != d->values.end(); ++it) {
it != d->values.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
819 if ((*it).role == role) {
(*it).role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
820 if (value.isValid()) {
value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
821 if ((*it).value.type() == value.type() && (*it).value == value)
(*it).value.ty...= value.type()Description
TRUEnever evaluated
FALSEnever evaluated
(*it).value == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
822 return;
never executed: return;
0
823 (*it).value = value;-
824 } else {
never executed: end of block
0
825 d->values.erase(it);-
826 }
never executed: end of block
0
827 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
828 d->model->d_func()->itemChanged(this);
never executed: d->model->d_func()->itemChanged(this);
0
829 return;
never executed: return;
0
830 }-
831 }
never executed: end of block
0
832 d->values.append(QStandardItemData(role, value));-
833 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
834 d->model->d_func()->itemChanged(this);
never executed: d->model->d_func()->itemChanged(this);
0
835}
never executed: end of block
0
836-
837/*!-
838 Returns the item's data for the given \a role, or an invalid-
839 QVariant if there is no data for the role.-
840-
841 \note The default implementation treats Qt::EditRole and Qt::DisplayRole-
842 as referring to the same data.-
843*/-
844QVariant QStandardItem::data(int role) const-
845{-
846 Q_D(const QStandardItem);-
847 role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
(role == Qt::EditRole)Description
TRUEnever evaluated
FALSEnever evaluated
0
848 QVector<QStandardItemData>::const_iterator it;-
849 for (it = d->values.begin(); it != d->values.end(); ++it) {
it != d->values.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
850 if ((*it).role == role)
(*it).role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
851 return (*it).value;
never executed: return (*it).value;
0
852 }
never executed: end of block
0
853 return QVariant();
never executed: return QVariant();
0
854}-
855-
856/*!-
857 \since 4.4-
858-
859 Causes the model associated with this item to emit a-
860 \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this-
861 item.-
862-
863 You normally only need to call this function if you have subclassed-
864 QStandardItem and reimplemented data() and/or setData().-
865-
866 \sa setData()-
867*/-
868void QStandardItem::emitDataChanged()-
869{-
870 Q_D(QStandardItem);-
871 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
872 d->model->d_func()->itemChanged(this);
never executed: d->model->d_func()->itemChanged(this);
0
873}
never executed: end of block
0
874-
875/*!-
876 Sets the item flags for the item to \a flags.-
877-
878 The item flags determine how the user can interact with the item.-
879 This is often used to disable an item.-
880-
881 \sa flags(), setData()-
882*/-
883void QStandardItem::setFlags(Qt::ItemFlags flags)-
884{-
885 setData((int)flags, Qt::UserRole - 1);-
886}
never executed: end of block
0
887-
888/*!-
889 Returns the item flags for the item.-
890-
891 The item flags determine how the user can interact with the item.-
892-
893 By default, items are enabled, editable, selectable, checkable, and can be-
894 used both as the source of a drag and drop operation and as a drop target.-
895-
896 \sa setFlags()-
897*/-
898Qt::ItemFlags QStandardItem::flags() const-
899{-
900 QVariant v = data(Qt::UserRole - 1);-
901 if (!v.isValid())
!v.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
902 return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable
never executed: return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);
0
903 |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);
never executed: return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);
0
904 return Qt::ItemFlags(v.toInt());
never executed: return Qt::ItemFlags(v.toInt());
0
905}-
906-
907/*!-
908 \fn QString QStandardItem::text() const-
909-
910 Returns the item's text. This is the text that's presented to the user-
911 in a view.-
912-
913 \sa setText()-
914*/-
915-
916/*!-
917 \fn void QStandardItem::setText(const QString &text)-
918-
919 Sets the item's text to the \a text specified.-
920-
921 \sa text(), setFont(), setForeground()-
922*/-
923-
924/*!-
925 \fn QIcon QStandardItem::icon() const-
926-
927 Returns the item's icon.-
928-
929 \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}-
930*/-
931-
932/*!-
933 \fn void QStandardItem::setIcon(const QIcon &icon)-
934-
935 Sets the item's icon to the \a icon specified.-
936*/-
937-
938/*!-
939 \fn QString QStandardItem::statusTip() const-
940-
941 Returns the item's status tip.-
942-
943 \sa setStatusTip(), toolTip(), whatsThis()-
944*/-
945-
946/*!-
947 \fn void QStandardItem::setStatusTip(const QString &statusTip)-
948-
949 Sets the item's status tip to the string specified by \a statusTip.-
950-
951 \sa statusTip(), setToolTip(), setWhatsThis()-
952*/-
953-
954/*!-
955 \fn QString QStandardItem::toolTip() const-
956-
957 Returns the item's tooltip.-
958-
959 \sa setToolTip(), statusTip(), whatsThis()-
960*/-
961-
962/*!-
963 \fn void QStandardItem::setToolTip(const QString &toolTip)-
964-
965 Sets the item's tooltip to the string specified by \a toolTip.-
966-
967 \sa toolTip(), setStatusTip(), setWhatsThis()-
968*/-
969-
970/*!-
971 \fn QString QStandardItem::whatsThis() const-
972-
973 Returns the item's "What's This?" help.-
974-
975 \sa setWhatsThis(), toolTip(), statusTip()-
976*/-
977-
978/*!-
979 \fn void QStandardItem::setWhatsThis(const QString &whatsThis)-
980-
981 Sets the item's "What's This?" help to the string specified by \a whatsThis.-
982-
983 \sa whatsThis(), setStatusTip(), setToolTip()-
984*/-
985-
986/*!-
987 \fn QFont QStandardItem::font() const-
988-
989 Returns the font used to render the item's text.-
990-
991 \sa setFont()-
992*/-
993-
994/*!-
995 \fn void QStandardItem::setFont(const QFont &font)-
996-
997 Sets the font used to display the item's text to the given \a font.-
998-
999 \sa font(), setText(), setForeground()-
1000*/-
1001-
1002/*!-
1003 \fn QBrush QStandardItem::background() const-
1004-
1005 Returns the brush used to render the item's background.-
1006-
1007 \sa foreground(), setBackground()-
1008*/-
1009-
1010/*!-
1011 \fn void QStandardItem::setBackground(const QBrush &brush)-
1012-
1013 Sets the item's background brush to the specified \a brush.-
1014-
1015 \sa background(), setForeground()-
1016*/-
1017-
1018/*!-
1019 \fn QBrush QStandardItem::foreground() const-
1020-
1021 Returns the brush used to render the item's foreground (e.g. text).-
1022-
1023 \sa setForeground(), background()-
1024*/-
1025-
1026/*!-
1027 \fn void QStandardItem::setForeground(const QBrush &brush)-
1028-
1029 Sets the brush used to display the item's foreground (e.g. text) to the-
1030 given \a brush.-
1031-
1032 \sa foreground(), setBackground(), setFont()-
1033*/-
1034-
1035/*!-
1036 \fn int QStandardItem::textAlignment() const-
1037-
1038 Returns the text alignment for the item's text.-
1039*/-
1040-
1041/*!-
1042 \fn void QStandardItem::setTextAlignment(Qt::Alignment alignment)-
1043-
1044 Sets the text alignment for the item's text to the \a alignment-
1045 specified.-
1046-
1047 \sa textAlignment()-
1048*/-
1049-
1050/*!-
1051 \fn QSize QStandardItem::sizeHint() const-
1052-
1053 Returns the size hint set for the item, or an invalid QSize if no-
1054 size hint has been set.-
1055-
1056 If no size hint has been set, the item delegate will compute the-
1057 size hint based on the item data.-
1058-
1059 \sa setSizeHint()-
1060*/-
1061-
1062/*!-
1063 \fn void QStandardItem::setSizeHint(const QSize &size)-
1064-
1065 Sets the size hint for the item to be \a size.-
1066 If no size hint is set, the item delegate will compute the-
1067 size hint based on the item data.-
1068-
1069 \sa sizeHint()-
1070*/-
1071-
1072/*!-
1073 \fn Qt::CheckState QStandardItem::checkState() const-
1074-
1075 Returns the checked state of the item.-
1076-
1077 \sa setCheckState(), isCheckable()-
1078*/-
1079-
1080/*!-
1081 \fn void QStandardItem::setCheckState(Qt::CheckState state)-
1082-
1083 Sets the check state of the item to be \a state.-
1084-
1085 \sa checkState(), setCheckable()-
1086*/-
1087-
1088/*!-
1089 \fn QString QStandardItem::accessibleText() const-
1090-
1091 Returns the item's accessible text.-
1092-
1093 The accessible text is used by assistive technologies (i.e. for users who-
1094 cannot use conventional means of interaction).-
1095-
1096 \sa setAccessibleText(), accessibleDescription()-
1097*/-
1098-
1099/*!-
1100 \fn void QStandardItem::setAccessibleText(const QString &accessibleText)-
1101-
1102 Sets the item's accessible text to the string specified by \a accessibleText.-
1103-
1104 The accessible text is used by assistive technologies (i.e. for users who-
1105 cannot use conventional means of interaction).-
1106-
1107 \sa accessibleText(), setAccessibleDescription()-
1108*/-
1109-
1110/*!-
1111 \fn QString QStandardItem::accessibleDescription() const-
1112-
1113 Returns the item's accessible description.-
1114-
1115 The accessible description is used by assistive technologies (i.e. for-
1116 users who cannot use conventional means of interaction).-
1117-
1118 \sa setAccessibleDescription(), accessibleText()-
1119*/-
1120-
1121/*!-
1122 \fn void QStandardItem::setAccessibleDescription(const QString &accessibleDescription)-
1123-
1124 Sets the item's accessible description to the string specified by \a-
1125 accessibleDescription.-
1126-
1127 The accessible description is used by assistive technologies (i.e. for-
1128 users who cannot use conventional means of interaction).-
1129-
1130 \sa accessibleDescription(), setAccessibleText()-
1131*/-
1132-
1133/*!-
1134 Sets whether the item is enabled. If \a enabled is true, the item is enabled,-
1135 meaning that the user can interact with the item; if \a enabled is false, the-
1136 user cannot interact with the item.-
1137-
1138 This flag takes precedence over the other item flags; e.g. if an item is not-
1139 enabled, it cannot be selected by the user, even if the Qt::ItemIsSelectable-
1140 flag has been set.-
1141-
1142 \sa isEnabled(), Qt::ItemIsEnabled, setFlags()-
1143*/-
1144void QStandardItem::setEnabled(bool enabled)-
1145{-
1146 Q_D(QStandardItem);-
1147 d->changeFlags(enabled, Qt::ItemIsEnabled);-
1148}
never executed: end of block
0
1149-
1150/*!-
1151 \fn bool QStandardItem::isEnabled() const-
1152-
1153 Returns whether the item is enabled.-
1154-
1155 When an item is enabled, the user can interact with it. The possible-
1156 types of interaction are specified by the other item flags, such as-
1157 isEditable() and isSelectable().-
1158-
1159 The default value is true.-
1160-
1161 \sa setEnabled(), flags()-
1162*/-
1163-
1164/*!-
1165 Sets whether the item is editable. If \a editable is true, the item can be-
1166 edited by the user; otherwise, the user cannot edit the item.-
1167-
1168 How the user can edit items in a view is determined by the view's edit-
1169 triggers; see QAbstractItemView::editTriggers.-
1170-
1171 \sa isEditable(), setFlags()-
1172*/-
1173void QStandardItem::setEditable(bool editable)-
1174{-
1175 Q_D(QStandardItem);-
1176 d->changeFlags(editable, Qt::ItemIsEditable);-
1177}
never executed: end of block
0
1178-
1179/*!-
1180 \fn bool QStandardItem::isEditable() const-
1181-
1182 Returns whether the item can be edited by the user.-
1183-
1184 When an item is editable (and enabled), the user can edit the item by-
1185 invoking one of the view's edit triggers; see-
1186 QAbstractItemView::editTriggers.-
1187-
1188 The default value is true.-
1189-
1190 \sa setEditable(), flags()-
1191*/-
1192-
1193/*!-
1194 Sets whether the item is selectable. If \a selectable is true, the item-
1195 can be selected by the user; otherwise, the user cannot select the item.-
1196-
1197 You can control the selection behavior and mode by manipulating their-
1198 view properties; see QAbstractItemView::selectionMode and-
1199 QAbstractItemView::selectionBehavior.-
1200-
1201 \sa isSelectable(), setFlags()-
1202*/-
1203void QStandardItem::setSelectable(bool selectable)-
1204{-
1205 Q_D(QStandardItem);-
1206 d->changeFlags(selectable, Qt::ItemIsSelectable);-
1207}
never executed: end of block
0
1208-
1209/*!-
1210 \fn bool QStandardItem::isSelectable() const-
1211-
1212 Returns whether the item is selectable by the user.-
1213-
1214 The default value is true.-
1215-
1216 \sa setSelectable(), flags()-
1217*/-
1218-
1219/*!-
1220 Sets whether the item is user-checkable. If \a checkable is true, the-
1221 item can be checked by the user; otherwise, the user cannot check-
1222 the item.-
1223-
1224 The item delegate will render a checkable item with a check box next to the-
1225 item's text.-
1226-
1227 \sa isCheckable(), setCheckState(), setUserTristate(), setAutoTristate()-
1228*/-
1229void QStandardItem::setCheckable(bool checkable)-
1230{-
1231 Q_D(QStandardItem);-
1232 if (checkable && !isCheckable()) {
checkableDescription
TRUEnever evaluated
FALSEnever evaluated
!isCheckable()Description
TRUEnever evaluated
FALSEnever evaluated
0
1233 // make sure there's data for the checkstate role-
1234 if (!data(Qt::CheckStateRole).isValid())
!data(Qt::Chec...ole).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1235 setData(Qt::Unchecked, Qt::CheckStateRole);
never executed: setData(Qt::Unchecked, Qt::CheckStateRole);
0
1236 }
never executed: end of block
0
1237 d->changeFlags(checkable, Qt::ItemIsUserCheckable);-
1238}
never executed: end of block
0
1239-
1240/*!-
1241 \fn bool QStandardItem::isCheckable() const-
1242-
1243 Returns whether the item is user-checkable.-
1244-
1245 The default value is false.-
1246-
1247 \sa setCheckable(), checkState(), isUserTristate(), isAutoTristate()-
1248*/-
1249-
1250/*!-
1251 \fn void QStandardItem::setTristate(bool tristate)-
1252 \obsolete-
1253-
1254 Use QStandardItem::setAutoTristate(bool tristate) instead.-
1255 For a tristate checkbox that the user can change between all three-
1256 states, use QStandardItem::setUserTristate(bool tristate) instead.-
1257*/-
1258-
1259/*!-
1260 \fn void QStandardItem::isTristate() const-
1261 \obsolete-
1262-
1263 Use QStandardItem::isAutoTristate() instead.-
1264 For a tristate checkbox that the user can change between all three-
1265 states, use QStandardItem::isUserTristate() instead.-
1266*/-
1267-
1268/*!-
1269 Determines that the item is tristate and controlled by QTreeWidget if \a tristate-
1270 is \c true.-
1271 This enables automatic management of the state of parent items in QTreeWidget-
1272 (checked if all children are checked, unchecked if all children are unchecked,-
1273 or partially checked if only some children are checked).-
1274-
1275 \since 5.6-
1276 \sa isAutoTristate(), setCheckable(), setCheckState()-
1277*/-
1278void QStandardItem::setAutoTristate(bool tristate)-
1279{-
1280 Q_D(QStandardItem);-
1281 d->changeFlags(tristate, Qt::ItemIsAutoTristate);-
1282}
never executed: end of block
0
1283-
1284/*!-
1285 \fn bool QStandardItem::isAutoTristate() const-
1286-
1287 Returns whether the item is tristate and is controlled by QTreeWidget.-
1288-
1289 The default value is false.-
1290-
1291 \since 5.6-
1292 \sa setAutoTristate(), isCheckable(), checkState()-
1293*/-
1294-
1295/*!-
1296 Sets whether the item is tristate and controlled by the user.-
1297 If \a tristate is true, the user can cycle through three separate states;-
1298 otherwise, the item is checkable with two states.-
1299 (Note that this also requires that the item is checkable; see isCheckable().)-
1300-
1301 \since 5.6-
1302 \sa isUserTristate(), setCheckable(), setCheckState()-
1303*/-
1304void QStandardItem::setUserTristate(bool tristate)-
1305{-
1306 Q_D(QStandardItem);-
1307 d->changeFlags(tristate, Qt::ItemIsUserTristate);-
1308}
never executed: end of block
0
1309-
1310/*!-
1311 \fn bool QStandardItem::isUserTristate() const-
1312 \since 5.6-
1313-
1314 Returns whether the item is tristate; that is, if it's checkable with three-
1315 separate states and the user can cycle through all three states.-
1316-
1317 The default value is false.-
1318-
1319 \sa setUserTristate(), isCheckable(), checkState()-
1320*/-
1321-
1322#if QT_DEPRECATED_SINCE(5, 6)-
1323void QStandardItem::setTristate(bool tristate)-
1324{-
1325 setAutoTristate(tristate);-
1326}
never executed: end of block
0
1327#endif-
1328-
1329#ifndef QT_NO_DRAGANDDROP-
1330-
1331/*!-
1332 Sets whether the item is drag enabled. If \a dragEnabled is true, the item-
1333 can be dragged by the user; otherwise, the user cannot drag the item.-
1334-
1335 Note that you also need to ensure that item dragging is enabled in the view;-
1336 see QAbstractItemView::dragEnabled.-
1337-
1338 \sa isDragEnabled(), setDropEnabled(), setFlags()-
1339*/-
1340void QStandardItem::setDragEnabled(bool dragEnabled)-
1341{-
1342 Q_D(QStandardItem);-
1343 d->changeFlags(dragEnabled, Qt::ItemIsDragEnabled);-
1344}
never executed: end of block
0
1345-
1346/*!-
1347 \fn bool QStandardItem::isDragEnabled() const-
1348-
1349 Returns whether the item is drag enabled. An item that is drag enabled can-
1350 be dragged by the user.-
1351-
1352 The default value is true.-
1353-
1354 Note that item dragging must be enabled in the view for dragging to work;-
1355 see QAbstractItemView::dragEnabled.-
1356-
1357 \sa setDragEnabled(), isDropEnabled(), flags()-
1358*/-
1359-
1360/*!-
1361 Sets whether the item is drop enabled. If \a dropEnabled is true, the item-
1362 can be used as a drop target; otherwise, it cannot.-
1363-
1364 Note that you also need to ensure that drops are enabled in the view; see-
1365 QWidget::acceptDrops(); and that the model supports the desired drop actions;-
1366 see QAbstractItemModel::supportedDropActions().-
1367-
1368 \sa isDropEnabled(), setDragEnabled(), setFlags()-
1369*/-
1370void QStandardItem::setDropEnabled(bool dropEnabled)-
1371{-
1372 Q_D(QStandardItem);-
1373 d->changeFlags(dropEnabled, Qt::ItemIsDropEnabled);-
1374}
never executed: end of block
0
1375-
1376/*!-
1377 \fn bool QStandardItem::isDropEnabled() const-
1378-
1379 Returns whether the item is drop enabled. When an item is drop enabled, it-
1380 can be used as a drop target.-
1381-
1382 The default value is true.-
1383-
1384 \sa setDropEnabled(), isDragEnabled(), flags()-
1385*/-
1386-
1387#endif // QT_NO_DRAGANDDROP-
1388-
1389/*!-
1390 Returns the row where the item is located in its parent's child table, or-
1391 -1 if the item has no parent.-
1392-
1393 \sa column(), parent()-
1394*/-
1395int QStandardItem::row() const-
1396{-
1397 Q_D(const QStandardItem);-
1398 QPair<int, int> pos = d->position();-
1399 return pos.first;
never executed: return pos.first;
0
1400}-
1401-
1402/*!-
1403 Returns the column where the item is located in its parent's child table,-
1404 or -1 if the item has no parent.-
1405-
1406 \sa row(), parent()-
1407*/-
1408int QStandardItem::column() const-
1409{-
1410 Q_D(const QStandardItem);-
1411 QPair<int, int> pos = d->position();-
1412 return pos.second;
never executed: return pos.second;
0
1413}-
1414-
1415/*!-
1416 Returns the QModelIndex associated with this item.-
1417-
1418 When you need to invoke item functionality in a QModelIndex-based API (e.g.-
1419 QAbstractItemView), you can call this function to obtain an index that-
1420 corresponds to the item's location in the model.-
1421-
1422 If the item is not associated with a model, an invalid QModelIndex is-
1423 returned.-
1424-
1425 \sa model(), QStandardItemModel::itemFromIndex()-
1426*/-
1427QModelIndex QStandardItem::index() const-
1428{-
1429 Q_D(const QStandardItem);-
1430 return d->model ? d->model->indexFromItem(this) : QModelIndex();
never executed: return d->model ? d->model->indexFromItem(this) : QModelIndex();
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1431}-
1432-
1433/*!-
1434 Returns the QStandardItemModel that this item belongs to.-
1435-
1436 If the item is not a child of another item that belongs to the model, this-
1437 function returns 0.-
1438-
1439 \sa index()-
1440*/-
1441QStandardItemModel *QStandardItem::model() const-
1442{-
1443 Q_D(const QStandardItem);-
1444 return d->model;
never executed: return d->model;
0
1445}-
1446-
1447/*!-
1448 Sets the number of child item rows to \a rows. If this is less than-
1449 rowCount(), the data in the unwanted rows is discarded.-
1450-
1451 \sa rowCount(), setColumnCount()-
1452*/-
1453void QStandardItem::setRowCount(int rows)-
1454{-
1455 int rc = rowCount();-
1456 if (rc == rows)
rc == rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1457 return;
never executed: return;
0
1458 if (rc < rows)
rc < rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1459 insertRows(qMax(rc, 0), rows - rc);
never executed: insertRows(qMax(rc, 0), rows - rc);
0
1460 else-
1461 removeRows(qMax(rows, 0), rc - rows);
never executed: removeRows(qMax(rows, 0), rc - rows);
0
1462}-
1463-
1464/*!-
1465 Returns the number of child item rows that the item has.-
1466-
1467 \sa setRowCount(), columnCount()-
1468*/-
1469int QStandardItem::rowCount() const-
1470{-
1471 Q_D(const QStandardItem);-
1472 return d->rowCount();
never executed: return d->rowCount();
0
1473}-
1474-
1475/*!-
1476 Sets the number of child item columns to \a columns. If this is less than-
1477 columnCount(), the data in the unwanted columns is discarded.-
1478-
1479 \sa columnCount(), setRowCount()-
1480*/-
1481void QStandardItem::setColumnCount(int columns)-
1482{-
1483 int cc = columnCount();-
1484 if (cc == columns)
cc == columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1485 return;
never executed: return;
0
1486 if (cc < columns)
cc < columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1487 insertColumns(qMax(cc, 0), columns - cc);
never executed: insertColumns(qMax(cc, 0), columns - cc);
0
1488 else-
1489 removeColumns(qMax(columns, 0), cc - columns);
never executed: removeColumns(qMax(columns, 0), cc - columns);
0
1490}-
1491-
1492/*!-
1493 Returns the number of child item columns that the item has.-
1494-
1495 \sa setColumnCount(), rowCount()-
1496*/-
1497int QStandardItem::columnCount() const-
1498{-
1499 Q_D(const QStandardItem);-
1500 return d->columnCount();
never executed: return d->columnCount();
0
1501}-
1502-
1503/*!-
1504 Inserts a row at \a row containing \a items. If necessary, the column-
1505 count is increased to the size of \a items.-
1506-
1507 \sa insertRows(), insertColumn()-
1508*/-
1509void QStandardItem::insertRow(int row, const QList<QStandardItem*> &items)-
1510{-
1511 Q_D(QStandardItem);-
1512 if (row < 0)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1513 return;
never executed: return;
0
1514 if (columnCount() < items.count())
columnCount() < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1515 setColumnCount(items.count());
never executed: setColumnCount(items.count());
0
1516 d->insertRows(row, 1, items);-
1517}
never executed: end of block
0
1518-
1519/*!-
1520 Inserts \a items at \a row. The column count won't be changed.-
1521-
1522 \sa insertRow(), insertColumn()-
1523*/-
1524void QStandardItem::insertRows(int row, const QList<QStandardItem*> &items)-
1525{-
1526 Q_D(QStandardItem);-
1527 if (row < 0)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1528 return;
never executed: return;
0
1529 d->insertRows(row, items);-
1530}
never executed: end of block
0
1531-
1532/*!-
1533 Inserts a column at \a column containing \a items. If necessary,-
1534 the row count is increased to the size of \a items.-
1535-
1536 \sa insertColumns(), insertRow()-
1537*/-
1538void QStandardItem::insertColumn(int column, const QList<QStandardItem*> &items)-
1539{-
1540 Q_D(QStandardItem);-
1541 if (column < 0)
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1542 return;
never executed: return;
0
1543 if (rowCount() < items.count())
rowCount() < items.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1544 setRowCount(items.count());
never executed: setRowCount(items.count());
0
1545 d->insertColumns(column, 1, items);-
1546}
never executed: end of block
0
1547-
1548/*!-
1549 Inserts \a count rows of child items at row \a row.-
1550-
1551 \sa insertRow(), insertColumns()-
1552*/-
1553void QStandardItem::insertRows(int row, int count)-
1554{-
1555 Q_D(QStandardItem);-
1556 if (rowCount() < row) {
rowCount() < rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1557 count += row - rowCount();-
1558 row = rowCount();-
1559 }
never executed: end of block
0
1560 d->insertRows(row, count, QList<QStandardItem*>());-
1561}
never executed: end of block
0
1562-
1563/*!-
1564 Inserts \a count columns of child items at column \a column.-
1565-
1566 \sa insertColumn(), insertRows()-
1567*/-
1568void QStandardItem::insertColumns(int column, int count)-
1569{-
1570 Q_D(QStandardItem);-
1571 if (columnCount() < column) {
columnCount() < columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1572 count += column - columnCount();-
1573 column = columnCount();-
1574 }
never executed: end of block
0
1575 d->insertColumns(column, count, QList<QStandardItem*>());-
1576}
never executed: end of block
0
1577-
1578/*!-
1579 \fn void QStandardItem::appendRow(const QList<QStandardItem*> &items)-
1580-
1581 Appends a row containing \a items. If necessary, the column count is-
1582 increased to the size of \a items.-
1583-
1584 \sa insertRow()-
1585*/-
1586-
1587/*!-
1588 \fn void QStandardItem::appendRows(const QList<QStandardItem*> &items)-
1589-
1590 Appends rows containing \a items. The column count will not change.-
1591-
1592 \sa insertRow()-
1593*/-
1594-
1595/*!-
1596 \fn void QStandardItem::appendColumn(const QList<QStandardItem*> &items)-
1597-
1598 Appends a column containing \a items. If necessary, the row count is-
1599 increased to the size of \a items.-
1600-
1601 \sa insertColumn()-
1602*/-
1603-
1604/*!-
1605 \fn bool QStandardItemModel::insertRow(int row, const QModelIndex &parent)-
1606-
1607 Inserts a single row before the given \a row in the child items of the-
1608 \a parent specified. Returns \c true if the row is inserted; otherwise-
1609 returns \c false.-
1610-
1611 \sa insertRows(), insertColumn(), removeRow()-
1612*/-
1613-
1614/*!-
1615 \fn bool QStandardItemModel::insertColumn(int column, const QModelIndex &parent)-
1616-
1617 Inserts a single column before the given \a column in the child items of-
1618 the \a parent specified. Returns \c true if the column is inserted; otherwise-
1619 returns \c false.-
1620-
1621 \sa insertColumns(), insertRow(), removeColumn()-
1622*/-
1623-
1624/*!-
1625 \fn QStandardItem::insertRow(int row, QStandardItem *item)-
1626 \overload-
1627-
1628 Inserts a row at \a row containing \a item.-
1629-
1630 When building a list or a tree that has only one column, this function-
1631 provides a convenient way to insert a single new item.-
1632*/-
1633-
1634/*!-
1635 \fn QStandardItem::appendRow(QStandardItem *item)-
1636 \overload-
1637-
1638 Appends a row containing \a item.-
1639-
1640 When building a list or a tree that has only one column, this function-
1641 provides a convenient way to append a single new item.-
1642*/-
1643-
1644/*!-
1645 Removes the given \a row. The items that were in the row are deleted.-
1646-
1647 \sa takeRow(), removeRows(), removeColumn()-
1648*/-
1649void QStandardItem::removeRow(int row)-
1650{-
1651 removeRows(row, 1);-
1652}
never executed: end of block
0
1653-
1654/*!-
1655 Removes the given \a column. The items that were in the-
1656 column are deleted.-
1657-
1658 \sa takeColumn(), removeColumns(), removeRow()-
1659*/-
1660void QStandardItem::removeColumn(int column)-
1661{-
1662 removeColumns(column, 1);-
1663}
never executed: end of block
0
1664-
1665/*!-
1666 Removes \a count rows at row \a row. The items that were in those rows are-
1667 deleted.-
1668-
1669 \sa removeRow(), removeColumn()-
1670*/-
1671void QStandardItem::removeRows(int row, int count)-
1672{-
1673 Q_D(QStandardItem);-
1674 if ((count < 1) || (row < 0) || ((row + count) > rowCount()))
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
((row + count) > rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
1675 return;
never executed: return;
0
1676 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1677 d->model->d_func()->rowsAboutToBeRemoved(this, row, row + count - 1);
never executed: d->model->d_func()->rowsAboutToBeRemoved(this, row, row + count - 1);
0
1678 int i = d->childIndex(row, 0);-
1679 int n = count * d->columnCount();-
1680 for (int j = i; j < n+i; ++j) {
j < n+iDescription
TRUEnever evaluated
FALSEnever evaluated
0
1681 QStandardItem *oldItem = d->children.at(j);-
1682 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1683 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
1684 delete oldItem;-
1685 }
never executed: end of block
0
1686 d->children.remove(qMax(i, 0), n);-
1687 d->rows -= count;-
1688 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1689 d->model->d_func()->rowsRemoved(this, row, count);
never executed: d->model->d_func()->rowsRemoved(this, row, count);
0
1690}
never executed: end of block
0
1691-
1692/*!-
1693 Removes \a count columns at column \a column. The items that were in those-
1694 columns are deleted.-
1695-
1696 \sa removeColumn(), removeRows()-
1697*/-
1698void QStandardItem::removeColumns(int column, int count)-
1699{-
1700 Q_D(QStandardItem);-
1701 if ((count < 1) || (column < 0) || ((column + count) > columnCount()))
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
((column + cou...columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
1702 return;
never executed: return;
0
1703 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1704 d->model->d_func()->columnsAboutToBeRemoved(this, column, column + count - 1);
never executed: d->model->d_func()->columnsAboutToBeRemoved(this, column, column + count - 1);
0
1705 for (int row = d->rowCount() - 1; row >= 0; --row) {
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1706 int i = d->childIndex(row, column);-
1707 for (int j=i; j<i+count; ++j) {
j<i+countDescription
TRUEnever evaluated
FALSEnever evaluated
0
1708 QStandardItem *oldItem = d->children.at(j);-
1709 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1710 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
1711 delete oldItem;-
1712 }
never executed: end of block
0
1713 d->children.remove(i, count);-
1714 }
never executed: end of block
0
1715 d->columns -= count;-
1716 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1717 d->model->d_func()->columnsRemoved(this, column, count);
never executed: d->model->d_func()->columnsRemoved(this, column, count);
0
1718}
never executed: end of block
0
1719-
1720/*!-
1721 Returns \c true if this item has any children; otherwise returns \c false.-
1722-
1723 \sa rowCount(), columnCount(), child()-
1724*/-
1725bool QStandardItem::hasChildren() const-
1726{-
1727 return (rowCount() > 0) && (columnCount() > 0);
never executed: return (rowCount() > 0) && (columnCount() > 0);
(rowCount() > 0)Description
TRUEnever evaluated
FALSEnever evaluated
(columnCount() > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1728}-
1729-
1730/*!-
1731 Sets the child item at (\a row, \a column) to \a item. This item (the parent-
1732 item) takes ownership of \a item. If necessary, the row count and column-
1733 count are increased to fit the item.-
1734-
1735 \sa child()-
1736*/-
1737void QStandardItem::setChild(int row, int column, QStandardItem *item)-
1738{-
1739 Q_D(QStandardItem);-
1740 d->setChild(row, column, item, true);-
1741}
never executed: end of block
0
1742-
1743/*!-
1744 \fn QStandardItem::setChild(int row, QStandardItem *item)-
1745 \overload-
1746-
1747 Sets the child at \a row to \a item.-
1748*/-
1749-
1750/*!-
1751 Returns the child item at (\a row, \a column) if one has been set; otherwise-
1752 returns 0.-
1753-
1754 \sa setChild(), takeChild(), parent()-
1755*/-
1756QStandardItem *QStandardItem::child(int row, int column) const-
1757{-
1758 Q_D(const QStandardItem);-
1759 int index = d->childIndex(row, column);-
1760 if (index == -1)
index == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1761 return 0;
never executed: return 0;
0
1762 return d->children.at(index);
never executed: return d->children.at(index);
0
1763}-
1764-
1765/*!-
1766 Removes the child item at (\a row, \a column) without deleting it, and returns-
1767 a pointer to the item. If there was no child at the given location, then-
1768 this function returns 0.-
1769-
1770 Note that this function, unlike takeRow() and takeColumn(), does not affect-
1771 the dimensions of the child table.-
1772-
1773 \sa child(), takeRow(), takeColumn()-
1774*/-
1775QStandardItem *QStandardItem::takeChild(int row, int column)-
1776{-
1777 Q_D(QStandardItem);-
1778 QStandardItem *item = 0;-
1779 int index = d->childIndex(row, column);-
1780 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1781 item = d->children.at(index);-
1782 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1783 item->d_func()->setParentAndModel(0, 0);
never executed: item->d_func()->setParentAndModel(0, 0);
0
1784 d->children.replace(index, 0);-
1785 }
never executed: end of block
0
1786 return item;
never executed: return item;
0
1787}-
1788-
1789/*!-
1790 Removes \a row without deleting the row items, and returns a list of-
1791 pointers to the removed items. For items in the row that have not been-
1792 set, the corresponding pointers in the list will be 0.-
1793-
1794 \sa removeRow(), insertRow(), takeColumn()-
1795*/-
1796QList<QStandardItem*> QStandardItem::takeRow(int row)-
1797{-
1798 Q_D(QStandardItem);-
1799 if ((row < 0) || (row >= rowCount()))
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(row >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
1800 return QList<QStandardItem*>();
never executed: return QList<QStandardItem*>();
0
1801 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1802 d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
never executed: d->model->d_func()->rowsAboutToBeRemoved(this, row, row);
0
1803 QList<QStandardItem*> items;-
1804 int index = d->childIndex(row, 0); // Will return -1 if there are no columns-
1805 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1806 int col_count = d->columnCount();-
1807 items.reserve(col_count);-
1808 for (int column = 0; column < col_count; ++column) {
column < col_countDescription
TRUEnever evaluated
FALSEnever evaluated
0
1809 QStandardItem *ch = d->children.at(index + column);-
1810 if (ch)
chDescription
TRUEnever evaluated
FALSEnever evaluated
0
1811 ch->d_func()->setParentAndModel(0, 0);
never executed: ch->d_func()->setParentAndModel(0, 0);
0
1812 items.append(ch);-
1813 }
never executed: end of block
0
1814 d->children.remove(index, col_count);-
1815 }
never executed: end of block
0
1816 d->rows--;-
1817 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1818 d->model->d_func()->rowsRemoved(this, row, 1);
never executed: d->model->d_func()->rowsRemoved(this, row, 1);
0
1819 return items;
never executed: return items;
0
1820}-
1821-
1822/*!-
1823 Removes \a column without deleting the column items, and returns a list of-
1824 pointers to the removed items. For items in the column that have not been-
1825 set, the corresponding pointers in the list will be 0.-
1826-
1827 \sa removeColumn(), insertColumn(), takeRow()-
1828*/-
1829QList<QStandardItem*> QStandardItem::takeColumn(int column)-
1830{-
1831 Q_D(QStandardItem);-
1832 if ((column < 0) || (column >= columnCount()))
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(column >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
1833 return QList<QStandardItem*>();
never executed: return QList<QStandardItem*>();
0
1834 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1835 d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
never executed: d->model->d_func()->columnsAboutToBeRemoved(this, column, column);
0
1836 QList<QStandardItem*> items;-
1837-
1838 for (int row = d->rowCount() - 1; row >= 0; --row) {
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1839 int index = d->childIndex(row, column);-
1840 QStandardItem *ch = d->children.at(index);-
1841 if (ch)
chDescription
TRUEnever evaluated
FALSEnever evaluated
0
1842 ch->d_func()->setParentAndModel(0, 0);
never executed: ch->d_func()->setParentAndModel(0, 0);
0
1843 d->children.remove(index);-
1844 items.prepend(ch);-
1845 }
never executed: end of block
0
1846 d->columns--;-
1847 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1848 d->model->d_func()->columnsRemoved(this, column, 1);
never executed: d->model->d_func()->columnsRemoved(this, column, 1);
0
1849 return items;
never executed: return items;
0
1850}-
1851-
1852/*!-
1853 Returns \c true if this item is less than \a other; otherwise returns \c false.-
1854-
1855 The default implementation uses the data for the item's sort role (see-
1856 QStandardItemModel::sortRole) to perform the comparison if the item-
1857 belongs to a model; otherwise, the data for the item's Qt::DisplayRole-
1858 (text()) is used to perform the comparison.-
1859-
1860 sortChildren() and QStandardItemModel::sort() use this function when-
1861 sorting items. If you want custom sorting, you can subclass QStandardItem-
1862 and reimplement this function.-
1863*/-
1864bool QStandardItem::operator<(const QStandardItem &other) const-
1865{-
1866 const int role = model() ? model()->sortRole() : Qt::DisplayRole;
model()Description
TRUEnever evaluated
FALSEnever evaluated
0
1867 const QVariant l = data(role), r = other.data(role);-
1868 // this code is copied from QSortFilterProxyModel::lessThan()-
1869 if (l.userType() == QVariant::Invalid)
l.userType() =...riant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
1870 return false;
never executed: return false;
0
1871 if (r.userType() == QVariant::Invalid)
r.userType() =...riant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
1872 return true;
never executed: return true;
0
1873 switch (l.userType()) {-
1874 case QVariant::Int:
never executed: case QVariant::Int:
0
1875 return l.toInt() < r.toInt();
never executed: return l.toInt() < r.toInt();
0
1876 case QVariant::UInt:
never executed: case QVariant::UInt:
0
1877 return l.toUInt() < r.toUInt();
never executed: return l.toUInt() < r.toUInt();
0
1878 case QVariant::LongLong:
never executed: case QVariant::LongLong:
0
1879 return l.toLongLong() < r.toLongLong();
never executed: return l.toLongLong() < r.toLongLong();
0
1880 case QVariant::ULongLong:
never executed: case QVariant::ULongLong:
0
1881 return l.toULongLong() < r.toULongLong();
never executed: return l.toULongLong() < r.toULongLong();
0
1882 case QMetaType::Float:
never executed: case QMetaType::Float:
0
1883 return l.toFloat() < r.toFloat();
never executed: return l.toFloat() < r.toFloat();
0
1884 case QVariant::Double:
never executed: case QVariant::Double:
0
1885 return l.toDouble() < r.toDouble();
never executed: return l.toDouble() < r.toDouble();
0
1886 case QVariant::Char:
never executed: case QVariant::Char:
0
1887 return l.toChar() < r.toChar();
never executed: return l.toChar() < r.toChar();
0
1888 case QVariant::Date:
never executed: case QVariant::Date:
0
1889 return l.toDate() < r.toDate();
never executed: return l.toDate() < r.toDate();
0
1890 case QVariant::Time:
never executed: case QVariant::Time:
0
1891 return l.toTime() < r.toTime();
never executed: return l.toTime() < r.toTime();
0
1892 case QVariant::DateTime:
never executed: case QVariant::DateTime:
0
1893 return l.toDateTime() < r.toDateTime();
never executed: return l.toDateTime() < r.toDateTime();
0
1894 case QVariant::String:
never executed: case QVariant::String:
0
1895 default:
never executed: default:
0
1896 return l.toString().compare(r.toString()) < 0;
never executed: return l.toString().compare(r.toString()) < 0;
0
1897 }-
1898}-
1899-
1900/*!-
1901 Sorts the children of the item using the given \a order, by the values in-
1902 the given \a column.-
1903-
1904 \note This function is recursive, therefore it sorts the children of the-
1905 item, its grandchildren, etc.-
1906-
1907 \sa {operator<()}-
1908*/-
1909void QStandardItem::sortChildren(int column, Qt::SortOrder order)-
1910{-
1911 Q_D(QStandardItem);-
1912 if ((column < 0) || (rowCount() == 0))
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(rowCount() == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1913 return;
never executed: return;
0
1914-
1915 QList<QPersistentModelIndex> parents;-
1916 if (d->model) {
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1917 parents << index();-
1918 emit d->model->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint);-
1919 }
never executed: end of block
0
1920 d->sortChildren(column, order);-
1921 if (d->model)
d->modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1922 emit d->model->layoutChanged(parents, QAbstractItemModel::VerticalSortHint);
never executed: d->model->layoutChanged(parents, QAbstractItemModel::VerticalSortHint);
0
1923}
never executed: end of block
0
1924-
1925/*!-
1926 Returns a copy of this item. The item's children are not copied.-
1927-
1928 When subclassing QStandardItem, you can reimplement this function-
1929 to provide QStandardItemModel with a factory that it can use to-
1930 create new items on demand.-
1931-
1932 \sa QStandardItemModel::setItemPrototype(), operator=()-
1933*/-
1934QStandardItem *QStandardItem::clone() const-
1935{-
1936 return new QStandardItem(*this);
never executed: return new QStandardItem(*this);
0
1937}-
1938-
1939/*!-
1940 Returns the type of this item. The type is used to distinguish custom-
1941 items from the base class. When subclassing QStandardItem, you should-
1942 reimplement this function and return a new value greater than or equal-
1943 to \l UserType.-
1944-
1945 \sa QStandardItem::Type-
1946*/-
1947int QStandardItem::type() const-
1948{-
1949 return Type;
never executed: return Type;
0
1950}-
1951-
1952#ifndef QT_NO_DATASTREAM-
1953-
1954/*!-
1955 Reads the item from stream \a in. Only the data and flags of the item are-
1956 read, not the child items.-
1957-
1958 \sa write()-
1959*/-
1960void QStandardItem::read(QDataStream &in)-
1961{-
1962 Q_D(QStandardItem);-
1963 in >> d->values;-
1964 qint32 flags;-
1965 in >> flags;-
1966 setFlags(Qt::ItemFlags(flags));-
1967}
never executed: end of block
0
1968-
1969/*!-
1970 Writes the item to stream \a out. Only the data and flags of the item-
1971 are written, not the child items.-
1972-
1973 \sa read()-
1974*/-
1975void QStandardItem::write(QDataStream &out) const-
1976{-
1977 Q_D(const QStandardItem);-
1978 out << d->values;-
1979 out << flags();-
1980}
never executed: end of block
0
1981-
1982/*!-
1983 \relates QStandardItem-
1984 \since 4.2-
1985-
1986 Reads a QStandardItem from stream \a in into \a item.-
1987-
1988 This operator uses QStandardItem::read().-
1989-
1990 \sa {Serializing Qt Data Types}-
1991*/-
1992QDataStream &operator>>(QDataStream &in, QStandardItem &item)-
1993{-
1994 item.read(in);-
1995 return in;
never executed: return in;
0
1996}-
1997-
1998/*!-
1999 \relates QStandardItem-
2000 \since 4.2-
2001-
2002 Writes the QStandardItem \a item to stream \a out.-
2003-
2004 This operator uses QStandardItem::write().-
2005-
2006 \sa {Serializing Qt Data Types}-
2007*/-
2008QDataStream &operator<<(QDataStream &out, const QStandardItem &item)-
2009{-
2010 item.write(out);-
2011 return out;
never executed: return out;
0
2012}-
2013-
2014#endif // QT_NO_DATASTREAM-
2015-
2016/*!-
2017 \class QStandardItemModel-
2018 \brief The QStandardItemModel class provides a generic model for storing custom data.-
2019 \ingroup model-view-
2020 \inmodule QtGui-
2021-
2022 QStandardItemModel can be used as a repository for standard Qt-
2023 data types. It is one of the \l {Model/View Classes} and is part-
2024 of Qt's \l {Model/View Programming}{model/view} framework.-
2025-
2026 QStandardItemModel provides a classic item-based approach to working with-
2027 the model. The items in a QStandardItemModel are provided by-
2028 QStandardItem.-
2029-
2030 QStandardItemModel implements the QAbstractItemModel interface, which-
2031 means that the model can be used to provide data in any view that supports-
2032 that interface (such as QListView, QTableView and QTreeView, and your own-
2033 custom views). For performance and flexibility, you may want to subclass-
2034 QAbstractItemModel to provide support for different kinds of data-
2035 repositories. For example, the QDirModel provides a model interface to the-
2036 underlying file system.-
2037-
2038 When you want a list or tree, you typically create an empty-
2039 QStandardItemModel and use appendRow() to add items to the model, and-
2040 item() to access an item. If your model represents a table, you typically-
2041 pass the dimensions of the table to the QStandardItemModel constructor and-
2042 use setItem() to position items into the table. You can also use setRowCount()-
2043 and setColumnCount() to alter the dimensions of the model. To insert items,-
2044 use insertRow() or insertColumn(), and to remove items, use removeRow() or-
2045 removeColumn().-
2046-
2047 You can set the header labels of your model with setHorizontalHeaderLabels()-
2048 and setVerticalHeaderLabels().-
2049-
2050 You can search for items in the model with findItems(), and sort the model by-
2051 calling sort().-
2052-
2053 Call clear() to remove all items from the model.-
2054-
2055 An example usage of QStandardItemModel to create a table:-
2056-
2057 \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 0-
2058-
2059 An example usage of QStandardItemModel to create a tree:-
2060-
2061 \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 1-
2062-
2063 After setting the model on a view, you typically want to react to user-
2064 actions, such as an item being clicked. Since a QAbstractItemView provides-
2065 QModelIndex-based signals and functions, you need a way to obtain the-
2066 QStandardItem that corresponds to a given QModelIndex, and vice-
2067 versa. itemFromIndex() and indexFromItem() provide this mapping. Typical-
2068 usage of itemFromIndex() includes obtaining the item at the current index-
2069 in a view, and obtaining the item that corresponds to an index carried by-
2070 a QAbstractItemView signal, such as QAbstractItemView::clicked(). First-
2071 you connect the view's signal to a slot in your class:-
2072-
2073 \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 2-
2074-
2075 When you receive the signal, you call itemFromIndex() on the given model-
2076 index to get a pointer to the item:-
2077-
2078 \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 3-
2079-
2080 Conversely, you must obtain the QModelIndex of an item when you want to-
2081 invoke a model/view function that takes an index as argument. You can-
2082 obtain the index either by using the model's indexFromItem() function, or,-
2083 equivalently, by calling QStandardItem::index():-
2084-
2085 \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 4-
2086-
2087 You are, of course, not required to use the item-based approach; you could-
2088 instead rely entirely on the QAbstractItemModel interface when working with-
2089 the model, or use a combination of the two as appropriate.-
2090-
2091 \sa QStandardItem, {Model/View Programming}, QAbstractItemModel,-
2092 {itemviews/simpletreemodel}{Simple Tree Model example},-
2093 {Item View Convenience Classes}-
2094*/-
2095-
2096/*!-
2097 \fn void QStandardItemModel::itemChanged(QStandardItem *item)-
2098 \since 4.2-
2099-
2100 This signal is emitted whenever the data of \a item has changed.-
2101*/-
2102-
2103/*!-
2104 Constructs a new item model with the given \a parent.-
2105*/-
2106QStandardItemModel::QStandardItemModel(QObject *parent)-
2107 : QAbstractItemModel(*new QStandardItemModelPrivate, parent)-
2108{-
2109 Q_D(QStandardItemModel);-
2110 d->init();-
2111 d->root->d_func()->setModel(this);-
2112}
never executed: end of block
0
2113-
2114/*!-
2115 Constructs a new item model that initially has \a rows rows and \a columns-
2116 columns, and that has the given \a parent.-
2117*/-
2118QStandardItemModel::QStandardItemModel(int rows, int columns, QObject *parent)-
2119 : QAbstractItemModel(*new QStandardItemModelPrivate, parent)-
2120{-
2121 Q_D(QStandardItemModel);-
2122 d->init();-
2123 d->root->insertColumns(0, columns);-
2124 d->columnHeaderItems.insert(0, columns, 0);-
2125 d->root->insertRows(0, rows);-
2126 d->rowHeaderItems.insert(0, rows, 0);-
2127 d->root->d_func()->setModel(this);-
2128}
never executed: end of block
0
2129-
2130/*!-
2131 \internal-
2132*/-
2133QStandardItemModel::QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent)-
2134 : QAbstractItemModel(dd, parent)-
2135{-
2136 Q_D(QStandardItemModel);-
2137 d->init();-
2138}
never executed: end of block
0
2139-
2140/*!-
2141 Destructs the model. The model destroys all its items.-
2142*/-
2143QStandardItemModel::~QStandardItemModel()-
2144{-
2145}-
2146-
2147/*!-
2148 Sets the item role names to \a roleNames.-
2149*/-
2150void QStandardItemModel::setItemRoleNames(const QHash<int,QByteArray> &roleNames)-
2151{-
2152 Q_D(QStandardItemModel);-
2153 d->roleNames = roleNames;-
2154}
never executed: end of block
0
2155-
2156/*!-
2157 Removes all items (including header items) from the model and sets the-
2158 number of rows and columns to zero.-
2159-
2160 \sa removeColumns(), removeRows()-
2161*/-
2162void QStandardItemModel::clear()-
2163{-
2164 Q_D(QStandardItemModel);-
2165 beginResetModel();-
2166 d->root.reset(new QStandardItem);-
2167 d->root->d_func()->setModel(this);-
2168 qDeleteAll(d->columnHeaderItems);-
2169 d->columnHeaderItems.clear();-
2170 qDeleteAll(d->rowHeaderItems);-
2171 d->rowHeaderItems.clear();-
2172 endResetModel();-
2173}
never executed: end of block
0
2174-
2175/*!-
2176 \since 4.2-
2177-
2178 Returns a pointer to the QStandardItem associated with the given \a index.-
2179-
2180 Calling this function is typically the initial step when processing-
2181 QModelIndex-based signals from a view, such as-
2182 QAbstractItemView::activated(). In your slot, you call itemFromIndex(),-
2183 with the QModelIndex carried by the signal as argument, to obtain a-
2184 pointer to the corresponding QStandardItem.-
2185-
2186 Note that this function will lazily create an item for the index (using-
2187 itemPrototype()), and set it in the parent item's child table, if no item-
2188 already exists at that index.-
2189-
2190 If \a index is an invalid index, this function returns 0.-
2191-
2192 \sa indexFromItem()-
2193*/-
2194QStandardItem *QStandardItemModel::itemFromIndex(const QModelIndex &index) const-
2195{-
2196 Q_D(const QStandardItemModel);-
2197 if ((index.row() < 0) || (index.column() < 0) || (index.model() != this))
(index.row() < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(index.column() < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(index.model() != this)Description
TRUEnever evaluated
FALSEnever evaluated
0
2198 return 0;
never executed: return 0;
0
2199 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());-
2200 if (parent == 0)
parent == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2201 return 0;
never executed: return 0;
0
2202 QStandardItem *item = parent->child(index.row(), index.column());-
2203 // lazy part-
2204 if (item == 0) {
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2205 item = d->createItem();-
2206 parent->d_func()->setChild(index.row(), index.column(), item);-
2207 }
never executed: end of block
0
2208 return item;
never executed: return item;
0
2209}-
2210-
2211/*!-
2212 \since 4.2-
2213-
2214 Returns the QModelIndex associated with the given \a item.-
2215-
2216 Use this function when you want to perform an operation that requires the-
2217 QModelIndex of the item, such as-
2218 QAbstractItemView::scrollTo(). QStandardItem::index() is provided as-
2219 convenience; it is equivalent to calling this function.-
2220-
2221 \sa itemFromIndex(), QStandardItem::index()-
2222*/-
2223QModelIndex QStandardItemModel::indexFromItem(const QStandardItem *item) const-
2224{-
2225 if (item && item->d_func()->parent) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
item->d_func()->parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
2226 QPair<int, int> pos = item->d_func()->position();-
2227 return createIndex(pos.first, pos.second, item->d_func()->parent);
never executed: return createIndex(pos.first, pos.second, item->d_func()->parent);
0
2228 }-
2229 return QModelIndex();
never executed: return QModelIndex();
0
2230}-
2231-
2232/*!-
2233 \since 4.2-
2234-
2235 Sets the number of rows in this model to \a rows. If-
2236 this is less than rowCount(), the data in the unwanted rows-
2237 is discarded.-
2238-
2239 \sa setColumnCount()-
2240*/-
2241void QStandardItemModel::setRowCount(int rows)-
2242{-
2243 Q_D(QStandardItemModel);-
2244 d->root->setRowCount(rows);-
2245}
never executed: end of block
0
2246-
2247/*!-
2248 \since 4.2-
2249-
2250 Sets the number of columns in this model to \a columns. If-
2251 this is less than columnCount(), the data in the unwanted columns-
2252 is discarded.-
2253-
2254 \sa setRowCount()-
2255*/-
2256void QStandardItemModel::setColumnCount(int columns)-
2257{-
2258 Q_D(QStandardItemModel);-
2259 d->root->setColumnCount(columns);-
2260}
never executed: end of block
0
2261-
2262/*!-
2263 \since 4.2-
2264-
2265 Sets the item for the given \a row and \a column to \a item. The model-
2266 takes ownership of the item. If necessary, the row count and column count-
2267 are increased to fit the item. The previous item at the given location (if-
2268 there was one) is deleted.-
2269-
2270 \sa item()-
2271*/-
2272void QStandardItemModel::setItem(int row, int column, QStandardItem *item)-
2273{-
2274 Q_D(QStandardItemModel);-
2275 d->root->d_func()->setChild(row, column, item, true);-
2276}
never executed: end of block
0
2277-
2278/*!-
2279 \fn QStandardItemModel::setItem(int row, QStandardItem *item)-
2280 \overload-
2281*/-
2282-
2283/*!-
2284 \since 4.2-
2285-
2286 Returns the item for the given \a row and \a column if one has been set;-
2287 otherwise returns 0.-
2288-
2289 \sa setItem(), takeItem(), itemFromIndex()-
2290*/-
2291QStandardItem *QStandardItemModel::item(int row, int column) const-
2292{-
2293 Q_D(const QStandardItemModel);-
2294 return d->root->child(row, column);
never executed: return d->root->child(row, column);
0
2295}-
2296-
2297/*!-
2298 \since 4.2-
2299-
2300 Returns the model's invisible root item.-
2301-
2302 The invisible root item provides access to the model's top-level items-
2303 through the QStandardItem API, making it possible to write functions that-
2304 can treat top-level items and their children in a uniform way; for-
2305 example, recursive functions involving a tree model.-
2306-
2307 \note Calling \l{QAbstractItemModel::index()}{index()} on the QStandardItem object-
2308 retrieved from this function is not valid.-
2309*/-
2310QStandardItem *QStandardItemModel::invisibleRootItem() const-
2311{-
2312 Q_D(const QStandardItemModel);-
2313 return d->root.data();
never executed: return d->root.data();
0
2314}-
2315-
2316/*!-
2317 \since 4.2-
2318-
2319 Sets the horizontal header item for \a column to \a item. The model takes-
2320 ownership of the item. If necessary, the column count is increased to fit-
2321 the item. The previous header item (if there was one) is deleted.-
2322-
2323 \sa horizontalHeaderItem(), setHorizontalHeaderLabels(),-
2324 setVerticalHeaderItem()-
2325*/-
2326void QStandardItemModel::setHorizontalHeaderItem(int column, QStandardItem *item)-
2327{-
2328 Q_D(QStandardItemModel);-
2329 if (column < 0)
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2330 return;
never executed: return;
0
2331 if (columnCount() <= column)
columnCount() <= columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
2332 setColumnCount(column + 1);
never executed: setColumnCount(column + 1);
0
2333-
2334 QStandardItem *oldItem = d->columnHeaderItems.at(column);-
2335 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2336 return;
never executed: return;
0
2337-
2338 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2339 if (item->model() == 0) {
item->model() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2340 item->d_func()->setModel(this);-
2341 } else {
never executed: end of block
0
2342 qWarning("QStandardItem::setHorizontalHeaderItem: Ignoring duplicate insertion of item %p",-
2343 item);-
2344 return;
never executed: return;
0
2345 }-
2346 }-
2347-
2348 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2349 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
2350 delete oldItem;-
2351-
2352 d->columnHeaderItems.replace(column, item);-
2353 emit headerDataChanged(Qt::Horizontal, column, column);-
2354}
never executed: end of block
0
2355-
2356/*!-
2357 \since 4.2-
2358-
2359 Returns the horizontal header item for \a column if one has been set;-
2360 otherwise returns 0.-
2361-
2362 \sa setHorizontalHeaderItem(), verticalHeaderItem()-
2363*/-
2364QStandardItem *QStandardItemModel::horizontalHeaderItem(int column) const-
2365{-
2366 Q_D(const QStandardItemModel);-
2367 if ((column < 0) || (column >= columnCount()))
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(column >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2368 return 0;
never executed: return 0;
0
2369 return d->columnHeaderItems.at(column);
never executed: return d->columnHeaderItems.at(column);
0
2370}-
2371-
2372/*!-
2373 \since 4.2-
2374-
2375 Sets the vertical header item for \a row to \a item. The model takes-
2376 ownership of the item. If necessary, the row count is increased to fit the-
2377 item. The previous header item (if there was one) is deleted.-
2378-
2379 \sa verticalHeaderItem(), setVerticalHeaderLabels(),-
2380 setHorizontalHeaderItem()-
2381*/-
2382void QStandardItemModel::setVerticalHeaderItem(int row, QStandardItem *item)-
2383{-
2384 Q_D(QStandardItemModel);-
2385 if (row < 0)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2386 return;
never executed: return;
0
2387 if (rowCount() <= row)
rowCount() <= rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
2388 setRowCount(row + 1);
never executed: setRowCount(row + 1);
0
2389-
2390 QStandardItem *oldItem = d->rowHeaderItems.at(row);-
2391 if (item == oldItem)
item == oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2392 return;
never executed: return;
0
2393-
2394 if (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2395 if (item->model() == 0) {
item->model() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2396 item->d_func()->setModel(this);-
2397 } else {
never executed: end of block
0
2398 qWarning("QStandardItem::setVerticalHeaderItem: Ignoring duplicate insertion of item %p",-
2399 item);-
2400 return;
never executed: return;
0
2401 }-
2402 }-
2403-
2404 if (oldItem)
oldItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2405 oldItem->d_func()->setModel(0);
never executed: oldItem->d_func()->setModel(0);
0
2406 delete oldItem;-
2407-
2408 d->rowHeaderItems.replace(row, item);-
2409 emit headerDataChanged(Qt::Vertical, row, row);-
2410}
never executed: end of block
0
2411-
2412/*!-
2413 \since 4.2-
2414-
2415 Returns the vertical header item for row \a row if one has been set;-
2416 otherwise returns 0.-
2417-
2418 \sa setVerticalHeaderItem(), horizontalHeaderItem()-
2419*/-
2420QStandardItem *QStandardItemModel::verticalHeaderItem(int row) const-
2421{-
2422 Q_D(const QStandardItemModel);-
2423 if ((row < 0) || (row >= rowCount()))
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(row >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2424 return 0;
never executed: return 0;
0
2425 return d->rowHeaderItems.at(row);
never executed: return d->rowHeaderItems.at(row);
0
2426}-
2427-
2428/*!-
2429 \since 4.2-
2430-
2431 Sets the horizontal header labels using \a labels. If necessary, the-
2432 column count is increased to the size of \a labels.-
2433-
2434 \sa setHorizontalHeaderItem()-
2435*/-
2436void QStandardItemModel::setHorizontalHeaderLabels(const QStringList &labels)-
2437{-
2438 Q_D(QStandardItemModel);-
2439 if (columnCount() < labels.count())
columnCount() < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2440 setColumnCount(labels.count());
never executed: setColumnCount(labels.count());
0
2441 for (int i = 0; i < labels.count(); ++i) {
i < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2442 QStandardItem *item = horizontalHeaderItem(i);-
2443 if (!item) {
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2444 item = d->createItem();-
2445 setHorizontalHeaderItem(i, item);-
2446 }
never executed: end of block
0
2447 item->setText(labels.at(i));-
2448 }
never executed: end of block
0
2449}
never executed: end of block
0
2450-
2451/*!-
2452 \since 4.2-
2453-
2454 Sets the vertical header labels using \a labels. If necessary, the row-
2455 count is increased to the size of \a labels.-
2456-
2457 \sa setVerticalHeaderItem()-
2458*/-
2459void QStandardItemModel::setVerticalHeaderLabels(const QStringList &labels)-
2460{-
2461 Q_D(QStandardItemModel);-
2462 if (rowCount() < labels.count())
rowCount() < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2463 setRowCount(labels.count());
never executed: setRowCount(labels.count());
0
2464 for (int i = 0; i < labels.count(); ++i) {
i < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2465 QStandardItem *item = verticalHeaderItem(i);-
2466 if (!item) {
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2467 item = d->createItem();-
2468 setVerticalHeaderItem(i, item);-
2469 }
never executed: end of block
0
2470 item->setText(labels.at(i));-
2471 }
never executed: end of block
0
2472}
never executed: end of block
0
2473-
2474/*!-
2475 \since 4.2-
2476-
2477 Sets the item prototype for the model to the specified \a item. The model-
2478 takes ownership of the prototype.-
2479-
2480 The item prototype acts as a QStandardItem factory, by relying on the-
2481 QStandardItem::clone() function. To provide your own prototype, subclass-
2482 QStandardItem, reimplement QStandardItem::clone() and set the prototype to-
2483 be an instance of your custom class. Whenever QStandardItemModel needs to-
2484 create an item on demand (for instance, when a view or item delegate calls-
2485 setData())), the new items will be instances of your custom class.-
2486-
2487 \sa itemPrototype(), QStandardItem::clone()-
2488*/-
2489void QStandardItemModel::setItemPrototype(const QStandardItem *item)-
2490{-
2491 Q_D(QStandardItemModel);-
2492 if (d->itemPrototype != item) {
d->itemPrototype != itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2493 delete d->itemPrototype;-
2494 d->itemPrototype = item;-
2495 }
never executed: end of block
0
2496}
never executed: end of block
0
2497-
2498/*!-
2499 \since 4.2-
2500-
2501 Returns the item prototype used by the model. The model uses the item-
2502 prototype as an item factory when it needs to construct new items on-
2503 demand (for instance, when a view or item delegate calls setData()).-
2504-
2505 \sa setItemPrototype()-
2506*/-
2507const QStandardItem *QStandardItemModel::itemPrototype() const-
2508{-
2509 Q_D(const QStandardItemModel);-
2510 return d->itemPrototype;
never executed: return d->itemPrototype;
0
2511}-
2512-
2513/*!-
2514 \since 4.2-
2515-
2516 Returns a list of items that match the given \a text, using the given \a-
2517 flags, in the given \a column.-
2518*/-
2519QList<QStandardItem*> QStandardItemModel::findItems(const QString &text,-
2520 Qt::MatchFlags flags, int column) const-
2521{-
2522 QModelIndexList indexes = match(index(0, column, QModelIndex()),-
2523 Qt::DisplayRole, text, -1, flags);-
2524 QList<QStandardItem*> items;-
2525 const int numIndexes = indexes.size();-
2526 items.reserve(numIndexes);-
2527 for (int i = 0; i < numIndexes; ++i)
i < numIndexesDescription
TRUEnever evaluated
FALSEnever evaluated
0
2528 items.append(itemFromIndex(indexes.at(i)));
never executed: items.append(itemFromIndex(indexes.at(i)));
0
2529 return items;
never executed: return items;
0
2530}-
2531-
2532/*!-
2533 \since 4.2-
2534-
2535 Appends a row containing \a items. If necessary, the column count is-
2536 increased to the size of \a items.-
2537-
2538 \sa insertRow(), appendColumn()-
2539*/-
2540void QStandardItemModel::appendRow(const QList<QStandardItem*> &items)-
2541{-
2542 invisibleRootItem()->appendRow(items);-
2543}
never executed: end of block
0
2544-
2545/*!-
2546 \since 4.2-
2547-
2548 Appends a column containing \a items. If necessary, the row count is-
2549 increased to the size of \a items.-
2550-
2551 \sa insertColumn(), appendRow()-
2552*/-
2553void QStandardItemModel::appendColumn(const QList<QStandardItem*> &items)-
2554{-
2555 invisibleRootItem()->appendColumn(items);-
2556}
never executed: end of block
0
2557-
2558/*!-
2559 \since 4.2-
2560 \fn QStandardItemModel::appendRow(QStandardItem *item)-
2561 \overload-
2562-
2563 When building a list or a tree that has only one column, this function-
2564 provides a convenient way to append a single new \a item.-
2565*/-
2566-
2567/*!-
2568 \since 4.2-
2569-
2570 Inserts a row at \a row containing \a items. If necessary, the column-
2571 count is increased to the size of \a items.-
2572-
2573 \sa takeRow(), appendRow(), insertColumn()-
2574*/-
2575void QStandardItemModel::insertRow(int row, const QList<QStandardItem*> &items)-
2576{-
2577 invisibleRootItem()->insertRow(row, items);-
2578}
never executed: end of block
0
2579-
2580/*!-
2581 \since 4.2-
2582-
2583 \fn void QStandardItemModel::insertRow(int row, QStandardItem *item)-
2584 \overload-
2585-
2586 Inserts a row at \a row containing \a item.-
2587-
2588 When building a list or a tree that has only one column, this function-
2589 provides a convenient way to append a single new item.-
2590*/-
2591-
2592/*!-
2593 \since 4.2-
2594-
2595 Inserts a column at \a column containing \a items. If necessary, the row-
2596 count is increased to the size of \a items.-
2597-
2598 \sa takeColumn(), appendColumn(), insertRow()-
2599*/-
2600void QStandardItemModel::insertColumn(int column, const QList<QStandardItem*> &items)-
2601{-
2602 invisibleRootItem()->insertColumn(column, items);-
2603}
never executed: end of block
0
2604-
2605/*!-
2606 \since 4.2-
2607-
2608 Removes the item at (\a row, \a column) without deleting it. The model-
2609 releases ownership of the item.-
2610-
2611 \sa item(), takeRow(), takeColumn()-
2612*/-
2613QStandardItem *QStandardItemModel::takeItem(int row, int column)-
2614{-
2615 Q_D(QStandardItemModel);-
2616 return d->root->takeChild(row, column);
never executed: return d->root->takeChild(row, column);
0
2617}-
2618-
2619/*!-
2620 \since 4.2-
2621-
2622 Removes the given \a row without deleting the row items, and returns a-
2623 list of pointers to the removed items. The model releases ownership of the-
2624 items. For items in the row that have not been set, the corresponding-
2625 pointers in the list will be 0.-
2626-
2627 \sa takeColumn()-
2628*/-
2629QList<QStandardItem*> QStandardItemModel::takeRow(int row)-
2630{-
2631 Q_D(QStandardItemModel);-
2632 return d->root->takeRow(row);
never executed: return d->root->takeRow(row);
0
2633}-
2634-
2635/*!-
2636 \since 4.2-
2637-
2638 Removes the given \a column without deleting the column items, and returns-
2639 a list of pointers to the removed items. The model releases ownership of-
2640 the items. For items in the column that have not been set, the-
2641 corresponding pointers in the list will be 0.-
2642-
2643 \sa takeRow()-
2644*/-
2645QList<QStandardItem*> QStandardItemModel::takeColumn(int column)-
2646{-
2647 Q_D(QStandardItemModel);-
2648 return d->root->takeColumn(column);
never executed: return d->root->takeColumn(column);
0
2649}-
2650-
2651/*!-
2652 \since 4.2-
2653-
2654 Removes the horizontal header item at \a column from the header without-
2655 deleting it, and returns a pointer to the item. The model releases-
2656 ownership of the item.-
2657-
2658 \sa horizontalHeaderItem(), takeVerticalHeaderItem()-
2659*/-
2660QStandardItem *QStandardItemModel::takeHorizontalHeaderItem(int column)-
2661{-
2662 Q_D(QStandardItemModel);-
2663 if ((column < 0) || (column >= columnCount()))
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(column >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2664 return 0;
never executed: return 0;
0
2665 QStandardItem *headerItem = d->columnHeaderItems.at(column);-
2666 if (headerItem) {
headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2667 headerItem->d_func()->setParentAndModel(0, 0);-
2668 d->columnHeaderItems.replace(column, 0);-
2669 }
never executed: end of block
0
2670 return headerItem;
never executed: return headerItem;
0
2671}-
2672-
2673/*!-
2674 \since 4.2-
2675-
2676 Removes the vertical header item at \a row from the header without-
2677 deleting it, and returns a pointer to the item. The model releases-
2678 ownership of the item.-
2679-
2680 \sa verticalHeaderItem(), takeHorizontalHeaderItem()-
2681*/-
2682QStandardItem *QStandardItemModel::takeVerticalHeaderItem(int row)-
2683{-
2684 Q_D(QStandardItemModel);-
2685 if ((row < 0) || (row >= rowCount()))
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
(row >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2686 return 0;
never executed: return 0;
0
2687 QStandardItem *headerItem = d->rowHeaderItems.at(row);-
2688 if (headerItem) {
headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2689 headerItem->d_func()->setParentAndModel(0, 0);-
2690 d->rowHeaderItems.replace(row, 0);-
2691 }
never executed: end of block
0
2692 return headerItem;
never executed: return headerItem;
0
2693}-
2694-
2695/*!-
2696 \since 4.2-
2697 \property QStandardItemModel::sortRole-
2698 \brief the item role that is used to query the model's data when sorting items-
2699-
2700 The default value is Qt::DisplayRole.-
2701-
2702 \sa sort(), QStandardItem::sortChildren()-
2703*/-
2704int QStandardItemModel::sortRole() const-
2705{-
2706 Q_D(const QStandardItemModel);-
2707 return d->sortRole;
never executed: return d->sortRole;
0
2708}-
2709-
2710void QStandardItemModel::setSortRole(int role)-
2711{-
2712 Q_D(QStandardItemModel);-
2713 d->sortRole = role;-
2714}
never executed: end of block
0
2715-
2716/*!-
2717 \reimp-
2718*/-
2719int QStandardItemModel::columnCount(const QModelIndex &parent) const-
2720{-
2721 Q_D(const QStandardItemModel);-
2722 QStandardItem *item = d->itemFromIndex(parent);-
2723 return item ? item->columnCount() : 0;
never executed: return item ? item->columnCount() : 0;
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2724}-
2725-
2726/*!-
2727 \reimp-
2728*/-
2729QVariant QStandardItemModel::data(const QModelIndex &index, int role) const-
2730{-
2731 Q_D(const QStandardItemModel);-
2732 QStandardItem *item = d->itemFromIndex(index);-
2733 return item ? item->data(role) : QVariant();
never executed: return item ? item->data(role) : QVariant();
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2734}-
2735-
2736/*!-
2737 \reimp-
2738*/-
2739Qt::ItemFlags QStandardItemModel::flags(const QModelIndex &index) const-
2740{-
2741 Q_D(const QStandardItemModel);-
2742 if (!d->indexValid(index))
!d->indexValid(index)Description
TRUEnever evaluated
FALSEnever evaluated
0
2743 return d->root->flags();
never executed: return d->root->flags();
0
2744 QStandardItem *item = d->itemFromIndex(index);-
2745 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2746 return item->flags();
never executed: return item->flags();
0
2747 return Qt::ItemIsSelectable
never executed: return Qt::ItemIsSelectable |Qt::ItemIsEnabled |Qt::ItemIsEditable |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled;
0
2748 |Qt::ItemIsEnabled
never executed: return Qt::ItemIsSelectable |Qt::ItemIsEnabled |Qt::ItemIsEditable |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled;
0
2749 |Qt::ItemIsEditable
never executed: return Qt::ItemIsSelectable |Qt::ItemIsEnabled |Qt::ItemIsEditable |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled;
0
2750 |Qt::ItemIsDragEnabled
never executed: return Qt::ItemIsSelectable |Qt::ItemIsEnabled |Qt::ItemIsEditable |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled;
0
2751 |Qt::ItemIsDropEnabled;
never executed: return Qt::ItemIsSelectable |Qt::ItemIsEnabled |Qt::ItemIsEditable |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled;
0
2752}-
2753-
2754/*!-
2755 \reimp-
2756*/-
2757bool QStandardItemModel::hasChildren(const QModelIndex &parent) const-
2758{-
2759 Q_D(const QStandardItemModel);-
2760 QStandardItem *item = d->itemFromIndex(parent);-
2761 return item ? item->hasChildren() : false;
never executed: return item ? item->hasChildren() : false;
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2762}-
2763-
2764/*!-
2765 \reimp-
2766*/-
2767QModelIndex QStandardItemModel::sibling(int row, int column, const QModelIndex &idx) const-
2768{-
2769 return QAbstractItemModel::sibling(row, column, idx);
never executed: return QAbstractItemModel::sibling(row, column, idx);
0
2770}-
2771-
2772/*!-
2773 \reimp-
2774*/-
2775QVariant QStandardItemModel::headerData(int section, Qt::Orientation orientation, int role) const-
2776{-
2777 Q_D(const QStandardItemModel);-
2778 if ((section < 0)
(section < 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
2779 || ((orientation == Qt::Horizontal) && (section >= columnCount()))
(orientation =...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
(section >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2780 || ((orientation == Qt::Vertical) && (section >= rowCount()))) {
(orientation == Qt::Vertical)Description
TRUEnever evaluated
FALSEnever evaluated
(section >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2781 return QVariant();
never executed: return QVariant();
0
2782 }-
2783 QStandardItem *headerItem = 0;-
2784 if (orientation == Qt::Horizontal)
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
2785 headerItem = d->columnHeaderItems.at(section);
never executed: headerItem = d->columnHeaderItems.at(section);
0
2786 else if (orientation == Qt::Vertical)
orientation == Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
2787 headerItem = d->rowHeaderItems.at(section);
never executed: headerItem = d->rowHeaderItems.at(section);
0
2788 return headerItem ? headerItem->data(role)
never executed: return headerItem ? headerItem->data(role) : QAbstractItemModel::headerData(section, orientation, role);
headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2789 : QAbstractItemModel::headerData(section, orientation, role);
never executed: return headerItem ? headerItem->data(role) : QAbstractItemModel::headerData(section, orientation, role);
0
2790}-
2791-
2792/*!-
2793 \reimp-
2794-
2795 QStandardItemModel supports both copy and move.-
2796*/-
2797Qt::DropActions QStandardItemModel::supportedDropActions () const-
2798{-
2799 return Qt::CopyAction | Qt::MoveAction;
never executed: return Qt::CopyAction | Qt::MoveAction;
0
2800}-
2801-
2802/*!-
2803 \reimp-
2804*/-
2805QModelIndex QStandardItemModel::index(int row, int column, const QModelIndex &parent) const-
2806{-
2807 Q_D(const QStandardItemModel);-
2808 QStandardItem *parentItem = d->itemFromIndex(parent);-
2809 if ((parentItem == 0)
(parentItem == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
2810 || (row < 0)
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
2811 || (column < 0)
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
2812 || (row >= parentItem->rowCount())
(row >= parent...m->rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2813 || (column >= parentItem->columnCount())) {
(column >= par...columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2814 return QModelIndex();
never executed: return QModelIndex();
0
2815 }-
2816 return createIndex(row, column, parentItem);
never executed: return createIndex(row, column, parentItem);
0
2817}-
2818-
2819/*!-
2820 \reimp-
2821*/-
2822bool QStandardItemModel::insertColumns(int column, int count, const QModelIndex &parent)-
2823{-
2824 Q_D(QStandardItemModel);-
2825 QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2826 if (item == 0)
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2827 return false;
never executed: return false;
0
2828 return item->d_func()->insertColumns(column, count, QList<QStandardItem*>());
never executed: return item->d_func()->insertColumns(column, count, QList<QStandardItem*>());
0
2829}-
2830-
2831/*!-
2832 \reimp-
2833*/-
2834bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &parent)-
2835{-
2836 Q_D(QStandardItemModel);-
2837 QStandardItem *item = parent.isValid() ? itemFromIndex(parent) : d->root.data();
parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2838 if (item == 0)
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2839 return false;
never executed: return false;
0
2840 return item->d_func()->insertRows(row, count, QList<QStandardItem*>());
never executed: return item->d_func()->insertRows(row, count, QList<QStandardItem*>());
0
2841}-
2842-
2843/*!-
2844 \reimp-
2845*/-
2846QMap<int, QVariant> QStandardItemModel::itemData(const QModelIndex &index) const-
2847{-
2848 Q_D(const QStandardItemModel);-
2849 QStandardItem *item = d->itemFromIndex(index);-
2850 return item ? item->d_func()->itemData() : QMap<int, QVariant>();
never executed: return item ? item->d_func()->itemData() : QMap<int, QVariant>();
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2851}-
2852-
2853/*!-
2854 \reimp-
2855*/-
2856QModelIndex QStandardItemModel::parent(const QModelIndex &child) const-
2857{-
2858 Q_D(const QStandardItemModel);-
2859 if (!d->indexValid(child))
!d->indexValid(child)Description
TRUEnever evaluated
FALSEnever evaluated
0
2860 return QModelIndex();
never executed: return QModelIndex();
0
2861 QStandardItem *parentItem = static_cast<QStandardItem*>(child.internalPointer());-
2862 return indexFromItem(parentItem);
never executed: return indexFromItem(parentItem);
0
2863}-
2864-
2865/*!-
2866 \reimp-
2867*/-
2868bool QStandardItemModel::removeColumns(int column, int count, const QModelIndex &parent)-
2869{-
2870 Q_D(QStandardItemModel);-
2871 QStandardItem *item = d->itemFromIndex(parent);-
2872 if ((item == 0) || (count < 1) || (column < 0) || ((column + count) > item->columnCount()))
(item == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(column < 0)Description
TRUEnever evaluated
FALSEnever evaluated
((column + cou...columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2873 return false;
never executed: return false;
0
2874 item->removeColumns(column, count);-
2875 return true;
never executed: return true;
0
2876}-
2877-
2878/*!-
2879 \reimp-
2880*/-
2881bool QStandardItemModel::removeRows(int row, int count, const QModelIndex &parent)-
2882{-
2883 Q_D(QStandardItemModel);-
2884 QStandardItem *item = d->itemFromIndex(parent);-
2885 if ((item == 0) || (count < 1) || (row < 0) || ((row + count) > item->rowCount()))
(item == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(count < 1)Description
TRUEnever evaluated
FALSEnever evaluated
(row < 0)Description
TRUEnever evaluated
FALSEnever evaluated
((row + count)...m->rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2886 return false;
never executed: return false;
0
2887 item->removeRows(row, count);-
2888 return true;
never executed: return true;
0
2889}-
2890-
2891/*!-
2892 \reimp-
2893*/-
2894int QStandardItemModel::rowCount(const QModelIndex &parent) const-
2895{-
2896 Q_D(const QStandardItemModel);-
2897 QStandardItem *item = d->itemFromIndex(parent);-
2898 return item ? item->rowCount() : 0;
never executed: return item ? item->rowCount() : 0;
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2899}-
2900-
2901/*!-
2902 \reimp-
2903*/-
2904bool QStandardItemModel::setData(const QModelIndex &index, const QVariant &value, int role)-
2905{-
2906 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2907 return false;
never executed: return false;
0
2908 QStandardItem *item = itemFromIndex(index);-
2909 if (item == 0)
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2910 return false;
never executed: return false;
0
2911 item->setData(value, role);-
2912 return true;
never executed: return true;
0
2913}-
2914-
2915/*!-
2916 \reimp-
2917*/-
2918bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)-
2919{-
2920 Q_D(QStandardItemModel);-
2921 if ((section < 0)
(section < 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
2922 || ((orientation == Qt::Horizontal) && (section >= columnCount()))
(orientation =...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
(section >= columnCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2923 || ((orientation == Qt::Vertical) && (section >= rowCount()))) {
(orientation == Qt::Vertical)Description
TRUEnever evaluated
FALSEnever evaluated
(section >= rowCount())Description
TRUEnever evaluated
FALSEnever evaluated
0
2924 return false;
never executed: return false;
0
2925 }-
2926 QStandardItem *headerItem = 0;-
2927 if (orientation == Qt::Horizontal) {
orientation == Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
2928 headerItem = d->columnHeaderItems.at(section);-
2929 if (headerItem == 0) {
headerItem == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2930 headerItem = d->createItem();-
2931 headerItem->d_func()->setModel(this);-
2932 d->columnHeaderItems.replace(section, headerItem);-
2933 }
never executed: end of block
0
2934 } else if (orientation == Qt::Vertical) {
never executed: end of block
orientation == Qt::VerticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
2935 headerItem = d->rowHeaderItems.at(section);-
2936 if (headerItem == 0) {
headerItem == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2937 headerItem = d->createItem();-
2938 headerItem->d_func()->setModel(this);-
2939 d->rowHeaderItems.replace(section, headerItem);-
2940 }
never executed: end of block
0
2941 }
never executed: end of block
0
2942 if (headerItem) {
headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2943 headerItem->setData(value, role);-
2944 return true;
never executed: return true;
0
2945 }-
2946 return false;
never executed: return false;
0
2947}-
2948-
2949/*!-
2950 \reimp-
2951*/-
2952bool QStandardItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)-
2953{-
2954 QStandardItem *item = itemFromIndex(index);-
2955 if (item == 0)
item == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2956 return false;
never executed: return false;
0
2957 item->d_func()->setItemData(roles);-
2958 return true;
never executed: return true;
0
2959}-
2960-
2961/*!-
2962 \reimp-
2963*/-
2964void QStandardItemModel::sort(int column, Qt::SortOrder order)-
2965{-
2966 Q_D(QStandardItemModel);-
2967 d->root->sortChildren(column, order);-
2968}
never executed: end of block
0
2969-
2970/*!-
2971 \reimp-
2972*/-
2973QStringList QStandardItemModel::mimeTypes() const-
2974{-
2975 return QAbstractItemModel::mimeTypes() << QLatin1String("application/x-qstandarditemmodeldatalist");
never executed: return QAbstractItemModel::mimeTypes() << QLatin1String("application/x-qstandarditemmodeldatalist");
0
2976}-
2977-
2978/*!-
2979 \reimp-
2980*/-
2981QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const-
2982{-
2983 QMimeData *data = QAbstractItemModel::mimeData(indexes);-
2984 if(!data)
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
2985 return 0;
never executed: return 0;
0
2986-
2987 QString format = QLatin1String("application/x-qstandarditemmodeldatalist");-
2988 if (!mimeTypes().contains(format))
!mimeTypes().contains(format)Description
TRUEnever evaluated
FALSEnever evaluated
0
2989 return data;
never executed: return data;
0
2990 QByteArray encoded;-
2991 QDataStream stream(&encoded, QIODevice::WriteOnly);-
2992-
2993 QSet<QStandardItem*> itemsSet;-
2994 QStack<QStandardItem*> stack;-
2995 itemsSet.reserve(indexes.count());-
2996 stack.reserve(indexes.count());-
2997 for (int i = 0; i < indexes.count(); ++i) {
i < indexes.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2998 if (QStandardItem *item = itemFromIndex(indexes.at(i))) {
QStandardItem ...indexes.at(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
2999 itemsSet << item;-
3000 stack.push(item);-
3001 } else {
never executed: end of block
0
3002 qWarning() << "QStandardItemModel::mimeData: No item associated with invalid index";-
3003 return 0;
never executed: return 0;
0
3004 }-
3005 }-
3006-
3007 //remove duplicates childrens-
3008 {-
3009 QSet<QStandardItem *> seen;-
3010 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3011 QStandardItem *itm = stack.pop();-
3012 if (seen.contains(itm))
seen.contains(itm)Description
TRUEnever evaluated
FALSEnever evaluated
0
3013 continue;
never executed: continue;
0
3014 seen.insert(itm);-
3015-
3016 const QVector<QStandardItem*> &childList = itm->d_func()->children;-
3017 for (int i = 0; i < childList.count(); ++i) {
i < childList.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3018 QStandardItem *chi = childList.at(i);-
3019 if (chi) {
chiDescription
TRUEnever evaluated
FALSEnever evaluated
0
3020 QSet<QStandardItem *>::iterator it = itemsSet.find(chi);-
3021 if (it != itemsSet.end()) {
it != itemsSet.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
3022 itemsSet.erase(it);-
3023 }
never executed: end of block
0
3024 stack.push(chi);-
3025 }
never executed: end of block
0
3026 }
never executed: end of block
0
3027 }
never executed: end of block
0
3028 }-
3029-
3030 stack.reserve(itemsSet.count());-
3031 foreach (QStandardItem *item, itemsSet) {-
3032 stack.push(item);-
3033 }
never executed: end of block
0
3034-
3035 //stream everything recursively-
3036 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3037 QStandardItem *item = stack.pop();-
3038 if (itemsSet.contains(item)) //if the item is selection 'top-level', stream its position
itemsSet.contains(item)Description
TRUEnever evaluated
FALSEnever evaluated
0
3039 stream << item->row() << item->column();
never executed: stream << item->row() << item->column();
0
3040-
3041 stream << *item << item->columnCount() << item->d_ptr->children.count();-
3042 stack += item->d_ptr->children;-
3043 }
never executed: end of block
0
3044-
3045 data->setData(format, encoded);-
3046 return data;
never executed: return data;
0
3047}-
3048-
3049-
3050/* \internal-
3051 Used by QStandardItemModel::dropMimeData-
3052 stream out an item and his children-
3053 */-
3054void QStandardItemModelPrivate::decodeDataRecursive(QDataStream &stream, QStandardItem *item)-
3055{-
3056 int colCount, childCount;-
3057 stream >> *item;-
3058 stream >> colCount >> childCount;-
3059 item->setColumnCount(colCount);-
3060-
3061 int childPos = childCount;-
3062-
3063 while(childPos > 0) {
childPos > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
3064 childPos--;-
3065 QStandardItem *child = createItem();-
3066 decodeDataRecursive(stream, child);-
3067 item->setChild( childPos / colCount, childPos % colCount, child);-
3068 }
never executed: end of block
0
3069}
never executed: end of block
0
3070-
3071-
3072/*!-
3073 \reimp-
3074*/-
3075bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action,-
3076 int row, int column, const QModelIndex &parent)-
3077{-
3078 Q_D(QStandardItemModel);-
3079 // check if the action is supported-
3080 if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction))
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
action == Qt::CopyActionDescription
TRUEnever evaluated
FALSEnever evaluated
action == Qt::MoveActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
3081 return false;
never executed: return false;
0
3082 // check if the format is supported-
3083 QString format = QLatin1String("application/x-qstandarditemmodeldatalist");-
3084 if (!data->hasFormat(format))
!data->hasFormat(format)Description
TRUEnever evaluated
FALSEnever evaluated
0
3085 return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
never executed: return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
0
3086-
3087 if (row > rowCount(parent))
row > rowCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
3088 row = rowCount(parent);
never executed: row = rowCount(parent);
0
3089 if (row == -1)
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
3090 row = rowCount(parent);
never executed: row = rowCount(parent);
0
3091 if (column == -1)
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
3092 column = 0;
never executed: column = 0;
0
3093-
3094 // decode and insert-
3095 QByteArray encoded = data->data(format);-
3096 QDataStream stream(&encoded, QIODevice::ReadOnly);-
3097-
3098-
3099 //code based on QAbstractItemModel::decodeData-
3100 // adapted to work with QStandardItem-
3101 int top = INT_MAX;-
3102 int left = INT_MAX;-
3103 int bottom = 0;-
3104 int right = 0;-
3105 QVector<int> rows, columns;-
3106 QVector<QStandardItem *> items;-
3107-
3108 while (!stream.atEnd()) {
!stream.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
3109 int r, c;-
3110 QStandardItem *item = d->createItem();-
3111 stream >> r >> c;-
3112 d->decodeDataRecursive(stream, item);-
3113-
3114 rows.append(r);-
3115 columns.append(c);-
3116 items.append(item);-
3117 top = qMin(r, top);-
3118 left = qMin(c, left);-
3119 bottom = qMax(r, bottom);-
3120 right = qMax(c, right);-
3121 }
never executed: end of block
0
3122-
3123 // insert the dragged items into the table, use a bit array to avoid overwriting items,-
3124 // since items from different tables can have the same row and column-
3125 int dragRowCount = 0;-
3126 int dragColumnCount = right - left + 1;-
3127-
3128 // Compute the number of continuous rows upon insertion and modify the rows to match-
3129 QVector<int> rowsToInsert(bottom + 1);-
3130 for (int i = 0; i < rows.count(); ++i)
i < rows.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3131 rowsToInsert[rows.at(i)] = 1;
never executed: rowsToInsert[rows.at(i)] = 1;
0
3132 for (int i = 0; i < rowsToInsert.count(); ++i) {
i < rowsToInsert.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3133 if (rowsToInsert[i] == 1){
rowsToInsert[i] == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
3134 rowsToInsert[i] = dragRowCount;-
3135 ++dragRowCount;-
3136 }
never executed: end of block
0
3137 }
never executed: end of block
0
3138 for (int i = 0; i < rows.count(); ++i)
i < rows.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3139 rows[i] = top + rowsToInsert[rows[i]];
never executed: rows[i] = top + rowsToInsert[rows[i]];
0
3140-
3141 QBitArray isWrittenTo(dragRowCount * dragColumnCount);-
3142-
3143 // make space in the table for the dropped data-
3144 int colCount = columnCount(parent);-
3145 if (colCount < dragColumnCount + column) {
colCount < dra...Count + columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
3146 insertColumns(colCount, dragColumnCount + column - colCount, parent);-
3147 colCount = columnCount(parent);-
3148 }
never executed: end of block
0
3149 insertRows(row, dragRowCount, parent);-
3150-
3151 row = qMax(0, row);-
3152 column = qMax(0, column);-
3153-
3154 QStandardItem *parentItem = itemFromIndex (parent);-
3155 if (!parentItem)
!parentItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3156 parentItem = invisibleRootItem();
never executed: parentItem = invisibleRootItem();
0
3157-
3158 QVector<QPersistentModelIndex> newIndexes(items.size());-
3159 // set the data in the table-
3160 for (int j = 0; j < items.size(); ++j) {
j < items.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
3161 int relativeRow = rows.at(j) - top;-
3162 int relativeColumn = columns.at(j) - left;-
3163 int destinationRow = relativeRow + row;-
3164 int destinationColumn = relativeColumn + column;-
3165 int flat = (relativeRow * dragColumnCount) + relativeColumn;-
3166 // if the item was already written to, or we just can't fit it in the table, create a new row-
3167 if (destinationColumn >= colCount || isWrittenTo.testBit(flat)) {
destinationColumn >= colCountDescription
TRUEnever evaluated
FALSEnever evaluated
isWrittenTo.testBit(flat)Description
TRUEnever evaluated
FALSEnever evaluated
0
3168 destinationColumn = qBound(column, destinationColumn, colCount - 1);-
3169 destinationRow = row + dragRowCount;-
3170 insertRows(row + dragRowCount, 1, parent);-
3171 flat = (dragRowCount * dragColumnCount) + relativeColumn;-
3172 isWrittenTo.resize(++dragRowCount * dragColumnCount);-
3173 }
never executed: end of block
0
3174 if (!isWrittenTo.testBit(flat)) {
!isWrittenTo.testBit(flat)Description
TRUEnever evaluated
FALSEnever evaluated
0
3175 newIndexes[j] = index(destinationRow, destinationColumn, parentItem->index());-
3176 isWrittenTo.setBit(flat);-
3177 }
never executed: end of block
0
3178 }
never executed: end of block
0
3179-
3180 for(int k = 0; k < newIndexes.size(); k++) {
k < newIndexes.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
3181 if (newIndexes.at(k).isValid()) {
newIndexes.at(k).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
3182 parentItem->setChild(newIndexes.at(k).row(), newIndexes.at(k).column(), items.at(k));-
3183 } else {
never executed: end of block
0
3184 delete items.at(k);-
3185 }
never executed: end of block
0
3186 }-
3187-
3188 return true;
never executed: return true;
0
3189}-
3190-
3191QT_END_NAMESPACE-
3192-
3193#include "moc_qstandarditemmodel.cpp"-
3194-
3195#endif // QT_NO_STANDARDITEMMODEL-
Source codeSwitch to Preprocessed file

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