From ed965a55bf38063cfb0b2204f787ed43895e16dc Mon Sep 17 00:00:00 2001 From: Andrzej Biniek Date: Tue, 31 Dec 2024 06:59:00 +0100 Subject: [PATCH] Clear node graph data on project change Change-Id: Ic778e4e8eef3b29e2025d786f2b9e7658a7b2dec Reviewed-by: spyro-adb --- .../qmldesigner/nodegrapheditor/Main.qml | 4 ++++ .../nodegrapheditor/nodegrapheditormodel.cpp | 10 +++++++++- .../nodegrapheditor/nodegrapheditormodel.h | 2 ++ .../nodegrapheditor/nodegrapheditorview.cpp | 15 ++++++++++++++- .../nodegrapheditor/nodegrapheditorview.h | 3 ++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml index f436dc70f83..57b1da90983 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml @@ -159,6 +159,10 @@ Item { initEdges(edges); NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false; } + onNodeGraphCleared: { + graphView.graph.clearGraph(); + NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false; + } } SaveAsDialog { diff --git a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp index ac431d70a14..92455988f1b 100644 --- a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp +++ b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp @@ -61,13 +61,13 @@ void NodeGraphEditorModel::saveFile(QString fileName){ void NodeGraphEditorModel::openFile(QString filePath){ const QString nodeGraphName = QFileInfo(filePath).baseName(); - setCurrentFileName(nodeGraphName); QFile nodeGraphFile(filePath); if (!nodeGraphFile.open(QIODevice::ReadOnly)) { QString error = QString("Couldn't open node graph file: '%1'").arg(filePath); qWarning() << qPrintable(error); return; } + setCurrentFileName(nodeGraphName); QByteArray data = nodeGraphFile.readAll(); m_graphData = QString::fromStdString(data.toStdString()); graphDataChanged(); @@ -77,6 +77,14 @@ void NodeGraphEditorModel::openFile(QString filePath){ if (data.isEmpty()) return; } + +void NodeGraphEditorModel::clear() +{ + setGraphData(""); + setCurrentFileName(""); + m_saveDirectory = ""; + nodeGraphCleared(); +} QString NodeGraphEditorModel::saveDirectory(){ if (m_saveDirectory!="") { return m_saveDirectory; diff --git a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.h b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.h index 06c3a7239dc..41e2c052a86 100644 --- a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.h +++ b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.h @@ -24,6 +24,7 @@ public: Q_INVOKABLE void openFileName(QString filePath); Q_INVOKABLE void saveFile(QString fileName); Q_INVOKABLE void createQmlComponent(qan::Graph* graph); + void clear(); private: QPointer m_editorView; @@ -34,6 +35,7 @@ Q_PROPERTY(bool hasUnsavedChanges MEMBER m_hasUnsavedChanges WRITE setHasUnsaved signals: void graphDataChanged(); void nodeGraphLoaded(); +void nodeGraphCleared(); void hasUnsavedChangesChanged(); void currentFileNameChanged(); public: diff --git a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.cpp b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.cpp index 5278a88e96c..fb3cbec042d 100644 --- a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.cpp +++ b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.cpp @@ -4,7 +4,7 @@ #include "nodegrapheditorview.h" #include "nodegrapheditormodel.h" #include "nodegrapheditorwidget.h" - +#include namespace QmlDesigner { NodeGraphEditorView::NodeGraphEditorView(ExternalDependenciesInterface &externalDependencies) @@ -19,6 +19,19 @@ NodeGraphEditorView::~NodeGraphEditorView() delete m_editorWidget.data(); } + +void NodeGraphEditorView::modelAttached(QmlDesigner::Model *model) +{ + AbstractView::modelAttached(model); + QString currProjectPath = QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString(); + if (m_currProjectPath != currProjectPath) { // starting a new project + m_editorModel->clear(); + } + + m_currProjectPath = currProjectPath; +} + + WidgetInfo NodeGraphEditorView::widgetInfo() { if (!m_editorWidget) diff --git a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.h b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.h index a02e17a4f31..0de069af201 100644 --- a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.h +++ b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditorview.h @@ -19,13 +19,14 @@ public: bool hasWidget() const override { return true; } WidgetInfo widgetInfo() override; + void modelAttached(QmlDesigner::Model * model) override; private: void customNotification(const AbstractView *view, const QString &identifier, const QList &nodeList, const QList &data) override; QPointer m_editorModel; QPointer m_editorWidget; - + QString m_currProjectPath; }; } // namespace QmlDesigner