Files
oak-editor/app/common/xmlutils.cpp
T
itsmattkc a1f5c85f49 various: use simpler/smarter XML reading functions
Should address any XML parsing issues and allows for simpler, more maintainable
code. Should also address a crash that could occur when pasting nodes that had
inputs that weren't copied.
2020-03-17 02:38:17 +11:00

57 lines
1.2 KiB
C++

#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) {
NodeOutput* out = output_ptrs.value(con.output);
if (out) {
NodeParam::ConnectEdge(out, con.input);
}
}
}
bool XMLReadNextStartElement(QXmlStreamReader *reader)
{
QXmlStreamReader::TokenType token;
while ((token = reader->readNext()) != QXmlStreamReader::Invalid
&& token != QXmlStreamReader::EndDocument) {
if (reader->isEndElement()) {
return false;
} else if (reader->isStartElement()) {
return true;
}
}
return false;
}