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/qtreeview.cpp | |
parent | b8be5b4002bd6163851bbae397171ebbf632f02f (diff) |
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/qtreeview.cpp')
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 9aba17be70..a3bebb8f3c 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -1396,6 +1396,24 @@ void QTreeViewPrivate::_q_modelDestroyed() QAbstractItemViewPrivate::_q_modelDestroyed(); } +QRect QTreeViewPrivate::intersectedRect(const QRect rect, const QModelIndex &topLeft, const QModelIndex &bottomRight) const +{ + Q_Q(const QTreeView); + + const auto parentIdx = topLeft.parent(); + executePostedLayout(); + QRect updateRect; + for (int r = topLeft.row(); r <= bottomRight.row(); ++r) { + if (isRowHidden(model->index(r, 0, parentIdx))) + continue; + for (int c = topLeft.column(); c <= bottomRight.column(); ++c) { + const QModelIndex idx(model->index(r, c, parentIdx)); + updateRect |= q->visualRect(idx); + } + } + return rect.intersected(updateRect); +} + /*! \reimp |