summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-12-06 21:56:41 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-12-14 08:46:05 +0100
commit4522b17159a29ffd12c4d93be8a6e8e1a05dccd0 (patch)
tree6e63dc27e8c3c1bf3b0b2bec84aa97155fc6a10d /src
parente076965542148b8c2341fd4418733febbf9ae1ec (diff)
QStandardItemModel: do not reset persisten index in setItem()
When an existing item is replaced with a new one in QStandardItemModel::setItem() then the persitent index is invalidated which leads to some unexpected behaviors (like e.g the header size and resize mode are reset). Therefore we have to make sure that the invalidation does not happen. This can be achieved by delaying the call to QStandardItem::setModel() for the old item until the new is properly added. After this, the old item no longer gets a valid QModelIndex from the model and therefore can't invalidate the persistent index anymore. Fixes: QTBUG-13605 Fixes: QTBUG-73000 Fixes: QTBUG-80586 Change-Id: I4e45e6feb81b7287c0859f638d7ab1a576fc2f0f Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index 2998808b54..9bdc22b49e 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -138,10 +138,19 @@ void QStandardItemPrivate::setChild(int row, int column, QStandardItem *item,
return;
}
}
+
+ // setting the model to nullptr invalidates the persistent index which we want to avoid
+ if (!item && oldItem)
+ oldItem->d_func()->setModel(nullptr);
+
+ children.replace(index, item);
+
+ // since now indexFromItem() does no longer return a valid index, the persistent index
+ // will not be invalidated anymore
if (oldItem)
oldItem->d_func()->setModel(nullptr);
delete oldItem;
- children.replace(index, item);
+
if (item)
item->d_func()->lastKnownIndex = index;