summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp39
-rw-r--r--src/widgets/itemviews/qabstractitemview.h5
-rw-r--r--src/widgets/itemviews/qabstractitemview_p.h2
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp4
4 files changed, 49 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index f0af233d882..0b90fedad5b 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -85,7 +85,8 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate()
delayedPendingLayout(true),
moveCursorUpdatedView(false),
verticalScrollModeSet(false),
- horizontalScrollModeSet(false)
+ horizontalScrollModeSet(false),
+ updateThreshold(200)
{
keyboardInputTime.invalidate();
}
@@ -3204,6 +3205,37 @@ int QAbstractItemView::sizeHintForColumn(int column) const
}
/*!
+ \property QAbstractItemView::updateThreshold
+ \since 6.9
+ This property holds the amount of changed indexes to directly trigger
+ a full update of the view inside dataChanged().
+
+ The algorithm inside dataChanged() tries to minimize a full update of the
+ view by calculating if the changed indexes are visible or not. For very
+ large models, with a lot of large changes, this might take longer than the
+ actual update so it's counter-productive. This property gives the ability
+ to control the algorithm to skip the check and directly trigger a full
+ update when the amount of changed indexes exceeds the given value.
+
+ The default value is 200.
+
+ \sa dataChanged()
+*/
+uint32_t QAbstractItemView::updateThreshold() const
+{
+ Q_D(const QAbstractItemView);
+ return d->updateThreshold;
+}
+
+void QAbstractItemView::setUpdateThreshold(uint32_t threshold)
+{
+ Q_D(QAbstractItemView);
+ if (d->updateThreshold == threshold)
+ return;
+ d->updateThreshold = threshold;
+}
+
+/*!
Opens a persistent editor on the item at the given \a index.
If no editor exists, the delegate will create a new editor.
@@ -3397,6 +3429,11 @@ void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelInde
topLeft.row() > bottomRight.row() ||
topLeft.column() > bottomRight.column()) {
// invalid parameter - call update() to redraw all
+ Q_ASSERT(false);
+ d->viewport->update();
+ } else if ((bottomRight.row() - topLeft.row() + 1ULL) *
+ (bottomRight.column() - topLeft.column() + 1ULL) > d->updateThreshold) {
+ // too many indices to check - force full update
d->viewport->update();
} else {
const QRect updateRect = d->intersectedRect(d->viewport->rect(), topLeft, bottomRight);
diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h
index 837419100a9..63f2eefe83a 100644
--- a/src/widgets/itemviews/qabstractitemview.h
+++ b/src/widgets/itemviews/qabstractitemview.h
@@ -46,6 +46,8 @@ class Q_WIDGETS_EXPORT QAbstractItemView : public QAbstractScrollArea
RESET resetVerticalScrollMode)
Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode
WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode)
+ Q_PROPERTY(uint32_t updateThreshold READ updateThreshold
+ WRITE setUpdateThreshold)
public:
enum SelectionMode {
@@ -177,6 +179,9 @@ public:
virtual int sizeHintForRow(int row) const;
virtual int sizeHintForColumn(int column) const;
+ uint32_t updateThreshold() const;
+ void setUpdateThreshold(uint32_t threshold);
+
void openPersistentEditor(const QModelIndex &index);
void closePersistentEditor(const QModelIndex &index);
bool isPersistentEditorOpen(const QModelIndex &index) const;
diff --git a/src/widgets/itemviews/qabstractitemview_p.h b/src/widgets/itemviews/qabstractitemview_p.h
index 433429f48b8..5a6d7957c76 100644
--- a/src/widgets/itemviews/qabstractitemview_p.h
+++ b/src/widgets/itemviews/qabstractitemview_p.h
@@ -421,6 +421,8 @@ public:
bool verticalScrollModeSet;
bool horizontalScrollModeSet;
+ uint32_t updateThreshold;
+
virtual QRect visualRect(const QModelIndex &index) const { return q_func()->visualRect(index); }
std::array<QMetaObject::Connection, 14> modelConnections;
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 4f2495375d9..b208c104a0d 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -295,6 +295,10 @@ void tst_QAbstractItemView::getSetCheck()
QCOMPARE(20, obj1->autoScrollMargin());
obj1->setAutoScrollMargin(16);
QCOMPARE(16, obj1->autoScrollMargin());
+
+ QCOMPARE(200U, obj1->updateThreshold());
+ obj1->setUpdateThreshold(4711);
+ QCOMPARE(4711U, obj1->updateThreshold());
}
void tst_QAbstractItemView::cleanup()