From f92d78241228f6a9c0b649c8addcc7ae82071167 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 13 May 2018 09:35:53 +0200 Subject: Added list of Instrument to Project including serialiser/deserialiser. --- src/projectserialiser.cc | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/projectserialiser.cc') 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 children() + // Get child nodes with tag_name or all child nodes if tag_name == "". + std::vector children(const QString& tag_name = "") { std::vector 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; } -- cgit v1.2.3