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>bb10
parent
03c5eacfbb
commit
03c761287f
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -181,6 +181,8 @@ public:
|
|||
const QStyleOptionViewItem &option, QBitArray *drawn,
|
||||
int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
|
||||
void drawCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||
int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const;
|
||||
int heightHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option) const;
|
||||
|
||||
bool showGrid;
|
||||
Qt::PenStyle gridStyle;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ public:
|
|||
// logicalIndices: vector of currently visibly logical indices
|
||||
// itemPositions: vector of view item positions (beginning/middle/end/onlyone)
|
||||
void calcLogicalIndices(QVector<int> *logicalIndices, QVector<QStyleOptionViewItem::ViewItemPosition> *itemPositions, int left, int right) const;
|
||||
|
||||
int widthHintForIndex(const QModelIndex &index, int hint, const QStyleOptionViewItem &option, int i) const;
|
||||
QHeaderView *header;
|
||||
int indent;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue