summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtableview.cpp
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-04-08 15:40:11 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-09 06:45:01 +0200
commit03c761287f1a007c7177d90ed81341d0147eae05 (patch)
treeffa6c4022f414cee643d3875050bb7f375bfc8f2 /src/widgets/itemviews/qtableview.cpp
parent03c5eacfbb7f8fa294368bff812428680a0b9f3b (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/qtableview.cpp')
-rw-r--r--src/widgets/itemviews/qtableview.cpp58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 8550e6fd84..45844173d3 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -931,6 +931,44 @@ void QTableViewPrivate::drawCell(QPainter *painter, const QStyleOptionViewItem &
}
/*!
+ \internal
+ Get sizeHint width for single Index (providing existing hint and style option)
+*/
+int QTableViewPrivate::widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const
+{
+ Q_Q(const QTableView);
+ 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);
+ }
+ hint = qMax(hint, q->itemDelegate(index)->sizeHint(option, index).width());
+ return hint;
+}
+
+/*!
+ \internal
+ Get sizeHint height for single Index (providing existing hint and style option)
+*/
+int QTableViewPrivate::heightHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const
+{
+ Q_Q(const QTableView);
+ QWidget *editor = editorForIndex(index).widget.data();
+ if (editor && persistent.contains(editor)) {
+ hint = qMax(hint, editor->sizeHint().height());
+ int min = editor->minimumSize().height();
+ int max = editor->maximumSize().height();
+ hint = qBound(min, hint, max);
+ }
+
+ hint = qMax(hint, q->itemDelegate(index)->sizeHint(option, index).height());
+ return hint;
+}
+
+
+/*!
\class QTableView
\brief The QTableView class provides a default model/view
@@ -2203,16 +2241,8 @@ int QTableView::sizeHintForRow(int row) const
option.rect.setX(columnViewportPosition(index.column()));
option.rect.setWidth(columnWidth(index.column()));
}
+ hint = d->heightHintForIndex(index, hint, option);
- QWidget *editor = d->editorForIndex(index).widget.data();
- if (editor && d->persistent.contains(editor)) {
- hint = qMax(hint, editor->sizeHint().height());
- int min = editor->minimumSize().height();
- int max = editor->maximumSize().height();
- hint = qBound(min, hint, max);
- }
-
- hint = qMax(hint, itemDelegate(index)->sizeHint(option, index).height());
++columnsProcessed;
if (columnsProcessed == maximumProcessCols)
break;
@@ -2262,15 +2292,7 @@ int QTableView::sizeHintForColumn(int column) const
continue;
index = d->model->index(logicalRow, column, d->root);
- QWidget *editor = d->editorForIndex(index).widget.data();
- if (editor && d->persistent.contains(editor)) {
- hint = qMax(hint, editor->sizeHint().width());
- int min = editor->minimumSize().width();
- int max = editor->maximumSize().width();
- hint = qBound(min, hint, max);
- }
-
- hint = qMax(hint, itemDelegate(index)->sizeHint(option, index).width());
+ hint = d->widthHintForIndex(index, hint, option);
++rowsProcessed;
if (rowsProcessed == maximumProcessRows)
break;