summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorLuca Beldi <v.ronin@yahoo.it>2021-04-23 20:30:17 +0100
committerLuca Beldi <v.ronin@yahoo.it>2021-04-26 13:44:51 +0100
commit6ec3fa2842b5c4714dc9a3953b2721ef70dd957b (patch)
treea317cb056400ba39928df53404a594acf4102211 /src/widgets/itemviews
parentfcea8e7aa8a65de9e80136c2d603478831b246d0 (diff)
Fix QTreeModel calling beginRemoveRows twice
For items that are children of other items, removeRows calls beginRemoveRows directly and then once again inside takeChild() The signal blocker that dates back to the monolitic import from Nokia prevents the model from emitting extra signals but the persistent indexes are corrupted nonetheless. Fixes: QTBUG-90030 Pick-to: 6.1 6.0 5.15 Change-Id: I5bc4b2598bf13247683b113faeec22471f1f04a4 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index 12b39f3541..e1f7da6fcd 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -506,22 +506,18 @@ bool QTreeModel::insertColumns(int column, int count, const QModelIndex &parent)
bool QTreeModel::removeRows(int row, int count, const QModelIndex &parent) {
if (count < 1 || row < 0 || (row + count) > rowCount(parent))
return false;
-
- beginRemoveRows(parent, row, row + count - 1);
-
- QSignalBlocker blocker(this);
-
- QTreeWidgetItem *itm = item(parent);
+ QTreeWidgetItem *parentItem = item(parent);
+ // if parentItem is valid, begin/end RemoveRows is handled by takeChild below
+ if (!parentItem)
+ beginRemoveRows(parent, row, row + count - 1);
for (int i = row + count - 1; i >= row; --i) {
- QTreeWidgetItem *child = itm ? itm->takeChild(i) : rootItem->children.takeAt(i);
+ QTreeWidgetItem *child = parentItem ? parentItem->takeChild(i) : rootItem->children.takeAt(i);
Q_ASSERT(child);
child->view = nullptr;
delete child;
- child = nullptr;
}
- blocker.unblock();
-
- endRemoveRows();
+ if (!parentItem)
+ endRemoveRows();
return true;
}