From 35fdf3a7b77a79806d0b5d9632b5066e3618adf5 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 14 Oct 2019 15:06:17 +0200 Subject: 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 --- src/qmlmodels/qqmldelegatemodel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/qmlmodels/qqmldelegatemodel.cpp') diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index 65c99d9bc0..24632fe16b 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -2123,7 +2123,7 @@ void QQmlDelegateModelItem::Dispose() delete this; } -void QQmlDelegateModelItem::setModelIndex(int idx, int newRow, int newColumn) +void QQmlDelegateModelItem::setModelIndex(int idx, int newRow, int newColumn, bool alwaysEmit) { const int prevIndex = index; const int prevRow = row; @@ -2133,11 +2133,11 @@ void QQmlDelegateModelItem::setModelIndex(int idx, int newRow, int newColumn) row = newRow; column = newColumn; - if (idx != prevIndex) + if (idx != prevIndex || alwaysEmit) emit modelIndexChanged(); - if (row != prevRow) + if (row != prevRow || alwaysEmit) emit rowChanged(); - if (column != prevColumn) + if (column != prevColumn || alwaysEmit) emit columnChanged(); } -- cgit v1.2.3