#include <qtreeview.h>
Inheritance diagram for QTreeView:


A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by the QListView class, but using the more flexible approach provided by Qt's model/view architecture.
The QTreeView class is one of the {Model/View Classes} and is part of Qt's {Model/View Programming}{model/view framework}.
QTreeView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.
It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QDirModel and displayed as a tree:
snippets/shareddirmodel/main.cpp QDirModel *model QTreeView *tree tree->setModel( tree->setModel(
The model/view architecture ensures that the contents of the tree view are updated as the model changes.
Items that have children can be in an expanded (children are visible) or collapsed (children are hidden) state. When this state changes a collapsed() or expanded() signal is emitted with the model index of the relevant item.
The amount of indentation used to indicate levels of hierarchy is controlled by the indentation property.
Headers in tree views are constructed using the QHeaderView class and can be hidden using header()->hide(). Note that each header is configured with its {QHeaderView::}{stretchLastSection} property set to true, ensuring that the view does not waste any of the space assigned to it for its header.
QTreeView supports a set of key bindings that enable the user to navigate in the view and interact with the contents of items: \table \header \o Key \o Action \row \o UpArrow \o Moves the cursor to the item in the same column on the previous row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the last row of the sibling that precedes the parent. \row \o DownArrow \o Moves the cursor to the item in the same column on the next row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the first row of the sibling that follows the parent. \row \o LeftArrow \o Hides the children of the current item (if present) by collapsing a branch. \row \o Minus \o Same as LeftArrow. \row \o RightArrow \o Reveals the children of the current item (if present) by expanding a branch. \row \o Plus \o Same as RightArrow. \row \o Asterisk \o Expands all children of the current item (if present). \row \o PageUp \o Moves the cursor up one page. \row \o PageDown \o Moves the cursor down one page. \row \o Home \o Moves the cursor to an item in the same column of the first row of the first top-level item in the model. \row \o End \o Moves the cursor to an item in the same column of the last row of the last top-level item in the model. \row \o F2 \o In editable models, this opens the current item for editing. The Escape key can be used to cancel the editing process and revert any changes to the data displayed. \endtable \omit Describe the expanding/collapsing concept if not covered elsewhere. \endomit \table 100% \row \o \inlineimage windowsxp-treeview.png Screenshot of a Windows XP style tree view \o \inlineimage macintosh-treeview.png Screenshot of a Macintosh style tree view \o \inlineimage plastique-treeview.png Screenshot of a Plastique style tree view \row \o A \l{Windows XP Style Widget Gallery}{Windows XP style} tree view. \o A \l{Macintosh Style Widget Gallery}{Macintosh style} tree view. \o A \l{Plastique Style Widget Gallery}{Plastique style} tree view. \endtable \sa QListView, QTreeWidget, {View Classes}, QAbstractItemModel, QAbstractItemView, {Dir View Example} Definition at line 38 of file qtreeview.h.
Public Slots | |
| void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight) |
| void | hideColumn (int column) |
| void | showColumn (int column) |
| void | expand (const QModelIndex &index) |
| void | collapse (const QModelIndex &index) |
| void | resizeColumnToContents (int column) |
| void | sortByColumn (int column) |
| void | selectAll () |
| void | expandAll () |
| void | collapseAll () |
Signals | |
| void | expanded (const QModelIndex &index) |
| void | collapsed (const QModelIndex &index) |
Public Member Functions | |
| QTreeView (QWidget *parent=0) | |
| ~QTreeView () | |
| void | setModel (QAbstractItemModel *model) |
| void | setRootIndex (const QModelIndex &index) |
| void | setSelectionModel (QItemSelectionModel *selectionModel) |
| QHeaderView * | header () const |
| void | setHeader (QHeaderView *header) |
| int | indentation () const |
| void | setIndentation (int i) |
| bool | rootIsDecorated () const |
| void | setRootIsDecorated (bool show) |
| bool | uniformRowHeights () const |
| void | setUniformRowHeights (bool uniform) |
| bool | itemsExpandable () const |
| void | setItemsExpandable (bool enable) |
| int | columnViewportPosition (int column) const |
| int | columnWidth (int column) const |
| void | setColumnWidth (int column, int width) |
| int | columnAt (int x) const |
| bool | isColumnHidden (int column) const |
| void | setColumnHidden (int column, bool hide) |
| bool | isRowHidden (int row, const QModelIndex &parent) const |
| void | setRowHidden (int row, const QModelIndex &parent, bool hide) |
| bool | isExpanded (const QModelIndex &index) const |
| void | setExpanded (const QModelIndex &index, bool expand) |
| void | setSortingEnabled (bool enable) |
| bool | isSortingEnabled () const |
| void | setAnimated (bool enable) |
| bool | isAnimated () const |
| void | setAllColumnsShowFocus (bool enable) |
| bool | allColumnsShowFocus () const |
| void | keyboardSearch (const QString &search) |
| QRect | visualRect (const QModelIndex &index) const |
| void | scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) |
| QModelIndex | indexAt (const QPoint &p) const |
| QModelIndex | indexAbove (const QModelIndex &index) const |
| QModelIndex | indexBelow (const QModelIndex &index) const |
| void | doItemsLayout () |
| void | reset () |
| void | sortByColumn (int column, Qt::SortOrder order) |
Protected Slots | |
| void | columnResized (int column, int oldSize, int newSize) |
| void | columnCountChanged (int oldCount, int newCount) |
| void | columnMoved () |
| void | reexpand () |
| void | rowsRemoved (const QModelIndex &parent, int first, int last) |
Protected Member Functions | |
| QTreeView (QTreeViewPrivate &dd, QWidget *parent=0) | |
| void | scrollContentsBy (int dx, int dy) |
| void | rowsInserted (const QModelIndex &parent, int start, int end) |
| void | rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) |
| QModelIndex | moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers) |
| int | horizontalOffset () const |
| int | verticalOffset () const |
| void | setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command) |
| QRegion | visualRegionForSelection (const QItemSelection &selection) const |
| QModelIndexList | selectedIndexes () const |
| void | timerEvent (QTimerEvent *event) |
| void | paintEvent (QPaintEvent *event) |
| void | drawTree (QPainter *painter, const QRegion ®ion) const |
| virtual void | drawRow (QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const |
| virtual void | drawBranches (QPainter *painter, const QRect &rect, const QModelIndex &index) const |
| void | mousePressEvent (QMouseEvent *event) |
| void | mouseReleaseEvent (QMouseEvent *event) |
| void | mouseDoubleClickEvent (QMouseEvent *event) |
| void | mouseMoveEvent (QMouseEvent *event) |
| void | keyPressEvent (QKeyEvent *event) |
| void | updateGeometries () |
| int | sizeHintForColumn (int column) const |
| int | indexRowSizeHint (const QModelIndex &index) const |
| void | horizontalScrollbarAction (int action) |
| bool | isIndexHidden (const QModelIndex &index) const |
Private Member Functions | |
| Q_PRIVATE_SLOT (d_func(), void _q_endAnimatedOperation()) Q_PRIVATE_SLOT(d_func() | |
| QTreeView::QTreeView | ( | QWidget * | parent = 0 |
) | [explicit] |
Constructs a table view with a parent to represent a model's data. Use setModel() to set the model.
Definition at line 156 of file qtreeview.cpp.
References d.
00157 : QAbstractItemView(*new QTreeViewPrivate, parent) 00158 { 00159 Q_D(QTreeView); 00160 d->initialize(); 00161 }
| QTreeView::~QTreeView | ( | ) |
| QTreeView::QTreeView | ( | QTreeViewPrivate & | dd, | |
| QWidget * | parent = 0 | |||
| ) | [protected] |
Definition at line 166 of file qtreeview.cpp.
References d.
00167 : QAbstractItemView(dd, parent) 00168 { 00169 Q_D(QTreeView); 00170 d->initialize(); 00171 }
| void QTreeView::setModel | ( | QAbstractItemModel * | model | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 183 of file qtreeview.cpp.
References QAbstractItemView::_q_rowsRemoved(), QObject::connect(), d, QObject::disconnect(), doItemsLayout(), header(), QAbstractItemView::model(), rowsRemoved(), QAbstractItemView::setModel(), SIGNAL, SLOT, and sortByColumn().
Referenced by qdesigner_internal::ResourceEditor::addView(), Main::Main(), main(), MessageEditor::MessageEditor(), QTreeWidget::QTreeWidget(), QDBusViewer::serviceChanged(), qdesigner_internal::SignalSlotEditorWindow::setActiveFormWindow(), MessagesTreeView::setModel(), Window::setSourceModel(), and QFileDialogPrivate::setupTreeView().
00184 { 00185 Q_D(QTreeView); 00186 if (d->selectionModel) { // support row editing 00187 disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), 00188 d->model, SLOT(submit())); 00189 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 00190 this, SLOT(rowsRemoved(QModelIndex,int,int))); 00191 } 00192 d->viewItems.clear(); 00193 d->expandedIndexes.clear(); 00194 d->hiddenIndexes.clear(); 00195 d->header->setModel(model); 00196 QAbstractItemView::setModel(model); 00197 00198 // QAbstractItemView connects to a private slot 00199 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 00200 this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); 00201 // do header layout after the tree 00202 disconnect(d->model, SIGNAL(layoutChanged()), 00203 d->header, SLOT(doItemsLayout())); 00204 // QTreeView has a public slot for this 00205 connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 00206 this, SLOT(rowsRemoved(QModelIndex,int,int))); 00207 00208 if (d->sortingEnabled) 00209 sortByColumn(header()->sortIndicatorSection()); 00210 }
Here is the call graph for this function:

| void QTreeView::setRootIndex | ( | const QModelIndex & | index | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 215 of file qtreeview.cpp.
References d, index, and QAbstractItemView::setRootIndex().
Referenced by qdesigner_internal::QPropertyEditor::setInitialInput(), QFileDialogPrivate::setRootIndex(), and QFileDialogPrivate::setupTreeView().
00216 { 00217 Q_D(QTreeView); 00218 d->header->setRootIndex(index); 00219 QAbstractItemView::setRootIndex(index); 00220 }
| void QTreeView::setSelectionModel | ( | QItemSelectionModel * | selectionModel | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 225 of file qtreeview.cpp.
References QObject::connect(), QAbstractItemView::currentChanged(), d, QObject::disconnect(), QAbstractItemView::selectionModel(), QAbstractItemView::setSelectionModel(), SIGNAL, and SLOT.
Referenced by main(), and QFileDialogPrivate::setupTreeView().
00226 { 00227 Q_D(QTreeView); 00228 Q_ASSERT(selectionModel); 00229 if (d->selectionModel) { 00230 if (d->allColumnsShowFocus) { 00231 QObject::disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), 00232 this, SLOT(_q_currentChanged(QModelIndex,QModelIndex))); 00233 } 00234 // support row editing 00235 disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), 00236 d->model, SLOT(submit())); 00237 } 00238 00239 d->header->setSelectionModel(selectionModel); 00240 QAbstractItemView::setSelectionModel(selectionModel); 00241 00242 if (d->selectionModel) { 00243 if (d->allColumnsShowFocus) { 00244 QObject::connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), 00245 this, SLOT(_q_currentChanged(QModelIndex,QModelIndex))); 00246 } 00247 // support row editing 00248 connect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), 00249 d->model, SLOT(submit())); 00250 } 00251 }
Here is the call graph for this function:

| QHeaderView * QTreeView::header | ( | ) | const |
Returns the header for the tree view.
Definition at line 258 of file qtreeview.cpp.
References d.
Referenced by ConnectionWidget::ConnectionWidget(), drawRow(), QTreeModel::executePendingSort(), QTreeWidgetItem::insertChild(), QTreeWidget::isItemHidden(), main(), MessageEditor::MessageEditor(), MessagesTreeView::MessagesTreeView(), qdesigner_internal::ObjectInspector::ObjectInspector(), PluginDialog::PluginDialog(), QFileDialogTreeView::QFileDialogTreeView(), qdesigner_internal::QrcView::QrcView(), QTreeWidget::QTreeWidget(), resizeColumnToContents(), TrWindow::revertSorting(), setHeader(), QTreeWidget::setItemHidden(), setModel(), MessagesTreeView::setModel(), setSortingEnabled(), SettingsTree::SettingsTree(), QFileDialogPrivate::setupTreeView(), MainWindow::sizeHint(), QTreeWidget::sortColumn(), QTreeWidget::sortItems(), TrWindow::TrWindow(), MainWindow::updateModel(), qdesigner_internal::WidgetBoxTreeView::WidgetBoxTreeView(), and XbelTree::XbelTree().
| void QTreeView::setHeader | ( | QHeaderView * | header | ) |
Sets the header for the tree view, to the given header.
The view takes ownership over the given header and deletes it when a new header is set.
Definition at line 272 of file qtreeview.cpp.
References columnCountChanged(), columnMoved(), columnResized(), QObject::connect(), d, header(), resizeColumnToContents(), setSortingEnabled(), SIGNAL, SLOT, and updateGeometries().
00273 { 00274 Q_D(QTreeView); 00275 if (header == d->header || !header) 00276 return; 00277 if (d->header && d->header->parent() == this) 00278 delete d->header; 00279 d->header = header; 00280 d->header->setParent(this); 00281 00282 if (!d->header->model()) 00283 d->header->setModel(d->model); 00284 00285 connect(d->header, SIGNAL(sectionResized(int,int,int)), 00286 this, SLOT(columnResized(int,int,int))); 00287 connect(d->header, SIGNAL(sectionMoved(int,int,int)), 00288 this, SLOT(columnMoved())); 00289 connect(d->header, SIGNAL(sectionCountChanged(int,int)), 00290 this, SLOT(columnCountChanged(int,int))); 00291 connect(d->header, SIGNAL(sectionHandleDoubleClicked(int)), 00292 this, SLOT(resizeColumnToContents(int))); 00293 connect(d->header, SIGNAL(geometriesChanged()), 00294 this, SLOT(updateGeometries())); 00295 d->header->setFocusProxy(this); 00296 00297 setSortingEnabled(d->sortingEnabled); 00298 }
Here is the call graph for this function:

| int QTreeView::indentation | ( | ) | const |
Definition at line 309 of file qtreeview.cpp.
References d.
Referenced by qdesigner_internal::TreeWidget::drawBranches(), and qdesigner_internal::QPropertyEditor::drawBranches().
| void QTreeView::setIndentation | ( | int | i | ) |
| bool QTreeView::rootIsDecorated | ( | ) | const |
| void QTreeView::setRootIsDecorated | ( | bool | show | ) |
Definition at line 341 of file qtreeview.cpp.
References d.
Referenced by FindFileDialog::createFilesTree(), Main::Main(), MessageEditor::MessageEditor(), MessagesTreeView::MessagesTreeView(), QDBusViewer::QDBusViewer(), qdesigner_internal::QPropertyEditor::setInitialInput(), QFileDialogPrivate::setupTreeView(), qdesigner_internal::SignalSlotEditorWindow::SignalSlotEditorWindow(), MainWindow::updateModel(), and qdesigner_internal::WidgetBoxTreeView::WidgetBoxTreeView().
00342 { 00343 Q_D(QTreeView); 00344 if (show != d->rootDecoration) { 00345 d->rootDecoration = show; 00346 d->viewport->update(); 00347 } 00348 }
| bool QTreeView::uniformRowHeights | ( | ) | const |
| void QTreeView::setUniformRowHeights | ( | bool | uniform | ) |
Definition at line 364 of file qtreeview.cpp.
References d.
Referenced by main(), and MessagesTreeView::MessagesTreeView().
| bool QTreeView::itemsExpandable | ( | ) | const |
| void QTreeView::setItemsExpandable | ( | bool | enable | ) |
Definition at line 384 of file qtreeview.cpp.
References d.
Referenced by MessageEditor::MessageEditor(), MessagesTreeView::MessagesTreeView(), and QFileDialogPrivate::setupTreeView().
| int QTreeView::columnViewportPosition | ( | int | column | ) | const |
Returns the horizontal position of the column in the viewport.
Definition at line 393 of file qtreeview.cpp.
References d.
Referenced by drawRow(), scrollTo(), timerEvent(), visualRect(), and visualRegionForSelection().
00394 { 00395 Q_D(const QTreeView); 00396 return d->header->sectionViewportPosition(column); 00397 }
| int QTreeView::columnWidth | ( | int | column | ) | const |
Returns the width of the column.
Definition at line 404 of file qtreeview.cpp.
References d.
Referenced by scrollTo(), timerEvent(), visualRect(), and visualRegionForSelection().
| void QTreeView::setColumnWidth | ( | int | column, | |
| int | width | |||
| ) |
Definition at line 417 of file qtreeview.cpp.
References d.
| int QTreeView::columnAt | ( | int | x | ) | const |
| bool QTreeView::isColumnHidden | ( | int | column | ) | const |
Returns true if the column is hidden; otherwise returns false.
Definition at line 438 of file qtreeview.cpp.
References d.
Referenced by isIndexHidden().
| void QTreeView::setColumnHidden | ( | int | column, | |
| bool | hide | |||
| ) |
If hide is true the column is hidden, otherwise the column is shown.
Definition at line 449 of file qtreeview.cpp.
References d.
00450 { 00451 Q_D(QTreeView); 00452 if (column < 0 || column >= d->header->count()) 00453 return; 00454 d->header->setSectionHidden(column, hide); 00455 }
| bool QTreeView::isRowHidden | ( | int | row, | |
| const QModelIndex & | parent | |||
| ) | const |
Returns true if the item in the given row of the parent is hidden; otherwise returns false.
Definition at line 463 of file qtreeview.cpp.
References d, i, index, and QObject::parent().
Referenced by isIndexHidden(), and QTreeWidget::isItemHidden().
00464 { 00465 Q_D(const QTreeView); 00466 if (d->hiddenIndexes.isEmpty() || !d->model) 00467 return false; 00468 QModelIndex index = d->model->index(row, 0, parent); 00469 for (int i = 0; i < d->hiddenIndexes.count(); ++i) 00470 if (d->hiddenIndexes.at(i) == index) 00471 return true; 00472 return false; 00473 }
Here is the call graph for this function:

| void QTreeView::setRowHidden | ( | int | row, | |
| const QModelIndex & | parent, | |||
| bool | hide | |||
| ) |
If hide is true the row with the given parent is hidden, otherwise the row is shown.
Definition at line 480 of file qtreeview.cpp.
References d, i, index, int, QWidget::isVisible(), level, p, QObject::parent(), and updateGeometries().
Referenced by QTreeWidget::setItemHidden().
00481 { 00482 Q_D(QTreeView); 00483 if (!d->model) 00484 return; 00485 QModelIndex index = d->model->index(row, 0, parent); 00486 if (!index.isValid()) 00487 return; 00488 00489 if (hide) { 00490 QPersistentModelIndex persistent(index); 00491 if (!d->hiddenIndexes.contains(persistent)) d->hiddenIndexes.append(persistent); 00492 } else { 00493 QPersistentModelIndex persistent(index); 00494 int i = d->hiddenIndexes.indexOf(persistent); 00495 if (i >= 0) d->hiddenIndexes.remove(i); 00496 } 00497 00498 if (hide && isVisible()) { 00499 int p = d->viewIndex(parent); 00500 if (p >= 0) { 00501 const int first = p + 1; 00502 const int last = first + d->viewItems.at(p).total - 1; 00503 for (int i = first; i <= last; ) { 00504 const int count = d->viewItems.at(i).total + 1; 00505 if (d->viewItems.at(i).index == index) { 00506 // remove child and its children 00507 d->viewItems.remove(i, count); 00508 // update children count of ancestors 00509 int level = d->viewItems.at(p).level; 00510 do { 00511 for ( ; int(d->viewItems.at(p).level) != level; --p) ; 00512 d->viewItems[p].total -= count; 00513 --level; 00514 } while (level >= 0); 00515 break; 00516 } else { 00517 i += count; 00518 } 00519 } 00520 updateGeometries(); 00521 d->viewport->update(); 00522 } 00523 else 00524 d->doDelayedItemsLayout(); 00525 } else { 00526 d->doDelayedItemsLayout(); 00527 } 00528 }
Here is the call graph for this function:

| bool QTreeView::isExpanded | ( | const QModelIndex & | index | ) | const |
Returns true if the model item index is expanded; otherwise returns false.
Definition at line 655 of file qtreeview.cpp.
Referenced by qdesigner_internal::TreeWidget::drawBranches(), qdesigner_internal::QPropertyEditor::drawBranches(), QTreeWidget::isItemExpanded(), qdesigner_internal::SheetDelegate::paint(), rowsAboutToBeRemoved(), and scrollTo().
00656 { 00657 Q_D(const QTreeView); 00658 int i = d->viewIndex(index); 00659 if (i != -1) // is visible 00660 return d->viewItems.at(i).expanded; 00661 return d->expandedIndexes.contains(index); 00662 }
| void QTreeView::setExpanded | ( | const QModelIndex & | index, | |
| bool | expanded | |||
| ) |
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded.
Definition at line 670 of file qtreeview.cpp.
References collapse(), expand(), and index.
Referenced by qdesigner_internal::ResourceEditor::addFiles(), Main::collapseView(), Main::completelyExpandIndex(), qdesigner_internal::ResourceEditor::deleteItem(), qdesigner_internal::QrcView::dropEvent(), QTreeWidget::setItemExpanded(), and Main::showInfo().
00671 { 00672 if (expanded) 00673 this->expand(index); 00674 else 00675 this->collapse(index); 00676 }
| void QTreeView::setSortingEnabled | ( | bool | enable | ) |
Definition at line 689 of file qtreeview.cpp.
References QObject::connect(), d, QObject::disconnect(), header(), QHeaderView::setClickable(), QHeaderView::setSortIndicatorShown(), SIGNAL, SLOT, and sortByColumn().
Referenced by MessagesTreeView::MessagesTreeView(), setHeader(), and QTreeWidget::setSortingEnabled().
00690 { 00691 Q_D(QTreeView); 00692 d->sortingEnabled = enable; 00693 header()->setSortIndicatorShown(enable); 00694 header()->setClickable(enable); 00695 if (enable) { 00696 connect(header(), SIGNAL(sectionClicked(int)), this, SLOT(sortByColumn(int))); 00697 sortByColumn(header()->sortIndicatorSection()); 00698 } else { 00699 disconnect(header(), SIGNAL(sectionClicked(int)), this, SLOT(sortByColumn(int))); 00700 } 00701 }
Here is the call graph for this function:

| bool QTreeView::isSortingEnabled | ( | ) | const |
Definition at line 703 of file qtreeview.cpp.
References d.
Referenced by QTreeWidget::isSortingEnabled().
| void QTreeView::setAnimated | ( | bool | enable | ) |
| bool QTreeView::isAnimated | ( | ) | const |
| void QTreeView::setAllColumnsShowFocus | ( | bool | enable | ) |
Definition at line 743 of file qtreeview.cpp.
References QObject::connect(), QAbstractItemView::currentChanged(), d, QObject::disconnect(), SIGNAL, and SLOT.
00744 { 00745 Q_D(QTreeView); 00746 if (d->allColumnsShowFocus == enable) 00747 return; 00748 if (d->selectionModel) { 00749 if (enable) { 00750 QObject::connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), 00751 this, SLOT(_q_currentChanged(QModelIndex,QModelIndex))); 00752 } else { 00753 QObject::disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), 00754 this, SLOT(_q_currentChanged(QModelIndex,QModelIndex))); 00755 } 00756 } 00757 d->allColumnsShowFocus = enable; 00758 d->viewport->update(); 00759 }
Here is the call graph for this function:

| bool QTreeView::allColumnsShowFocus | ( | ) | const |
| void QTreeView::keyboardSearch | ( | const QString & | search | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 770 of file qtreeview.cpp.
References c, QItemSelectionModel::ClearAndSelect, QAbstractItemView::currentIndex(), QTime::currentTime(), d, Qt::DisplayRole, flags, i, index, indexBelow(), QString::isEmpty(), QApplication::keyboardInputInterval(), match(), QItemSelectionModel::NoUpdate, now(), qMin(), QAbstractItemView::selectionModel(), QItemSelectionModel::setCurrentIndex(), QAbstractItemView::SingleSelection, and start.
00771 { 00772 Q_D(QTreeView); 00773 if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root)) 00774 return; 00775 00776 QModelIndex start; 00777 if (currentIndex().isValid()) 00778 start = currentIndex(); 00779 else 00780 start = d->model->index(0, 0, d->root); 00781 00782 QTime now(QTime::currentTime()); 00783 bool skipRow = false; 00784 if (search.isEmpty() 00785 || (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { 00786 d->keyboardInput = search; 00787 skipRow = true; 00788 } else { 00789 d->keyboardInput += search; 00790 } 00791 d->keyboardInputTime = now; 00792 00793 // special case for searches with same key like 'aaaaa' 00794 bool sameKey = false; 00795 if (d->keyboardInput.length() > 1) { 00796 int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); 00797 sameKey = (c == d->keyboardInput.length()); 00798 if (sameKey) 00799 skipRow = true; 00800 } 00801 00802 // skip if we are searching for the same key or a new search started 00803 if (skipRow) { 00804 if (indexBelow(start).isValid()) 00805 start = indexBelow(start); 00806 else 00807 start = d->model->index(0, start.column(), d->root); 00808 } 00809 00810 int startIndex = d->viewIndex(start); 00811 if (startIndex <= -1) 00812 return; 00813 00814 int previousLevel = -1; 00815 int bestAbove = -1; 00816 int bestBelow = -1; 00817 QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput; 00818 for (int i = 0; i < d->viewItems.count(); ++i) { 00819 if ((int)d->viewItems.at(i).level > previousLevel) { 00820 QModelIndex searchFrom = d->viewItems.at(i).index; 00821 if (searchFrom.parent() == start.parent()) 00822 searchFrom = start; 00823 QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString); 00824 if (match.count()) { 00825 int hitIndex = d->viewIndex(match.at(0)); 00826 if (hitIndex >= 0 && hitIndex < startIndex) 00827 bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove); 00828 else if (hitIndex >= startIndex) 00829 bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow); 00830 } 00831 } 00832 previousLevel = d->viewItems.at(i).level; 00833 } 00834 00835 QModelIndex index; 00836 if (bestBelow > -1) 00837 index = d->viewItems.at(bestBelow).index; 00838 else if (bestAbove > -1) 00839 index = d->viewItems.at(bestAbove).index; 00840 00841 if (index.isValid()) { 00842 QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection 00843 ? QItemSelectionModel::SelectionFlags( 00844 QItemSelectionModel::ClearAndSelect 00845 |d->selectionBehaviorFlags()) 00846 : QItemSelectionModel::SelectionFlags( 00847 QItemSelectionModel::NoUpdate)); 00848 selectionModel()->setCurrentIndex(index, flags); 00849 } 00850 }
Here is the call graph for this function:

| QRect QTreeView::visualRect | ( | const QModelIndex & | index | ) | const [virtual] |
Returns the rectangle on the viewport occupied by the item at index. If the index is not visible or explicitly hidden, the returned rectangle is invalid.
Implements QAbstractItemView.
Definition at line 856 of file qtreeview.cpp.
References columnViewportPosition(), columnWidth(), d, h, i, index, isIndexHidden(), w, QWidget::x(), and QWidget::y().
Referenced by QTreeWidget::visualItemRect(), and visualRegionForSelection().
00857 { 00858 Q_D(const QTreeView); 00859 00860 if (!d->isIndexValid(index) || isIndexHidden(index)) 00861 return QRect(); 00862 00863 d->executePostedLayout(); 00864 00865 int vi = d->viewIndex(index); 00866 if (vi < 0) 00867 return QRect(); 00868 00869 int x = columnViewportPosition(index.column()); 00870 int w = columnWidth(index.column()); 00871 00872 if (index.column() == 0) { 00873 int i = d->indentationForItem(vi); 00874 x += i; 00875 w -= i; 00876 } 00877 int y = d->coordinateForItem(vi); 00878 int h = d->itemHeight(vi); 00879 return QRect(x, y, w, h); 00880 }
Here is the call graph for this function:

| void QTreeView::scrollTo | ( | const QModelIndex & | index, | |
| ScrollHint | hint = EnsureVisible | |||
| ) | [virtual] |
Scroll the contents of the tree view until the given model item index is visible. The hint parameter specifies more precisely where the item should be located after the operation. If any of the parents of the model item are collapsed, they will be expanded to ensure that the model item is visible.
Implements QAbstractItemView.
Definition at line 890 of file qtreeview.cpp.
References area(), QRect::bottom(), columnViewportPosition(), columnWidth(), d, QAbstractItemView::EnsureVisible, expand(), QRect::height(), horizontalOffset(), QAbstractScrollArea::horizontalScrollBar(), index, QRect::isEmpty(), isExpanded(), QAbstractItemView::NoState, QObject::parent(), QAbstractItemView::PositionAtBottom, QAbstractItemView::PositionAtCenter, QAbstractItemView::PositionAtTop, QWidget::rect(), QAbstractItemView::ScrollPerItem, QAbstractSlider::setValue(), QAbstractItemView::state(), QRect::top(), QAbstractSlider::value(), QAbstractScrollArea::verticalScrollBar(), QAbstractItemView::verticalScrollMode(), and QWidget::y().
Referenced by QTreeWidget::scrollToItem(), TrWindow::setCurrentContext(), TrWindow::setCurrentContextRow(), TrWindow::setCurrentMessage(), and Main::showInfo().
00891 { 00892 Q_D(QTreeView); 00893 00894 if (!d->isIndexValid(index)) 00895 return; 00896 00897 d->executePostedLayout(); 00898 d->updateScrollBars(); 00899 00900 // Expand all parents if the parent(s) of the node are not expanded. 00901 QModelIndex parent = index.parent(); 00902 while (parent.isValid() && state() == NoState && d->itemsExpandable) { 00903 if (!isExpanded(parent)) 00904 expand(parent); 00905 parent = d->model->parent(parent); 00906 } 00907 00908 int item = d->viewIndex(index); 00909 if (item < 0) 00910 return; 00911 QRect rect(columnViewportPosition(index.column()), 00912 d->coordinateForItem(item), 00913 columnWidth(index.column()), 00914 d->itemHeight(item)); 00915 00916 if (rect.isEmpty()) 00917 return; 00918 00919 // check if we really need to do anything 00920 QRect area = d->viewport->rect(); 00921 if (hint == EnsureVisible && area.contains(rect)) { 00922 d->setDirtyRegion(rect); 00923 return; 00924 } 00925 00926 // vertical 00927 bool above = (hint == EnsureVisible && (rect.top() < area.top() || area.height() < rect.height())); 00928 bool below = (hint == EnsureVisible && rect.bottom() > area.bottom() && rect.height() < area.height()); 00929 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { 00930 if (hint == PositionAtTop || above) { 00931 verticalScrollBar()->setValue(item); 00932 } else if (hint == PositionAtCenter || hint == PositionAtBottom || below) { 00933 int y = area.height(); 00934 if (hint == PositionAtCenter) 00935 y = y / 2; 00936 while (y > 0 && item > 0) 00937 y -= d->itemHeight(item--); 00938 item += 1 + ((y < 0) ? 1 : 0); 00939 verticalScrollBar()->setValue(item); 00940 } 00941 } else { // ScrollPerPixel 00942 int verticalValue = verticalScrollBar()->value(); 00943 if (hint == PositionAtTop || above) 00944 verticalValue += rect.top(); 00945 else if (hint == PositionAtBottom || below) 00946 verticalValue += rect.bottom() - area.height(); 00947 else if (hint == PositionAtCenter) 00948 verticalValue += rect.top() - ((area.height() - rect.height()) / 2); 00949 verticalScrollBar()->setValue(verticalValue); 00950 } 00951 00952 // horizontal 00953 int viewportWidth = d->viewport->width(); 00954 int horizontalOffset = d->header->offset(); 00955 int horizontalPosition = d->header->sectionPosition(index.column()); 00956 int cellWidth = d->header->sectionSize(index.column()); 00957 00958 if (hint == PositionAtCenter) { 00959 horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2)); 00960 } else { 00961 if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth) 00962 horizontalScrollBar()->setValue(horizontalPosition); 00963 else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth) 00964 horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth); 00965 } 00966 }
Here is the call graph for this function:

| QModelIndex QTreeView::indexAt | ( | const QPoint & | point | ) | const [virtual] |
Implements QAbstractItemView.
Definition at line 1476 of file qtreeview.cpp.
References d, QModelIndex::isValid(), QModelIndex::row(), QPoint::x(), and QPoint::y().
Referenced by qdesigner_internal::QrcView::dragMoveEvent(), qdesigner_internal::QrcView::dropEvent(), QTreeWidget::itemAt(), setSelection(), and QDBusViewer::showContextMenu().
01477 { 01478 Q_D(const QTreeView); 01479 d->executePostedLayout(); 01480 01481 int visualIndex = d->itemAtCoordinate(point.y()); 01482 QModelIndex idx = d->modelIndex(visualIndex); 01483 int column = d->columnAt(point.x()); 01484 if (idx.isValid() && column >= 0) 01485 return d->model->sibling(idx.row(), column, idx); 01486 return idx; 01487 }
Here is the call graph for this function:

| QModelIndex QTreeView::indexAbove | ( | const QModelIndex & | index | ) | const |
Returns the model index of the item above index.
Definition at line 1492 of file qtreeview.cpp.
01493 { 01494 Q_D(const QTreeView); 01495 if (!d->isIndexValid(index)) 01496 return QModelIndex(); 01497 d->executePostedLayout(); 01498 int i = d->viewIndex(index); 01499 if (--i < 0) 01500 return QModelIndex(); 01501 return d->viewItems.at(i).index; 01502 }
| QModelIndex QTreeView::indexBelow | ( | const QModelIndex & | index | ) | const |
Returns the model index of the item below index.
Definition at line 1507 of file qtreeview.cpp.
Referenced by keyboardSearch().
01508 { 01509 Q_D(const QTreeView); 01510 if (!d->isIndexValid(index)) 01511 return QModelIndex(); 01512 d->executePostedLayout(); 01513 int i = d->viewIndex(index); 01514 if (++i >= d->viewItems.count()) 01515 return QModelIndex(); 01516 return d->viewItems.at(i).index; 01517 }
| void QTreeView::doItemsLayout | ( | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1524 of file qtreeview.cpp.
References d, QAbstractItemView::doItemsLayout(), index, indexRowSizeHint(), and QObject::parent().
Referenced by QFileDialogPrivate::_q_showDetails(), collapseAll(), ConnectionWidget::refresh(), and setModel().
01525 { 01526 Q_D(QTreeView); 01527 d->viewItems.clear(); // prepare for new layout 01528 QModelIndex parent = d->root; 01529 if (d->model->hasChildren(parent)) { 01530 QModelIndex index = d->model->index(0, 0, parent); 01531 d->defaultItemHeight = indexRowSizeHint(index); 01532 d->layout(-1); 01533 d->reexpandChildren(parent); 01534 } 01535 QAbstractItemView::doItemsLayout(); 01536 d->header->doItemsLayout(); 01537 }
Here is the call graph for this function:

| void QTreeView::reset | ( | ) | [virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1542 of file qtreeview.cpp.
References d, and QAbstractItemView::reset().
Referenced by Main::clear().
01543 { 01544 Q_D(QTreeView); 01545 d->expandedIndexes.clear(); 01546 d->hiddenIndexes.clear(); 01547 d->viewItems.clear(); 01548 QAbstractItemView::reset(); 01549 }
| void QTreeView::sortByColumn | ( | int | column, | |
| Qt::SortOrder | order | |||
| ) |
Definition at line 1968 of file qtreeview.cpp.
References d.
Referenced by QFileDialogPrivate::_q_sortByColumn(), QFileDialogTreeView::QFileDialogTreeView(), setModel(), and setSortingEnabled().
01969 { 01970 Q_D(QTreeView); 01971 d->header->setSortIndicator(column, order); 01972 sortByColumn(column); 01973 }
| void QTreeView::expanded | ( | const QModelIndex & | index | ) | [signal] |
This signal is emitted when the item specified by index is expanded.
Referenced by drawBranches(), expand(), QTreeWidget::QTreeWidget(), rowsAboutToBeRemoved(), and rowsRemoved().
| void QTreeView::collapsed | ( | const QModelIndex & | index | ) | [signal] |
This signal is emitted when the item specified by index is collapsed.
Referenced by collapse(), and QTreeWidget::QTreeWidget().
| void QTreeView::dataChanged | ( | const QModelIndex & | topLeft, | |
| const QModelIndex & | bottomRight | |||
| ) | [virtual, slot] |
Reimplemented from QAbstractItemView.
Definition at line 533 of file qtreeview.cpp.
References QModelIndex::column(), d, QAbstractItemView::dataChanged(), i, and QModelIndex::row().
Referenced by QTreeWidget::QTreeWidget().
00534 { 00535 Q_D(QTreeView); 00536 00537 // if we are going to do a complete realyout anyway, there is no need to update 00538 if (d->delayedLayout.isActive()) 00539 return; 00540 00541 // refresh the height cache here; we don't really lose anything by getting the size hint, 00542 // since QAbstractItemView::dataChanged() will get the visualRect for the items anyway 00543 00544 QModelIndex top = (topLeft.column() == 0) ? topLeft 00545 : d->model->sibling(topLeft.row(), 0, topLeft); 00546 int topViewIndex = d->viewIndex(top); 00547 bool sizeChanged = false; 00548 if (topViewIndex != -1) { 00549 if (topLeft == bottomRight) { 00550 int oldHeight = d->itemHeight(topViewIndex); 00551 d->invalidateHeightCache(topViewIndex); 00552 sizeChanged = (oldHeight != d->itemHeight(topViewIndex)); 00553 } else { 00554 QModelIndex bottom = (bottomRight.column() == 0) ? bottomRight 00555 : d->model->sibling(bottomRight.row(), 0, bottomRight); 00556 int bottomViewIndex = d->viewIndex(bottom); 00557 for (int i = topViewIndex; i <= bottomViewIndex; ++i) { 00558 int oldHeight = d->itemHeight(i); 00559 d->invalidateHeightCache(i); 00560 sizeChanged |= (oldHeight != d->itemHeight(i)); 00561 } 00562 } 00563 } 00564 00565 if (sizeChanged) { 00566 d->updateScrollBars(); 00567 d->viewport->update(); 00568 } 00569 QAbstractItemView::dataChanged(topLeft, bottomRight); 00570 }
| void QTreeView::hideColumn | ( | int | column | ) | [slot] |
Hides the column given.
Definition at line 577 of file qtreeview.cpp.
References d.
| void QTreeView::showColumn | ( | int | column | ) | [slot] |
Shows the given column in the tree view.
Definition at line 588 of file qtreeview.cpp.
References d.
| void QTreeView::expand | ( | const QModelIndex & | index | ) | [slot] |
Expands the model item specified by the index.
Definition at line 601 of file qtreeview.cpp.
References d, emit, expanded(), i, index, and updateGeometries().
Referenced by QTreeWidget::expandItem(), keyPressEvent(), scrollTo(), and setExpanded().
00602 { 00603 Q_D(QTreeView); 00604 if (!d->isIndexValid(index)) 00605 return; 00606 int i = d->viewIndex(index); 00607 if (i != -1) { // is visible 00608 d->expand(i, true); 00609 if (!d->isAnimating()) { 00610 updateGeometries(); 00611 d->viewport->update(); 00612 } 00613 } else if (!d->expandedIndexes.contains(index)) { 00614 d->expandedIndexes.append(index); 00615 emit expanded(index); 00616 } 00617 }
| void QTreeView::collapse | ( | const QModelIndex & | index | ) | [slot] |
Collapses the model item specified by the index.
Definition at line 626 of file qtreeview.cpp.
References collapsed(), d, emit, i, index, QWidget::update(), updateGeometries(), and QAbstractScrollArea::viewport().
Referenced by QTreeWidget::collapseItem(), keyPressEvent(), and setExpanded().
00627 { 00628 Q_D(QTreeView); 00629 if (!d->isIndexValid(index)) 00630 return; 00631 int i = d->viewIndex(index); 00632 if (i != -1) { // is visible 00633 d->collapse(i, true); 00634 if (!d->isAnimating()) { 00635 updateGeometries(); 00636 viewport()->update(); 00637 } 00638 } else { 00639 int i = d->expandedIndexes.indexOf(index); 00640 if (i != -1) { 00641 d->expandedIndexes.remove(i); 00642 emit collapsed(index); 00643 } 00644 } 00645 }
| void QTreeView::resizeColumnToContents | ( | int | column | ) | [slot] |
Resizes the column given to the size of its contents.
Definition at line 1936 of file qtreeview.cpp.
References d, header(), qMax(), and sizeHintForColumn().
Referenced by Main::loadFeatures(), setHeader(), qdesigner_internal::QPropertyEditor::setInitialInput(), and qdesigner_internal::ObjectInspector::showEvent().
01937 { 01938 Q_D(QTreeView); 01939 d->executePostedLayout(); 01940 if (column < 0 || column >= d->header->count()) 01941 return; 01942 int contents = sizeHintForColumn(column); 01943 int header = d->header->isHidden() ? 0 : d->header->sectionSizeHint(column); 01944 d->header->resizeSection(column, qMax(contents, header)); 01945 }
| void QTreeView::sortByColumn | ( | int | column | ) | [slot] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sorts the model by the values in the given column.
Definition at line 1953 of file qtreeview.cpp.
References d.
01954 { 01955 Q_D(QTreeView); 01956 if (column == -1) 01957 return; 01958 d->model->sort(column, d->header->sortIndicatorOrder()); 01959 }
| void QTreeView::selectAll | ( | ) | [virtual, slot] |
Selects all the items in the underlying model.
Reimplemented from QAbstractItemView.
Definition at line 1978 of file qtreeview.cpp.
References QItemSelectionModel::ClearAndSelect, d, QItemSelectionModel::Rows, and QAbstractItemView::selectionModel().
01979 { 01980 Q_D(QTreeView); 01981 if (!selectionModel()) 01982 return; 01983 d->select(0, d->viewItems.count() - 1, 01984 QItemSelectionModel::ClearAndSelect 01985 |QItemSelectionModel::Rows); 01986 }
| void QTreeView::expandAll | ( | ) | [slot] |
Definition at line 1994 of file qtreeview.cpp.
References d, i, and updateGeometries().
01995 { 01996 Q_D(QTreeView); 01997 d->executePostedLayout(); 01998 d->expandedIndexes.clear(); 01999 for (int i = 0; i < d->viewItems.count(); ++i) 02000 if (!d->viewItems.at(i).expanded) 02001 d->expand(i, false); 02002 updateGeometries(); 02003 d->viewport->update(); 02004 }
| void QTreeView::collapseAll | ( | ) | [slot] |
Definition at line 2013 of file qtreeview.cpp.
References d, and doItemsLayout().
02014 { 02015 Q_D(QTreeView); 02016 d->expandedIndexes.clear(); 02017 doItemsLayout(); 02018 }
| void QTreeView::columnResized | ( | int | column, | |
| int | oldSize, | |||
| int | newSize | |||
| ) | [protected, slot] |
This function is called whenever {column}'s size is changed in the header. oldSize and newSize give the previous size and the new size in pixels.
Definition at line 2027 of file qtreeview.cpp.
References d, and QObject::startTimer().
Referenced by setHeader().
02028 { 02029 Q_D(QTreeView); 02030 d->columnsToUpdate.append(column); 02031 if (d->columnResizeTimerID == 0) 02032 d->columnResizeTimerID = startTimer(0); 02033 }
| void QTreeView::columnCountChanged | ( | int | oldCount, | |
| int | newCount | |||
| ) | [protected, slot] |
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount.
Definition at line 1924 of file qtreeview.cpp.
References QWidget::isVisible(), QWidget::update(), updateGeometries(), and QAbstractScrollArea::viewport().
Referenced by setHeader().
01925 { 01926 if (isVisible()) 01927 updateGeometries(); 01928 viewport()->update(); 01929 }
| void QTreeView::columnMoved | ( | ) | [protected, slot] |
This slot is called whenever a column has been moved.
Definition at line 1823 of file qtreeview.cpp.
References QAbstractItemView::dataChanged().
Referenced by setHeader().
01824 { 01825 QAbstractItemView::dataChanged(QModelIndex(), QModelIndex()); 01826 }
| void QTreeView::reexpand | ( | ) | [protected, slot] |
| void QTreeView::rowsRemoved | ( | const QModelIndex & | parent, | |
| int | start, | |||
| int | end | |||
| ) | [protected, slot] |
Definition at line 1887 of file qtreeview.cpp.
References d, expanded(), QAbstractItemView::NoState, p, QObject::parent(), and QAbstractItemView::setState().
Referenced by setModel().
01888 { 01889 Q_UNUSED(start); 01890 Q_UNUSED(end); 01891 Q_D(QTreeView); 01892 01893 if (d->viewItems.isEmpty()) { 01894 d->_q_rowsRemoved(parent, start, end); 01895 return; 01896 } 01897 if (parent == d->root) { 01898 d->viewItems.clear(); 01899 d->doDelayedItemsLayout(); 01900 d->_q_rowsRemoved(parent, start, end); 01901 return; 01902 } 01903 01904 bool expanded = d->expandParent.pop(); 01905 if (expanded) { 01906 int p = d->viewIndex(parent); 01907 if (p != -1) { // item is visible 01908 d->expand(p, false); 01909 d->viewport->update(); 01910 } else if (!d->expandedIndexes.contains(parent)) { 01911 d->expandedIndexes.append(parent); 01912 } 01913 } 01914 if (d->expandParent.isEmpty()) { 01915 setState(NoState); 01916 d->updateScrollBars(); 01917 } 01918 }
| void QTreeView::scrollContentsBy | ( | int | dx, | |
| int | dy | |||
| ) | [protected, virtual] |
Scrolls the contents of the tree view by (dx, dy).
Reimplemented from QAbstractScrollArea.
Definition at line 1758 of file qtreeview.cpp.
References c, QVector< T >::count(), d, QAbstractScrollArea::horizontalScrollBar(), QAbstractItemView::horizontalScrollMode(), i, QWidget::isRightToLeft(), l, qMin(), QWidget::repaint(), QAbstractItemView::ScrollPerItem, value, QAbstractSlider::value(), QAbstractScrollArea::verticalScrollBar(), and QAbstractItemView::verticalScrollMode().
01759 { 01760 Q_D(QTreeView); 01761 dx = isRightToLeft() ? -dx : dx; 01762 if (dx) { 01763 if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) { 01764 int currentScrollbarValue = horizontalScrollBar()->value(); 01765 int previousScrollbarValue = currentScrollbarValue + dx; // -(-dx) 01766 d->header->setOffsetToSectionPosition(currentScrollbarValue); 01767 dx = 0; 01768 if (previousScrollbarValue < currentScrollbarValue) { // scrolling right 01769 for (int c = previousScrollbarValue; c < currentScrollbarValue; ++c) { 01770 int l = d->header->logicalIndex(c); 01771 dx -= d->header->sectionSize(l); 01772 } 01773 } else if (previousScrollbarValue > currentScrollbarValue) { // scrolling left 01774 for (int c = previousScrollbarValue; c >= currentScrollbarValue; --c) { 01775 int l = d->header->logicalIndex(c); 01776 dx += d->header->sectionSize(l); 01777 } 01778 } 01779 } else { 01780 d->header->setOffset(horizontalScrollBar()->value()); 01781 } 01782 } 01783 01784 if (d->viewItems.isEmpty() || d->defaultItemHeight == 0) 01785 return; 01786 01787 // guestimate the number of items in the viewport 01788 int viewCount = d->viewport->height() / d->defaultItemHeight; 01789 int maxDeltaY = qMin(d->viewItems.count(), viewCount); 01790 // no need to do a lot of work if we are going to redraw the whole thing anyway 01791 if (qAbs(dy) > qAbs(maxDeltaY) && d->editors.isEmpty()) { 01792 verticalScrollBar()->repaint(); 01793 d->viewport->update(); 01794 return; 01795 } 01796 01797 if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) { 01798 int currentScrollbarValue = verticalScrollBar()->value(); 01799 int previousScrollbarValue = currentScrollbarValue + dy; // -(-dy) 01800 int currentViewIndex = currentScrollbarValue; // the first visible item 01801 int previousViewIndex = previousScrollbarValue; 01802 const QVector<QTreeViewItem> viewItems = d->viewItems; 01803 dy = 0; 01804 if (previousViewIndex < currentViewIndex) { // scrolling down 01805 for (int i = previousViewIndex; i < currentViewIndex; ++i) { 01806 if (i < d->viewItems.count()) 01807 dy -= d->itemHeight(i); 01808 } 01809 } else if (previousViewIndex > currentViewIndex) { // scrolling up 01810 for (int i = previousViewIndex - 1; i >= currentViewIndex; --i) { 01811 if (i < d->viewItems.count()) 01812 dy += d->itemHeight(i); 01813 } 01814 } 01815 } 01816 01817 d->scrollContentsBy(dx, dy); 01818 }
Here is the call graph for this function:

| void QTreeView::rowsInserted | ( | const QModelIndex & | parent, | |
| int | start, | |||
| int | end | |||
| ) | [protected, virtual] |
Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.
Reimplemented from QAbstractItemView.
Definition at line 1840 of file qtreeview.cpp.
References d, QObject::parent(), and QAbstractItemView::rowsInserted().
01841 { 01842 Q_D(QTreeView); 01843 d->doDelayedItemsLayout(); 01844 QAbstractItemView::rowsInserted(parent, start, end); 01845 }
Here is the call graph for this function:

| void QTreeView::rowsAboutToBeRemoved | ( | const QModelIndex & | parent, | |
| int | start, | |||
| int | end | |||
| ) | [protected, virtual] |
Informs the view that the rows from the start row to the end row inclusive are about to removed from the given parent model item.
Reimplemented from QAbstractItemView.
Definition at line 1851 of file qtreeview.cpp.
References QAbstractItemView::CollapsingState, d, expanded(), isExpanded(), p, QObject::parent(), QAbstractItemView::rowsAboutToBeRemoved(), and QAbstractItemView::setState().
01852 { 01853 Q_D(QTreeView); 01854 if (d->viewItems.isEmpty()) { 01855 QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); 01856 return; 01857 } 01858 01859 if (parent == d->root) { 01860 d->viewItems.clear(); 01861 d->doDelayedItemsLayout(); 01862 QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); 01863 return; 01864 } 01865 01866 d->executePostedLayout(); 01867 setState(CollapsingState); 01868 01869 // collapse the parent 01870 bool expanded = isExpanded(parent); 01871 d->expandParent.push(expanded); 01872 if (expanded) { 01873 int p = d->viewIndex(parent); 01874 if (p != -1) 01875 d->collapse(p, false); 01876 } 01877 01878 QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); 01879 }
Here is the call graph for this function:

| QModelIndex QTreeView::moveCursor | ( | CursorAction | cursorAction, | |
| Qt::KeyboardModifiers | modifiers | |||
| ) | [protected, virtual] |
Move the cursor in the way described by cursorAction, using the information provided by the button modifiers.
Implements QAbstractItemView.
Definition at line 1595 of file qtreeview.cpp.
References QAbstractItemView::currentIndex(), d, QAbstractScrollArea::horizontalScrollBar(), i, QModelIndex::isValid(), QAbstractSlider::minimum(), QAbstractItemView::MoveDown, QAbstractItemView::MoveEnd, QAbstractItemView::MoveHome, QAbstractItemView::MoveLeft, QAbstractItemView::MoveNext, QAbstractItemView::MovePageDown, QAbstractItemView::MovePageUp, QAbstractItemView::MovePrevious, QAbstractItemView::MoveRight, QAbstractItemView::MoveUp, qMax(), QAbstractSlider::setValue(), QAbstractSlider::singleStep(), QWidget::update(), updateGeometries(), QAbstractSlider::value(), and QAbstractScrollArea::viewport().
01596 { 01597 Q_D(QTreeView); 01598 Q_UNUSED(modifiers); 01599 01600 d->executePostedLayout(); 01601 01602 QModelIndex current = currentIndex(); 01603 if (!current.isValid()) { 01604 int i = 0; 01605 while (i < d->viewItems.count() && d->hiddenIndexes.contains(d->viewItems.at(i).index)) 01606 ++i; 01607 return d->viewItems.value(i).index; 01608 } 01609 int vi = qMax(0, d->viewIndex(current)); 01610 switch (cursorAction) { 01611 case MoveNext: 01612 case MoveDown: 01613 #ifdef QT_KEYPAD_NAVIGATION 01614 if (vi == d->viewItems.count()-1 && QApplication::keypadNavigationEnabled()) 01615 return d->model->index(0, 0, d->root); 01616 #endif 01617 return d->modelIndex(d->below(vi)); 01618 case MovePrevious: 01619 case MoveUp: 01620 #ifdef QT_KEYPAD_NAVIGATION 01621 if (vi == 0 && QApplication::keypadNavigationEnabled()) 01622 return d->modelIndex(d->viewItems.count() - 1); 01623 #endif 01624 return d->modelIndex(d->above(vi)); 01625 case MoveLeft: { 01626 QScrollBar *sb = horizontalScrollBar(); 01627 if (d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) 01628 d->collapse(vi, true); 01629 else 01630 sb->setValue(sb->value() - sb->singleStep()); 01631 updateGeometries(); 01632 viewport()->update(); 01633 break; 01634 } 01635 case MoveRight: 01636 if (!d->viewItems.at(vi).expanded && d->itemsExpandable) { 01637 d->expand(vi, true); 01638 } 01639 else { 01640 QScrollBar *sb = horizontalScrollBar(); 01641 sb->setValue(sb->value() + sb->singleStep()); 01642 } 01643 updateGeometries(); 01644 viewport()->update(); 01645 break; 01646 case MovePageUp: 01647 return d->modelIndex(d->pageUp(vi)); 01648 case MovePageDown: 01649 return d->modelIndex(d->pageDown(vi)); 01650 case MoveHome: 01651 return d->model->index(0, 0, d->root); 01652 case MoveEnd: 01653 return d->modelIndex(d->viewItems.count() - 1); 01654 } 01655 return current; 01656 }
Here is the call graph for this function:

| int QTreeView::horizontalOffset | ( | ) | const [protected, virtual] |
Returns the horizontal offset of the items in the treeview.
Note that the tree view uses the horizontal header section positions to determine the positions of columns in the view.
Implements QAbstractItemView.
Definition at line 1559 of file qtreeview.cpp.
References d.
Referenced by scrollTo().
| int QTreeView::verticalOffset | ( | ) | const [protected, virtual] |
Returns the vertical offset of the items in the tree view.
Implements QAbstractItemView.
Definition at line 1570 of file qtreeview.cpp.
References d, i, QAbstractItemView::ScrollPerItem, uniformRowHeights(), value, QAbstractSlider::value(), QAbstractScrollArea::verticalScrollBar(), and QAbstractItemView::verticalScrollMode().
Referenced by drawBranches().
01571 { 01572 Q_D(const QTreeView); 01573 if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { 01574 if (uniformRowHeights()) 01575 return verticalScrollBar()->value() * d->defaultItemHeight; 01576 // If we are scrolling per item and have non-uniform row heights, 01577 // finding the vertical offset in pixels is going to be relatively slow. 01578 // ### find a faster way to do this 01579 int offset = 0; 01580 for (int i = 0; i < d->viewItems.count(); ++i) { 01581 if (i == verticalScrollBar()->value()) 01582 return offset; 01583 offset += d->itemHeight(i); 01584 } 01585 return 0; 01586 } 01587 // scroll per pixel 01588 return verticalScrollBar()->value(); 01589 }
Here is the call graph for this function:

| void QTreeView::setSelection | ( | const QRect & | rect, | |
| QItemSelectionModel::SelectionFlags | command | |||
| ) | [protected, virtual] |
Applies the selection command to the items in or touched by the rectangle, rect.
Implements QAbstractItemView.
Definition at line 1664 of file qtreeview.cpp.
References QList< T >::append(), QRect::bottom(), d, indexAt(), QWidget::isRightToLeft(), QModelIndex::isValid(), QRect::left(), qMax(), qMin(), QWidget::rect(), QRect::right(), QItemSelectionModel::select(), QAbstractItemView::selectionBehavior(), QAbstractItemView::selectionModel(), QAbstractItemView::SelectRows, and QRect::top().
01665 { 01666 Q_D(QTreeView); 01667 if (!selectionModel()) 01668 return; 01669 01670 QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right()) 01671 : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom())); 01672 QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) : 01673 qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom())); 01674 QModelIndex topLeft = indexAt(tl); 01675 QModelIndex bottomRight = indexAt(br); 01676 if (selectionBehavior() != SelectRows) { 01677 QItemSelection selection; 01678 if (topLeft.isValid() && bottomRight.isValid()) { 01679 selection.append(QItemSelectionRange(topLeft, bottomRight)); 01680 selectionModel()->select(selection, command); 01681 } 01682 } else { 01683 d->select(d->viewIndex(topLeft), d->viewIndex(bottomRight), command); 01684 } 01685 }
Here is the call graph for this function:

| QRegion QTreeView::visualRegionForSelection | ( | const QItemSelection & | selection | ) | const [protected, virtual] |
Returns the rectangle from the viewport of the items in the given selection.
Implements QAbstractItemView.
Definition at line 1691 of file qtreeview.cpp.
References QList< T >::at(), QRect::bottom(), c, QModelIndex::column(), columnViewportPosition(), columnWidth(), QList< T >::count(), d, QWidget::height(), i, QList< T >::isEmpty(), isIndexHidden(), QModelIndex::isValid(), QObject::parent(), QModelIndex::row(), QRect::top(), and visualRect().
01692 { 01693 Q_D(const QTreeView); 01694 if (selection.isEmpty()) 01695 return QRegion(); 01696 01697 QRegion selectionRegion; 01698 for (int i = 0; i < selection.count(); ++i) { 01699 QItemSelectionRange range = selection.at(i); 01700 if (!range.isValid()) 01701 continue; 01702 QModelIndex parent = range.parent(); 01703 QModelIndex leftIndex = range.topLeft(); 01704 int columnCount = d->model->columnCount(parent); 01705 while (leftIndex.isValid() && isIndexHidden(leftIndex)) { 01706 if (leftIndex.column() + 1 < columnCount) 01707 leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent); 01708 else 01709 leftIndex = QModelIndex(); 01710 } 01711 if (!leftIndex.isValid()) 01712 continue; 01713 int top = visualRect(leftIndex).top(); 01714 QModelIndex rightIndex = range.bottomRight(); 01715 while (rightIndex.isValid() && isIndexHidden(rightIndex)) { 01716 if (rightIndex.column() - 1 >= 0) 01717 rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent); 01718 else 01719 rightIndex = QModelIndex(); 01720 } 01721 if (!rightIndex.isValid()) 01722 continue; 01723 int bottom = visualRect(rightIndex).bottom(); 01724 if (top > bottom) 01725 qSwap<int>(top, bottom); 01726 int height = bottom - top + 1; 01727 for (int c = range.left(); c <= range.right(); ++c) 01728 selectionRegion += QRegion(QRect(columnViewportPosition(c), top, 01729 columnWidth(c), height)); 01730 } 01731 return selectionRegion; 01732 }
Here is the call graph for this function:

| QModelIndexList QTreeView::selectedIndexes | ( | ) | const [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1737 of file qtreeview.cpp.
References QList< T >::append(), QList< T >::at(), QList< T >::count(), i, index, isIndexHidden(), QItemSelectionModel::selectedIndexes(), and QAbstractItemView::selectionModel().
Referenced by QTreeWidget::dropEvent().
01738 { 01739 QModelIndexList viewSelected; 01740 QModelIndexList modelSelected; 01741 if (selectionModel()) 01742 modelSelected = selectionModel()->selectedIndexes(); 01743 for (int i = 0; i < modelSelected.count(); ++i) { 01744 // check that neither the parents nor the index is hidden before we add 01745 QModelIndex index = modelSelected.at(i); 01746 while (index.isValid() && !isIndexHidden(index)) 01747 index = index.parent(); 01748 if (index.isValid()) 01749 continue; 01750 viewSelected.append(modelSelected.at(i)); 01751 } 01752 return viewSelected; 01753 }
Here is the call graph for this function:

| void QTreeView::timerEvent | ( | QTimerEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 971 of file qtreeview.cpp.
References columnViewportPosition(), columnWidth(), d, QAbstractItemView::event(), i, QWidget::isRightToLeft(), QObject::killTimer(), QRect::normalized(), QWidget::rect(), QAbstractItemView::timerEvent(), updateGeometries(), and QWidget::x().
00972 { 00973 Q_D(QTreeView); 00974 if (event->timerId() == d->columnResizeTimerID) { 00975 updateGeometries(); 00976 killTimer(d->columnResizeTimerID); 00977 d->columnResizeTimerID = 0; 00978 QRect rect; 00979 int viewportHeight = d->viewport->height(); 00980 int viewportWidth = d->viewport->width(); 00981 for (int i = d->columnsToUpdate.size() - 1; i >= 0; --i) { 00982 int column = d->columnsToUpdate.at(i); 00983 int x = columnViewportPosition(column); 00984 if (isRightToLeft()) 00985 rect |= QRect(0, 0, x + columnWidth(column), viewportHeight); 00986 else 00987 rect |= QRect(x, 0, viewportWidth - x, viewportHeight); 00988 } 00989 d->viewport->update(rect.normalized()); 00990 d->columnsToUpdate.clear(); 00991 } 00992 QAbstractItemView::timerEvent(event); 00993 }
Here is the call graph for this function:

| void QTreeView::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractScrollArea.
Definition at line 998 of file qtreeview.cpp.
References d, drawTree(), QAbstractItemView::event(), QWidget::layout(), and QAbstractScrollArea::viewport().
00999 { 01000 Q_D(QTreeView); 01001 bool layout = d->delayedLayout.isActive(); 01002 d->delayedLayout.stop(); 01003 QPainter painter(viewport()); 01004 if (d->isAnimating()) { 01005 drawTree(&painter, event->region() - d->animationRect()); 01006 d->drawAnimatedOperation(&painter); 01007 } else { 01008 drawTree(&painter, event->region()); 01009 #ifndef QT_NO_DRAGANDDROP 01010 d->paintDropIndicator(&painter); 01011 #endif 01012 } 01013 if (layout) 01014 d->doDelayedItemsLayout(); 01015 }
Here is the call graph for this function:

Definition at line 1024 of file qtreeview.cpp.
References a, area(), QVector< T >::at(), QPalette::Base, QRegion::boundingRect(), QPalette::brush(), QVector< T >::count(), d, QPainter::device(), drawRow(), QTreeViewItem::expanded, QPainter::fillRect(), i, QTreeViewItem::index, QWidget::isRightToLeft(), QWidget::palette(), QStyleOption::rect, QRegion::rects(), QRect::setRect(), QVector< T >::size(), QAbstractItemView::state(), QStyleOption::state, QStyle::State_None, QStyle::State_Open, QPaintDevice::width(), and QWidget::y().
Referenced by paintEvent().
01025 { 01026 Q_D(const QTreeView); 01027 const QVector<QTreeViewItem> viewItems = d->viewItems; 01028 01029 if (viewItems.count() == 0 || d->header->count() == 0 || !d->itemDelegate) { 01030 painter->fillRect(region.boundingRect(), palette().brush(QPalette::Base)); 01031 return; 01032 } 01033 01034 QStyleOptionViewItemV2 option = d->viewOptionsV2(); 01035 const QStyle::State state = option.state; 01036 const int deviceWidth = painter->device()->width(); 01037 const int headerLength = d->header->length(); 01038 01039 int firstVisibleItemOffset = 0; 01040 const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset); 01041 if (firstVisibleItem < 0) 01042 return; 01043 01044 QVector<QRect> rects = region.rects(); 01045 for (int a = 0; a < rects.size(); ++a) { 01046 01047 const QRect area = rects.at(a); 01048 d->leftAndRight = d->startAndEndColumns(area); 01049 01050 int i = firstVisibleItem; // the first item at the top of the viewport 01051 int y = firstVisibleItemOffset; // we may only see part of the first item 01052 01053 // start at the top of the viewport and iterate down to the update area 01054 for (; i < viewItems.count(); ++i) { 01055 const int itemHeight = d->itemHeight(i); 01056 if (y + itemHeight >= area.top()) 01057 break; 01058 y += itemHeight; 01059 } 01060 01061 // paint the visible rows 01062 for (; i < viewItems.count() && y <= area.bottom(); ++i) { 01063 const int itemHeight = d->itemHeight(i); 01064 option.rect.setRect(0, y, 0, itemHeight); 01065 option.state = state | (viewItems.at(i).expanded 01066 ? QStyle::State_Open : QStyle::State_None); 01067 d->current = i; 01068 drawRow(painter, option, viewItems.at(i).index); 01069 y += itemHeight; 01070 } 01071 01072 if (y <= area.bottom()) { 01073 QRect bottomArea(0, y, deviceWidth, area.bottom() - y + 1); 01074 if (area.intersects(bottomArea)) 01075 painter->fillRect(bottomArea, palette().brush(QPalette::Base)); 01076 } 01077 if (isRightToLeft()) { 01078 QRect rightArea(0, 0, deviceWidth - headerLength, area.height()); 01079 if (headerLength < deviceWidth && area.intersects(rightArea)) 01080 painter->fillRect(rightArea, palette().brush(QPalette::Base)); 01081 } else { 01082 QRect leftArea(headerLength, 0, deviceWidth - headerLength, area.height()); 01083 if (headerLength < deviceWidth && area.intersects(leftArea)) 01084 painter->fillRect(leftArea, palette().brush(QPalette::Base)); 01085 } 01086 } 01087 }
Here is the call graph for this function:

| void QTreeView::drawRow | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) | const [protected, virtual] |
Draws the row in the tree view that contains the model item index, using the painter given. The option control how the item is displayed.
Definition at line 1106 of file qtreeview.cpp.
References QPalette::Active, allColumnsShowFocus(), QStyleOptionViewItemV2::Alternate, QPalette::AlternateBase, ancestorOf(), QPalette::Background, QPalette::Base, QPalette::brush(), c, QPalette::color(), columnViewportPosition(), QHeaderView::count(), QAbstractItemView::currentIndex(), d, QPalette::Disabled, drawBranches(), QStyle::drawPrimitive(), QStyleOptionViewItemV2::features, QPainter::fillRect(), QApplication::focusWidget(), QWidget::hasFocus(), header(), QWidget::height(), QRect::height(), QPalette::Highlight, i, QPalette::Inactive, index, QAbstractItemView::indexWidget(), QWidget::isRightToLeft(), QHeaderView::isSectionHidden(), QModelIndex::isValid(), QAbstractItemView::itemDelegate(), Qt::ItemIsEnabled, left(), QHeaderView::length(), QHeaderView::logicalIndex(), QPalette::Normal, o, QHeaderView::offset(), QAbstractItemDelegate::paint(), QWidget::palette(), QStyleOption::palette, QObject::parent(), QStyle::PE_FrameFocusRect, QStyleOption::rect, reverse(), right(), QModelIndex::row(), QHeaderView::sectionSize(), QAbstractItemView::SelectRows, QPalette::setCurrentColorGroup(), QRect::setRect(), QStyleOptionViewItem::showDecorationSelected, QAbstractItemView::state(), QStyleOption::state, QStyle::State_Active, QStyle::State_Enabled, QStyle::State_HasFocus, QStyle::State_KeyboardFocusChange, QStyle::State_MouseOver, QStyle::State_Selected, QWidget::style(), QWidget::width(), QPoint::x(), QWidget::x(), QRect::y(), QPoint::y(), and QWidget::y().
Referenced by drawTree().
01108 { 01109 Q_D(const QTreeView); 01110 QStyleOptionViewItemV2 opt = option; 01111 const QPoint offset = d->scrollDelayOffset; 01112 const int y = option.rect.y() + offset.y(); 01113 const QModelIndex parent = index.parent(); 01114 const QHeaderView *header = d->header; 01115 const QModelIndex current = currentIndex(); 01116 const QModelIndex hover = d->hover; 01117 const bool reverse = isRightToLeft(); 01118 const QStyle::State state = opt.state; 01119 const int left = d->leftAndRight.first; 01120 const int right = d->leftAndRight.second; 01121 const bool alternate = d->alternatingColors; 01122 const bool enabled = (state & QStyle::State_Enabled) != 0; 01123 const bool allColumnsShowFocus = d->allColumnsShowFocus; 01124 01125 // when the row contains an index widget which has focus, 01126 // we want to paint the entire row as active 01127 bool indexWidgetHasFocus = false; 01128 if ((current.row() == index.row()) && !d->editors.isEmpty()) { 01129 const int r = index.row(); 01130 QWidget *fw = QApplication::focusWidget(); 01131 for (int c = 0; c < header->count(); ++c) { 01132 if (QWidget *editor = indexWidget(index.sibling(r, c))) { 01133 if (ancestorOf(editor, fw)) { 01134 indexWidgetHasFocus = true; 01135 break; 01136 } 01137 } 01138 } 01139 } 01140 01141 bool currentRowHasFocus = false; 01142 if (allColumnsShowFocus && current.isValid()) { // check if the focus index is before or after the visible columns 01143 const int r = index.row(); 01144 for (int c = 0; c < left && !currentRowHasFocus; ++c) 01145 currentRowHasFocus = (index.sibling(r, c) == current); 01146 for (int c = right; c < header->count() && !currentRowHasFocus; ++c) 01147 currentRowHasFocus = (index.sibling(r, c) == current); 01148 } 01149 01150 // ### special case: treeviews with multiple columns draw 01151 // the selections differently than with only one column 01152 opt.showDecorationSelected = (d->selectionBehavior & SelectRows) 01153 || option.showDecorationSelected; 01154 01155 int width, height = option.rect.height(); 01156 int position; 01157 int headerSection; 01158 QModelIndex modelIndex; 01159 01160 QBrush fill; 01161 for (int headerIndex = left; headerIndex <= right; ++headerIndex) { 01162 headerSection = header->logicalIndex(headerIndex); 01163 if (header->isSectionHidden(headerSection)) 01164 continue; 01165 position = columnViewportPosition(headerSection) + offset.x(); 01166 width = header->sectionSize(headerSection); 01167 modelIndex = d->model->index(index.row(), headerSection, parent); 01168 opt.state = state; 01169 if (!modelIndex.isValid()) { 01170 opt.rect.setRect(position, y, width, height); 01171 painter->fillRect(opt.rect, palette().brush(QPalette::Base)); 01172 continue; 01173 } 01174 01175 // fake activeness when row editor has focus 01176 if (indexWidgetHasFocus) 01177 opt.state |= QStyle::State_Active; 01178 01179 if (d->selectionModel->isSelected(modelIndex)) 01180 opt.state |= QStyle::State_Selected; 01181 if ((current == modelIndex) && hasFocus()) { 01182 if (allColumnsShowFocus) 01183 currentRowHasFocus = true; 01184 else 01185 opt.state |= QStyle::State_HasFocus; 01186 } 01187 if (modelIndex == hover) 01188 opt.state |= QStyle::State_MouseOver; 01189 else 01190 opt.state &= ~QStyle::State_MouseOver; 01191 01192 if (enabled) { 01193 QPalette::ColorGroup cg; 01194 if ((d->model->flags(index) & Qt::ItemIsEnabled) == 0) { 01195 opt.state &= ~QStyle::State_Enabled; 01196 cg = QPalette::Disabled; 01197 } else { 01198 cg = QPalette::Active; 01199 } 01200 opt.palette.setCurrentColorGroup(cg); 01201 } 01202 01203 if (alternate) { 01204 if (d->current & 1) { 01205 opt.features |= QStyleOptionViewItemV2::Alternate; 01206 fill = opt.palette.brush(QPalette::AlternateBase); 01207 } else { 01208 opt.features &= ~QStyleOptionViewItemV2::Alternate; 01209 fill = opt.palette.brush(QPalette::Base); 01210 } 01211 } else { 01212 fill = opt.palette.brush(QPalette::Base); 01213 } 01214 01215 if (headerSection == 0) { 01216 const int i = d->indentationForItem(d->current); 01217 opt.rect.setRect(reverse ? position : i + position, y, width - i, height); 01218 painter->fillRect(opt.rect, fill); 01219 QRect branches(reverse ? position + width - i : position, y, i, height); 01220 QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled 01221 ? QPalette::Active : QPalette::Disabled; 01222 if (cg == QPalette::Active && !(opt.state & QStyle::State_Active)) 01223 cg = QPalette::Inactive; 01224 01225 if ((opt.state & QStyle::State_Selected) && option.showDecorationSelected) 01226 painter->fillRect(branches, opt.palette.brush(cg, QPalette::Highlight)); 01227 else 01228 painter->fillRect(branches, fill); 01229 drawBranches(painter, branches, index); 01230 } else { 01231 opt.rect.setRect(position, y, width, height); 01232 painter->fillRect(opt.rect, fill); 01233 } 01234 itemDelegate()->paint(painter, opt, modelIndex); 01235 } 01236 01237 if (currentRowHasFocus) { 01238 const int x = (option.showDecorationSelected ? 0 : d->indentationForItem(d->current)); 01239 const int width = header->length() - x; 01240 QStyleOptionFocusRect o; 01241 o.QStyleOption::operator=(option); 01242 o.rect.setRect(x - header->offset(), y, width, height); 01243 o.state |= QStyle::State_KeyboardFocusChange; 01244 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) 01245 ? QPalette::Normal : QPalette::Disabled; 01246 o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index) 01247 ? QPalette::Highlight : QPalette::Background); 01248 style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); 01249 } 01250 }
Here is the call graph for this function:

| void QTreeView::drawBranches | ( | QPainter * | painter, | |
| const QRect & | rect, | |||
| const QModelIndex & | index | |||
| ) | const [protected, virtual] |
Draws the branches in the tree view on the same row as the model item index, using the painter given. The branches are drawn in the rectangle specified by rect.
Definition at line 1257 of file qtreeview.cpp.
References QPainter::brushOrigin(), QObject::children(), d, QStyle::drawPrimitive(), QTreeViewItem::expanded, expanded(), QRect::height(), index, QStyleOption::initFrom(), QWidget::isActiveWindow(), QWidget::isEnabled(), QWidget::isRightToLeft(), QRect::left(), level, QTreeViewItem::level, QModelIndex::parent(), QObject::parent(), QStyle::PE_IndicatorBranch, QStyleOption::rect, QWidget::rect(), reverse(), QRect::right(), QModelIndex::row(), QAbstractItemView::ScrollPerPixel, QPainter::setBrushOrigin(), QStyleOption::state, QStyle::State_Active, QStyle::State_Children, QStyle::State_Enabled, QStyle::State_Item, QStyle::State_None, QStyle::State_Open, QStyle::State_Sibling, QWidget::style(), QRect::top(), QTreeViewItem::total, verticalOffset(), QAbstractItemView::verticalScrollMode(), and QWidget::window().
Referenced by drawRow().
01259 { 01260 Q_D(const QTreeView); 01261 const bool reverse = isRightToLeft(); 01262 const int indent = d->indent; 01263 const int outer = d->rootDecoration ? 0 : 1; 01264 const int item = d->current; 01265 const QTreeViewItem &viewItem = d->viewItems.at(item); 01266 int level = viewItem.level; 01267 QRect primitive(reverse ? rect.left() : rect.right(), rect.top(), indent, rect.height()); 01268 01269 QModelIndex parent = index.parent(); 01270 QModelIndex current = parent; 01271 QModelIndex ancestor = current.parent(); 01272 01273 QStyleOption opt; 01274 opt.initFrom(this); 01275 QStyle::State extraFlags = QStyle::State_None; 01276 if (isEnabled()) 01277 extraFlags |= QStyle::State_Enabled; 01278 if (window()->isActiveWindow()) 01279 extraFlags |= QStyle::State_Active; 01280 01281 QPoint oldBO = painter->brushOrigin(); 01282 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) 01283 painter->setBrushOrigin(QPoint(0, verticalOffset())); 01284 01285 if (level >= outer) { 01286 // start with the innermost branch 01287 primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent); 01288 opt.rect = primitive; 01289 01290 const bool expanded = viewItem.expanded; 01291 const bool children = (((expanded && viewItem.total > 0)) // already laid out and has children 01292 || d->hasVisibleChildren(index)); // not laid out yet, so we don't know 01293 bool moreSiblings = false; 01294 if (d->hiddenIndexes.isEmpty()) 01295 moreSiblings = (d->model->rowCount(parent) - 1 > index.row()); 01296 else 01297 moreSiblings = ((d->viewItems.size() > item +1) 01298 && (d->viewItems.at(item + 1).index.parent() == parent)); 01299 01300 opt.state = QStyle::State_Item | extraFlags 01301 | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None) 01302 | (children ? QStyle::State_Children : QStyle::State_None) 01303 | (expanded ? QStyle::State_Open : QStyle::State_None); 01304 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); 01305 } 01306 // then go out level by level 01307 for (--level; level >= outer; --level) { // we have already drawn the innermost branch 01308 primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent); 01309 opt.rect = primitive; 01310 opt.state = extraFlags; 01311 bool moreSiblings = false; 01312 if (d->hiddenIndexes.isEmpty()) { 01313 moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row()); 01314 } else { 01315 int successor = item + viewItem.total + 1; 01316 while (successor < d->viewItems.size() 01317 && d->viewItems.at(successor).level >= uint(level)) { 01318 const QTreeViewItem &successorItem = d->viewItems.at(successor); 01319 if (successorItem.level == uint(level)) { 01320 moreSiblings = true; 01321 break; 01322 } 01323 successor += successorItem.total + 1; 01324 } 01325 } 01326 if (moreSiblings) 01327 opt.state |= QStyle::State_Sibling; 01328 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); 01329 current = ancestor; 01330 ancestor = current.parent(); 01331 } 01332 painter->setBrushOrigin(oldBO); 01333 }
Here is the call graph for this function:

| void QTreeView::mousePressEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1338 of file qtreeview.cpp.
References d, QAbstractItemView::EditingState, QAbstractItemView::event(), i, itemsExpandable(), QAbstractItemView::mousePressEvent(), QAbstractItemView::NoState, QAbstractItemView::state(), QWidget::update(), updateGeometries(), and QAbstractScrollArea::viewport().
01339 { 01340 Q_D(QTreeView); 01341 // we want to handle mousePress in EditingState (persistent editors) 01342 if ((state() != NoState && state() != EditingState) || !d->viewport->rect().contains(event->pos())) { 01343 return; 01344 } 01345 int i = d->itemDecorationAt(event->pos()); 01346 if (i == -1) { 01347 QAbstractItemView::mousePressEvent(event); 01348 } else if (itemsExpandable() && d->hasVisibleChildren(d->viewItems.at(i).index)) { 01349 if (d->viewItems.at(i).expanded) 01350 d->collapse(i, true); 01351 else 01352 d->expand(i, true); 01353 if (!d->isAnimating()) { 01354 updateGeometries(); 01355 viewport()->update(); 01356 } 01357 } 01358 }
Here is the call graph for this function:

| void QTreeView::mouseReleaseEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1363 of file qtreeview.cpp.
References d, QAbstractItemView::DragSelectingState, QAbstractItemView::event(), QAbstractItemView::mouseReleaseEvent(), QAbstractItemView::NoState, QAbstractItemView::setState(), and QAbstractItemView::state().
01364 { 01365 Q_D(QTreeView); 01366 if (d->itemDecorationAt(event->pos()) == -1) { // ### what about expanding/collapsing state ? 01367 QAbstractItemView::mouseReleaseEvent(event); 01368 } else { 01369 if (state() == QAbstractItemView::DragSelectingState) 01370 setState(QAbstractItemView::NoState); 01371 } 01372 }
Here is the call graph for this function:

| void QTreeView::mouseDoubleClickEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1377 of file qtreeview.cpp.
References QAbstractItemView::activated(), d, QAbstractItemView::doubleClicked(), QAbstractItemView::DoubleClicked, QAbstractItemView::edit(), emit, QAbstractItemView::event(), i, index, QPersistentModelIndex::isValid(), QAbstractItemView::NoState, QStyle::SH_ItemView_ActivateItemOnSingleClick, QAbstractItemView::state(), QWidget::style(), styleHint(), QWidget::update(), updateGeometries(), and QAbstractScrollArea::viewport().
01378 { 01379 Q_D(QTreeView); 01380 if (state() != NoState || !d->viewport->rect().contains(event->pos())) 01381 return; 01382 01383 int i = d->itemDecorationAt(event->pos()); 01384 if (i == -1) { 01385 i = d->itemAtCoordinate(event->y()); 01386 if (i == -1) 01387 return; // user clicked outside the items 01388 01389 // signal handlers may change the model 01390 const QModelIndex &index = d->viewItems.at(i).index; 01391 int column = d->header->logicalIndexAt(event->x()); 01392 QPersistentModelIndex persistent = index.sibling(index.row(), column); 01393 emit doubleClicked(persistent); 01394 01395 if (!persistent.isValid()) 01396 return; 01397 01398 if (edit(persistent, DoubleClicked, event) || state() != NoState) 01399 return; // the double click triggered editing 01400 01401 if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) 01402 emit activated(persistent); 01403 01404 d->executePostedLayout(); // we need to make sure viewItems is updated 01405 if (d->itemsExpandable && d->hasVisibleChildren(persistent)) { 01406 if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == persistent))) { 01407 // find the new index of the item 01408 for (i = 0; i < d->viewItems.count(); ++i) { 01409 if (d->viewItems.at(i).index == persistent) 01410 break; 01411 } 01412 if (i == d->viewItems.count()) 01413 return; 01414 } 01415 if (d->viewItems.at(i).expanded) 01416 d->collapse(i, true); 01417 else 01418 d->expand(i, true); 01419 updateGeometries(); 01420 viewport()->update(); 01421 } 01422 } 01423 }
Here is the call graph for this function:

| void QTreeView::mouseMoveEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1428 of file qtreeview.cpp.
References d, QAbstractItemView::event(), and QAbstractItemView::mouseMoveEvent().
01429 { 01430 Q_D(QTreeView); 01431 if (d->itemDecorationAt(event->pos()) == -1) // ### what about expanding/collapsing state ? 01432 QAbstractItemView::mouseMoveEvent(event); 01433 }
Here is the call graph for this function:

| void QTreeView::keyPressEvent | ( | QKeyEvent * | event | ) | [protected, virtual] |
Reimplemented from QAbstractItemView.
Definition at line 1438 of file qtreeview.cpp.
References collapse(), QAbstractItemView::currentIndex(), d, QAbstractItemView::event(), expand(), Qt::Key_Asterisk, Qt::Key_Minus, Qt::Key_Plus, QAbstractItemView::keyPressEvent(), QObject::parent(), and row.
Referenced by QFileDialogTreeView::keyPressEvent(), and qdesigner_internal::QPropertyEditor::keyPressEvent().
01439 { 01440 Q_D(QTreeView); 01441 QModelIndex current = currentIndex(); 01442 if (d->isIndexValid(current) && d->model) { 01443 switch (event->key()) { 01444 case Qt::Key_Asterisk: { 01445 QStack<QModelIndex> parents; 01446 parents.push(current); 01447 if (d->itemsExpandable) { 01448 while (!parents.isEmpty()) { 01449 QModelIndex parent = parents.pop(); 01450 for (int row = 0; row < d->model->rowCount(parent); ++row) { 01451