diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-10-14 15:06:17 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2019-11-14 11:19:26 +0100 |
commit | 35fdf3a7b77a79806d0b5d9632b5066e3618adf5 (patch) | |
tree | 34dff9cf397da2da7ac71cff82b30b7b6675e546 /src/qmlmodels/qqmltableinstancemodel.cpp | |
parent | 1619b7d207f7a84810e4790766ac33a3ac9aaa1a (diff) |
QQmlTableInstanceModel: always emit index changed when an item is reused
When reusing a delegate item, it can sometimes happen that the item
ends up being reused at the same location in the table as it had
before it was pooled. And in that case, we don't emit changes to
index, row and column since they technically didn't change.
The problem is that the model might have changed in-between, e.g if
a row has been removed. And in that case, row and column will, even
when unchanged, point to other parts of the model. So all bindings
needs to be reevaluated to ensure that the values they use are
refreshed.
This patch will therefore ensure that we always emit changes to
the mentioned properties when an item is reused, regardless if
they change or not.
Fixes: QTBUG-79209
Change-Id: Icec201a43a30b9f677303fbf652baf6487621deb
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/qmlmodels/qqmltableinstancemodel.cpp')
-rw-r--r-- | src/qmlmodels/qqmltableinstancemodel.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qmlmodels/qqmltableinstancemodel.cpp b/src/qmlmodels/qqmltableinstancemodel.cpp index b244a007e5..fb2f7ee98b 100644 --- a/src/qmlmodels/qqmltableinstancemodel.cpp +++ b/src/qmlmodels/qqmltableinstancemodel.cpp @@ -342,9 +342,13 @@ void QQmlTableInstanceModel::reuseItem(QQmlDelegateModelItem *item, int newModel { // Update the context properties index, row and column on // the delegate item, and inform the application about it. + // Note that we set alwaysEmit to true, to force all bindings + // to be reevaluated, even if the index didn't change (since + // the model can have changed size since last usage). + const bool alwaysEmit = true; const int newRow = m_adaptorModel.rowAt(newModelIndex); const int newColumn = m_adaptorModel.columnAt(newModelIndex); - item->setModelIndex(newModelIndex, newRow, newColumn); + item->setModelIndex(newModelIndex, newRow, newColumn, alwaysEmit); // Notify the application that all 'dynamic'/role-based context data has // changed as well (their getter function will use the updated index). |