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>
This commit is contained in:
parent
5668e059f2
commit
b53f997d8f
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user