Skip to content
Snippets Groups Projects
Commit c42b7e2f authored by Mikhail Svechnikov's avatar Mikhail Svechnikov Committed by Mikhail Svechnikov
Browse files

RoughnessItems: add writeTo & readFrom

parent c903e0e9
No related branches found
No related tags found
1 merge request!1191GUI: serialization refactoring part 3
......@@ -14,6 +14,7 @@
#include "GUI/Model/Sample/RoughnessItems.h"
#include "GUI/Support/XML/Serialize.h"
#include "GUI/Support/XML/UtilXML.h"
namespace {
namespace Tag {
......@@ -40,7 +41,59 @@ BasicRoughnessItem::BasicRoughnessItem()
void BasicRoughnessItem::serialize(Streamer& s)
{
s.assertVersion(0);
Serialize::rwProperty(s, Tag::Sigma, m_sigma);
Serialize::rwProperty(s, Tag::Hurst, m_hurst);
Serialize::rwProperty(s, Tag::LateralCorrelationLength, m_lateralCorrelationLength);
// Serialize::rwProperty(s, Tag::Sigma, m_sigma);
// Serialize::rwProperty(s, Tag::Hurst, m_hurst);
// Serialize::rwProperty(s, Tag::LateralCorrelationLength, m_lateralCorrelationLength);
if (s.xmlReader())
readFrom(s.xmlReader());
else if (s.xmlWriter())
writeTo(s.xmlWriter());
}
void BasicRoughnessItem::writeTo(QXmlStreamWriter *w) const
{
XML::writeAttribute(w, XML::Attrib::version, uint(1));
// sigma
w->writeStartElement(Tag::Sigma);
m_sigma.writeTo(w);
w->writeEndElement();
// hurst
w->writeStartElement(Tag::Hurst);
m_hurst.writeTo(w);
w->writeEndElement();
// lateral correlation length
w->writeStartElement(Tag::LateralCorrelationLength);
m_lateralCorrelationLength.writeTo(w);
w->writeEndElement();
}
void BasicRoughnessItem::readFrom(QXmlStreamReader *r)
{
const uint version = XML::readUIntAttribute(r, XML::Attrib::version);
Q_UNUSED(version)
while (r->readNextStartElement()) {
QString tag = r->name().toString();
// sigma
if (tag == Tag::Sigma) {
m_sigma.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
// hurst
} else if (tag == Tag::Hurst) {
m_hurst.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
// lateral correlation length
} else if (tag == Tag::LateralCorrelationLength) {
m_lateralCorrelationLength.readFrom(r);
XML::gotoEndElementOfTag(r, tag);
} else
r->skipCurrentElement();
}
}
......@@ -16,15 +16,16 @@
#define BORNAGAIN_GUI_MODEL_SAMPLE_ROUGHNESSITEMS_H
#include "GUI/Model/Descriptor/DoubleProperty.h"
#include <QXmlStreamReader>
class QXmlStreamReader;
class QXmlStreamWriter;
class Streamer;
class RoughnessItem {
public:
virtual ~RoughnessItem() = default;
virtual void serialize(Streamer& s) = 0;
virtual void writeTo(QXmlStreamWriter* w) const = 0;
virtual void readFrom(QXmlStreamReader* r) = 0;
virtual DoubleProperties roughnessProperties() = 0;
protected:
......@@ -48,6 +49,8 @@ public:
void setLateralCorrelationLength(double v) { m_lateralCorrelationLength.setValue(v); }
void serialize(Streamer& s) override;
void writeTo(QXmlStreamWriter* w) const;
void readFrom(QXmlStreamReader* r);
DoubleProperties roughnessProperties() override
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment