diff options
author | Thorbjørn Martsum <tmartsum@gmail.com> | 2013-04-08 15:40:11 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-09 06:45:01 +0200 |
commit | 03c761287f1a007c7177d90ed81341d0147eae05 (patch) | |
tree | ffa6c4022f414cee643d3875050bb7f375bfc8f2 /src/widgets/itemviews/qtreeview.cpp | |
parent | 03c5eacfbb7f8fa294368bff812428680a0b9f3b (diff) |
resizeToContents - move some of sizeHint into separate functions
Some of sizeHintForColumn is now moved into widthHintForIndex.
(and in QTreeView some of sizeHintForRow into heightHintForIndex)
This makes the code a bit more readable and it prepares some
extensions that will use these functions more. There should
be no semantic changes in this patch.
In releasemode this does not seem to have a performance cost.
(QTableView actually seemed to be a bit faster)
Change-Id: I940432ee01715ce94cd6aab5f3b2aa00dcd19ace
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qtreeview.cpp')
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 0977f7a2c1..c4f2236b93 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1527,6 +1527,23 @@ void QTreeViewPrivate::calcLogicalIndices(QVector<int> *logicalIndices, QVector< } } +/*! + \internal + Get sizeHint width for single index (providing existing hint and style option) and index in viewIndex i. +*/ +int QTreeViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const +{ + QWidget *editor = editorForIndex(index).widget.data(); + if (editor && persistent.contains(editor)) { + hint = qMax(hint, editor->sizeHint().width()); + int min = editor->minimumSize().width(); + int max = editor->maximumSize().width(); + hint = qBound(min, hint, max); + } + int xhint = delegateForIndex(index)->sizeHint(option, index).width(); + hint = qMax(hint, xhint + (index.column() == 0 ? indentationForItem(i) : 0)); + return hint; +} /*! Draws the row in the tree view that contains the model item \a index, @@ -2811,15 +2828,7 @@ int QTreeView::sizeHintForColumn(int column) const continue; // we have no good size hint QModelIndex index = viewItems.at(i).index; index = index.sibling(index.row(), column); - QWidget *editor = d->editorForIndex(index).widget.data(); - if (editor && d->persistent.contains(editor)) { - w = qMax(w, editor->sizeHint().width()); - int min = editor->minimumSize().width(); - int max = editor->maximumSize().width(); - w = qBound(min, w, max); - } - int hint = d->delegateForIndex(index)->sizeHint(option, index).width(); - w = qMax(w, hint + (column == 0 ? d->indentationForItem(i) : 0)); + w = d->widthHintForIndex(index, w, option, i); } return w; } |