move xmlnodedata to serializers

Since this differs between serializers too, move the class into each with changes as appropriate
This commit is contained in:
itsmattkc
2022-01-22 21:09:36 -08:00
parent 83fad2a438
commit 8f8d43f634
9 changed files with 88 additions and 40 deletions
-31
View File
@@ -36,37 +36,6 @@ class NodeGroup;
#define XMLAttributeLoop(reader, item) \
foreach (const QXmlStreamAttribute& item, reader->attributes())
struct XMLNodeData {
struct SerializedConnection {
NodeInput input;
quintptr output_node;
/// Deprecated
QString output_param;
};
struct BlockLink {
Node* block;
quintptr link;
};
struct GroupLink {
NodeGroup *group;
quintptr input_node;
QString input_id;
int input_element;
};
QHash<quintptr, Node*> node_ptrs;
QList<SerializedConnection> desired_connections;
QList<BlockLink> block_links;
QVector<GroupLink> group_input_links;
QHash<NodeGroup*, quintptr> group_output_links;
void PostConnect(uint version, MultiUndoCommand *command = nullptr) const;
};
/**
* @brief Workaround for QXmlStreamReader::readNextStartElement not detecting the end of a document
*
@@ -40,7 +40,7 @@ ProjectSerializer210528::LoadData ProjectSerializer210528::Load(Project *project
// can continue loading and queue it with the main window so it can handle the data
// appropriately in its own thread.
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data));
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data.node_ptrs));
} else if (reader->name() == QStringLiteral("uuid")) {
@@ -39,6 +39,33 @@ protected:
}
private:
struct XMLNodeData {
struct SerializedConnection {
NodeInput input;
quintptr output_node;
QString output_param;
};
struct BlockLink {
Node* block;
quintptr link;
};
struct GroupLink {
NodeGroup *group;
quintptr input_node;
QString input_id;
int input_element;
};
QHash<quintptr, Node*> node_ptrs;
QList<SerializedConnection> desired_connections;
QList<BlockLink> block_links;
QVector<GroupLink> group_input_links;
QHash<NodeGroup*, quintptr> group_output_links;
};
void LoadNode(Node *node, XMLNodeData &xml_node_data, QXmlStreamReader *reader) const;
void LoadInput(Node *node, QXmlStreamReader* reader, XMLNodeData &xml_node_data) const;
@@ -40,7 +40,7 @@ ProjectSerializer210907::LoadData ProjectSerializer210907::Load(Project *project
// can continue loading and queue it with the main window so it can handle the data
// appropriately in its own thread.
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data));
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data.node_ptrs));
} else if (reader->name() == QStringLiteral("uuid")) {
@@ -219,7 +219,7 @@ void ProjectSerializer210907::LoadNode(Node *node, XMLNodeData &xml_node_data, Q
}
}
xml_node_data.desired_connections.append({NodeInput(node, param_id, ele), output_node_id.toULongLong(), QString()});
xml_node_data.desired_connections.append({NodeInput(node, param_id, ele), output_node_id.toULongLong()});
} else {
reader->skipCurrentElement();
}
@@ -39,6 +39,32 @@ protected:
}
private:
struct XMLNodeData {
struct SerializedConnection {
NodeInput input;
quintptr output_node;
};
struct BlockLink {
Node* block;
quintptr link;
};
struct GroupLink {
NodeGroup *group;
quintptr input_node;
QString input_id;
int input_element;
};
QHash<quintptr, Node*> node_ptrs;
QList<SerializedConnection> desired_connections;
QList<BlockLink> block_links;
QVector<GroupLink> group_input_links;
QHash<NodeGroup*, quintptr> group_output_links;
};
void LoadNode(Node *node, XMLNodeData &xml_node_data, QXmlStreamReader *reader) const;
void LoadInput(Node *node, QXmlStreamReader* reader, XMLNodeData &xml_node_data) const;
@@ -42,7 +42,7 @@ ProjectSerializer211228::LoadData ProjectSerializer211228::Load(Project *project
// can continue loading and queue it with the main window so it can handle the data
// appropriately in its own thread.
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data));
project->SetLayoutInfo(MainWindowLayoutInfo::fromXml(reader, xml_node_data.node_ptrs));
} else if (reader->name() == QStringLiteral("uuid")) {
@@ -341,7 +341,7 @@ void ProjectSerializer211228::LoadNode(Node *node, XMLNodeData &xml_node_data, Q
}
}
xml_node_data.desired_connections.append({NodeInput(node, param_id, ele), output_node_id.toULongLong(), QString()});
xml_node_data.desired_connections.append({NodeInput(node, param_id, ele), output_node_id.toULongLong()});
} else {
reader->skipCurrentElement();
}
@@ -41,6 +41,32 @@ protected:
}
private:
struct XMLNodeData {
struct SerializedConnection {
NodeInput input;
quintptr output_node;
};
struct BlockLink {
Node* block;
quintptr link;
};
struct GroupLink {
NodeGroup *group;
quintptr input_node;
QString input_id;
int input_element;
};
QHash<quintptr, Node*> node_ptrs;
QList<SerializedConnection> desired_connections;
QList<BlockLink> block_links;
QVector<GroupLink> group_input_links;
QHash<NodeGroup*, quintptr> group_output_links;
};
void LoadNode(Node *node, XMLNodeData &xml_node_data, QXmlStreamReader *reader) const;
void SaveNode(Node *node, QXmlStreamWriter *writer) const;
@@ -32,7 +32,7 @@ void MainWindowLayoutInfo::toXml(QXmlStreamWriter *writer) const
writer->writeEndElement(); // layout
}
MainWindowLayoutInfo MainWindowLayoutInfo::fromXml(QXmlStreamReader *reader, XMLNodeData &xml_data)
MainWindowLayoutInfo MainWindowLayoutInfo::fromXml(QXmlStreamReader *reader, const QHash<quintptr, Node *> &node_ptrs)
{
MainWindowLayoutInfo info;
@@ -43,7 +43,7 @@ MainWindowLayoutInfo MainWindowLayoutInfo::fromXml(QXmlStreamReader *reader, XML
if (reader->name() == QStringLiteral("folder")) {
quintptr item_id = reader->readElementText().toULongLong();
Folder* open_item = static_cast<Folder*>(xml_data.node_ptrs.value(item_id));
Folder* open_item = static_cast<Folder*>(node_ptrs.value(item_id));
info.open_folders_.append(open_item);
} else {
reader->skipCurrentElement();
@@ -59,7 +59,7 @@ MainWindowLayoutInfo MainWindowLayoutInfo::fromXml(QXmlStreamReader *reader, XML
if (reader->name() == QStringLiteral("sequence")) {
quintptr item_id = reader->readElementText().toULongLong();
open_seq = static_cast<Sequence*>(xml_data.node_ptrs.value(item_id));
open_seq = static_cast<Sequence*>(node_ptrs.value(item_id));
} else if (reader->name() == QStringLiteral("state")) {
tl_state = QByteArray::fromBase64(reader->readElementText().toUtf8());
} else {
+1 -1
View File
@@ -13,7 +13,7 @@ public:
void toXml(QXmlStreamWriter* writer) const;
static MainWindowLayoutInfo fromXml(QXmlStreamReader* reader, XMLNodeData &xml_data);
static MainWindowLayoutInfo fromXml(QXmlStreamReader* reader, const QHash<quintptr, Node*> &node_map);
void add_folder(Folder* f);