summaryrefslogtreecommitdiff
path: root/src/projectserialiser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/projectserialiser.cc')
-rw-r--r--src/projectserialiser.cc43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/projectserialiser.cc b/src/projectserialiser.cc
index 4b8247f..707ff18 100644
--- a/src/projectserialiser.cc
+++ b/src/projectserialiser.cc
@@ -75,14 +75,31 @@ public:
return elem.text();
}
- std::vector<DomHelper> children()
+ // Get child nodes with tag_name or all child nodes if tag_name == "".
+ std::vector<DomHelper> children(const QString& tag_name = "")
{
std::vector<DomHelper> children;
+ auto child_nodes = elem.childNodes();
+ for(int i = 0; i < child_nodes.count(); ++i)
+ {
+ auto node = child_nodes.at(i);
+ if(!node.isElement())
+ {
+ continue;
+ }
+
+ auto elem = node.toElement();
+ if(elem.tagName() == tag_name || tag_name == "")
+ {
+ children.emplace_back(DomHelper(elem));
+ }
+ }
+
return children;
}
private:
- const QDomElement& elem;
+ QDomElement elem;
};
QString ProjectSerialiser::serialise(const Project& project)
@@ -105,6 +122,19 @@ QString ProjectSerialiser::serialise(const Project& project)
raw_file_root.appendChild(doc.createTextNode(project.raw_file_root));
dgedit.appendChild(raw_file_root);
+ auto instruments = doc.createElement("instruments");
+ dgedit.appendChild(instruments);
+
+ for(const auto& i : project.instruments)
+ {
+ auto instrument = doc.createElement("instrument");
+ instruments.appendChild(instrument);
+
+ auto instrument_name = doc.createElement("instrument_name");
+ instrument_name.appendChild(doc.createTextNode(i.instrument_name));
+ instrument.appendChild(instrument_name);
+ }
+
return doc.toString();
}
@@ -130,5 +160,14 @@ bool ProjectSerialiser::deserialise(const QString& data, Project& project)
project.project_name = dom("project_name").text();
project.raw_file_root = dom("raw_file_root").text();
+ auto instruments = dom("instruments").children("instrument");
+ for(auto& instrument : instruments)
+ {
+ project.instruments.emplace_back(Instrument(project, project.next_id));
+ ++project.next_id;
+ auto& instr = project.instruments.back();
+ instr.instrument_name = instrument("instrument_name").text();
+ }
+
return true;
}