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);
|
||||
NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false;
|
||||
}
|
||||
onNodeGraphCleared: {
|
||||
graphView.graph.clearGraph();
|
||||
NodeGraphEditorBackend.nodeGraphEditorModel.hasUnsavedChanges = false;
|
||||
}
|
||||
}
|
||||
|
||||
SaveAsDialog {
|
||||
|
@@ -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;
|
||||
|
@@ -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<NodeGraphEditorView> 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:
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include "nodegrapheditorview.h"
|
||||
#include "nodegrapheditormodel.h"
|
||||
#include "nodegrapheditorwidget.h"
|
||||
|
||||
#include <qmldesignerplugin.h>
|
||||
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)
|
||||
|
@@ -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<QmlDesigner::ModelNode> &nodeList, const QList<QVariant> &data) override;
|
||||
QPointer<NodeGraphEditorModel> m_editorModel;
|
||||
QPointer<NodeGraphEditorWidget> m_editorWidget;
|
||||
|
||||
QString m_currProjectPath;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
Reference in New Issue
Block a user