diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-10-20 21:23:04 +0200 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2018-11-08 18:23:50 +0000 |
commit | b53f997d8f20938d46b755eca54b4ec9a40e4ffe (patch) | |
tree | 6d6f02eb9913876cbcdff16e63c73e4b661c58da /src/widgets/itemviews | |
parent | 5668e059f2ffcf12b4171ea54ff016689ff91239 (diff) |
QHeaderView: check for changed roles in dataChanged()
QHeaderView::dataChanged() did not check for the modified roles which
lead to unneeded size calculations even if the size did not change.
Avoid it by only looking at the relevant roles (DisplayRole, DecorationRole,
SizeHintRole and FontRole).
[ChangeLog][QtWidgets][QHeaderView] dataChanged now respects the given
roles to avoid useless recomputations
Fixes: QTBUG-71172
Change-Id: I0de53897347a72bddc425ae1fae8f2560ad0e977
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e9091ca1a2..62abf56751 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3117,9 +3117,25 @@ void QHeaderView::scrollContentsBy(int dx, int dy) \reimp \internal */ -void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &) +void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { Q_D(QHeaderView); + if (!roles.isEmpty()) { + const auto doesRoleAffectSize = [](int role) -> bool { + switch (role) { + case Qt::DisplayRole: + case Qt::DecorationRole: + case Qt::SizeHintRole: + case Qt::FontRole: + return true; + default: + // who knows what a subclass or custom style might do + return role >= Qt::UserRole; + } + }; + if (std::none_of(roles.begin(), roles.end(), doesRoleAffectSize)) + return; + } d->invalidateCachedSizeHint(); if (d->hasAutoResizeSections()) { bool resizeRequired = d->globalResizeMode == ResizeToContents; |