OpenCoverage

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

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