QmlDesigner: Notify tools before deleting FormEditorItems

Calling itemsAboutToRemoved() prior to deleting FormEditorItems ensures
selection-related tools don’t access freed pointers during an undo
operation.

Found in https://the-qt-company-00.sentry.io/issues/6416987849

Change-Id: I94dc1e93b380c2dc22120dbe43568815f0c484ed
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
(cherry picked from commit c486e78d37)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tim Jenßen
2025-06-04 08:41:57 +02:00
committed by Tim Jenssen
parent be2f2b5bb7
commit d476bc7edf

View File

@@ -175,23 +175,21 @@ void FormEditorView::removeNodeFromScene(const QmlItemNode &qmlItemNode)
QList<FormEditorItem*> removedItemList;
if (qmlItemNode.isValid()) {
QList<QmlItemNode> nodeList;
nodeList.append(qmlItemNode.allSubModelNodes());
QList<QmlItemNode> nodeList = qmlItemNode.allSubModelNodes();
nodeList.append(qmlItemNode);
removedItemList.append(scene()->itemsForQmlItemNodes(nodeList));
} else if (isFlowNonItem(qmlItemNode)) {
removedItemList.append(scene()->itemsForQmlItemNodes({qmlItemNode}));
}
if (!removedItemList.isEmpty()) {
m_currentTool->itemsAboutToRemoved(removedItemList);
//The destructor of QGraphicsItem does delete all its children.
//We have to keep the children if they are not children in the model anymore.
//Otherwise we delete the children explicitly anyway.
deleteWithoutChildren(removedItemList);
} else if (isFlowNonItem(qmlItemNode)) {
removedItemList.append(scene()->itemsForQmlItemNodes({qmlItemNode}));
deleteWithoutChildren(removedItemList);
}
if (!removedItemList.isEmpty())
m_currentTool->itemsAboutToRemoved(removedItemList);
}
void FormEditorView::createFormEditorWidget()