Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/QtNodes/internal/DagGraphicsScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NODE_EDITOR_PUBLIC DagGraphicsScene : public BasicGraphicsScene
bool isBlank() const { return _graphModel.isEmpty(); }

public Q_SLOTS:
bool save(const QString &filePath) const;
bool save(const QString &filePath, const QJsonObject &metadata = {}) const;
bool load(const QString &filePath);
void createNodeAt(const QString &name, const QPointF &pos);

Expand Down
18 changes: 16 additions & 2 deletions src/DagGraphicsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,29 @@ QMenu *DagGraphicsScene::createSceneMenu(QPointF const scenePos)
return modelMenu;
}

bool DagGraphicsScene::save(const QString &filePath) const
bool DagGraphicsScene::save(const QString &filePath, const QJsonObject &metadata) const
{
QFileInfo fileInfo(filePath);
if (fileInfo.suffix().compare("dag", Qt::CaseInsensitive) != 0)
fileInfo.setFile(fileInfo.dir(), fileInfo.baseName() + '.' + FILE_EXTENSION);
QFile file(fileInfo.absoluteFilePath());
if (!file.open(QIODevice::WriteOnly))
return false;
file.write(QJsonDocument(_graphModel.save()).toJson());

QJsonObject sceneJson = _graphModel.save();
// Merge metadata safely
if (!metadata.isEmpty()) {
QJsonObject globals;
for (auto it = metadata.begin(); it != metadata.end(); ++it) {
if (!it.value().isUndefined())
globals[it.key()] = it.value();
}

if (!globals.isEmpty())
sceneJson["globals"] = globals;
}

file.write(QJsonDocument(sceneJson).toJson());
file.close();
return true;
}
Expand Down
Loading