forked from qt-creator/qt-creator
Clear node graph data on project change
Change-Id: Ic778e4e8eef3b29e2025d786f2b9e7658a7b2dec Reviewed-by: spyro-adb <adb@spyro-soft.com>
This commit is contained in:
committed by
spyro-adb
parent
d1e475f9f2
commit
ed965a55bf
@@ -159,6 +159,10 @@ Item {
|
|||||||
initEdges(edges);
|
initEdges(edges);
|
||||||
NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false;
|
NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false;
|
||||||
}
|
}
|
||||||
|
onNodeGraphCleared: {
|
||||||
|
graphView.graph.clearGraph();
|
||||||
|
NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveAsDialog {
|
SaveAsDialog {
|
||||||
|
@@ -61,13 +61,13 @@ void NodeGraphEditorModel::saveFile(QString fileName){
|
|||||||
|
|
||||||
void NodeGraphEditorModel::openFile(QString filePath){
|
void NodeGraphEditorModel::openFile(QString filePath){
|
||||||
const QString nodeGraphName = QFileInfo(filePath).baseName();
|
const QString nodeGraphName = QFileInfo(filePath).baseName();
|
||||||
setCurrentFileName(nodeGraphName);
|
|
||||||
QFile nodeGraphFile(filePath);
|
QFile nodeGraphFile(filePath);
|
||||||
if (!nodeGraphFile.open(QIODevice::ReadOnly)) {
|
if (!nodeGraphFile.open(QIODevice::ReadOnly)) {
|
||||||
QString error = QString("Couldn't open node graph file: '%1'").arg(filePath);
|
QString error = QString("Couldn't open node graph file: '%1'").arg(filePath);
|
||||||
qWarning() << qPrintable(error);
|
qWarning() << qPrintable(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setCurrentFileName(nodeGraphName);
|
||||||
QByteArray data = nodeGraphFile.readAll();
|
QByteArray data = nodeGraphFile.readAll();
|
||||||
m_graphData = QString::fromStdString(data.toStdString());
|
m_graphData = QString::fromStdString(data.toStdString());
|
||||||
graphDataChanged();
|
graphDataChanged();
|
||||||
@@ -77,6 +77,14 @@ void NodeGraphEditorModel::openFile(QString filePath){
|
|||||||
if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeGraphEditorModel::clear()
|
||||||
|
{
|
||||||
|
setGraphData("");
|
||||||
|
setCurrentFileName("");
|
||||||
|
m_saveDirectory = "";
|
||||||
|
nodeGraphCleared();
|
||||||
|
}
|
||||||
QString NodeGraphEditorModel::saveDirectory(){
|
QString NodeGraphEditorModel::saveDirectory(){
|
||||||
if (m_saveDirectory!="") {
|
if (m_saveDirectory!="") {
|
||||||
return m_saveDirectory;
|
return m_saveDirectory;
|
||||||
|
@@ -24,6 +24,7 @@ public:
|
|||||||
Q_INVOKABLE void openFileName(QString filePath);
|
Q_INVOKABLE void openFileName(QString filePath);
|
||||||
Q_INVOKABLE void saveFile(QString fileName);
|
Q_INVOKABLE void saveFile(QString fileName);
|
||||||
Q_INVOKABLE void createQmlComponent(qan::Graph* graph);
|
Q_INVOKABLE void createQmlComponent(qan::Graph* graph);
|
||||||
|
void clear();
|
||||||
private:
|
private:
|
||||||
QPointer<NodeGraphEditorView> m_editorView;
|
QPointer<NodeGraphEditorView> m_editorView;
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ Q_PROPERTY(bool hasUnsavedChanges MEMBER m_hasUnsavedChanges WRITE setHasUnsaved
|
|||||||
signals:
|
signals:
|
||||||
void graphDataChanged();
|
void graphDataChanged();
|
||||||
void nodeGraphLoaded();
|
void nodeGraphLoaded();
|
||||||
|
void nodeGraphCleared();
|
||||||
void hasUnsavedChangesChanged();
|
void hasUnsavedChangesChanged();
|
||||||
void currentFileNameChanged();
|
void currentFileNameChanged();
|
||||||
public:
|
public:
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
#include "nodegrapheditorview.h"
|
#include "nodegrapheditorview.h"
|
||||||
#include "nodegrapheditormodel.h"
|
#include "nodegrapheditormodel.h"
|
||||||
#include "nodegrapheditorwidget.h"
|
#include "nodegrapheditorwidget.h"
|
||||||
|
#include <qmldesignerplugin.h>
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
NodeGraphEditorView::NodeGraphEditorView(ExternalDependenciesInterface &externalDependencies)
|
NodeGraphEditorView::NodeGraphEditorView(ExternalDependenciesInterface &externalDependencies)
|
||||||
@@ -19,6 +19,19 @@ NodeGraphEditorView::~NodeGraphEditorView()
|
|||||||
delete m_editorWidget.data();
|
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()
|
WidgetInfo NodeGraphEditorView::widgetInfo()
|
||||||
{
|
{
|
||||||
if (!m_editorWidget)
|
if (!m_editorWidget)
|
||||||
|
@@ -19,13 +19,14 @@ public:
|
|||||||
|
|
||||||
bool hasWidget() const override { return true; }
|
bool hasWidget() const override { return true; }
|
||||||
WidgetInfo widgetInfo() override;
|
WidgetInfo widgetInfo() override;
|
||||||
|
void modelAttached(QmlDesigner::Model * model) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void customNotification(const AbstractView *view, const QString &identifier,
|
void customNotification(const AbstractView *view, const QString &identifier,
|
||||||
const QList<QmlDesigner::ModelNode> &nodeList, const QList<QVariant> &data) override;
|
const QList<QmlDesigner::ModelNode> &nodeList, const QList<QVariant> &data) override;
|
||||||
QPointer<NodeGraphEditorModel> m_editorModel;
|
QPointer<NodeGraphEditorModel> m_editorModel;
|
||||||
QPointer<NodeGraphEditorWidget> m_editorWidget;
|
QPointer<NodeGraphEditorWidget> m_editorWidget;
|
||||||
|
QString m_currProjectPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user