From 1b9ed62028a60a4cf155bca82cea553c8390952f Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 18 Sep 2023 17:34:39 +0200 Subject: [PATCH] QmlDesigner: Close dialog if target is removed If the target is removed also the connection is removed and we close the dialog. Change-Id: I361e89ef64484e39bc0068e103f542cbc9dcbf78 Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Aleksei German --- .../connectionseditor/ConnectionsDialog.qml | 10 +++++++++- .../components/connectioneditor/connectionmodel.cpp | 11 +++++++++++ .../components/connectioneditor/connectionmodel.h | 3 +++ .../components/connectioneditor/connectionview.cpp | 5 +++++ .../components/connectioneditor/connectionview.h | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml index b880916e4d8..7405f82a47b 100644 --- a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml +++ b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialog.qml @@ -7,7 +7,7 @@ import StudioTheme 1.0 as StudioTheme import HelperWidgets 2.0 as HelperWidgets PopupDialog { - + id: root property alias backend: form.backend titleBar: Row { @@ -41,5 +41,13 @@ PopupDialog { ConnectionsDialogForm { id: form + + Connections { + target: root.backend + onPopupTargetRemoved: { + root.close() + } + } } + } diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp index 9fca617e359..c0b819371a8 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp @@ -487,6 +487,17 @@ void ConnectionModel::selectProperty(const SignalHandlerProperty &property) } } +void ConnectionModel::nodeAboutToBeRemoved(const ModelNode &removedNode) +{ + SignalHandlerProperty selectedSignal = signalHandlerPropertyForRow(currentIndex()); + if (selectedSignal.isValid()) { + ModelNode targetNode = getTargetNodeForConnection(selectedSignal.parentModelNode()); + if (targetNode == removedNode) { + emit m_delegate->popupTargetRemoved(); + } + } +} + void ConnectionModel::handleException() { QMessageBox::warning(nullptr, tr("Error"), m_exceptionError); diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h index 03ee4e7144c..d9b13cb22d2 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h @@ -71,6 +71,8 @@ public: void selectProperty(const SignalHandlerProperty &property); + void nodeAboutToBeRemoved(const ModelNode &removedNode); + signals: void currentIndexChanged(); @@ -296,6 +298,7 @@ signals: void hasConditionChanged(); void hasElseChanged(); void sourceChanged(); + void popupTargetRemoved(); private: int currentRow() const; diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp index 41eee97be48..0b02ee0e34b 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionview.cpp @@ -176,6 +176,11 @@ void ConnectionView::nodeCreated(const ModelNode & /*createdNode*/) connectionModel()->resetModel(); } +void ConnectionView::nodeAboutToBeRemoved(const ModelNode &removedNode) +{ + connectionModel()->nodeAboutToBeRemoved(removedNode); +} + void ConnectionView::nodeRemoved(const ModelNode & /*removedNode*/, const NodeAbstractProperty & /*parentProperty*/, AbstractView::PropertyChangeFlags /*propertyChange*/) diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionview.h b/src/plugins/qmldesigner/components/connectioneditor/connectionview.h index b865bf51cc4..338d1fb14ed 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionview.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionview.h @@ -39,6 +39,7 @@ public: void modelAboutToBeDetached(Model *model) override; void nodeCreated(const ModelNode &createdNode) override; + void nodeAboutToBeRemoved(const ModelNode &removedNode) override; void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange) override; void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange) override;