QmlDesigner: Fix crash

Do not call validId in updateContext.

Calling validId does mutate the model and will set an id if none exists.
Since updateContext is called on selection change the user does not expect
the model to mutate and when switching/creating documents this could even
lead to a crash.

Instead we give the created MosueArea always an id and disable the menu
in case there is no id.

Task-number: QDS-7806
Change-Id: I3d5d1ce41025d94db3cfff48f483366e56b58a32
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2022-09-28 13:07:17 +02:00
committed by Tim Jenssen
parent 4adb4911e6
commit 535a4eefe4
2 changed files with 12 additions and 1 deletions

View File

@@ -595,6 +595,8 @@ public:
{
menu()->clear();
menu()->setEnabled(true);
const auto selection = selectionContext();
if (!selection.isValid())
return;
@@ -604,11 +606,19 @@ public:
return;
ModelNode currentNode = selection.currentSingleSelectedNode();
if (!currentNode.isValid())
return;
QmlObjectNode currentObjectNode(currentNode);
QStringList signalsList = getSignalsList(currentNode);
QList<SlotEntry> slotsList = getSlotsLists(currentNode);
currentNode.validId();
if (!currentNode.hasId()) {
menu()->setEnabled(false);
return;
}
for (const ModelNode &connectionNode : currentObjectNode.getAllConnections()) {
for (const AbstractProperty &property : connectionNode.properties()) {

View File

@@ -1638,6 +1638,7 @@ void addMouseAreaFill(const SelectionContext &selectionContext)
QmlDesigner::ModelNode mouseAreaNode =
selectionContext.view()->createModelNode("QtQuick.MouseArea", itemMetaInfo.majorVersion(), itemMetaInfo.minorVersion());
mouseAreaNode.validId();
modelNode.defaultNodeListProperty().reparentHere(mouseAreaNode);
QmlItemNode mouseAreaItemNode(mouseAreaNode);