From 03c761287f1a007c7177d90ed81341d0147eae05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Martsum?= Date: Mon, 8 Apr 2013 15:40:11 +0200 Subject: 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 --- src/widgets/itemviews/qtableview.cpp | 58 +++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'src/widgets/itemviews/qtableview.cpp') 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 @@ -930,6 +930,44 @@ void QTableViewPrivate::drawCell(QPainter *painter, const QStyleOptionViewItem & q->itemDelegate(index)->paint(painter, opt, index); } +/*! + \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 @@ -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; -- cgit v1.2.3