summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qabstractitemview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 3b2aebff15..300795d3bf 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -3341,8 +3341,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
@@ -3626,6 +3637,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