Skip to content
Snippets Groups Projects

GUI: serialization refactoring part 7

Merged Mikhail Svechnikov requested to merge serialization_7 into main
2 files
+ 39
3
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -14,6 +14,7 @@
#include "GUI/Model/Device/BackgroundItems.h"
#include "GUI/Support/XML/Serialize.h"
#include "GUI/Support/XML/UtilXML.h"
#include "Sim/Background/ConstantBackground.h"
#include "Sim/Background/PoissonBackground.h"
@@ -38,8 +39,40 @@ std::unique_ptr<IBackground> ConstantBackgroundItem::createBackground() const
void ConstantBackgroundItem::serialize(Streamer& s)
{
s.assertVersion(0);
Serialize::rwProperty(s, Tag::BackgroundValue, m_backgroundValue);
// s.assertVersion(0);
// Serialize::rwProperty(s, Tag::BackgroundValue, m_backgroundValue);
if (s.xmlReader())
readFrom(s.xmlReader());
else if (s.xmlWriter())
writeTo(s.xmlWriter());
}
void ConstantBackgroundItem::writeTo(QXmlStreamWriter *w) const
{
XML::writeAttribute(w, XML::Attrib::version, uint(1));
// background value
w->writeStartElement(Tag::BackgroundValue);
m_backgroundValue.writeTo(w);
w->writeEndElement();
}
void ConstantBackgroundItem::readFrom(QXmlStreamReader *r)
{
const uint version = XML::readUIntAttribute(r, XML::Attrib::version);
Q_UNUSED(version)
while (r->readNextStartElement()) {
QString tag = r->name().toString();
// background value
if (tag == Tag::BackgroundValue) {
m_backgroundValue.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
} else
r->skipCurrentElement();
}
}
std::unique_ptr<IBackground> PoissonBackgroundItem::createBackground() const
Loading