nodeview: implemented copying/pasting nodes
Re-uses XML-based project saving/loading functions to store nodes, their parameters, and their connections in a text-based format in the clipboard.
This commit is contained in:
@@ -45,5 +45,7 @@ set(OLIVE_SOURCES
|
||||
common/timelinecommon.h
|
||||
common/timerange.h
|
||||
common/timerange.cpp
|
||||
common/xmlutils.h
|
||||
common/xmlutils.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "xmlutils.h"
|
||||
|
||||
#include "node/factory.h"
|
||||
|
||||
Node* XMLLoadNode(QXmlStreamReader* reader) {
|
||||
QString node_id;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == "id") {
|
||||
node_id = attr.value().toString();
|
||||
|
||||
// Currently the only thing we need
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (node_id.isEmpty()) {
|
||||
qWarning() << "Found node with no ID";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node* node = NodeFactory::CreateFromID(node_id);
|
||||
|
||||
if (!node) {
|
||||
qWarning() << "Failed to load" << node_id << "- no node with that ID is installed";
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void XMLConnectNodes(const QHash<quintptr, NodeOutput*>& output_ptrs, const QList<NodeParam::SerializedConnection>& desired_connections)
|
||||
{
|
||||
foreach (const NodeParam::SerializedConnection& con, desired_connections) {
|
||||
NodeParam::ConnectEdge(output_ptrs.value(con.output),
|
||||
con.input);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef XMLREADLOOP_H
|
||||
#define XMLREADLOOP_H
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
#define XMLReadLoop(reader, section) \
|
||||
while (!reader->atEnd() && !(reader->name() == section && reader->isEndElement()) && reader->readNext())
|
||||
|
||||
@@ -8,4 +12,8 @@
|
||||
QXmlStreamAttributes __attributes = reader->attributes(); \
|
||||
foreach (const QXmlStreamAttribute& item, __attributes)
|
||||
|
||||
Node *XMLLoadNode(QXmlStreamReader* reader);
|
||||
|
||||
void XMLConnectNodes(const QHash<quintptr, NodeOutput *> &output_ptrs, const QList<NodeParam::SerializedConnection> &desired_connections);
|
||||
|
||||
#endif // XMLREADLOOP_H
|
||||
Reference in New Issue
Block a user