From 2d9cf3ef0fc09254b1a63ab04b86d9beb52e71bc Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 16 May 2019 10:10:30 +0200 Subject: 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 --- src/qmlmodels/qqmldelegatemodel.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/qmlmodels/qqmldelegatemodel.cpp') diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index e7868517cd..65c99d9bc0 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -454,7 +454,8 @@ void QQmlDelegateModel::setDelegate(QQmlComponent *delegate) } if (d->m_delegate == delegate) return; - bool wasValid = d->m_delegate != nullptr; + if (d->m_complete) + _q_itemsRemoved(0, d->m_count); d->m_delegate.setObject(delegate, this); d->m_delegateValidated = false; if (d->m_delegateChooser) @@ -470,7 +471,11 @@ void QQmlDelegateModel::setDelegate(QQmlComponent *delegate) [d](){ d->delegateChanged(); }); } } - d->delegateChanged(d->m_delegate, wasValid); + if (d->m_complete) { + _q_itemsInserted(0, d->adaptorModelCount()); + d->requestMoreIfNecessary(); + } + emit delegateChanged(); } /*! -- cgit v1.2.3