diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-12-23 15:44:48 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2020-03-28 09:03:18 +0100 |
commit | 8de62d34321cd827e60b0a7b6e7434070de301ae (patch) | |
tree | 048f18f000b6d9235057d800e5f3d79be35a5570 /src/widgets/itemviews/qabstractitemview.cpp | |
parent | b8be5b4002bd6163851bbae397171ebbf632f02f (diff) | |
download | qtbase-8de62d34321cd827e60b0a7b6e7434070de301ae.tar.gz |
QAbstractItemView::dataChanged(): optimize call to QWidget::update()
When topLeft and bottomRight are different in QAIV::dataChanged(), the
current implementation simply calls QWidget::update() without checking
if the affected cells are visible. This results in a big performance hit
when cells are updated frequently.
Now try to compute the exact update rect by iterating through the
modified indexes.
Fixes: QTBUG-58580
Change-Id: I97de567d494e40ed8cdb1ea1f5b3cf3a2f60455e
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index ebef36d033..b8c30321ff 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -3335,8 +3335,19 @@ void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelInde } } else { d->updateEditorData(topLeft, bottomRight); - if (isVisible() && !d->delayedPendingLayout) - d->viewport->update(); + if (isVisible() && !d->delayedPendingLayout) { + if (!topLeft.isValid() || + topLeft.parent() != bottomRight.parent() || + topLeft.row() > bottomRight.row() || + topLeft.column() > bottomRight.column()) { + // invalid parameter - call update() to redraw all + d->viewport->update(); + } else { + const QRect updateRect = d->intersectedRect(d->viewport->rect(), topLeft, bottomRight); + if (!updateRect.isEmpty()) + d->viewport->update(updateRect); + } + } } #ifndef QT_NO_ACCESSIBILITY @@ -3620,6 +3631,19 @@ void QAbstractItemViewPrivate::_q_columnsMoved(const QModelIndex &, int, int, co _q_layoutChanged(); } +QRect QAbstractItemViewPrivate::intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const +{ + Q_Q(const QAbstractItemView); + + const auto parentIdx = topLeft.parent(); + QRect updateRect; + for (int r = topLeft.row(); r <= bottomRight.row(); ++r) { + for (int c = topLeft.column(); c <= bottomRight.column(); ++c) + updateRect |= q->visualRect(model->index(r, c, parentIdx)); + } + return rect.intersected(updateRect); +} + /*! This slot is called when the selection is changed. The previous selection (which may be empty), is specified by \a deselected, and the |