qtreewidget.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qtreewidget.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 QtWidgets 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 "qtreewidget.h"-
41-
42#ifndef QT_NO_TREEWIDGET-
43#include <qheaderview.h>-
44#include <qpainter.h>-
45#include <qitemdelegate.h>-
46#include <qstack.h>-
47#include <qdebug.h>-
48#include <private/qtreewidget_p.h>-
49#include <private/qwidgetitemdata_p.h>-
50#include <private/qtreewidgetitemiterator_p.h>-
51-
52#include <algorithm>-
53-
54QT_BEGIN_NAMESPACE-
55-
56// workaround for VC++ 6.0 linker bug (?)-
57typedef bool(*LessThan)(const QPair<QTreeWidgetItem*,int>&,const QPair<QTreeWidgetItem*,int>&);-
58-
59class QTreeModelLessThan-
60{-
61public:-
62 inline bool operator()(QTreeWidgetItem *i1, QTreeWidgetItem *i2) const-
63 { return *i1 < *i2; }
never executed: return *i1 < *i2;
0
64};-
65-
66class QTreeModelGreaterThan-
67{-
68public:-
69 inline bool operator()(QTreeWidgetItem *i1, QTreeWidgetItem *i2) const-
70 { return *i2 < *i1; }
never executed: return *i2 < *i1;
0
71};-
72-
73/*-
74 \class QTreeModel-
75 \brief The QTreeModel class manages the items stored in a tree view.-
76-
77 \ingroup model-view-
78 \inmodule QtWidgets-
79-
80*/-
81-
82/*!-
83 \enum QTreeWidgetItem::ChildIndicatorPolicy-
84 \since 4.3-
85-
86 \value ShowIndicator The controls for expanding and collapsing will be shown for this item even if there are no children.-
87 \value DontShowIndicator The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.-
88 \value DontShowIndicatorWhenChildless The controls for expanding and collapsing will be shown if the item contains children.-
89*/-
90-
91/*!-
92 \fn void QTreeWidgetItem::setDisabled(bool disabled)-
93 \since 4.3-
94-
95 Disables the item if \a disabled is true; otherwise enables the item.-
96-
97 \sa setFlags()-
98*/-
99-
100/*!-
101 \fn bool QTreeWidgetItem::isDisabled() const-
102 \since 4.3-
103-
104 Returns \c true if the item is disabled; otherwise returns \c false.-
105-
106 \sa setFlags()-
107*/-
108-
109/*!-
110 \internal-
111-
112 Constructs a tree model with a \a parent object and the given-
113 number of \a columns.-
114*/-
115-
116QTreeModel::QTreeModel(int columns, QTreeWidget *parent)-
117 : QAbstractItemModel(parent), rootItem(new QTreeWidgetItem),-
118 headerItem(new QTreeWidgetItem), skipPendingSort(false)-
119{-
120 rootItem->view = parent;-
121 rootItem->itemFlags = Qt::ItemIsDropEnabled;-
122 headerItem->view = parent;-
123 setColumnCount(columns);-
124}
never executed: end of block
0
125-
126/*!-
127 \internal-
128-
129*/-
130-
131QTreeModel::QTreeModel(QTreeModelPrivate &dd, QTreeWidget *parent)-
132 : QAbstractItemModel(dd, parent), rootItem(new QTreeWidgetItem),-
133 headerItem(new QTreeWidgetItem), skipPendingSort(false)-
134{-
135 rootItem->view = parent;-
136 rootItem->itemFlags = Qt::ItemIsDropEnabled;-
137 headerItem->view = parent;-
138}
never executed: end of block
0
139-
140/*!-
141 \internal-
142-
143 Destroys this tree model.-
144*/-
145-
146QTreeModel::~QTreeModel()-
147{-
148 clear();-
149 headerItem->view = Q_NULLPTR;-
150 delete headerItem;-
151 rootItem->view = 0;-
152 delete rootItem;-
153}
never executed: end of block
0
154-
155/*!-
156 \internal-
157-
158 Removes all items in the model.-
159*/-
160-
161void QTreeModel::clear()-
162{-
163 SkipSorting skipSorting(this);-
164 beginResetModel();-
165 for (int i = 0; i < rootItem->childCount(); ++i) {
i < rootItem->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
166 QTreeWidgetItem *item = rootItem->children.at(i);-
167 item->par = 0;-
168 item->view = 0;-
169 delete item;-
170 }
never executed: end of block
0
171 rootItem->children.clear();-
172 sortPendingTimer.stop();-
173 endResetModel();-
174}
never executed: end of block
0
175-
176/*!-
177 \internal-
178-
179 Sets the number of \a columns in the tree model.-
180*/-
181-
182void QTreeModel::setColumnCount(int columns)-
183{-
184 SkipSorting skipSorting(this);-
185 if (columns < 0)
columns < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
186 return;
never executed: return;
0
187 if (!headerItem) {
!headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
188 headerItem = new QTreeWidgetItem();-
189 headerItem->view = view();-
190 }
never executed: end of block
0
191 int count = columnCount();-
192 if (count == columns)
count == columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 return;
never executed: return;
0
194-
195 if (columns < count) {
columns < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
196 beginRemoveColumns(QModelIndex(), columns, count - 1);-
197 headerItem->values.resize(columns);-
198 endRemoveColumns();-
199 } else {
never executed: end of block
0
200 beginInsertColumns(QModelIndex(), count, columns - 1);-
201 headerItem->values.resize(columns);-
202 for (int i = count; i < columns; ++i) {// insert data without emitting the dataChanged signal
i < columnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
203 headerItem->values[i].append(QWidgetItemData(Qt::DisplayRole, QString::number(i + 1)));-
204 headerItem->d->display.append(QString::number(i + 1));-
205 }
never executed: end of block
0
206 endInsertColumns();-
207 }
never executed: end of block
0
208}-
209-
210/*!-
211 \internal-
212-
213 Returns the tree view item corresponding to the \a index given.-
214-
215 \sa QModelIndex-
216*/-
217-
218QTreeWidgetItem *QTreeModel::item(const QModelIndex &index) const-
219{-
220 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
221 return 0;
never executed: return 0;
0
222 return static_cast<QTreeWidgetItem*>(index.internalPointer());
never executed: return static_cast<QTreeWidgetItem*>(index.internalPointer());
0
223}-
224-
225/*!-
226 \internal-
227-
228 Returns the model index that refers to the-
229 tree view \a item and \a column.-
230*/-
231-
232QModelIndex QTreeModel::index(const QTreeWidgetItem *item, int column) const-
233{-
234 executePendingSort();-
235-
236 if (!item || (item == rootItem))
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
(item == rootItem)Description
TRUEnever evaluated
FALSEnever evaluated
0
237 return QModelIndex();
never executed: return QModelIndex();
0
238 const QTreeWidgetItem *par = item->parent();-
239 QTreeWidgetItem *itm = const_cast<QTreeWidgetItem*>(item);-
240 if (!par)
!parDescription
TRUEnever evaluated
FALSEnever evaluated
0
241 par = rootItem;
never executed: par = rootItem;
0
242 int row;-
243 int guess = item->d->rowGuess;-
244 if (guess >= 0
guess >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
245 && par->children.count() > guess
par->children.count() > guessDescription
TRUEnever evaluated
FALSEnever evaluated
0
246 && par->children.at(guess) == itm) {
par->children.at(guess) == itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
247 row = guess;-
248 } else {
never executed: end of block
0
249 row = par->children.lastIndexOf(itm);-
250 itm->d->rowGuess = row;-
251 }
never executed: end of block
0
252 return createIndex(row, column, itm);
never executed: return createIndex(row, column, itm);
0
253}-
254-
255/*!-
256 \internal-
257 \reimp-
258-
259 Returns the model index with the given \a row,-
260 \a column and \a parent.-
261*/-
262-
263QModelIndex QTreeModel::index(int row, int column, const QModelIndex &parent) const-
264{-
265 executePendingSort();-
266-
267 int c = columnCount(parent);-
268 if (row < 0 || column < 0 || column >= c)
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column >= cDescription
TRUEnever evaluated
FALSEnever evaluated
0
269 return QModelIndex();
never executed: return QModelIndex();
0
270-
271 QTreeWidgetItem *parentItem = parent.isValid() ? item(parent) : rootItem;
parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
272 if (parentItem && row < parentItem->childCount()) {
parentItemDescription
TRUEnever evaluated
FALSEnever evaluated
row < parentItem->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
273 QTreeWidgetItem *itm = parentItem->child(row);-
274 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
275 return createIndex(row, column, itm);
never executed: return createIndex(row, column, itm);
0
276 return QModelIndex();
never executed: return QModelIndex();
0
277 }-
278-
279 return QModelIndex();
never executed: return QModelIndex();
0
280}-
281-
282/*!-
283 \internal-
284 \reimp-
285-
286 Returns the parent model index of the index given as-
287 the \a child.-
288*/-
289-
290QModelIndex QTreeModel::parent(const QModelIndex &child) const-
291{-
292 SkipSorting skipSorting(this); //The reason we don't sort here is that this might be called from a valid QPersistentModelIndex-
293 //We don't want it to become suddenly invalid-
294-
295 if (!child.isValid())
!child.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
296 return QModelIndex();
never executed: return QModelIndex();
0
297 QTreeWidgetItem *itm = static_cast<QTreeWidgetItem *>(child.internalPointer());-
298 if (!itm || itm == rootItem)
!itmDescription
TRUEnever evaluated
FALSEnever evaluated
itm == rootItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
299 return QModelIndex();
never executed: return QModelIndex();
0
300 QTreeWidgetItem *parent = itm->parent();-
301 return index(parent, 0);
never executed: return index(parent, 0);
0
302}-
303-
304/*!-
305 \internal-
306 \reimp-
307-
308 Returns the number of rows in the \a parent model index.-
309*/-
310-
311int QTreeModel::rowCount(const QModelIndex &parent) const-
312{-
313 if (!parent.isValid())
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
314 return rootItem->childCount();
never executed: return rootItem->childCount();
0
315-
316 QTreeWidgetItem *parentItem = item(parent);-
317 if (parentItem)
parentItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
318 return parentItem->childCount();
never executed: return parentItem->childCount();
0
319 return 0;
never executed: return 0;
0
320}-
321-
322/*!-
323 \internal-
324 \reimp-
325-
326 Returns the number of columns in the item referred to by-
327 the given \a index.-
328*/-
329-
330int QTreeModel::columnCount(const QModelIndex &index) const-
331{-
332 Q_UNUSED(index);-
333 if (!headerItem)
!headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
334 return 0;
never executed: return 0;
0
335 return headerItem->columnCount();
never executed: return headerItem->columnCount();
0
336}-
337-
338bool QTreeModel::hasChildren(const QModelIndex &parent) const-
339{-
340 if (!parent.isValid())
!parent.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
341 return (rootItem->childCount() > 0);
never executed: return (rootItem->childCount() > 0);
0
342-
343 QTreeWidgetItem *itm = item(parent);-
344 if (!itm)
!itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
345 return false;
never executed: return false;
0
346 switch (itm->d->policy) {-
347 case QTreeWidgetItem::ShowIndicator:
never executed: case QTreeWidgetItem::ShowIndicator:
0
348 return true;
never executed: return true;
0
349 case QTreeWidgetItem::DontShowIndicator:
never executed: case QTreeWidgetItem::DontShowIndicator:
0
350 return false;
never executed: return false;
0
351 case QTreeWidgetItem::DontShowIndicatorWhenChildless:
never executed: case QTreeWidgetItem::DontShowIndicatorWhenChildless:
0
352 return (itm->childCount() > 0);
never executed: return (itm->childCount() > 0);
0
353 }-
354 return false;
never executed: return false;
0
355}-
356-
357/*!-
358 \internal-
359 \reimp-
360-
361 Returns the data corresponding to the given model \a index-
362 and \a role.-
363*/-
364-
365QVariant QTreeModel::data(const QModelIndex &index, int role) const-
366{-
367 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
368 return QVariant();
never executed: return QVariant();
0
369 QTreeWidgetItem *itm = item(index);-
370 if (itm)
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
371 return itm->data(index.column(), role);
never executed: return itm->data(index.column(), role);
0
372 return QVariant();
never executed: return QVariant();
0
373}-
374-
375/*!-
376 \internal-
377 \reimp-
378-
379 Sets the data for the item specified by the \a index and \a role-
380 to that referred to by the \a value.-
381-
382 Returns \c true if successful; otherwise returns \c false.-
383*/-
384-
385bool QTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)-
386{-
387 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
388 return false;
never executed: return false;
0
389 QTreeWidgetItem *itm = item(index);-
390 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
391 itm->setData(index.column(), role, value);-
392 return true;
never executed: return true;
0
393 }-
394 return false;
never executed: return false;
0
395}-
396-
397QMap<int, QVariant> QTreeModel::itemData(const QModelIndex &index) const-
398{-
399 QMap<int, QVariant> roles;-
400 QTreeWidgetItem *itm = item(index);-
401 if (itm) {
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
402 int column = index.column();-
403 if (column < itm->values.count()) {
column < itm->values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
404 for (int i = 0; i < itm->values.at(column).count(); ++i) {
i < itm->value...olumn).count()Description
TRUEnever evaluated
FALSEnever evaluated
0
405 roles.insert(itm->values.at(column).at(i).role,-
406 itm->values.at(column).at(i).value);-
407 }
never executed: end of block
0
408 }
never executed: end of block
0
409-
410 // the two special cases-
411 QVariant displayValue = itm->data(column, Qt::DisplayRole);-
412 if (displayValue.isValid())
displayValue.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
413 roles.insert(Qt::DisplayRole, displayValue);
never executed: roles.insert(Qt::DisplayRole, displayValue);
0
414-
415 QVariant checkValue = itm->data(column, Qt::CheckStateRole);-
416 if (checkValue.isValid())
checkValue.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
417 roles.insert(Qt::CheckStateRole, checkValue);
never executed: roles.insert(Qt::CheckStateRole, checkValue);
0
418 }
never executed: end of block
0
419 return roles;
never executed: return roles;
0
420}-
421-
422/*!-
423 \internal-
424 \reimp-
425*/-
426bool QTreeModel::insertRows(int row, int count, const QModelIndex &parent)-
427{-
428 SkipSorting skipSorting(this);-
429 if (count < 1 || row < 0 || row > rowCount(parent) || parent.column() > 0)
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
row > rowCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
parent.column() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
430 return false;
never executed: return false;
0
431-
432 beginInsertRows(parent, row, row + count - 1);-
433 QTreeWidgetItem *par = item(parent);-
434 while (count > 0) {
count > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
435 QTreeWidgetItem *item = new QTreeWidgetItem();-
436 item->view = view();-
437 item->par = par;-
438 if (par)
parDescription
TRUEnever evaluated
FALSEnever evaluated
0
439 par->children.insert(row++, item);
never executed: par->children.insert(row++, item);
0
440 else-
441 rootItem->children.insert(row++, item);
never executed: rootItem->children.insert(row++, item);
0
442 --count;-
443 }
never executed: end of block
0
444 endInsertRows();-
445 return true;
never executed: return true;
0
446}-
447-
448/*!-
449 \internal-
450 \reimp-
451*/-
452bool QTreeModel::insertColumns(int column, int count, const QModelIndex &parent)-
453{-
454 SkipSorting skipSorting(this);-
455 if (count < 1 || column < 0 || column > columnCount(parent) || parent.column() > 0 || !headerItem)
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column > columnCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
parent.column() > 0Description
TRUEnever evaluated
FALSEnever evaluated
!headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
456 return false;
never executed: return false;
0
457-
458 beginInsertColumns(parent, column, column + count - 1);-
459-
460 int oldCount = columnCount(parent);-
461 column = qBound(0, column, oldCount);-
462 headerItem->values.resize(oldCount + count);-
463 for (int i = oldCount; i < oldCount + count; ++i) {
i < oldCount + countDescription
TRUEnever evaluated
FALSEnever evaluated
0
464 headerItem->values[i].append(QWidgetItemData(Qt::DisplayRole, QString::number(i + 1)));-
465 headerItem->d->display.append(QString::number(i + 1));-
466 }
never executed: end of block
0
467-
468 QStack<QTreeWidgetItem*> itemstack;-
469 itemstack.push(0);-
470 while (!itemstack.isEmpty()) {
!itemstack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
471 QTreeWidgetItem *par = itemstack.pop();-
472 QList<QTreeWidgetItem*> children = par ? par->children : rootItem->children;
parDescription
TRUEnever evaluated
FALSEnever evaluated
0
473 for (int row = 0; row < children.count(); ++row) {
row < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
474 QTreeWidgetItem *child = children.at(row);-
475 if (child->children.count())
child->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
476 itemstack.push(child);
never executed: itemstack.push(child);
0
477 child->values.insert(column, count, QVector<QWidgetItemData>());-
478 }
never executed: end of block
0
479 }
never executed: end of block
0
480-
481 endInsertColumns();-
482 return true;
never executed: return true;
0
483}-
484-
485/*!-
486 \internal-
487 \reimp-
488*/-
489bool QTreeModel::removeRows(int row, int count, const QModelIndex &parent) {-
490 if (count < 1 || row < 0 || (row + count) > rowCount(parent))
count < 1Description
TRUEnever evaluated
FALSEnever evaluated
row < 0Description
TRUEnever evaluated
FALSEnever evaluated
(row + count) ...wCount(parent)Description
TRUEnever evaluated
FALSEnever evaluated
0
491 return false;
never executed: return false;
0
492-
493 beginRemoveRows(parent, row, row + count - 1);-
494-
495 QSignalBlocker blocker(this);-
496-
497 QTreeWidgetItem *itm = item(parent);-
498 for (int i = row + count - 1; i >= row; --i) {
i >= rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
499 QTreeWidgetItem *child = itm ? itm->takeChild(i) : rootItem->children.takeAt(i);
itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
500 Q_ASSERT(child);-
501 child->view = 0;-
502 delete child;-
503 child = 0;-
504 }
never executed: end of block
0
505 blocker.unblock();-
506-
507 endRemoveRows();-
508 return true;
never executed: return true;
0
509}-
510-
511/*!-
512 \internal-
513 \reimp-
514-
515 Returns the header data corresponding to the given header \a section,-
516 \a orientation and data \a role.-
517*/-
518-
519QVariant QTreeModel::headerData(int section, Qt::Orientation orientation, int role) const-
520{-
521 if (orientation != Qt::Horizontal)
orientation != Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
522 return QVariant();
never executed: return QVariant();
0
523-
524 if (headerItem)
headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
525 return headerItem->data(section, role);
never executed: return headerItem->data(section, role);
0
526 if (role == Qt::DisplayRole)
role == Qt::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
527 return QString::number(section + 1);
never executed: return QString::number(section + 1);
0
528 return QVariant();
never executed: return QVariant();
0
529}-
530-
531/*!-
532 \internal-
533 \reimp-
534-
535 Sets the header data for the item specified by the header \a section,-
536 \a orientation and data \a role to the given \a value.-
537-
538 Returns \c true if successful; otherwise returns \c false.-
539*/-
540-
541bool QTreeModel::setHeaderData(int section, Qt::Orientation orientation,-
542 const QVariant &value, int role)-
543{-
544 if (section < 0 || orientation != Qt::Horizontal || !headerItem || section >= columnCount())
section < 0Description
TRUEnever evaluated
FALSEnever evaluated
orientation != Qt::HorizontalDescription
TRUEnever evaluated
FALSEnever evaluated
!headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
section >= columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
545 return false;
never executed: return false;
0
546-
547 headerItem->setData(section, role, value);-
548 return true;
never executed: return true;
0
549}-
550-
551/*!-
552 \reimp-
553-
554 Returns the flags for the item referred to the given \a index.-
555-
556*/-
557-
558Qt::ItemFlags QTreeModel::flags(const QModelIndex &index) const-
559{-
560 if (!index.isValid())
!index.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
561 return rootItem->flags();
never executed: return rootItem->flags();
0
562 QTreeWidgetItem *itm = item(index);-
563 Q_ASSERT(itm);-
564 return itm->flags();
never executed: return itm->flags();
0
565}-
566-
567/*!-
568 \internal-
569-
570 Sorts the entire tree in the model in the given \a order,-
571 by the values in the given \a column.-
572*/-
573-
574void QTreeModel::sort(int column, Qt::SortOrder order)-
575{-
576 SkipSorting skipSorting(this);-
577 sortPendingTimer.stop();-
578-
579 if (column < 0 || column >= columnCount())
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column >= columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
580 return;
never executed: return;
0
581-
582 //layoutAboutToBeChanged and layoutChanged will be called by sortChildren-
583 rootItem->sortChildren(column, order, true);-
584}
never executed: end of block
0
585-
586/*!-
587 \internal-
588*/-
589void QTreeModel::ensureSorted(int column, Qt::SortOrder order,-
590 int start, int end, const QModelIndex &parent)-
591{-
592 if (isChanging())
isChanging()Description
TRUEnever evaluated
FALSEnever evaluated
0
593 return;
never executed: return;
0
594-
595 sortPendingTimer.stop();-
596-
597 if (column < 0 || column >= columnCount())
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
column >= columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
598 return;
never executed: return;
0
599-
600 SkipSorting skipSorting(this);-
601-
602 QTreeWidgetItem *itm = item(parent);-
603 if (!itm)
!itmDescription
TRUEnever evaluated
FALSEnever evaluated
0
604 itm = rootItem;
never executed: itm = rootItem;
0
605 QList<QTreeWidgetItem*> lst = itm->children;-
606-
607 int count = end - start + 1;-
608 QVector < QPair<QTreeWidgetItem*,int> > sorting(count);-
609 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
610 sorting[i].first = lst.at(start + i);-
611 sorting[i].second = start + i;-
612 }
never executed: end of block
0
613-
614 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
615 std::stable_sort(sorting.begin(), sorting.end(), compare);-
616-
617 QModelIndexList oldPersistentIndexes;-
618 QModelIndexList newPersistentIndexes;-
619 QList<QTreeWidgetItem*>::iterator lit = lst.begin();-
620 bool changed = false;-
621-
622 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
623 int oldRow = sorting.at(i).second;-
624-
625 int tmpitepos = lit - lst.begin();-
626 QTreeWidgetItem *item = lst.takeAt(oldRow);-
627 if (tmpitepos > lst.size())
tmpitepos > lst.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
628 --tmpitepos;
never executed: --tmpitepos;
0
629 lit = lst.begin() + tmpitepos;-
630-
631 lit = sortedInsertionIterator(lit, lst.end(), order, item);-
632 int newRow = qMax(lit - lst.begin(), 0);-
633-
634 if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1)) && !(*lst.at(oldRow - 1) < *item ))
(newRow < oldRow)Description
TRUEnever evaluated
FALSEnever evaluated
!(*item < *lst.at(oldRow - 1))Description
TRUEnever evaluated
FALSEnever evaluated
!(*lst.at(oldR...- 1) < *item )Description
TRUEnever evaluated
FALSEnever evaluated
0
635 newRow = oldRow;
never executed: newRow = oldRow;
0
636-
637 lit = lst.insert(lit, item);-
638 if (newRow != oldRow) {
newRow != oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 // we are going to change the persistent indexes, so we need to prepare-
640 if (!changed) { // this will only happen once
!changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
641 changed = true;-
642 emit layoutAboutToBeChanged(); // the selection model needs to know-
643 oldPersistentIndexes = persistentIndexList();-
644 newPersistentIndexes = oldPersistentIndexes;-
645 }
never executed: end of block
0
646 for (int j = i + 1; j < count; ++j) {
j < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
647 int otherRow = sorting.at(j).second;-
648 if (oldRow < otherRow && newRow >= otherRow)
oldRow < otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow >= otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
649 --sorting[j].second;
never executed: --sorting[j].second;
0
650 else if (oldRow > otherRow && newRow <= otherRow)
oldRow > otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow <= otherRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
651 ++sorting[j].second;
never executed: ++sorting[j].second;
0
652 }
never executed: end of block
0
653 for (int k = 0; k < newPersistentIndexes.count(); ++k) {
k < newPersist...ndexes.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
654 QModelIndex pi = newPersistentIndexes.at(k);-
655 if (pi.parent() != parent)
pi.parent() != parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
656 continue;
never executed: continue;
0
657 int oldPersistentRow = pi.row();-
658 int newPersistentRow = oldPersistentRow;-
659 if (oldPersistentRow == oldRow)
oldPersistentRow == oldRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
660 newPersistentRow = newRow;
never executed: newPersistentRow = newRow;
0
661 else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
oldRow < oldPersistentRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow >= oldPersistentRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
662 newPersistentRow = oldPersistentRow - 1;
never executed: newPersistentRow = oldPersistentRow - 1;
0
663 else if (oldRow > oldPersistentRow && newRow <= oldPersistentRow)
oldRow > oldPersistentRowDescription
TRUEnever evaluated
FALSEnever evaluated
newRow <= oldPersistentRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 newPersistentRow = oldPersistentRow + 1;
never executed: newPersistentRow = oldPersistentRow + 1;
0
665 if (newPersistentRow != oldPersistentRow)
newPersistentR...dPersistentRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
666 newPersistentIndexes[k] = createIndex(newPersistentRow,
never executed: newPersistentIndexes[k] = createIndex(newPersistentRow, pi.column(), pi.internalPointer());
0
667 pi.column(), pi.internalPointer());
never executed: newPersistentIndexes[k] = createIndex(newPersistentRow, pi.column(), pi.internalPointer());
0
668 }
never executed: end of block
0
669 }
never executed: end of block
0
670 }
never executed: end of block
0
671-
672 if (changed) {
changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
673 itm->children = lst;-
674 changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes);-
675 emit layoutChanged();-
676 }
never executed: end of block
0
677}
never executed: end of block
0
678-
679/*!-
680 \internal-
681-
682 Returns \c true if the value of the \a left item is-
683 less than the value of the \a right item.-
684-
685 Used by the sorting functions.-
686*/-
687-
688bool QTreeModel::itemLessThan(const QPair<QTreeWidgetItem*,int> &left,-
689 const QPair<QTreeWidgetItem*,int> &right)-
690{-
691 return *(left.first) < *(right.first);
never executed: return *(left.first) < *(right.first);
0
692}-
693-
694/*!-
695 \internal-
696-
697 Returns \c true if the value of the \a left item is-
698 greater than the value of the \a right item.-
699-
700 Used by the sorting functions.-
701*/-
702-
703bool QTreeModel::itemGreaterThan(const QPair<QTreeWidgetItem*,int> &left,-
704 const QPair<QTreeWidgetItem*,int> &right)-
705{-
706 return *(right.first) < *(left.first);
never executed: return *(right.first) < *(left.first);
0
707}-
708-
709/*!-
710 \internal-
711*/-
712QList<QTreeWidgetItem*>::iterator QTreeModel::sortedInsertionIterator(-
713 const QList<QTreeWidgetItem*>::iterator &begin,-
714 const QList<QTreeWidgetItem*>::iterator &end,-
715 Qt::SortOrder order, QTreeWidgetItem *item)-
716{-
717 if (order == Qt::AscendingOrder)
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
718 return std::lower_bound(begin, end, item, QTreeModelLessThan());
never executed: return std::lower_bound(begin, end, item, QTreeModelLessThan());
0
719 return std::lower_bound(begin, end, item, QTreeModelGreaterThan());
never executed: return std::lower_bound(begin, end, item, QTreeModelGreaterThan());
0
720}-
721-
722QStringList QTreeModel::mimeTypes() const-
723{-
724 return view()->mimeTypes();
never executed: return view()->mimeTypes();
0
725}-
726-
727QMimeData *QTreeModel::internalMimeData() const-
728{-
729 return QAbstractItemModel::mimeData(cachedIndexes);
never executed: return QAbstractItemModel::mimeData(cachedIndexes);
0
730}-
731-
732QMimeData *QTreeModel::mimeData(const QModelIndexList &indexes) const-
733{-
734 QList<QTreeWidgetItem*> items;-
735 for (const auto &index : indexes) {-
736 if (index.column() == 0) // only one item per row
index.column() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
737 items << item(index);
never executed: items << item(index);
0
738 }
never executed: end of block
0
739-
740 // cachedIndexes is a little hack to avoid copying from QModelIndexList to-
741 // QList<QTreeWidgetItem*> and back again in the view-
742 cachedIndexes = indexes;-
743 QMimeData *mimeData = view()->mimeData(items);-
744 cachedIndexes.clear();-
745 return mimeData;
never executed: return mimeData;
0
746}-
747-
748bool QTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action,-
749 int row, int column, const QModelIndex &parent)-
750{-
751 if (row == -1 && column == -1)
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
752 row = rowCount(parent); // append
never executed: row = rowCount(parent);
0
753 return view()->dropMimeData(item(parent), row, data, action);
never executed: return view()->dropMimeData(item(parent), row, data, action);
0
754}-
755-
756Qt::DropActions QTreeModel::supportedDropActions() const-
757{-
758 return view()->supportedDropActions();
never executed: return view()->supportedDropActions();
0
759}-
760-
761void QTreeModel::itemChanged(QTreeWidgetItem *item)-
762{-
763 SkipSorting skipSorting(this); //this is kind of wrong, but not doing this would kill performence-
764 QModelIndex left = index(item, 0);-
765 QModelIndex right = index(item, item->columnCount() - 1);-
766 emit dataChanged(left, right);-
767}
never executed: end of block
0
768-
769bool QTreeModel::isChanging() const-
770{-
771 Q_D(const QTreeModel);-
772 return !d->changes.isEmpty();
never executed: return !d->changes.isEmpty();
0
773}-
774-
775/*!-
776 \internal-
777 Emits the dataChanged() signal for the given \a item.-
778 if column is -1 then all columns have changed-
779*/-
780-
781void QTreeModel::emitDataChanged(QTreeWidgetItem *item, int column)-
782{-
783 if (signalsBlocked())
signalsBlocked()Description
TRUEnever evaluated
FALSEnever evaluated
0
784 return;
never executed: return;
0
785-
786 if (headerItem == item && column < item->columnCount()) {
headerItem == itemDescription
TRUEnever evaluated
FALSEnever evaluated
column < item->columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
787 if (column == -1)
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
788 emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1);
never executed: headerDataChanged(Qt::Horizontal, 0, columnCount() - 1);
0
789 else-
790 emit headerDataChanged(Qt::Horizontal, column, column);
never executed: headerDataChanged(Qt::Horizontal, column, column);
0
791 return;
never executed: return;
0
792 }-
793-
794 SkipSorting skipSorting(this); //This is a little bit wrong, but not doing it would kill performence-
795-
796 QModelIndex bottomRight, topLeft;-
797 if (column == -1) {
column == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
798 topLeft = index(item, 0);-
799 bottomRight = createIndex(topLeft.row(), columnCount() - 1, item);-
800 } else {
never executed: end of block
0
801 topLeft = index(item, column);-
802 bottomRight = topLeft;-
803 }
never executed: end of block
0
804 emit dataChanged(topLeft, bottomRight);-
805}
never executed: end of block
0
806-
807void QTreeModel::beginInsertItems(QTreeWidgetItem *parent, int row, int count)-
808{-
809 QModelIndex par = index(parent, 0);-
810 beginInsertRows(par, row, row + count - 1);-
811}
never executed: end of block
0
812-
813void QTreeModel::endInsertItems()-
814{-
815 endInsertRows();-
816}
never executed: end of block
0
817-
818void QTreeModel::beginRemoveItems(QTreeWidgetItem *parent, int row, int count)-
819{-
820 Q_ASSERT(row >= 0);-
821 Q_ASSERT(count > 0);-
822 beginRemoveRows(index(parent, 0), row, row + count - 1);-
823 if (!parent)
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
824 parent = rootItem;
never executed: parent = rootItem;
0
825 // now update the iterators-
826 for (int i = 0; i < iterators.count(); ++i) {
i < iterators.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
827 for (int j = 0; j < count; j++) {
j < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
828 QTreeWidgetItem *c = parent->child(row + j);-
829 iterators[i]->d_func()->ensureValidIterator(c);-
830 }
never executed: end of block
0
831 }
never executed: end of block
0
832}
never executed: end of block
0
833-
834void QTreeModel::endRemoveItems()-
835{-
836 endRemoveRows();-
837}
never executed: end of block
0
838-
839void QTreeModel::sortItems(QList<QTreeWidgetItem*> *items, int column, Qt::SortOrder order)-
840{-
841 // see QTreeViewItem::operator<-
842 Q_UNUSED(column);-
843 if (isChanging())
isChanging()Description
TRUEnever evaluated
FALSEnever evaluated
0
844 return;
never executed: return;
0
845-
846 // store the original order of indexes-
847 QVector< QPair<QTreeWidgetItem*,int> > sorting(items->count());-
848 for (int i = 0; i < sorting.count(); ++i) {
i < sorting.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
849 sorting[i].first = items->at(i);-
850 sorting[i].second = i;-
851 }
never executed: end of block
0
852-
853 // do the sorting-
854 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
order == Qt::AscendingOrderDescription
TRUEnever evaluated
FALSEnever evaluated
0
855 std::stable_sort(sorting.begin(), sorting.end(), compare);-
856-
857 QModelIndexList fromList;-
858 QModelIndexList toList;-
859 int colCount = columnCount();-
860 for (int r = 0; r < sorting.count(); ++r) {
r < sorting.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
861 int oldRow = sorting.at(r).second;-
862 if (oldRow == r)
oldRow == rDescription
TRUEnever evaluated
FALSEnever evaluated
0
863 continue;
never executed: continue;
0
864 QTreeWidgetItem *item = sorting.at(r).first;-
865 items->replace(r, item);-
866 for (int c = 0; c < colCount; ++c) {
c < colCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
867 QModelIndex from = createIndex(oldRow, c, item);-
868 if (static_cast<QAbstractItemModelPrivate *>(d_ptr.data())->persistent.indexes.contains(from)) {
static_cast<QA...contains(from)Description
TRUEnever evaluated
FALSEnever evaluated
0
869 QModelIndex to = createIndex(r, c, item);-
870 fromList << from;-
871 toList << to;-
872 }
never executed: end of block
0
873 }
never executed: end of block
0
874 }
never executed: end of block
0
875 changePersistentIndexList(fromList, toList);-
876}
never executed: end of block
0
877-
878void QTreeModel::timerEvent(QTimerEvent *ev)-
879{-
880 if (ev->timerId() == sortPendingTimer.timerId()) {
ev->timerId() ...imer.timerId()Description
TRUEnever evaluated
FALSEnever evaluated
0
881 executePendingSort();-
882 } else {
never executed: end of block
0
883 QAbstractItemModel::timerEvent(ev);-
884 }
never executed: end of block
0
885}-
886-
887/*!-
888 \class QTreeWidgetItem-
889-
890 \brief The QTreeWidgetItem class provides an item for use with the-
891 QTreeWidget convenience class.-
892-
893 \ingroup model-view-
894 \inmodule QtWidgets-
895-
896 Tree widget items are used to hold rows of information for tree widgets.-
897 Rows usually contain several columns of data, each of which can contain-
898 a text label and an icon.-
899-
900 The QTreeWidgetItem class is a convenience class that replaces the-
901 QListViewItem class in Qt 3. It provides an item for use with-
902 the QTreeWidget class.-
903-
904 Items are usually constructed with a parent that is either a QTreeWidget-
905 (for top-level items) or a QTreeWidgetItem (for items on lower levels of-
906 the tree). For example, the following code constructs a top-level item-
907 to represent cities of the world, and adds a entry for Oslo as a child-
908 item:-
909-
910 \snippet qtreewidget-using/mainwindow.cpp 3-
911-
912 Items can be added in a particular order by specifying the item they-
913 follow when they are constructed:-
914-
915 \snippet qtreewidget-using/mainwindow.cpp 5-
916-
917 Each column in an item can have its own background brush which is set with-
918 the setBackground() function. The current background brush can be-
919 found with background().-
920 The text label for each column can be rendered with its own font and brush.-
921 These are specified with the setFont() and setForeground() functions,-
922 and read with font() and foreground().-
923-
924 The main difference between top-level items and those in lower levels of-
925 the tree is that a top-level item has no parent(). This information-
926 can be used to tell the difference between items, and is useful to know-
927 when inserting and removing items from the tree.-
928 Children of an item can be removed with takeChild() and inserted at a-
929 given index in the list of children with the insertChild() function.-
930-
931 By default, items are enabled, selectable, checkable, and can be the source-
932 of a drag and drop operation.-
933 Each item's flags can be changed by calling setFlags() with the appropriate-
934 value (see \l{Qt::ItemFlags}). Checkable items can be checked and unchecked-
935 with the setCheckState() function. The corresponding checkState() function-
936 indicates whether the item is currently checked.-
937-
938 \section1 Subclassing-
939-
940 When subclassing QTreeWidgetItem to provide custom items, it is possible to-
941 define new types for them so that they can be distinguished from standard-
942 items. The constructors for subclasses that require this feature need to-
943 call the base class constructor with a new type value equal to or greater-
944 than \l UserType.-
945-
946 \sa QTreeWidget, QTreeWidgetItemIterator, {Model/View Programming},-
947 QListWidgetItem, QTableWidgetItem-
948*/-
949-
950/*!-
951 \enum QTreeWidgetItem::ItemType-
952-
953 This enum describes the types that are used to describe tree widget items.-
954-
955 \value Type The default type for tree widget items.-
956 \value UserType The minimum value for custom types. Values below UserType are-
957 reserved by Qt.-
958-
959 You can define new user types in QTreeWidgetItem subclasses to ensure that-
960 custom items are treated specially; for example, when items are sorted.-
961-
962 \sa type()-
963*/-
964-
965/*!-
966 \fn int QTreeWidgetItem::type() const-
967-
968 Returns the type passed to the QTreeWidgetItem constructor.-
969*/-
970-
971/*!-
972 \fn void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order)-
973 \since 4.2-
974-
975 Sorts the children of the item using the given \a order,-
976 by the values in the given \a column.-
977-
978 \note This function does nothing if the item is not associated with a-
979 QTreeWidget.-
980*/-
981-
982/*!-
983 \fn QTreeWidget *QTreeWidgetItem::treeWidget() const-
984-
985 Returns the tree widget that contains the item.-
986*/-
987-
988/*!-
989 \fn void QTreeWidgetItem::setSelected(bool select)-
990 \since 4.2-
991-
992 Sets the selected state of the item to \a select.-
993-
994 \sa isSelected()-
995-
996*/-
997-
998/*!-
999 \fn bool QTreeWidgetItem::isSelected() const-
1000 \since 4.2-
1001-
1002 Returns \c true if the item is selected, otherwise returns \c false.-
1003-
1004 \sa setSelected()-
1005*/-
1006-
1007/*!-
1008 \fn void QTreeWidgetItem::setHidden(bool hide)-
1009 \since 4.2-
1010-
1011 Hides the item if \a hide is true, otherwise shows the item.-
1012 \note A call to this function has no effect if the item is not currently in a view. In particular,-
1013 calling \c setHidden(true) on an item and only then adding it to a view will result in-
1014 a visible item.-
1015-
1016 \sa isHidden()-
1017*/-
1018-
1019/*!-
1020 \fn bool QTreeWidgetItem::isHidden() const-
1021 \since 4.2-
1022-
1023 Returns \c true if the item is hidden, otherwise returns \c false.-
1024-
1025 \sa setHidden()-
1026*/-
1027-
1028/*!-
1029 \fn void QTreeWidgetItem::setExpanded(bool expand)-
1030 \since 4.2-
1031-
1032 Expands the item if \a expand is true, otherwise collapses the item.-
1033 \warning The QTreeWidgetItem must be added to the QTreeWidget before calling this function.-
1034-
1035 \sa isExpanded()-
1036*/-
1037-
1038/*!-
1039 \fn bool QTreeWidgetItem::isExpanded() const-
1040 \since 4.2-
1041-
1042 Returns \c true if the item is expanded, otherwise returns \c false.-
1043-
1044 \sa setExpanded()-
1045*/-
1046-
1047/*!-
1048 \fn void QTreeWidgetItem::setFirstColumnSpanned(bool span)-
1049 \since 4.3-
1050-
1051 Sets the first section to span all columns if \a span is true;-
1052 otherwise all item sections are shown.-
1053-
1054 \sa isFirstColumnSpanned()-
1055*/-
1056-
1057/*!-
1058 \fn bool QTreeWidgetItem::isFirstColumnSpanned() const-
1059 \since 4.3-
1060-
1061 Returns \c true if the item is spanning all the columns in a row; otherwise returns \c false.-
1062-
1063 \sa setFirstColumnSpanned()-
1064*/-
1065-
1066/*!-
1067 \fn QString QTreeWidgetItem::text(int column) const-
1068-
1069 Returns the text in the specified \a column.-
1070-
1071 \sa setText()-
1072*/-
1073-
1074/*!-
1075 \fn void QTreeWidgetItem::setText(int column, const QString &text)-
1076-
1077 Sets the text to be displayed in the given \a column to the given \a text.-
1078-
1079 \sa text(), setFont(), setForeground()-
1080*/-
1081-
1082/*!-
1083 \fn QIcon QTreeWidgetItem::icon(int column) const-
1084-
1085 Returns the icon that is displayed in the specified \a column.-
1086-
1087 \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}-
1088*/-
1089-
1090/*!-
1091 \fn void QTreeWidgetItem::setIcon(int column, const QIcon &icon)-
1092-
1093 Sets the icon to be displayed in the given \a column to \a icon.-
1094-
1095 \sa icon(), setText(), {QAbstractItemView::iconSize}{iconSize}-
1096*/-
1097-
1098/*!-
1099 \fn QString QTreeWidgetItem::statusTip(int column) const-
1100-
1101 Returns the status tip for the contents of the given \a column.-
1102-
1103 \sa setStatusTip()-
1104*/-
1105-
1106/*!-
1107 \fn void QTreeWidgetItem::setStatusTip(int column, const QString &statusTip)-
1108-
1109 Sets the status tip for the given \a column to the given \a statusTip.-
1110 QTreeWidget mouse tracking needs to be enabled for this feature to work.-
1111-
1112 \sa statusTip(), setToolTip(), setWhatsThis()-
1113*/-
1114-
1115/*!-
1116 \fn QString QTreeWidgetItem::toolTip(int column) const-
1117-
1118 Returns the tool tip for the given \a column.-
1119-
1120 \sa setToolTip()-
1121*/-
1122-
1123/*!-
1124 \fn void QTreeWidgetItem::setToolTip(int column, const QString &toolTip)-
1125-
1126 Sets the tooltip for the given \a column to \a toolTip.-
1127-
1128 \sa toolTip(), setStatusTip(), setWhatsThis()-
1129*/-
1130-
1131/*!-
1132 \fn QString QTreeWidgetItem::whatsThis(int column) const-
1133-
1134 Returns the "What's This?" help for the contents of the given \a column.-
1135-
1136 \sa setWhatsThis()-
1137*/-
1138-
1139/*!-
1140 \fn void QTreeWidgetItem::setWhatsThis(int column, const QString &whatsThis)-
1141-
1142 Sets the "What's This?" help for the given \a column to \a whatsThis.-
1143-
1144 \sa whatsThis(), setStatusTip(), setToolTip()-
1145*/-
1146-
1147/*!-
1148 \fn QFont QTreeWidgetItem::font(int column) const-
1149-
1150 Returns the font used to render the text in the specified \a column.-
1151-
1152 \sa setFont()-
1153*/-
1154-
1155/*!-
1156 \fn void QTreeWidgetItem::setFont(int column, const QFont &font)-
1157-
1158 Sets the font used to display the text in the given \a column to the given-
1159 \a font.-
1160-
1161 \sa font(), setText(), setForeground()-
1162*/-
1163-
1164/*!-
1165 \fn QColor QTreeWidgetItem::backgroundColor(int column) const-
1166 \obsolete-
1167-
1168 This function is deprecated. Use background() instead.-
1169*/-
1170-
1171/*!-
1172 \fn void QTreeWidgetItem::setBackgroundColor(int column, const QColor &color)-
1173 \obsolete-
1174-
1175 This function is deprecated. Use setBackground() instead.-
1176*/-
1177-
1178/*!-
1179 \fn QBrush QTreeWidgetItem::background(int column) const-
1180 \since 4.2-
1181-
1182 Returns the brush used to render the background of the specified \a column.-
1183-
1184 \sa foreground()-
1185*/-
1186-
1187/*!-
1188 \fn void QTreeWidgetItem::setBackground(int column, const QBrush &brush)-
1189 \since 4.2-
1190-
1191 Sets the background brush of the label in the given \a column to the-
1192 specified \a brush.-
1193-
1194 \sa setForeground()-
1195*/-
1196-
1197/*!-
1198 \fn QColor QTreeWidgetItem::textColor(int column) const-
1199 \obsolete-
1200-
1201 This function is deprecated. Use foreground() instead.-
1202*/-
1203-
1204/*!-
1205 \fn void QTreeWidgetItem::setTextColor(int column, const QColor &color)-
1206 \obsolete-
1207-
1208 This function is deprecated. Use setForeground() instead.-
1209*/-
1210-
1211/*!-
1212 \fn QBrush QTreeWidgetItem::foreground(int column) const-
1213 \since 4.2-
1214-
1215 Returns the brush used to render the foreground (e.g. text) of the-
1216 specified \a column.-
1217-
1218 \sa background()-
1219*/-
1220-
1221/*!-
1222 \fn void QTreeWidgetItem::setForeground(int column, const QBrush &brush)-
1223 \since 4.2-
1224-
1225 Sets the foreground brush of the label in the given \a column to the-
1226 specified \a brush.-
1227-
1228 \sa setBackground()-
1229*/-
1230-
1231/*!-
1232 \fn Qt::CheckState QTreeWidgetItem::checkState(int column) const-
1233-
1234 Returns the check state of the label in the given \a column.-
1235-
1236 \sa Qt::CheckState-
1237*/-
1238-
1239/*!-
1240 \fn void QTreeWidgetItem::setCheckState(int column, Qt::CheckState state)-
1241-
1242 Sets the item in the given \a column check state to be \a state.-
1243-
1244 \sa checkState()-
1245*/-
1246-
1247/*!-
1248 \fn QSize QTreeWidgetItem::sizeHint(int column) const-
1249 \since 4.1-
1250-
1251 Returns the size hint set for the tree item in the given-
1252 \a column (see \l{QSize}).-
1253*/-
1254-
1255/*!-
1256 \fn void QTreeWidgetItem::setSizeHint(int column, const QSize &size)-
1257 \since 4.1-
1258-
1259 Sets the size hint for the tree item in the given \a column to be \a size.-
1260 If no size hint is set, the item delegate will compute the size hint based-
1261 on the item data.-
1262*/-
1263-
1264/*!-
1265 \fn QTreeWidgetItem *QTreeWidgetItem::parent() const-
1266-
1267 Returns the item's parent.-
1268-
1269 \sa child()-
1270*/-
1271-
1272/*!-
1273 \fn QTreeWidgetItem *QTreeWidgetItem::child(int index) const-
1274-
1275 Returns the item at the given \a index in the list of the item's children.-
1276-
1277 \sa parent()-
1278*/-
1279-
1280/*!-
1281 \fn int QTreeWidgetItem::childCount() const-
1282-
1283 Returns the number of child items.-
1284*/-
1285-
1286/*!-
1287 \fn int QTreeWidgetItem::columnCount() const-
1288-
1289 Returns the number of columns in the item.-
1290*/-
1291-
1292/*!-
1293 \fn int QTreeWidgetItem::textAlignment(int column) const-
1294-
1295 Returns the text alignment for the label in the given \a column-
1296 (see \l{Qt::AlignmentFlag}).-
1297*/-
1298-
1299/*!-
1300 \fn void QTreeWidgetItem::setTextAlignment(int column, int alignment)-
1301-
1302 Sets the text alignment for the label in the given \a column to-
1303 the \a alignment specified (see \l{Qt::AlignmentFlag}).-
1304*/-
1305-
1306/*!-
1307 \fn int QTreeWidgetItem::indexOfChild(QTreeWidgetItem *child) const-
1308-
1309 Returns the index of the given \a child in the item's list of children.-
1310*/-
1311-
1312/*!-
1313 Constructs a tree widget item of the specified \a type. The item-
1314 must be inserted into a tree widget.-
1315-
1316 \sa type()-
1317*/-
1318QTreeWidgetItem::QTreeWidgetItem(int type)-
1319 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1320 itemFlags(Qt::ItemIsSelectable-
1321 |Qt::ItemIsUserCheckable-
1322 |Qt::ItemIsEnabled-
1323 |Qt::ItemIsDragEnabled-
1324 |Qt::ItemIsDropEnabled)-
1325{-
1326}
never executed: end of block
0
1327-
1328-
1329/*!-
1330 Constructs a tree widget item of the specified \a type. The item-
1331 must be inserted into a tree widget.-
1332 The given list of \a strings will be set as the item text for each-
1333 column in the item.-
1334-
1335 \sa type()-
1336*/-
1337QTreeWidgetItem::QTreeWidgetItem(const QStringList &strings, int type)-
1338 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1339 itemFlags(Qt::ItemIsSelectable-
1340 |Qt::ItemIsUserCheckable-
1341 |Qt::ItemIsEnabled-
1342 |Qt::ItemIsDragEnabled-
1343 |Qt::ItemIsDropEnabled)-
1344{-
1345 for (int i = 0; i < strings.count(); ++i)
i < strings.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1346 setText(i, strings.at(i));
never executed: setText(i, strings.at(i));
0
1347}
never executed: end of block
0
1348-
1349/*!-
1350 \fn QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *parent, int type)-
1351-
1352 Constructs a tree widget item of the specified \a type and appends it-
1353 to the items in the given \a parent.-
1354-
1355 \sa type()-
1356*/-
1357-
1358QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, int type)-
1359 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1360 itemFlags(Qt::ItemIsSelectable-
1361 |Qt::ItemIsUserCheckable-
1362 |Qt::ItemIsEnabled-
1363 |Qt::ItemIsDragEnabled-
1364 |Qt::ItemIsDropEnabled)-
1365{-
1366 if (view && view->model()) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
view->model()Description
TRUEnever evaluated
FALSEnever evaluated
0
1367 QTreeModel *model = qobject_cast<QTreeModel*>(view->model());-
1368 model->rootItem->addChild(this);-
1369 values.reserve(model->headerItem->columnCount());-
1370 }
never executed: end of block
0
1371}
never executed: end of block
0
1372-
1373/*!-
1374 \fn QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *parent, const QStringList &strings, int type)-
1375-
1376 Constructs a tree widget item of the specified \a type and appends it-
1377 to the items in the given \a parent. The given list of \a strings will be set as-
1378 the item text for each column in the item.-
1379-
1380 \sa type()-
1381*/-
1382-
1383QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type)-
1384 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1385 itemFlags(Qt::ItemIsSelectable-
1386 |Qt::ItemIsUserCheckable-
1387 |Qt::ItemIsEnabled-
1388 |Qt::ItemIsDragEnabled-
1389 |Qt::ItemIsDropEnabled)-
1390{-
1391 for (int i = 0; i < strings.count(); ++i)
i < strings.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1392 setText(i, strings.at(i));
never executed: setText(i, strings.at(i));
0
1393 if (view && view->model()) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
view->model()Description
TRUEnever evaluated
FALSEnever evaluated
0
1394 QTreeModel *model = qobject_cast<QTreeModel*>(view->model());-
1395 model->rootItem->addChild(this);-
1396 values.reserve(model->headerItem->columnCount());-
1397 }
never executed: end of block
0
1398}
never executed: end of block
0
1399-
1400/*!-
1401 \fn QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *parent, QTreeWidgetItem *preceding, int type)-
1402-
1403 Constructs a tree widget item of the specified \a type and inserts it into-
1404 the given \a parent after the \a preceding item.-
1405-
1406 \sa type()-
1407*/-
1408QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int type)-
1409 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1410 itemFlags(Qt::ItemIsSelectable-
1411 |Qt::ItemIsUserCheckable-
1412 |Qt::ItemIsEnabled-
1413 |Qt::ItemIsDragEnabled-
1414 |Qt::ItemIsDropEnabled)-
1415{-
1416 if (view) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1417 QTreeModel *model = qobject_cast<QTreeModel*>(view->model());-
1418 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1419 int i = model->rootItem->children.indexOf(after) + 1;-
1420 model->rootItem->insertChild(i, this);-
1421 values.reserve(model->headerItem->columnCount());-
1422 }
never executed: end of block
0
1423 }
never executed: end of block
0
1424}
never executed: end of block
0
1425-
1426/*!-
1427 Constructs a tree widget item and append it to the given \a parent.-
1428-
1429 \sa type()-
1430*/-
1431QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, int type)-
1432 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1433 itemFlags(Qt::ItemIsSelectable-
1434 |Qt::ItemIsUserCheckable-
1435 |Qt::ItemIsEnabled-
1436 |Qt::ItemIsDragEnabled-
1437 |Qt::ItemIsDropEnabled)-
1438{-
1439 if (parent)
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1440 parent->addChild(this);
never executed: parent->addChild(this);
0
1441}
never executed: end of block
0
1442-
1443/*!-
1444 Constructs a tree widget item and append it to the given \a parent.-
1445 The given list of \a strings will be set as the item text for each column in the item.-
1446-
1447 \sa type()-
1448*/-
1449QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &strings, int type)-
1450 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1451 itemFlags(Qt::ItemIsSelectable-
1452 |Qt::ItemIsUserCheckable-
1453 |Qt::ItemIsEnabled-
1454 |Qt::ItemIsDragEnabled-
1455 |Qt::ItemIsDropEnabled)-
1456{-
1457 for (int i = 0; i < strings.count(); ++i)
i < strings.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1458 setText(i, strings.at(i));
never executed: setText(i, strings.at(i));
0
1459 if (parent)
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1460 parent->addChild(this);
never executed: parent->addChild(this);
0
1461}
never executed: end of block
0
1462-
1463/*!-
1464 \fn QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding, int type)-
1465-
1466 Constructs a tree widget item of the specified \a type that is inserted-
1467 into the \a parent after the \a preceding child item.-
1468-
1469 \sa type()-
1470*/-
1471QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, int type)-
1472 : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),-
1473 itemFlags(Qt::ItemIsSelectable-
1474 |Qt::ItemIsUserCheckable-
1475 |Qt::ItemIsEnabled-
1476 |Qt::ItemIsDragEnabled-
1477 |Qt::ItemIsDropEnabled)-
1478{-
1479 if (parent) {
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1480 int i = parent->children.indexOf(after) + 1;-
1481 parent->insertChild(i, this);-
1482 }
never executed: end of block
0
1483}
never executed: end of block
0
1484-
1485/*!-
1486 Destroys this tree widget item.-
1487-
1488 The item will be removed from \l{QTreeWidget}s to which it has-
1489 been added. This makes it safe to delete an item at any time.-
1490-
1491*/-
1492-
1493QTreeWidgetItem::~QTreeWidgetItem()-
1494{-
1495 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1496 bool wasSkipSort = false;-
1497 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1498 wasSkipSort = model->skipPendingSort;-
1499 model->skipPendingSort = true;-
1500 }
never executed: end of block
0
1501 if (par) {
parDescription
TRUEnever evaluated
FALSEnever evaluated
0
1502 int i = par->children.indexOf(this);-
1503 if (i >= 0) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1504 if (model) model->beginRemoveItems(par, i, 1);
never executed: model->beginRemoveItems(par, i, 1);
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1505 // users _could_ do changes when connected to rowsAboutToBeRemoved,-
1506 // so we check again to make sure 'i' is valid-
1507 if (!par->children.isEmpty() && par->children.at(i) == this)
!par->children.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
par->children.at(i) == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1508 par->children.takeAt(i);
never executed: par->children.takeAt(i);
0
1509 if (model) model->endRemoveItems();
never executed: model->endRemoveItems();
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1510 }
never executed: end of block
0
1511 } else if (model) {
never executed: end of block
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1512 if (this == model->headerItem) {
this == model->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1513 model->headerItem = 0;-
1514 } else {
never executed: end of block
0
1515 int i = model->rootItem->children.indexOf(this);-
1516 if (i >= 0) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1517 model->beginRemoveItems(0, i, 1);-
1518 // users _could_ do changes when connected to rowsAboutToBeRemoved,-
1519 // so we check again to make sure 'i' is valid-
1520 if (!model->rootItem->children.isEmpty() && model->rootItem->children.at(i) == this)
!model->rootIt...dren.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
model->rootIte....at(i) == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1521 model->rootItem->children.takeAt(i);
never executed: model->rootItem->children.takeAt(i);
0
1522 model->endRemoveItems();-
1523 }
never executed: end of block
0
1524 }
never executed: end of block
0
1525 }-
1526 // at this point the persistent indexes for the children should also be invalidated-
1527 // since we invalidated the parent-
1528 for (int i = 0; i < children.count(); ++i) {
i < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1529 QTreeWidgetItem *child = children.at(i);-
1530 // make sure the child does not try to remove itself from our children list-
1531 child->par = 0;-
1532 // make sure the child does not try to remove itself from the top level list-
1533 child->view = 0;-
1534 delete child;-
1535 }
never executed: end of block
0
1536-
1537 children.clear();-
1538 delete d;-
1539 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1540 model->skipPendingSort = wasSkipSort;-
1541 }
never executed: end of block
0
1542}
never executed: end of block
0
1543-
1544/*!-
1545 Creates a deep copy of the item and of its children.-
1546*/-
1547QTreeWidgetItem *QTreeWidgetItem::clone() const-
1548{-
1549 QTreeWidgetItem *copy = 0;-
1550-
1551 QStack<const QTreeWidgetItem*> stack;-
1552 QStack<QTreeWidgetItem*> parentStack;-
1553 stack.push(this);-
1554 parentStack.push(0);-
1555-
1556 QTreeWidgetItem *root = 0;-
1557 const QTreeWidgetItem *item = 0;-
1558 QTreeWidgetItem *parent = 0;-
1559 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1560 // get current item, and copied parent-
1561 item = stack.pop();-
1562 parent = parentStack.pop();-
1563-
1564 // copy item-
1565 copy = new QTreeWidgetItem(*item);-
1566 if (!root)
!rootDescription
TRUEnever evaluated
FALSEnever evaluated
0
1567 root = copy;
never executed: root = copy;
0
1568-
1569 // set parent and add to parents children list-
1570 if (parent) {
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1571 copy->par = parent;-
1572 parent->children.insert(0, copy);-
1573 }
never executed: end of block
0
1574-
1575 for (int i = 0; i < item->childCount(); ++i) {
i < item->childCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
1576 stack.push(item->child(i));-
1577 parentStack.push(copy);-
1578 }
never executed: end of block
0
1579 }
never executed: end of block
0
1580 return root;
never executed: return root;
0
1581}-
1582-
1583/*!-
1584 Sets the item indicator \a policy. This policy decides when the-
1585 tree branch expand/collapse indicator is shown.-
1586 The default value is ShowForChildren.-
1587-
1588 \sa childIndicatorPolicy()-
1589*/-
1590void QTreeWidgetItem::setChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPolicy policy)-
1591{-
1592 if (d->policy == policy)
d->policy == policyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1593 return;
never executed: return;
0
1594 d->policy = policy;-
1595-
1596 if (!view)
!viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1597 return;
never executed: return;
0
1598-
1599 view->scheduleDelayedItemsLayout();-
1600}
never executed: end of block
0
1601-
1602/*!-
1603 Returns the item indicator policy. This policy decides when the-
1604 tree branch expand/collapse indicator is shown.-
1605-
1606 \sa setChildIndicatorPolicy()-
1607*/-
1608QTreeWidgetItem::ChildIndicatorPolicy QTreeWidgetItem::childIndicatorPolicy() const-
1609{-
1610 return d->policy;
never executed: return d->policy;
0
1611}-
1612-
1613/*!-
1614 \fn void QTreeWidgetItem::setFlags(Qt::ItemFlags flags)-
1615-
1616 Sets the flags for the item to the given \a flags. These determine whether-
1617 the item can be selected or modified. This is often used to disable an item.-
1618-
1619 \sa flags()-
1620*/-
1621void QTreeWidgetItem::setFlags(Qt::ItemFlags flags)-
1622{-
1623 const bool enable = (flags & Qt::ItemIsEnabled);-
1624 const bool changedState = bool(itemFlags & Qt::ItemIsEnabled) != enable;-
1625 const bool changedExplicit = d->disabled != !enable;-
1626-
1627 d->disabled = !enable;-
1628-
1629 if (enable && par && !(par->itemFlags & Qt::ItemIsEnabled)) // inherit from parent
enableDescription
TRUEnever evaluated
FALSEnever evaluated
parDescription
TRUEnever evaluated
FALSEnever evaluated
!(par->itemFla...ItemIsEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
1630 itemFlags = flags & ~Qt::ItemIsEnabled;
never executed: itemFlags = flags & ~Qt::ItemIsEnabled;
0
1631 else // this item is explicitly disabled or has no parent-
1632 itemFlags = flags;
never executed: itemFlags = flags;
0
1633-
1634 if (changedState && changedExplicit) { // if the propagate the change to the children
changedStateDescription
TRUEnever evaluated
FALSEnever evaluated
changedExplicitDescription
TRUEnever evaluated
FALSEnever evaluated
0
1635 QStack<QTreeWidgetItem*> parents;-
1636 parents.push(this);-
1637 while (!parents.isEmpty()) {
!parents.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1638 QTreeWidgetItem *parent = parents.pop();-
1639 for (int i = 0; i < parent->children.count(); ++i) {
i < parent->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1640 QTreeWidgetItem *child = parent->children.at(i);-
1641 if (!child->d->disabled) { // if not explicitly disabled
!child->d->disabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1642 parents.push(child);-
1643 if (enable)
enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1644 child->itemFlags = child->itemFlags | Qt::ItemIsEnabled;
never executed: child->itemFlags = child->itemFlags | Qt::ItemIsEnabled;
0
1645 else-
1646 child->itemFlags = child->itemFlags & ~Qt::ItemIsEnabled;
never executed: child->itemFlags = child->itemFlags & ~Qt::ItemIsEnabled;
0
1647 child->itemChanged(); // ### we may want to optimize this-
1648 }
never executed: end of block
0
1649 }
never executed: end of block
0
1650 }
never executed: end of block
0
1651 }
never executed: end of block
0
1652 itemChanged();-
1653}
never executed: end of block
0
1654-
1655void QTreeWidgetItemPrivate::propagateDisabled(QTreeWidgetItem *item)-
1656{-
1657 Q_ASSERT(item);-
1658 const bool enable = item->par ? (item->par->itemFlags.testFlag(Qt::ItemIsEnabled)) : true;
item->parDescription
TRUEnever evaluated
FALSEnever evaluated
0
1659-
1660 QStack<QTreeWidgetItem*> parents;-
1661 parents.push(item);-
1662 while (!parents.isEmpty()) {
!parents.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1663 QTreeWidgetItem *parent = parents.pop();-
1664 if (!parent->d->disabled) { // if not explicitly disabled
!parent->d->disabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
1665 Qt::ItemFlags oldFlags = parent->itemFlags;-
1666 if (enable)
enableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1667 parent->itemFlags = parent->itemFlags | Qt::ItemIsEnabled;
never executed: parent->itemFlags = parent->itemFlags | Qt::ItemIsEnabled;
0
1668 else-
1669 parent->itemFlags = parent->itemFlags & ~Qt::ItemIsEnabled;
never executed: parent->itemFlags = parent->itemFlags & ~Qt::ItemIsEnabled;
0
1670 if (parent->itemFlags != oldFlags)
parent->itemFlags != oldFlagsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1671 parent->itemChanged();
never executed: parent->itemChanged();
0
1672 }
never executed: end of block
0
1673-
1674 for (int i = 0; i < parent->children.count(); ++i) {
i < parent->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1675 QTreeWidgetItem *child = parent->children.at(i);-
1676 parents.push(child);-
1677 }
never executed: end of block
0
1678 }
never executed: end of block
0
1679}
never executed: end of block
0
1680/*!-
1681 \fn Qt::ItemFlags QTreeWidgetItem::flags() const-
1682-
1683 Returns the flags used to describe the item. These determine whether-
1684 the item can be checked, edited, and selected.-
1685-
1686 The default value for flags is-
1687 Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |-
1688 Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled.-
1689-
1690 \sa setFlags()-
1691*/-
1692Qt::ItemFlags QTreeWidgetItem::flags() const-
1693{-
1694 return itemFlags;
never executed: return itemFlags;
0
1695}-
1696-
1697/*!-
1698 Sets the value for the item's \a column and \a role to the given-
1699 \a value.-
1700-
1701 The \a role describes the type of data specified by \a value, and is defined by-
1702 the Qt::ItemDataRole enum.-
1703*/-
1704void QTreeWidgetItem::setData(int column, int role, const QVariant &value)-
1705{-
1706 if (column < 0)
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1707 return;
never executed: return;
0
1708-
1709 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1710 switch (role) {-
1711 case Qt::EditRole:
never executed: case Qt::EditRole:
0
1712 case Qt::DisplayRole: {
never executed: case Qt::DisplayRole:
0
1713 if (values.count() <= column) {
values.count() <= columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1714 if (model && this == model->headerItem)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
this == model->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1715 model->setColumnCount(column + 1);
never executed: model->setColumnCount(column + 1);
0
1716 else-
1717 values.resize(column + 1);
never executed: values.resize(column + 1);
0
1718 }-
1719 if (d->display.count() <= column) {
d->display.count() <= columnDescription
TRUEnever evaluated
FALSEnever evaluated
0
1720 for (int i = d->display.count() - 1; i < column - 1; ++i)
i < column - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1721 d->display.append(QVariant());
never executed: d->display.append(QVariant());
0
1722 d->display.append(value);-
1723 } else if (d->display[column] != value) {
never executed: end of block
d->display[column] != valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1724 d->display[column] = value;-
1725 } else {
never executed: end of block
0
1726 return; // value is unchanged
never executed: return;
0
1727 }-
1728 } break;
never executed: break;
0
1729 case Qt::CheckStateRole:
never executed: case Qt::CheckStateRole:
0
1730 if ((itemFlags & Qt::ItemIsAutoTristate) && value != Qt::PartiallyChecked) {
(itemFlags & Q...sAutoTristate)Description
TRUEnever evaluated
FALSEnever evaluated
value != Qt::PartiallyCheckedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1731 for (int i = 0; i < children.count(); ++i) {
i < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1732 QTreeWidgetItem *child = children.at(i);-
1733 if (child->data(column, role).isValid()) {// has a CheckState
child->data(co...ole).isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
1734 Qt::ItemFlags f = itemFlags; // a little hack to avoid multiple dataChanged signals-
1735 itemFlags &= ~Qt::ItemIsAutoTristate;-
1736 child->setData(column, role, value);-
1737 itemFlags = f;-
1738 }
never executed: end of block
0
1739 }
never executed: end of block
0
1740 }
never executed: end of block
0
1741 // Don't break, but fall through-
1742 default:
code before this statement never executed: default:
never executed: default:
0
1743 if (column < values.count()) {
column < values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1744 bool found = false;-
1745 const QVector<QWidgetItemData> column_values = values.at(column);-
1746 for (int i = 0; i < column_values.count(); ++i) {
i < column_values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1747 if (column_values.at(i).role == role) {
column_values....).role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1748 if (column_values.at(i).value == value)
column_values....value == valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1749 return; // value is unchanged
never executed: return;
0
1750 values[column][i].value = value;-
1751 found = true;-
1752 break;
never executed: break;
0
1753 }-
1754 }
never executed: end of block
0
1755 if (!found)
!foundDescription
TRUEnever evaluated
FALSEnever evaluated
0
1756 values[column].append(QWidgetItemData(role, value));
never executed: values[column].append(QWidgetItemData(role, value));
0
1757 } else {
never executed: end of block
0
1758 if (model && this == model->headerItem)
modelDescription
TRUEnever evaluated
FALSEnever evaluated
this == model->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1759 model->setColumnCount(column + 1);
never executed: model->setColumnCount(column + 1);
0
1760 else-
1761 values.resize(column + 1);
never executed: values.resize(column + 1);
0
1762 values[column].append(QWidgetItemData(role, value));-
1763 }
never executed: end of block
0
1764 }-
1765-
1766 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1767 model->emitDataChanged(this, column);-
1768 if (role == Qt::CheckStateRole) {
role == Qt::CheckStateRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1769 QTreeWidgetItem *p;-
1770 for (p = par; p && (p->itemFlags & Qt::ItemIsAutoTristate); p = p->par)
pDescription
TRUEnever evaluated
FALSEnever evaluated
(p->itemFlags ...sAutoTristate)Description
TRUEnever evaluated
FALSEnever evaluated
0
1771 model->emitDataChanged(p, column);
never executed: model->emitDataChanged(p, column);
0
1772 }
never executed: end of block
0
1773 }
never executed: end of block
0
1774}
never executed: end of block
0
1775-
1776/*!-
1777 Returns the value for the item's \a column and \a role.-
1778*/-
1779QVariant QTreeWidgetItem::data(int column, int role) const-
1780{-
1781 switch (role) {-
1782 case Qt::EditRole:
never executed: case Qt::EditRole:
0
1783 case Qt::DisplayRole:
never executed: case Qt::DisplayRole:
0
1784 if (column >= 0 && column < d->display.count())
column >= 0Description
TRUEnever evaluated
FALSEnever evaluated
column < d->display.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1785 return d->display.at(column);
never executed: return d->display.at(column);
0
1786 break;
never executed: break;
0
1787 case Qt::CheckStateRole:
never executed: case Qt::CheckStateRole:
0
1788 // special case for check state in tristate-
1789 if (children.count() && (itemFlags & Qt::ItemIsAutoTristate))
children.count()Description
TRUEnever evaluated
FALSEnever evaluated
(itemFlags & Q...sAutoTristate)Description
TRUEnever evaluated
FALSEnever evaluated
0
1790 return childrenCheckState(column);
never executed: return childrenCheckState(column);
0
1791 // fallthrough intended-
1792 default:
code before this statement never executed: default:
never executed: default:
0
1793 if (column >= 0 && column < values.size()) {
column >= 0Description
TRUEnever evaluated
FALSEnever evaluated
column < values.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1794 const QVector<QWidgetItemData> &column_values = values.at(column);-
1795 for (const auto &column_value : column_values) {-
1796 if (column_value.role == role)
column_value.role == roleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1797 return column_value.value;
never executed: return column_value.value;
0
1798 }
never executed: end of block
0
1799 }
never executed: end of block
0
1800 }
never executed: end of block
0
1801 return QVariant();
never executed: return QVariant();
0
1802}-
1803-
1804/*!-
1805 Returns \c true if the text in the item is less than the text in the-
1806 \a other item, otherwise returns \c false.-
1807*/-
1808-
1809bool QTreeWidgetItem::operator<(const QTreeWidgetItem &other) const-
1810{-
1811 int column = view ? view->sortColumn() : 0;
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1812 const QVariant v1 = data(column, Qt::DisplayRole);-
1813 const QVariant v2 = other.data(column, Qt::DisplayRole);-
1814 return QAbstractItemModelPrivate::variantLessThan(v1, v2);
never executed: return QAbstractItemModelPrivate::variantLessThan(v1, v2);
0
1815}-
1816-
1817#ifndef QT_NO_DATASTREAM-
1818-
1819/*!-
1820 Reads the item from stream \a in. This only reads data into a single item.-
1821-
1822 \sa write()-
1823*/-
1824void QTreeWidgetItem::read(QDataStream &in)-
1825{-
1826 // convert from streams written before we introduced display (4.2.0)-
1827 if (in.version() < QDataStream::Qt_4_2) {
in.version() <...Stream::Qt_4_2Description
TRUEnever evaluated
FALSEnever evaluated
0
1828 d->display.clear();-
1829 in >> values;-
1830 // move the display value over to the display string list-
1831 for (int column = 0; column < values.count(); ++column) {
column < values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1832 d->display << QVariant();-
1833 for (int i = 0; i < values.at(column).count(); ++i) {
i < values.at(column).count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1834 if (values.at(column).at(i).role == Qt::DisplayRole) {
values.at(colu...t::DisplayRoleDescription
TRUEnever evaluated
FALSEnever evaluated
0
1835 d->display[column] = values.at(column).at(i).value;-
1836 values[column].remove(i--);-
1837 }
never executed: end of block
0
1838 }
never executed: end of block
0
1839 }
never executed: end of block
0
1840 } else {
never executed: end of block
0
1841 in >> values >> d->display;-
1842 }
never executed: end of block
0
1843}-
1844-
1845/*!-
1846 Writes the item to stream \a out. This only writes data from one single item.-
1847-
1848 \sa read()-
1849*/-
1850void QTreeWidgetItem::write(QDataStream &out) const-
1851{-
1852 out << values << d->display;-
1853}
never executed: end of block
0
1854#endif // QT_NO_DATASTREAM-
1855-
1856/*!-
1857 \since 4.1-
1858-
1859 Constructs a copy of \a other. Note that type() and treeWidget()-
1860 are not copied.-
1861-
1862 This function is useful when reimplementing clone().-
1863-
1864 \sa data(), flags()-
1865*/-
1866QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem &other)-
1867 : rtti(Type), values(other.values), view(0),-
1868 d(new QTreeWidgetItemPrivate(this)), par(0),-
1869 itemFlags(other.itemFlags)-
1870{-
1871 d->display = other.d->display;-
1872}
never executed: end of block
0
1873-
1874/*!-
1875 Assigns \a other's data and flags to this item. Note that type()-
1876 and treeWidget() are not copied.-
1877-
1878 This function is useful when reimplementing clone().-
1879-
1880 \sa data(), flags()-
1881*/-
1882QTreeWidgetItem &QTreeWidgetItem::operator=(const QTreeWidgetItem &other)-
1883{-
1884 values = other.values;-
1885 d->display = other.d->display;-
1886 d->policy = other.d->policy;-
1887 itemFlags = other.itemFlags;-
1888 return *this;
never executed: return *this;
0
1889}-
1890-
1891/*!-
1892 Appends the \a child item to the list of children.-
1893-
1894 \sa insertChild(), takeChild()-
1895*/-
1896void QTreeWidgetItem::addChild(QTreeWidgetItem *child)-
1897{-
1898 if (child) {
childDescription
TRUEnever evaluated
FALSEnever evaluated
0
1899 insertChild(children.count(), child);-
1900 child->d->rowGuess = children.count() - 1;-
1901 }
never executed: end of block
0
1902}
never executed: end of block
0
1903-
1904/*!-
1905 Inserts the \a child item at \a index in the list of children.-
1906-
1907 If the child has already been inserted somewhere else it won't be inserted again.-
1908*/-
1909void QTreeWidgetItem::insertChild(int index, QTreeWidgetItem *child)-
1910{-
1911 if (index < 0 || index > children.count() || child == 0 || child->view != 0 || child->par != 0)
index < 0Description
TRUEnever evaluated
FALSEnever evaluated
index > children.count()Description
TRUEnever evaluated
FALSEnever evaluated
child == 0Description
TRUEnever evaluated
FALSEnever evaluated
child->view != 0Description
TRUEnever evaluated
FALSEnever evaluated
child->par != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1912 return;
never executed: return;
0
1913-
1914 if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0)) {
QTreeModel *mo...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1915 const bool wasSkipSort = model->skipPendingSort;-
1916 model->skipPendingSort = true;-
1917 if (model->rootItem == this)
model->rootItem == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1918 child->par = 0;
never executed: child->par = 0;
0
1919 else-
1920 child->par = this;
never executed: child->par = this;
0
1921 if (view->isSortingEnabled()) {
view->isSortingEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
1922 // do a delayed sort instead-
1923 if (!model->sortPendingTimer.isActive())
!model->sortPe...mer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
1924 model->sortPendingTimer.start(0, model);
never executed: model->sortPendingTimer.start(0, model);
0
1925 }
never executed: end of block
0
1926 model->beginInsertItems(this, index, 1);-
1927 int cols = model->columnCount();-
1928 QStack<QTreeWidgetItem*> stack;-
1929 stack.push(child);-
1930 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1931 QTreeWidgetItem *i = stack.pop();-
1932 i->view = view;-
1933 i->values.reserve(cols);-
1934 for (int c = 0; c < i->children.count(); ++c)
c < i->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1935 stack.push(i->children.at(c));
never executed: stack.push(i->children.at(c));
0
1936 }
never executed: end of block
0
1937 children.insert(index, child);-
1938 model->endInsertItems();-
1939 model->skipPendingSort = wasSkipSort;-
1940 } else {
never executed: end of block
0
1941 child->par = this;-
1942 children.insert(index, child);-
1943 }
never executed: end of block
0
1944 if (child->par)
child->parDescription
TRUEnever evaluated
FALSEnever evaluated
0
1945 d->propagateDisabled(child);
never executed: d->propagateDisabled(child);
0
1946}
never executed: end of block
0
1947-
1948/*!-
1949 Removes the given item indicated by \a child.-
1950 The removed item will not be deleted.-
1951*/-
1952void QTreeWidgetItem::removeChild(QTreeWidgetItem *child)-
1953{-
1954 (void)takeChild(children.indexOf(child));-
1955}
never executed: end of block
0
1956-
1957/*!-
1958 Removes the item at \a index and returns it, otherwise return 0.-
1959*/-
1960QTreeWidgetItem *QTreeWidgetItem::takeChild(int index)-
1961{-
1962 // we move this outside the check of the index to allow executing-
1963 // pending sorts from inline functions, using this function (hack)-
1964 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
1965 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1966 // This will trigger a layoutChanged signal, thus we might want to optimize-
1967 // this function by not emitting the rowsRemoved signal etc to the view.-
1968 // On the other hand we also need to make sure that the selectionmodel-
1969 // is updated in case we take an item that is selected.-
1970 model->skipPendingSort = false;-
1971 model->executePendingSort();-
1972 }
never executed: end of block
0
1973 if (index >= 0 && index < children.count()) {
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
index < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1974 if (model) model->beginRemoveItems(this, index, 1);
never executed: model->beginRemoveItems(this, index, 1);
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1975 QTreeWidgetItem *item = children.takeAt(index);-
1976 item->par = 0;-
1977 QStack<QTreeWidgetItem*> stack;-
1978 stack.push(item);-
1979 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1980 QTreeWidgetItem *i = stack.pop();-
1981 i->view = 0;-
1982 for (int c = 0; c < i->children.count(); ++c)
c < i->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1983 stack.push(i->children.at(c));
never executed: stack.push(i->children.at(c));
0
1984 }
never executed: end of block
0
1985 d->propagateDisabled(item);-
1986 if (model) model->endRemoveRows();
never executed: model->endRemoveRows();
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1987 return item;
never executed: return item;
0
1988 }-
1989 return 0;
never executed: return 0;
0
1990}-
1991-
1992/*!-
1993 \since 4.1-
1994-
1995 Appends the given list of \a children to the item.-
1996-
1997 \sa insertChildren(), takeChildren()-
1998*/-
1999void QTreeWidgetItem::addChildren(const QList<QTreeWidgetItem*> &children)-
2000{-
2001 insertChildren(this->children.count(), children);-
2002}
never executed: end of block
0
2003-
2004/*!-
2005 \since 4.1-
2006-
2007 Inserts the given list of \a children into the list of the item children at \a index .-
2008-
2009 Children that have already been inserted somewhere else won't be inserted.-
2010*/-
2011void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &children)-
2012{-
2013 if (view && view->isSortingEnabled()) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
view->isSortingEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
2014 for (int n = 0; n < children.count(); ++n)
n < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2015 insertChild(index, children.at(n));
never executed: insertChild(index, children.at(n));
0
2016 return;
never executed: return;
0
2017 }-
2018 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2019 QStack<QTreeWidgetItem*> stack;-
2020 QList<QTreeWidgetItem*> itemsToInsert;-
2021 for (int n = 0; n < children.count(); ++n) {
n < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2022 QTreeWidgetItem *child = children.at(n);-
2023 if (child->view || child->par)
child->viewDescription
TRUEnever evaluated
FALSEnever evaluated
child->parDescription
TRUEnever evaluated
FALSEnever evaluated
0
2024 continue;
never executed: continue;
0
2025 itemsToInsert.append(child);-
2026 if (view && model) {
viewDescription
TRUEnever evaluated
FALSEnever evaluated
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2027 if (child->childCount() == 0)
child->childCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2028 child->view = view;
never executed: child->view = view;
0
2029 else-
2030 stack.push(child);
never executed: stack.push(child);
0
2031 }-
2032 if (model && (model->rootItem == this))
modelDescription
TRUEnever evaluated
FALSEnever evaluated
(model->rootItem == this)Description
TRUEnever evaluated
FALSEnever evaluated
0
2033 child->par = 0;
never executed: child->par = 0;
0
2034 else-
2035 child->par = this;
never executed: child->par = this;
0
2036 }-
2037 if (!itemsToInsert.isEmpty()) {
!itemsToInsert.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2038 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2039 QTreeWidgetItem *i = stack.pop();-
2040 i->view = view;-
2041 for (int c = 0; c < i->children.count(); ++c)
c < i->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2042 stack.push(i->children.at(c));
never executed: stack.push(i->children.at(c));
0
2043 }
never executed: end of block
0
2044 if (model) model->beginInsertItems(this, index, itemsToInsert.count());
never executed: model->beginInsertItems(this, index, itemsToInsert.count());
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2045 for (int n = 0; n < itemsToInsert.count(); ++n) {
n < itemsToInsert.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2046 QTreeWidgetItem *child = itemsToInsert.at(n);-
2047 this->children.insert(index + n, child);-
2048 if (child->par)
child->parDescription
TRUEnever evaluated
FALSEnever evaluated
0
2049 d->propagateDisabled(child);
never executed: d->propagateDisabled(child);
0
2050 }
never executed: end of block
0
2051 if (model) model->endInsertItems();
never executed: model->endInsertItems();
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2052 }
never executed: end of block
0
2053}
never executed: end of block
0
2054-
2055/*!-
2056 \since 4.1-
2057-
2058 Removes the list of children and returns it, otherwise returns an empty list.-
2059*/-
2060QList<QTreeWidgetItem*> QTreeWidgetItem::takeChildren()-
2061{-
2062 QList<QTreeWidgetItem*> removed;-
2063 if (children.count() > 0) {
children.count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2064 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2065 if (model) {
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2066 // This will trigger a layoutChanged signal, thus we might want to optimize-
2067 // this function by not emitting the rowsRemoved signal etc to the view.-
2068 // On the other hand we also need to make sure that the selectionmodel-
2069 // is updated in case we take an item that is selected.-
2070 model->executePendingSort();-
2071 }
never executed: end of block
0
2072 if (model) model->beginRemoveItems(this, 0, children.count());
never executed: model->beginRemoveItems(this, 0, children.count());
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2073 for (int n = 0; n < children.count(); ++n) {
n < children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2074 QTreeWidgetItem *item = children.at(n);-
2075 item->par = 0;-
2076 QStack<QTreeWidgetItem*> stack;-
2077 stack.push(item);-
2078 while (!stack.isEmpty()) {
!stack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2079 QTreeWidgetItem *i = stack.pop();-
2080 i->view = 0;-
2081 for (int c = 0; c < i->children.count(); ++c)
c < i->children.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2082 stack.push(i->children.at(c));
never executed: stack.push(i->children.at(c));
0
2083 }
never executed: end of block
0
2084 d->propagateDisabled(item);-
2085 }
never executed: end of block
0
2086 removed = children;-
2087 children.clear(); // detach-
2088 if (model) model->endRemoveItems();
never executed: model->endRemoveItems();
modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2089 }
never executed: end of block
0
2090 return removed;
never executed: return removed;
0
2091}-
2092-
2093-
2094void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool climb)-
2095{-
2096 QTreeModel *model = (q->view ? qobject_cast<QTreeModel*>(q->view->model()) : 0);
q->viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2097 if (!model)
!modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2098 return;
never executed: return;
0
2099 model->sortItems(&q->children, column, order);-
2100 if (climb) {
climbDescription
TRUEnever evaluated
FALSEnever evaluated
0
2101 QList<QTreeWidgetItem*>::iterator it = q->children.begin();-
2102 for (; it != q->children.end(); ++it) {
it != q->children.end()Description
TRUEnever evaluated
FALSEnever evaluated
0
2103 //here we call the private object's method to avoid emitting-
2104 //the layoutAboutToBeChanged and layoutChanged signals-
2105 (*it)->d->sortChildren(column, order, climb);-
2106 }
never executed: end of block
0
2107 }
never executed: end of block
0
2108}
never executed: end of block
0
2109-
2110/*!-
2111 \internal-
2112-
2113 Sorts the children by the value in the given \a column, in the \a order-
2114 specified. If \a climb is true, the items below each of the children will-
2115 also be sorted.-
2116*/-
2117void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order, bool climb)-
2118{-
2119 QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2120 if (!model)
!modelDescription
TRUEnever evaluated
FALSEnever evaluated
0
2121 return;
never executed: return;
0
2122 if (model->isChanging())
model->isChanging()Description
TRUEnever evaluated
FALSEnever evaluated
0
2123 return;
never executed: return;
0
2124 QTreeModel::SkipSorting skipSorting(model);-
2125 int oldSortColumn = view->d_func()->explicitSortColumn;-
2126 view->d_func()->explicitSortColumn = column;-
2127 emit model->layoutAboutToBeChanged();-
2128 d->sortChildren(column, order, climb);-
2129 emit model->layoutChanged();-
2130 view->d_func()->explicitSortColumn = oldSortColumn;-
2131}
never executed: end of block
0
2132-
2133/*!-
2134 \internal-
2135-
2136 Calculates the checked state of the item based on the checked state-
2137 of its children. E.g. if all children checked => this item is also-
2138 checked; if some children checked => this item is partially checked;-
2139 if no children checked => this item is unchecked.-
2140*/-
2141QVariant QTreeWidgetItem::childrenCheckState(int column) const-
2142{-
2143 if (column < 0)
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2144 return QVariant();
never executed: return QVariant();
0
2145 bool checkedChildren = false;-
2146 bool uncheckedChildren = false;-
2147 for (const auto *child : children) {-
2148 QVariant value = child->data(column, Qt::CheckStateRole);-
2149 if (!value.isValid())
!value.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2150 return QVariant();
never executed: return QVariant();
0
2151-
2152 switch (static_cast<Qt::CheckState>(value.toInt()))-
2153 {-
2154 case Qt::Unchecked:
never executed: case Qt::Unchecked:
0
2155 uncheckedChildren = true;-
2156 break;
never executed: break;
0
2157 case Qt::Checked:
never executed: case Qt::Checked:
0
2158 checkedChildren = true;-
2159 break;
never executed: break;
0
2160 case Qt::PartiallyChecked:
never executed: case Qt::PartiallyChecked:
0
2161 default:
never executed: default:
0
2162 return Qt::PartiallyChecked;
never executed: return Qt::PartiallyChecked;
0
2163 }-
2164-
2165 if (uncheckedChildren && checkedChildren)
uncheckedChildrenDescription
TRUEnever evaluated
FALSEnever evaluated
checkedChildrenDescription
TRUEnever evaluated
FALSEnever evaluated
0
2166 return Qt::PartiallyChecked;
never executed: return Qt::PartiallyChecked;
0
2167 }
never executed: end of block
0
2168-
2169 if (uncheckedChildren)
uncheckedChildrenDescription
TRUEnever evaluated
FALSEnever evaluated
0
2170 return Qt::Unchecked;
never executed: return Qt::Unchecked;
0
2171 else if (checkedChildren)
checkedChildrenDescription
TRUEnever evaluated
FALSEnever evaluated
0
2172 return Qt::Checked;
never executed: return Qt::Checked;
0
2173 else-
2174 return QVariant(); // value was not defined
never executed: return QVariant();
0
2175}-
2176-
2177/*!-
2178 \since 4.5-
2179-
2180 Causes the model associated with this item to emit a-
2181 \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this-
2182 item.-
2183-
2184 You normally only need to call this function if you have subclassed-
2185 QTreeWidgetItem and reimplemented data() and/or setData().-
2186-
2187 \sa setData()-
2188*/-
2189void QTreeWidgetItem::emitDataChanged()-
2190{-
2191 itemChanged();-
2192}
never executed: end of block
0
2193-
2194/*!-
2195 \internal-
2196*/-
2197void QTreeWidgetItem::itemChanged()-
2198{-
2199 if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
QTreeModel *mo...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2200 model->itemChanged(this);
never executed: model->itemChanged(this);
0
2201}
never executed: end of block
0
2202-
2203/*!-
2204 \internal-
2205*/-
2206void QTreeWidgetItem::executePendingSort() const-
2207{-
2208 if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
QTreeModel *mo...>model()) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
viewDescription
TRUEnever evaluated
FALSEnever evaluated
0
2209 model->executePendingSort();
never executed: model->executePendingSort();
0
2210}
never executed: end of block
0
2211-
2212-
2213#ifndef QT_NO_DATASTREAM-
2214/*!-
2215 \relates QTreeWidgetItem-
2216-
2217 Writes the tree widget item \a item to stream \a out.-
2218-
2219 This operator uses QTreeWidgetItem::write().-
2220-
2221 \sa {Serializing Qt Data Types}-
2222*/-
2223QDataStream &operator<<(QDataStream &out, const QTreeWidgetItem &item)-
2224{-
2225 item.write(out);-
2226 return out;
never executed: return out;
0
2227}-
2228-
2229/*!-
2230 \relates QTreeWidgetItem-
2231-
2232 Reads a tree widget item from stream \a in into \a item.-
2233-
2234 This operator uses QTreeWidgetItem::read().-
2235-
2236 \sa {Serializing Qt Data Types}-
2237*/-
2238QDataStream &operator>>(QDataStream &in, QTreeWidgetItem &item)-
2239{-
2240 item.read(in);-
2241 return in;
never executed: return in;
0
2242}-
2243#endif // QT_NO_DATASTREAM-
2244-
2245-
2246void QTreeWidgetPrivate::_q_emitItemPressed(const QModelIndex &index)-
2247{-
2248 Q_Q(QTreeWidget);-
2249 emit q->itemPressed(item(index), index.column());-
2250}
never executed: end of block
0
2251-
2252void QTreeWidgetPrivate::_q_emitItemClicked(const QModelIndex &index)-
2253{-
2254 Q_Q(QTreeWidget);-
2255 emit q->itemClicked(item(index), index.column());-
2256}
never executed: end of block
0
2257-
2258void QTreeWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index)-
2259{-
2260 Q_Q(QTreeWidget);-
2261 emit q->itemDoubleClicked(item(index), index.column());-
2262}
never executed: end of block
0
2263-
2264void QTreeWidgetPrivate::_q_emitItemActivated(const QModelIndex &index)-
2265{-
2266 Q_Q(QTreeWidget);-
2267 emit q->itemActivated(item(index), index.column());-
2268}
never executed: end of block
0
2269-
2270void QTreeWidgetPrivate::_q_emitItemEntered(const QModelIndex &index)-
2271{-
2272 Q_Q(QTreeWidget);-
2273 emit q->itemEntered(item(index), index.column());-
2274}
never executed: end of block
0
2275-
2276void QTreeWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)-
2277{-
2278 Q_Q(QTreeWidget);-
2279 QTreeWidgetItem *indexItem = item(index);-
2280 if (indexItem)
indexItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2281 emit q->itemChanged(indexItem, index.column());
never executed: q->itemChanged(indexItem, index.column());
0
2282}
never executed: end of block
0
2283-
2284void QTreeWidgetPrivate::_q_emitItemExpanded(const QModelIndex &index)-
2285{-
2286 Q_Q(QTreeWidget);-
2287 emit q->itemExpanded(item(index));-
2288}
never executed: end of block
0
2289-
2290void QTreeWidgetPrivate::_q_emitItemCollapsed(const QModelIndex &index)-
2291{-
2292 Q_Q(QTreeWidget);-
2293 emit q->itemCollapsed(item(index));-
2294}
never executed: end of block
0
2295-
2296void QTreeWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex &current,-
2297 const QModelIndex &previous)-
2298{-
2299 Q_Q(QTreeWidget);-
2300 QTreeWidgetItem *currentItem = item(current);-
2301 QTreeWidgetItem *previousItem = item(previous);-
2302 emit q->currentItemChanged(currentItem, previousItem);-
2303}
never executed: end of block
0
2304-
2305void QTreeWidgetPrivate::_q_sort()-
2306{-
2307 if (sortingEnabled) {
sortingEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
2308 int column = header->sortIndicatorSection();-
2309 Qt::SortOrder order = header->sortIndicatorOrder();-
2310 treeModel()->sort(column, order);-
2311 }
never executed: end of block
0
2312}
never executed: end of block
0
2313-
2314void QTreeWidgetPrivate::_q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)-
2315{-
2316 Q_Q(QTreeWidget);-
2317 QModelIndexList indices = selected.indexes();-
2318 int i;-
2319 QTreeModel *m = treeModel();-
2320 for (i = 0; i < indices.count(); ++i) {
i < indices.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2321 QTreeWidgetItem *item = m->item(indices.at(i));-
2322 item->d->selected = true;-
2323 }
never executed: end of block
0
2324-
2325 indices = deselected.indexes();-
2326 for (i = 0; i < indices.count(); ++i) {
i < indices.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2327 QTreeWidgetItem *item = m->item(indices.at(i));-
2328 item->d->selected = false;-
2329 }
never executed: end of block
0
2330-
2331 emit q->itemSelectionChanged();-
2332}
never executed: end of block
0
2333-
2334void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,-
2335 const QModelIndex &bottomRight)-
2336{-
2337 if (sortingEnabled && topLeft.isValid() && bottomRight.isValid()
sortingEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
topLeft.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
bottomRight.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2338 && !treeModel()->sortPendingTimer.isActive()) {
!treeModel()->...mer.isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
2339 int column = header->sortIndicatorSection();-
2340 if (column >= topLeft.column() && column <= bottomRight.column()) {
column >= topLeft.column()Description
TRUEnever evaluated
FALSEnever evaluated
column <= bottomRight.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
2341 Qt::SortOrder order = header->sortIndicatorOrder();-
2342 treeModel()->ensureSorted(column, order, topLeft.row(),-
2343 bottomRight.row(), topLeft.parent());-
2344 }
never executed: end of block
0
2345 }
never executed: end of block
0
2346}
never executed: end of block
0
2347-
2348/*!-
2349 \class QTreeWidget-
2350-
2351 \brief The QTreeWidget class provides a tree view that uses a predefined-
2352 tree model.-
2353-
2354 \ingroup model-view-
2355 \inmodule QtWidgets-
2356-
2357 The QTreeWidget class is a convenience class that provides a standard-
2358 tree widget with a classic item-based interface similar to that used by-
2359 the QListView class in Qt 3.-
2360 This class is based on Qt's Model/View architecture and uses a default-
2361 model to hold items, each of which is a QTreeWidgetItem.-
2362-
2363 Developers who do not need the flexibility of the Model/View framework-
2364 can use this class to create simple hierarchical lists very easily. A more-
2365 flexible approach involves combining a QTreeView with a standard item model.-
2366 This allows the storage of data to be separated from its representation.-
2367-
2368 In its simplest form, a tree widget can be constructed in the following way:-
2369-
2370 \snippet code/src_gui_itemviews_qtreewidget.cpp 0-
2371-
2372 Before items can be added to the tree widget, the number of columns must-
2373 be set with setColumnCount(). This allows each item to have one or more-
2374 labels or other decorations. The number of columns in use can be found-
2375 with the columnCount() function.-
2376-
2377 The tree can have a header that contains a section for each column in-
2378 the widget. It is easiest to set up the labels for each section by-
2379 supplying a list of strings with setHeaderLabels(), but a custom header-
2380 can be constructed with a QTreeWidgetItem and inserted into the tree-
2381 with the setHeaderItem() function.-
2382-
2383 The items in the tree can be sorted by column according to a predefined-
2384 sort order. If sorting is enabled, the user can sort the items by clicking-
2385 on a column header. Sorting can be enabled or disabled by calling-
2386 \l{QTreeView::setSortingEnabled()}{setSortingEnabled()}. The-
2387 \l{QTreeView::isSortingEnabled()}{isSortingEnabled()} function indicates-
2388 whether sorting is enabled.-
2389-
2390 \table 100%-
2391 \row \li \inlineimage windowsvista-treeview.png Screenshot of a Windows Vista style tree widget-
2392 \li \inlineimage macintosh-treeview.png Screenshot of a Macintosh style tree widget-
2393 \li \inlineimage fusion-treeview.png Screenshot of a Fusion style tree widget-
2394 \row \li A \l{Windows Vista Style Widget Gallery}{Windows Vista style} tree widget.-
2395 \li A \l{Macintosh Style Widget Gallery}{Macintosh style} tree widget.-
2396 \li A \l{Fusion Style Widget Gallery}{Fusion style} tree widget.-
2397 \endtable-
2398-
2399 \sa QTreeWidgetItem, QTreeWidgetItemIterator, QTreeView,-
2400 {Model/View Programming}, {Settings Editor Example}-
2401*/-
2402-
2403/*!-
2404 \property QTreeWidget::columnCount-
2405 \brief the number of columns displayed in the tree widget-
2406-
2407 By default, this property has a value of 1.-
2408*/-
2409-
2410/*!-
2411 \fn void QTreeWidget::itemActivated(QTreeWidgetItem *item, int column)-
2412-
2413 This signal is emitted when the user activates an item by single--
2414 or double-clicking (depending on the platform, i.e. on the-
2415 QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or-
2416 pressing a special key (e.g., \uicontrol Enter).-
2417-
2418 The specified \a item is the item that was clicked, or 0 if no-
2419 item was clicked. The \a column is the item's column that was-
2420 clicked, or -1 if no item was clicked.-
2421*/-
2422-
2423/*!-
2424 \fn void QTreeWidget::itemPressed(QTreeWidgetItem *item, int column)-
2425-
2426 This signal is emitted when the user presses a mouse button inside-
2427 the widget.-
2428-
2429 The specified \a item is the item that was clicked, or 0 if no-
2430 item was clicked. The \a column is the item's column that was-
2431 clicked, or -1 if no item was clicked.-
2432*/-
2433-
2434/*!-
2435 \fn void QTreeWidget::itemClicked(QTreeWidgetItem *item, int column)-
2436-
2437 This signal is emitted when the user clicks inside the widget.-
2438-
2439 The specified \a item is the item that was clicked. The \a column is the-
2440 item's column that was clicked. If no item was clicked, no signal will be-
2441 emitted.-
2442*/-
2443-
2444/*!-
2445 \fn void QTreeWidget::itemDoubleClicked(QTreeWidgetItem *item, int column)-
2446-
2447 This signal is emitted when the user double clicks inside the-
2448 widget.-
2449-
2450 The specified \a item is the item that was clicked, or 0 if no-
2451 item was clicked. The \a column is the item's column that was-
2452 clicked. If no item was double clicked, no signal will be emitted.-
2453*/-
2454-
2455/*!-
2456 \fn void QTreeWidget::itemExpanded(QTreeWidgetItem *item)-
2457-
2458 This signal is emitted when the specified \a item is expanded so that-
2459 all of its children are displayed.-
2460-
2461 \note This signal will not be emitted if an item changes its state when-
2462 expandAll() is invoked.-
2463-
2464 \sa QTreeWidgetItem::isExpanded(), itemCollapsed(), expandItem()-
2465*/-
2466-
2467/*!-
2468 \fn void QTreeWidget::itemCollapsed(QTreeWidgetItem *item)-
2469-
2470 This signal is emitted when the specified \a item is collapsed so that-
2471 none of its children are displayed.-
2472-
2473 \note This signal will not be emitted if an item changes its state when-
2474 collapseAll() is invoked.-
2475-
2476 \sa QTreeWidgetItem::isExpanded(), itemExpanded(), collapseItem()-
2477*/-
2478-
2479/*!-
2480 \fn void QTreeWidget::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)-
2481-
2482 This signal is emitted when the current item changes. The current-
2483 item is specified by \a current, and this replaces the \a previous-
2484 current item.-
2485-
2486 \sa setCurrentItem()-
2487*/-
2488-
2489/*!-
2490 \fn void QTreeWidget::itemSelectionChanged()-
2491-
2492 This signal is emitted when the selection changes in the tree widget.-
2493 The current selection can be found with selectedItems().-
2494*/-
2495-
2496/*!-
2497 \fn void QTreeWidget::itemEntered(QTreeWidgetItem *item, int column)-
2498-
2499 This signal is emitted when the mouse cursor enters an \a item over the-
2500 specified \a column.-
2501 QTreeWidget mouse tracking needs to be enabled for this feature to work.-
2502*/-
2503-
2504/*!-
2505 \fn void QTreeWidget::itemChanged(QTreeWidgetItem *item, int column)-
2506-
2507 This signal is emitted when the contents of the \a column in the specified-
2508 \a item changes.-
2509*/-
2510-
2511/*!-
2512 \since 4.3-
2513-
2514 \fn void QTreeWidget::removeItemWidget(QTreeWidgetItem *item, int column)-
2515-
2516 Removes the widget set in the given \a item in the given \a column.-
2517*/-
2518-
2519/*!-
2520 Constructs a tree widget with the given \a parent.-
2521*/-
2522QTreeWidget::QTreeWidget(QWidget *parent)-
2523 : QTreeView(*new QTreeWidgetPrivate(), parent)-
2524{-
2525 QTreeView::setModel(new QTreeModel(1, this));-
2526 connect(this, SIGNAL(pressed(QModelIndex)),-
2527 SLOT(_q_emitItemPressed(QModelIndex)));-
2528 connect(this, SIGNAL(clicked(QModelIndex)),-
2529 SLOT(_q_emitItemClicked(QModelIndex)));-
2530 connect(this, SIGNAL(doubleClicked(QModelIndex)),-
2531 SLOT(_q_emitItemDoubleClicked(QModelIndex)));-
2532 connect(this, SIGNAL(activated(QModelIndex)),-
2533 SLOT(_q_emitItemActivated(QModelIndex)));-
2534 connect(this, SIGNAL(entered(QModelIndex)),-
2535 SLOT(_q_emitItemEntered(QModelIndex)));-
2536 connect(this, SIGNAL(expanded(QModelIndex)),-
2537 SLOT(_q_emitItemExpanded(QModelIndex)));-
2538 connect(this, SIGNAL(collapsed(QModelIndex)),-
2539 SLOT(_q_emitItemCollapsed(QModelIndex)));-
2540 connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),-
2541 this, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex)));-
2542 connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
2543 this, SLOT(_q_emitItemChanged(QModelIndex)));-
2544 connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),-
2545 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));-
2546 connect(model(), SIGNAL(columnsRemoved(QModelIndex,int,int)),-
2547 this, SLOT(_q_sort()));-
2548 connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),-
2549 this, SLOT(_q_selectionChanged(QItemSelection,QItemSelection)));-
2550 header()->setSectionsClickable(false);-
2551}
never executed: end of block
0
2552-
2553/*!-
2554 Destroys the tree widget and all its items.-
2555*/-
2556-
2557QTreeWidget::~QTreeWidget()-
2558{-
2559}-
2560-
2561/*-
2562 Retuns the number of header columns in the view.-
2563-
2564 \sa sortColumn(), currentColumn(), topLevelItemCount()-
2565*/-
2566-
2567int QTreeWidget::columnCount() const-
2568{-
2569 Q_D(const QTreeWidget);-
2570 return d->model->columnCount();
never executed: return d->model->columnCount();
0
2571}-
2572-
2573/*-
2574 Sets the number of header \a columns in the tree widget.-
2575*/-
2576-
2577void QTreeWidget::setColumnCount(int columns)-
2578{-
2579 Q_D(QTreeWidget);-
2580 if (columns < 0)
columns < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2581 return;
never executed: return;
0
2582 d->treeModel()->setColumnCount(columns);-
2583}
never executed: end of block
0
2584-
2585/*!-
2586 \since 4.2-
2587-
2588 Returns the tree widget's invisible root item.-
2589-
2590 The invisible root item provides access to the tree widget's top-level items-
2591 through the QTreeWidgetItem API, making it possible to write functions that-
2592 can treat top-level items and their children in a uniform way; for example,-
2593 recursive functions.-
2594*/-
2595-
2596QTreeWidgetItem *QTreeWidget::invisibleRootItem() const-
2597{-
2598 Q_D(const QTreeWidget);-
2599 return d->treeModel()->rootItem;
never executed: return d->treeModel()->rootItem;
0
2600}-
2601-
2602/*!-
2603 Returns the top level item at the given \a index, or 0 if the item does-
2604 not exist.-
2605-
2606 \sa topLevelItemCount(), insertTopLevelItem()-
2607*/-
2608-
2609QTreeWidgetItem *QTreeWidget::topLevelItem(int index) const-
2610{-
2611 Q_D(const QTreeWidget);-
2612 return d->treeModel()->rootItem->child(index);
never executed: return d->treeModel()->rootItem->child(index);
0
2613}-
2614-
2615/*!-
2616 \property QTreeWidget::topLevelItemCount-
2617 \brief the number of top-level items-
2618-
2619 By default, this property has a value of 0.-
2620-
2621 \sa columnCount(), currentItem()-
2622*/-
2623-
2624int QTreeWidget::topLevelItemCount() const-
2625{-
2626 Q_D(const QTreeWidget);-
2627 return d->treeModel()->rootItem->childCount();
never executed: return d->treeModel()->rootItem->childCount();
0
2628}-
2629-
2630/*!-
2631 Inserts the \a item at \a index in the top level in the view.-
2632-
2633 If the item has already been inserted somewhere else it won't be inserted.-
2634-
2635 \sa addTopLevelItem(), columnCount()-
2636*/-
2637-
2638void QTreeWidget::insertTopLevelItem(int index, QTreeWidgetItem *item)-
2639{-
2640 Q_D(QTreeWidget);-
2641 d->treeModel()->rootItem->insertChild(index, item);-
2642}
never executed: end of block
0
2643-
2644/*!-
2645 \since 4.1-
2646-
2647 Appends the \a item as a top-level item in the widget.-
2648-
2649 \sa insertTopLevelItem()-
2650*/-
2651void QTreeWidget::addTopLevelItem(QTreeWidgetItem *item)-
2652{-
2653 insertTopLevelItem(topLevelItemCount(), item);-
2654}
never executed: end of block
0
2655-
2656/*!-
2657 Removes the top-level item at the given \a index in the tree and-
2658 returns it, otherwise returns 0;-
2659-
2660 \sa insertTopLevelItem(), topLevelItem(), topLevelItemCount()-
2661*/-
2662-
2663QTreeWidgetItem *QTreeWidget::takeTopLevelItem(int index)-
2664{-
2665 Q_D(QTreeWidget);-
2666 return d->treeModel()->rootItem->takeChild(index);
never executed: return d->treeModel()->rootItem->takeChild(index);
0
2667}-
2668-
2669/*!-
2670 Returns the index of the given top-level \a item, or -1 if the item-
2671 cannot be found.-
2672-
2673 \sa sortItems(), topLevelItemCount()-
2674 */-
2675int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) const-
2676{-
2677 Q_D(const QTreeWidget);-
2678 d->treeModel()->executePendingSort();-
2679 return d->treeModel()->rootItem->children.indexOf(item);
never executed: return d->treeModel()->rootItem->children.indexOf(item);
0
2680}-
2681-
2682/*!-
2683 \since 4.1-
2684-
2685 Inserts the list of \a items at \a index in the top level in the view.-
2686-
2687 Items that have already been inserted somewhere else won't be inserted.-
2688-
2689 \sa addTopLevelItems()-
2690*/-
2691void QTreeWidget::insertTopLevelItems(int index, const QList<QTreeWidgetItem*> &items)-
2692{-
2693 Q_D(QTreeWidget);-
2694 d->treeModel()->rootItem->insertChildren(index, items);-
2695}
never executed: end of block
0
2696-
2697/*!-
2698 Appends the list of \a items as a top-level items in the widget.-
2699-
2700 \sa insertTopLevelItems()-
2701*/-
2702void QTreeWidget::addTopLevelItems(const QList<QTreeWidgetItem*> &items)-
2703{-
2704 insertTopLevelItems(topLevelItemCount(), items);-
2705}
never executed: end of block
0
2706-
2707/*!-
2708 Returns the item used for the tree widget's header.-
2709-
2710 \sa setHeaderItem()-
2711*/-
2712-
2713QTreeWidgetItem *QTreeWidget::headerItem() const-
2714{-
2715 Q_D(const QTreeWidget);-
2716 return d->treeModel()->headerItem;
never executed: return d->treeModel()->headerItem;
0
2717}-
2718-
2719/*!-
2720 Sets the header \a item for the tree widget. The label for each column in-
2721 the header is supplied by the corresponding label in the item.-
2722-
2723 The tree widget takes ownership of the item.-
2724-
2725 \sa headerItem(), setHeaderLabels()-
2726*/-
2727-
2728void QTreeWidget::setHeaderItem(QTreeWidgetItem *item)-
2729{-
2730 Q_D(QTreeWidget);-
2731 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2732 return;
never executed: return;
0
2733 item->view = this;-
2734-
2735 int oldCount = columnCount();-
2736 if (oldCount < item->columnCount())
oldCount < item->columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
2737 d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount());
never executed: d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount());
0
2738 else-
2739 d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount);
never executed: d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount);
0
2740 delete d->treeModel()->headerItem;-
2741 d->treeModel()->headerItem = item;-
2742 if (oldCount < item->columnCount())
oldCount < item->columnCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
2743 d->treeModel()->endInsertColumns();
never executed: d->treeModel()->endInsertColumns();
0
2744 else-
2745 d->treeModel()->endRemoveColumns();
never executed: d->treeModel()->endRemoveColumns();
0
2746 d->treeModel()->headerDataChanged(Qt::Horizontal, 0, oldCount);-
2747}
never executed: end of block
0
2748-
2749-
2750/*!-
2751 Adds a column in the header for each item in the \a labels list, and sets-
2752 the label for each column.-
2753-
2754 Note that setHeaderLabels() won't remove existing columns.-
2755-
2756 \sa setHeaderItem(), setHeaderLabel()-
2757*/-
2758void QTreeWidget::setHeaderLabels(const QStringList &labels)-
2759{-
2760 Q_D(QTreeWidget);-
2761 if (columnCount() < labels.count())
columnCount() < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2762 setColumnCount(labels.count());
never executed: setColumnCount(labels.count());
0
2763 QTreeWidgetItem *item = d->treeModel()->headerItem;-
2764 for (int i = 0; i < labels.count(); ++i)
i < labels.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
2765 item->setText(i, labels.at(i));
never executed: item->setText(i, labels.at(i));
0
2766}
never executed: end of block
0
2767-
2768/*!-
2769 \fn void QTreeWidget::setHeaderLabel(const QString &label)-
2770 \since 4.2-
2771-
2772 Same as setHeaderLabels(QStringList(\a label)).-
2773*/-
2774-
2775/*!-
2776 Returns the current item in the tree widget.-
2777-
2778 \sa setCurrentItem(), currentItemChanged()-
2779*/-
2780QTreeWidgetItem *QTreeWidget::currentItem() const-
2781{-
2782 Q_D(const QTreeWidget);-
2783 return d->item(currentIndex());
never executed: return d->item(currentIndex());
0
2784}-
2785-
2786/*!-
2787 \since 4.1-
2788 Returns the current column in the tree widget.-
2789-
2790 \sa setCurrentItem(), columnCount()-
2791*/-
2792int QTreeWidget::currentColumn() const-
2793{-
2794 return currentIndex().column();
never executed: return currentIndex().column();
0
2795}-
2796-
2797/*!-
2798 Sets the current \a item in the tree widget.-
2799-
2800 Unless the selection mode is \l{QAbstractItemView::}{NoSelection},-
2801 the item is also selected.-
2802-
2803 \sa currentItem(), currentItemChanged()-
2804*/-
2805void QTreeWidget::setCurrentItem(QTreeWidgetItem *item)-
2806{-
2807 setCurrentItem(item, 0);-
2808}
never executed: end of block
0
2809-
2810/*!-
2811 \since 4.1-
2812 Sets the current \a item in the tree widget and the current column to \a column.-
2813-
2814 \sa currentItem()-
2815*/-
2816void QTreeWidget::setCurrentItem(QTreeWidgetItem *item, int column)-
2817{-
2818 Q_D(QTreeWidget);-
2819 setCurrentIndex(d->index(item, column));-
2820}
never executed: end of block
0
2821-
2822/*!-
2823 \since 4.4-
2824 Sets the current \a item in the tree widget and the current column to \a column,-
2825 using the given \a command.-
2826-
2827 \sa currentItem()-
2828*/-
2829void QTreeWidget::setCurrentItem(QTreeWidgetItem *item, int column,-
2830 QItemSelectionModel::SelectionFlags command)-
2831{-
2832 Q_D(QTreeWidget);-
2833 d->selectionModel->setCurrentIndex(d->index(item, column), command);-
2834}
never executed: end of block
0
2835-
2836-
2837/*!-
2838 Returns a pointer to the item at the coordinates \a p. The coordinates-
2839 are relative to the tree widget's \l{QAbstractScrollArea::}{viewport()}.-
2840-
2841 \sa visualItemRect()-
2842*/-
2843QTreeWidgetItem *QTreeWidget::itemAt(const QPoint &p) const-
2844{-
2845 Q_D(const QTreeWidget);-
2846 return d->item(indexAt(p));
never executed: return d->item(indexAt(p));
0
2847}-
2848-
2849/*!-
2850 \fn QTreeWidgetItem *QTreeWidget::itemAt(int x, int y) const-
2851 \overload-
2852-
2853 Returns a pointer to the item at the coordinates (\a x, \a y). The coordinates-
2854 are relative to the tree widget's \l{QAbstractScrollArea::}{viewport()}.-
2855*/-
2856-
2857/*!-
2858 Returns the rectangle on the viewport occupied by the item at \a item.-
2859-
2860 \sa itemAt()-
2861*/-
2862QRect QTreeWidget::visualItemRect(const QTreeWidgetItem *item) const-
2863{-
2864 Q_D(const QTreeWidget);-
2865 //the visual rect for an item is across all columns. So we need to determine-
2866 //what is the first and last column and get their visual index rects-
2867 QModelIndex base = d->index(item);-
2868 const int firstVisiblesection = header()->logicalIndexAt(- header()->offset());-
2869 const int lastVisibleSection = header()->logicalIndexAt(header()->length() - header()->offset() - 1);-
2870 QModelIndex first = base.sibling(base.row(), header()->logicalIndex(firstVisiblesection));-
2871 QModelIndex last = base.sibling(base.row(), header()->logicalIndex(lastVisibleSection));-
2872 return visualRect(first) | visualRect(last);
never executed: return visualRect(first) | visualRect(last);
0
2873}-
2874-
2875/*!-
2876 \since 4.1-
2877-
2878 Returns the column used to sort the contents of the widget.-
2879-
2880 \sa sortItems()-
2881*/-
2882int QTreeWidget::sortColumn() const-
2883{-
2884 Q_D(const QTreeWidget);-
2885 return (d->explicitSortColumn != -1
never executed: return (d->explicitSortColumn != -1 ? d->explicitSortColumn : header()->sortIndicatorSection());
0
2886 ? d->explicitSortColumn
never executed: return (d->explicitSortColumn != -1 ? d->explicitSortColumn : header()->sortIndicatorSection());
0
2887 : header()->sortIndicatorSection());
never executed: return (d->explicitSortColumn != -1 ? d->explicitSortColumn : header()->sortIndicatorSection());
0
2888}-
2889-
2890/*!-
2891 Sorts the items in the widget in the specified \a order by the values in-
2892 the given \a column.-
2893-
2894 \sa sortColumn()-
2895*/-
2896-
2897void QTreeWidget::sortItems(int column, Qt::SortOrder order)-
2898{-
2899 Q_D(QTreeWidget);-
2900 header()->setSortIndicator(column, order);-
2901 d->model->sort(column, order);-
2902}
never executed: end of block
0
2903-
2904/*!-
2905 Starts editing the \a item in the given \a column if it is editable.-
2906*/-
2907-
2908void QTreeWidget::editItem(QTreeWidgetItem *item, int column)-
2909{-
2910 Q_D(QTreeWidget);-
2911 edit(d->index(item, column));-
2912}
never executed: end of block
0
2913-
2914/*!-
2915 Opens a persistent editor for the \a item in the given \a column.-
2916-
2917 \sa closePersistentEditor()-
2918*/-
2919-
2920void QTreeWidget::openPersistentEditor(QTreeWidgetItem *item, int column)-
2921{-
2922 Q_D(QTreeWidget);-
2923 QAbstractItemView::openPersistentEditor(d->index(item, column));-
2924}
never executed: end of block
0
2925-
2926/*!-
2927 Closes the persistent editor for the \a item in the given \a column.-
2928-
2929 This function has no effect if no persistent editor is open for this-
2930 combination of item and column.-
2931-
2932 \sa openPersistentEditor()-
2933*/-
2934-
2935void QTreeWidget::closePersistentEditor(QTreeWidgetItem *item, int column)-
2936{-
2937 Q_D(QTreeWidget);-
2938 QAbstractItemView::closePersistentEditor(d->index(item, column));-
2939}
never executed: end of block
0
2940-
2941/*!-
2942 \since 4.1-
2943-
2944 Returns the widget displayed in the cell specified by \a item and the given \a column.-
2945-
2946*/-
2947QWidget *QTreeWidget::itemWidget(QTreeWidgetItem *item, int column) const-
2948{-
2949 Q_D(const QTreeWidget);-
2950 return QAbstractItemView::indexWidget(d->index(item, column));
never executed: return QAbstractItemView::indexWidget(d->index(item, column));
0
2951}-
2952-
2953/*!-
2954 \since 4.1-
2955-
2956 Sets the given \a widget to be displayed in the cell specified by the given-
2957 \a item and \a column.-
2958-
2959 The given \a widget's \l {QWidget::}{autoFillBackground} property must be-
2960 set to true, otherwise the widget's background will be transparent, showing-
2961 both the model data and the tree widget item.-
2962-
2963 This function should only be used to display static content in the place of-
2964 a tree widget item. If you want to display custom dynamic content or-
2965 implement a custom editor widget, use QTreeView and subclass QItemDelegate-
2966 instead.-
2967-
2968 This function cannot be called before the item hierarchy has been set up,-
2969 i.e., the QTreeWidgetItem that will hold \a widget must have been added to-
2970 the view before \a widget is set.-
2971-
2972 \note The tree takes ownership of the widget.-
2973-
2974 \sa {Delegate Classes}-
2975*/-
2976void QTreeWidget::setItemWidget(QTreeWidgetItem *item, int column, QWidget *widget)-
2977{-
2978 Q_D(QTreeWidget);-
2979 QAbstractItemView::setIndexWidget(d->index(item, column), widget);-
2980}
never executed: end of block
0
2981-
2982/*!-
2983 Returns \c true if the \a item is selected; otherwise returns \c false.-
2984-
2985 \sa itemSelectionChanged()-
2986-
2987 \obsolete-
2988-
2989 This function is deprecated. Use \l{QTreeWidgetItem::isSelected()} instead.-
2990*/-
2991bool QTreeWidget::isItemSelected(const QTreeWidgetItem *item) const-
2992{-
2993 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
2994 return false;
never executed: return false;
0
2995 return item->d->selected;
never executed: return item->d->selected;
0
2996}-
2997-
2998/*!-
2999 If \a select is true, the given \a item is selected; otherwise it is-
3000 deselected.-
3001-
3002 \sa itemSelectionChanged()-
3003-
3004 \obsolete-
3005-
3006 This function is deprecated. Use \l{QTreeWidgetItem::setSelected()} instead.-
3007*/-
3008void QTreeWidget::setItemSelected(const QTreeWidgetItem *item, bool select)-
3009{-
3010 Q_D(QTreeWidget);-
3011-
3012 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3013 return;
never executed: return;
0
3014-
3015 selectionModel()->select(d->index(item), (select ? QItemSelectionModel::Select-
3016 : QItemSelectionModel::Deselect)-
3017 |QItemSelectionModel::Rows);-
3018 item->d->selected = select;-
3019}
never executed: end of block
0
3020-
3021/*!-
3022 Returns a list of all selected non-hidden items.-
3023-
3024 \sa itemSelectionChanged()-
3025*/-
3026QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const-
3027{-
3028 Q_D(const QTreeWidget);-
3029 const QModelIndexList indexes = selectionModel()->selectedIndexes();-
3030 QList<QTreeWidgetItem*> items;-
3031 items.reserve(indexes.count());-
3032 QSet<QTreeWidgetItem *> seen;-
3033 seen.reserve(indexes.count());-
3034 for (const auto &index : indexes) {-
3035 QTreeWidgetItem *item = d->item(index);-
3036 if (isItemHidden(item) || seen.contains(item))
isItemHidden(item)Description
TRUEnever evaluated
FALSEnever evaluated
seen.contains(item)Description
TRUEnever evaluated
FALSEnever evaluated
0
3037 continue;
never executed: continue;
0
3038 seen.insert(item);-
3039 items.append(item);-
3040 }
never executed: end of block
0
3041 return items;
never executed: return items;
0
3042}-
3043-
3044/*!-
3045 Returns a list of items that match the given \a text, using the given \a flags, in the given \a column.-
3046*/-
3047QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFlags flags, int column) const-
3048{-
3049 Q_D(const QTreeWidget);-
3050 QModelIndexList indexes = d->model->match(model()->index(0, column, QModelIndex()),-
3051 Qt::DisplayRole, text, -1, flags);-
3052 QList<QTreeWidgetItem*> items;-
3053 const int indexesSize = indexes.size();-
3054 items.reserve(indexesSize);-
3055 for (int i = 0; i < indexesSize; ++i)
i < indexesSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
3056 items.append(d->item(indexes.at(i)));
never executed: items.append(d->item(indexes.at(i)));
0
3057 return items;
never executed: return items;
0
3058}-
3059-
3060/*!-
3061 Returns \c true if the \a item is explicitly hidden, otherwise returns \c false.-
3062-
3063 \obsolete-
3064-
3065 This function is deprecated. Use \l{QTreeWidgetItem::isHidden()} instead.-
3066*/-
3067bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const-
3068{-
3069 Q_D(const QTreeWidget);-
3070 if (item == d->treeModel()->headerItem)
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3071 return header()->isHidden();
never executed: return header()->isHidden();
0
3072 if (d->hiddenIndexes.isEmpty())
d->hiddenIndexes.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3073 return false;
never executed: return false;
0
3074 QTreeModel::SkipSorting skipSorting(d->treeModel());-
3075 return d->isRowHidden(d->index(item));
never executed: return d->isRowHidden(d->index(item));
0
3076}-
3077-
3078/*!-
3079 Hides the given \a item if \a hide is true; otherwise shows the item.-
3080-
3081 \sa itemChanged()-
3082-
3083 \obsolete-
3084-
3085 This function is deprecated. Use \l{QTreeWidgetItem::setHidden()} instead.-
3086*/-
3087void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide)-
3088{-
3089 Q_D(QTreeWidget);-
3090 if (item == d->treeModel()->headerItem) {
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3091 header()->setHidden(hide);-
3092 } else {
never executed: end of block
0
3093 const QModelIndex index = d->index(item);-
3094 setRowHidden(index.row(), index.parent(), hide);-
3095 }
never executed: end of block
0
3096}-
3097-
3098/*!-
3099 Returns \c true if the given \a item is open; otherwise returns \c false.-
3100-
3101 \sa itemExpanded()-
3102-
3103 \obsolete-
3104-
3105 This function is deprecated. Use \l{QTreeWidgetItem::isExpanded()} instead.-
3106*/-
3107bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const-
3108{-
3109 Q_D(const QTreeWidget);-
3110 QTreeModel::SkipSorting skipSorting(d->treeModel());-
3111 return isExpanded(d->index(item));
never executed: return isExpanded(d->index(item));
0
3112}-
3113-
3114/*!-
3115 Sets the item referred to by \a item to either closed or opened,-
3116 depending on the value of \a expand.-
3117-
3118 \sa expandItem(), collapseItem(), itemExpanded()-
3119-
3120 \obsolete-
3121-
3122 This function is deprecated. Use \l{QTreeWidgetItem::setExpanded()} instead.-
3123*/-
3124void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)-
3125{-
3126 Q_D(QTreeWidget);-
3127 QTreeModel::SkipSorting skipSorting(d->treeModel());-
3128 setExpanded(d->index(item), expand);-
3129}
never executed: end of block
0
3130-
3131/*!-
3132 \since 4.3-
3133-
3134 Returns \c true if the given \a item is set to show only one section over all columns;-
3135 otherwise returns \c false.-
3136-
3137 \sa setFirstItemColumnSpanned()-
3138*/-
3139bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const-
3140{-
3141 Q_D(const QTreeWidget);-
3142 if (item == d->treeModel()->headerItem)
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3143 return false; // We can't set the header items to spanning
never executed: return false;
0
3144 const QModelIndex index = d->index(item);-
3145 return isFirstColumnSpanned(index.row(), index.parent());
never executed: return isFirstColumnSpanned(index.row(), index.parent());
0
3146}-
3147-
3148/*!-
3149 \since 4.3-
3150-
3151 Sets the given \a item to only show one section for all columns if \a span is true;-
3152 otherwise the item will show one section per column.-
3153-
3154 \sa isFirstItemColumnSpanned()-
3155*/-
3156void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span)-
3157{-
3158 Q_D(QTreeWidget);-
3159 if (item == d->treeModel()->headerItem)
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3160 return; // We can't set header items to spanning
never executed: return;
0
3161 const QModelIndex index = d->index(item);-
3162 setFirstColumnSpanned(index.row(), index.parent(), span);-
3163}
never executed: end of block
0
3164-
3165/*!-
3166 \since 4.3-
3167-
3168 Returns the item above the given \a item.-
3169*/-
3170QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const-
3171{-
3172 Q_D(const QTreeWidget);-
3173 if (item == d->treeModel()->headerItem)
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3174 return 0;
never executed: return 0;
0
3175 const QModelIndex index = d->index(item);-
3176 const QModelIndex above = indexAbove(index);-
3177 return d->item(above);
never executed: return d->item(above);
0
3178}-
3179-
3180/*!-
3181 \since 4.3-
3182-
3183 Returns the item visually below the given \a item.-
3184*/-
3185QTreeWidgetItem *QTreeWidget::itemBelow(const QTreeWidgetItem *item) const-
3186{-
3187 Q_D(const QTreeWidget);-
3188 if (item == d->treeModel()->headerItem)
item == d->tre...()->headerItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
3189 return 0;
never executed: return 0;
0
3190 const QModelIndex index = d->index(item);-
3191 const QModelIndex below = indexBelow(index);-
3192 return d->item(below);
never executed: return d->item(below);
0
3193}-
3194-
3195/*!-
3196 \reimp-
3197 */-
3198void QTreeWidget::setSelectionModel(QItemSelectionModel *selectionModel)-
3199{-
3200 Q_D(QTreeWidget);-
3201 QTreeView::setSelectionModel(selectionModel);-
3202 QItemSelection newSelection = selectionModel->selection();-
3203 if (!newSelection.isEmpty())
!newSelection.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3204 d->_q_selectionChanged(newSelection, QItemSelection());
never executed: d->_q_selectionChanged(newSelection, QItemSelection());
0
3205}
never executed: end of block
0
3206-
3207/*!-
3208 Ensures that the \a item is visible, scrolling the view if necessary using-
3209 the specified \a hint.-
3210-
3211 \sa currentItem(), itemAt(), topLevelItem()-
3212*/-
3213void QTreeWidget::scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint)-
3214{-
3215 Q_D(QTreeWidget);-
3216 QTreeView::scrollTo(d->index(item), hint);-
3217}
never executed: end of block
0
3218-
3219/*!-
3220 Expands the \a item. This causes the tree containing the item's children-
3221 to be expanded.-
3222-
3223 \sa collapseItem(), currentItem(), itemAt(), topLevelItem(), itemExpanded()-
3224*/-
3225void QTreeWidget::expandItem(const QTreeWidgetItem *item)-
3226{-
3227 Q_D(QTreeWidget);-
3228 QTreeModel::SkipSorting skipSorting(d->treeModel());-
3229 expand(d->index(item));-
3230}
never executed: end of block
0
3231-
3232/*!-
3233 Closes the \a item. This causes the tree containing the item's children-
3234 to be collapsed.-
3235-
3236 \sa expandItem(), currentItem(), itemAt(), topLevelItem()-
3237*/-
3238void QTreeWidget::collapseItem(const QTreeWidgetItem *item)-
3239{-
3240 Q_D(QTreeWidget);-
3241 QTreeModel::SkipSorting skipSorting(d->treeModel());-
3242 collapse(d->index(item));-
3243}
never executed: end of block
0
3244-
3245/*!-
3246 Clears the tree widget by removing all of its items and selections.-
3247-
3248 \b{Note:} Since each item is removed from the tree widget before being-
3249 deleted, the return value of QTreeWidgetItem::treeWidget() will be invalid-
3250 when called from an item's destructor.-
3251-
3252 \sa takeTopLevelItem(), topLevelItemCount(), columnCount()-
3253*/-
3254void QTreeWidget::clear()-
3255{-
3256 Q_D(QTreeWidget);-
3257 selectionModel()->clear();-
3258 d->treeModel()->clear();-
3259}
never executed: end of block
0
3260-
3261/*!-
3262 Returns a list of MIME types that can be used to describe a list of-
3263 treewidget items.-
3264-
3265 \sa mimeData()-
3266*/-
3267QStringList QTreeWidget::mimeTypes() const-
3268{-
3269 return model()->QAbstractItemModel::mimeTypes();
never executed: return model()->QAbstractItemModel::mimeTypes();
0
3270}-
3271-
3272/*!-
3273 Returns an object that contains a serialized description of the specified-
3274 \a items. The format used to describe the items is obtained from the-
3275 mimeTypes() function.-
3276-
3277 If the list of items is empty, 0 is returned rather than a serialized-
3278 empty list.-
3279*/-
3280#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)-
3281QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem *> &items) const-
3282#else-
3283QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const-
3284#endif-
3285{-
3286 Q_D(const QTreeWidget);-
3287 if (d->treeModel()->cachedIndexes.isEmpty()) {
d->treeModel()...exes.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3288 QList<QModelIndex> indexes;-
3289 for (const auto *item : items) {-
3290 if (Q_UNLIKELY(!item)) {
__builtin_expe...!item), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
3291 qWarning("QTreeWidget::mimeData: Null-item passed");-
3292 return 0;
never executed: return 0;
0
3293 }-
3294-
3295 for (int c = 0; c < item->values.count(); ++c) {
c < item->values.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3296 const QModelIndex index = indexFromItem(item, c);-
3297 if (Q_UNLIKELY(!index.isValid())) {
__builtin_expe...lid()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
3298 qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item;-
3299 return 0;
never executed: return 0;
0
3300 }-
3301 indexes << index;-
3302 }
never executed: end of block
0
3303 }
never executed: end of block
0
3304 return d->model->QAbstractItemModel::mimeData(indexes);
never executed: return d->model->QAbstractItemModel::mimeData(indexes);
0
3305 }-
3306 return d->treeModel()->internalMimeData();
never executed: return d->treeModel()->internalMimeData();
0
3307}-
3308-
3309/*!-
3310 Handles the \a data supplied by a drag and drop operation that ended with-
3311 the given \a action in the \a index in the given \a parent item.-
3312-
3313 The default implementation returns \c true if the drop was-
3314 successfully handled by decoding the mime data and inserting it-
3315 into the model; otherwise it returns \c false.-
3316-
3317 \sa supportedDropActions()-
3318*/-
3319bool QTreeWidget::dropMimeData(QTreeWidgetItem *parent, int index,-
3320 const QMimeData *data, Qt::DropAction action)-
3321{-
3322 QModelIndex idx;-
3323 if (parent) idx = indexFromItem(parent);
never executed: idx = indexFromItem(parent);
parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
3324 return model()->QAbstractItemModel::dropMimeData(data, action , index, 0, idx);
never executed: return model()->QAbstractItemModel::dropMimeData(data, action , index, 0, idx);
0
3325}-
3326-
3327/*!-
3328 Returns the drop actions supported by this view.-
3329-
3330 \sa Qt::DropActions-
3331*/-
3332Qt::DropActions QTreeWidget::supportedDropActions() const-
3333{-
3334 return model()->QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
never executed: return model()->QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
0
3335}-
3336-
3337/*!-
3338 \obsolete-
3339 Returns an empty list-
3340-
3341 \sa mimeData()-
3342*/-
3343QList<QTreeWidgetItem*> QTreeWidget::items(const QMimeData *data) const-
3344{-
3345 Q_UNUSED(data);-
3346 return QList<QTreeWidgetItem*>();
never executed: return QList<QTreeWidgetItem*>();
0
3347}-
3348-
3349/*!-
3350 Returns the QModelIndex associated with the given \a item in the given \a column.-
3351-
3352 \note In Qt versions prior to 5.7, this function took a non-\c{const} \a item.-
3353-
3354 \sa itemFromIndex(), topLevelItem()-
3355*/-
3356QModelIndex QTreeWidget::indexFromItem(const QTreeWidgetItem *item, int column) const-
3357{-
3358 Q_D(const QTreeWidget);-
3359 return d->index(item, column);
never executed: return d->index(item, column);
0
3360}-
3361-
3362/*!-
3363 \overload-
3364 \internal-
3365*/-
3366QModelIndex QTreeWidget::indexFromItem(QTreeWidgetItem *item, int column) const-
3367{-
3368 return indexFromItem(const_cast<const QTreeWidgetItem *>(item), column);
never executed: return indexFromItem(const_cast<const QTreeWidgetItem *>(item), column);
0
3369}-
3370-
3371/*!-
3372 Returns a pointer to the QTreeWidgetItem associated with the given \a index.-
3373-
3374 \sa indexFromItem()-
3375*/-
3376QTreeWidgetItem *QTreeWidget::itemFromIndex(const QModelIndex &index) const-
3377{-
3378 Q_D(const QTreeWidget);-
3379 return d->item(index);
never executed: return d->item(index);
0
3380}-
3381-
3382#ifndef QT_NO_DRAGANDDROP-
3383/*! \reimp */-
3384void QTreeWidget::dropEvent(QDropEvent *event) {-
3385 Q_D(QTreeWidget);-
3386 if (event->source() == this && (event->dropAction() == Qt::MoveAction ||
event->source() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
event->dropAct...Qt::MoveActionDescription
TRUEnever evaluated
FALSEnever evaluated
0
3387 dragDropMode() == QAbstractItemView::InternalMove)) {
dragDropMode()...::InternalMoveDescription
TRUEnever evaluated
FALSEnever evaluated
0
3388 QModelIndex topIndex;-
3389 int col = -1;-
3390 int row = -1;-
3391 if (d->dropOn(event, &row, &col, &topIndex)) {
d->dropOn(even...ol, &topIndex)Description
TRUEnever evaluated
FALSEnever evaluated
0
3392 const QList<QModelIndex> idxs = selectedIndexes();-
3393 QList<QPersistentModelIndex> indexes;-
3394 const int indexesCount = idxs.count();-
3395 indexes.reserve(indexesCount);-
3396 for (const auto &idx : idxs)-
3397 indexes.append(idx);
never executed: indexes.append(idx);
0
3398-
3399 if (indexes.contains(topIndex))
indexes.contains(topIndex)Description
TRUEnever evaluated
FALSEnever evaluated
0
3400 return;
never executed: return;
0
3401-
3402 // When removing items the drop location could shift-
3403 QPersistentModelIndex dropRow = model()->index(row, col, topIndex);-
3404-
3405 // Remove the items-
3406 QList<QTreeWidgetItem *> taken;-
3407 for (const auto &index : indexes) {-
3408 QTreeWidgetItem *parent = itemFromIndex(index);-
3409 if (!parent || !parent->parent()) {
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
!parent->parent()Description
TRUEnever evaluated
FALSEnever evaluated
0
3410 taken.append(takeTopLevelItem(index.row()));-
3411 } else {
never executed: end of block
0
3412 taken.append(parent->parent()->takeChild(index.row()));-
3413 }
never executed: end of block
0
3414 }-
3415-
3416 // insert them back in at their new positions-
3417 for (int i = 0; i < indexes.count(); ++i) {
i < indexes.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
3418 // Either at a specific point or appended-
3419 if (row == -1) {
row == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
3420 if (topIndex.isValid()) {
topIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
3421 QTreeWidgetItem *parent = itemFromIndex(topIndex);-
3422 parent->insertChild(parent->childCount(), taken.takeFirst());-
3423 } else {
never executed: end of block
0
3424 insertTopLevelItem(topLevelItemCount(), taken.takeFirst());-
3425 }
never executed: end of block
0
3426 } else {-
3427 int r = dropRow.row() >= 0 ? dropRow.row() : row;
dropRow.row() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
3428 if (topIndex.isValid()) {
topIndex.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
3429 QTreeWidgetItem *parent = itemFromIndex(topIndex);-
3430 parent->insertChild(qMin(r, parent->childCount()), taken.takeFirst());-
3431 } else {
never executed: end of block
0
3432 insertTopLevelItem(qMin(r, topLevelItemCount()), taken.takeFirst());-
3433 }
never executed: end of block
0
3434 }-
3435 }-
3436-
3437 event->accept();-
3438 // Don't want QAbstractItemView to delete it because it was "moved" we already did it-
3439 event->setDropAction(Qt::CopyAction);-
3440 }
never executed: end of block
0
3441 }
never executed: end of block
0
3442-
3443 QTreeView::dropEvent(event);-
3444}
never executed: end of block
0
3445#endif-
3446-
3447/*!-
3448 \reimp-
3449*/-
3450-
3451void QTreeWidget::setModel(QAbstractItemModel * /*model*/)-
3452{-
3453 Q_ASSERT(!"QTreeWidget::setModel() - Changing the model of the QTreeWidget is not allowed.");-
3454}
never executed: end of block
0
3455-
3456/*!-
3457 \reimp-
3458*/-
3459bool QTreeWidget::event(QEvent *e)-
3460{-
3461 Q_D(QTreeWidget);-
3462 if (e->type() == QEvent::Polish)
e->type() == QEvent::PolishDescription
TRUEnever evaluated
FALSEnever evaluated
0
3463 d->treeModel()->executePendingSort();
never executed: d->treeModel()->executePendingSort();
0
3464 return QTreeView::event(e);
never executed: return QTreeView::event(e);
0
3465}-
3466-
3467QT_END_NAMESPACE-
3468-
3469#include "moc_qtreewidget.cpp"-
3470#include "moc_qtreewidget_p.cpp"-
3471-
3472#endif // QT_NO_TREEWIDGET-
Source codeSwitch to Preprocessed file

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