aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitemview.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-16 10:10:30 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-10-09 18:58:18 +0200
commit2d9cf3ef0fc09254b1a63ab04b86d9beb52e71bc (patch)
tree2a4a09fc481336b193677b7e58fc995aeda41681 /src/quick/items/qquickitemview.cpp
parentd522746afa394960bef225ba08080d8364b69a7e (diff)
When a DelegateModel delegate changes, refill the view
It looked a bit odd that the DelegateModel delegate property was not a notifying property. Adding the delegateChanged signal makes it easier to update the view when this happens. The previous approach of removing all delegates and adding all new ones resulted in the view losing its currentIndex and often scrolling to a different place. It's also nice to reduce the number of d-> indirections by adding the QQuickItemViewPrivate::applyDelegateChange() function, so that we just need one indirection to call it, and then it updates all the internal stuff in one place. Done-with: Frederik Gladhorn Done-with: Joni Poikelin Fixes: QTBUG-63477 Change-Id: I2d17fd11ff4a2fcb20968a7182dd2c403abb715a Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quick/items/qquickitemview.cpp')
-rw-r--r--src/quick/items/qquickitemview.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index bbfbf6244c..e1af65c986 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -247,6 +247,8 @@ void QQuickItemView::setModel(const QVariant &m)
connect(d->model, SIGNAL(modelUpdated(QQmlChangeSet,bool)),
this, SLOT(modelUpdated(QQmlChangeSet,bool)));
+ if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel*>(d->model))
+ QObjectPrivate::connect(dataModel, &QQmlDelegateModel::delegateChanged, d, &QQuickItemViewPrivate::applyDelegateChange);
emit countChanged();
}
emit modelChanged();
@@ -277,22 +279,8 @@ void QQuickItemView::setDelegate(QQmlComponent *delegate)
if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel*>(d->model)) {
int oldCount = dataModel->count();
dataModel->setDelegate(delegate);
- if (isComponentComplete()) {
- d->releaseVisibleItems();
- d->releaseItem(d->currentItem);
- d->currentItem = nullptr;
- d->updateSectionCriteria();
- d->refill();
- d->moveReason = QQuickItemViewPrivate::SetIndex;
- d->updateCurrent(d->currentIndex);
- if (d->highlight && d->currentItem) {
- if (d->autoHighlight)
- d->resetHighlightPosition();
- d->updateTrackedItem();
- }
- d->moveReason = QQuickItemViewPrivate::Other;
- d->updateViewport();
- }
+ if (isComponentComplete())
+ d->applyDelegateChange();
if (oldCount != dataModel->count())
emit countChanged();
}
@@ -1089,6 +1077,24 @@ qreal QQuickItemViewPrivate::calculatedMaxExtent() const
return maxExtent;
}
+void QQuickItemViewPrivate::applyDelegateChange()
+{
+ releaseVisibleItems();
+ releaseItem(currentItem);
+ currentItem = nullptr;
+ updateSectionCriteria();
+ refill();
+ moveReason = QQuickItemViewPrivate::SetIndex;
+ updateCurrent(currentIndex);
+ if (highlight && currentItem) {
+ if (autoHighlight)
+ resetHighlightPosition();
+ updateTrackedItem();
+ }
+ moveReason = QQuickItemViewPrivate::Other;
+ updateViewport();
+}
+
// for debugging only
void QQuickItemViewPrivate::checkVisible() const
{