timeline/project: block serializations to and from xml now include links

Fixes issue where blocks would become unlinked after copy/paste or save/load.
This commit is contained in:
itsmattkc
2020-03-31 02:38:14 +11:00
parent 53955e9632
commit a855dea8de
8 changed files with 73 additions and 9 deletions
+16 -3
View File
@@ -1,5 +1,6 @@
#include "xmlutils.h"
#include "node/block/block.h"
#include "node/factory.h"
#include "widget/nodeview/nodeviewundo.h"
@@ -31,10 +32,10 @@ Node* XMLLoadNode(QXmlStreamReader* reader) {
return node;
}
void XMLConnectNodes(const QHash<quintptr, NodeOutput*>& output_ptrs, const QList<XMLNodeData::SerializedConnection>& desired_connections, QUndoCommand *command)
void XMLConnectNodes(const XMLNodeData &xml_node_data, QUndoCommand *command)
{
foreach (const XMLNodeData::SerializedConnection& con, desired_connections) {
NodeOutput* out = output_ptrs.value(con.output);
foreach (const XMLNodeData::SerializedConnection& con, xml_node_data.desired_connections) {
NodeOutput* out = xml_node_data.output_ptrs.value(con.output);
if (out) {
if (command) {
@@ -61,3 +62,15 @@ bool XMLReadNextStartElement(QXmlStreamReader *reader)
return false;
}
void XMLLinkBlocks(const XMLNodeData &xml_node_data)
{
foreach (const XMLNodeData::BlockLink& l1, xml_node_data.block_links) {
foreach (const XMLNodeData::BlockLink& l2, xml_node_data.block_links) {
if (l1.link == l2.block->property("xml_ptr")) {
Block::Link(l1.block, l2.block);
break;
}
}
}
}
+13 -3
View File
@@ -4,13 +4,14 @@
#include <QUndoCommand>
#include <QXmlStreamReader>
#include "project/item/footage/stream.h"
class Block;
class Node;
class NodeParam;
class NodeInput;
class NodeOutput;
#include "project/item/footage/stream.h"
#define XMLAttributeLoop(reader, item) \
QXmlStreamAttributes __attributes = reader->attributes(); \
foreach (const QXmlStreamAttribute& item, __attributes)
@@ -28,14 +29,23 @@ struct XMLNodeData {
quintptr footage;
};
struct BlockLink {
Block* block;
quintptr link;
};
QHash<quintptr, NodeOutput*> output_ptrs;
QList<SerializedConnection> desired_connections;
QHash<quintptr, StreamPtr> footage_ptrs;
QList<FootageConnection> footage_connections;
QList<BlockLink> block_links;
};
void XMLConnectNodes(const QHash<quintptr, NodeOutput *> &output_ptrs, const QList<XMLNodeData::SerializedConnection> &desired_connections, QUndoCommand* command = nullptr);
void XMLConnectNodes(const XMLNodeData& xml_node_data, QUndoCommand* command = nullptr);
bool XMLReadNextStartElement(QXmlStreamReader* reader);
void XMLLinkBlocks(const XMLNodeData& xml_node_data);
#endif // XMLREADLOOP_H