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

AxesItems: upd r/w

parent d424ef7a
No related branches found
No related tags found
1 merge request!1197GUI: serialization refactoring part 5
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "GUI/Support/XML/UtilXML.h" #include "GUI/Support/XML/UtilXML.h"
namespace { namespace {
namespace Tag { namespace Tag {
const QString IsVisible("IsVisible"); const QString IsVisible("IsVisible");
...@@ -25,18 +24,11 @@ const QString Nbins("Nbins"); ...@@ -25,18 +24,11 @@ const QString Nbins("Nbins");
const QString MinDeg("MinDeg"); const QString MinDeg("MinDeg");
const QString MaxDeg("MaxDeg"); const QString MaxDeg("MaxDeg");
const QString Title("Title"); const QString Title("Title");
const QString BaseData("BaseData");
const QString LockMinMax("LockMinMax"); const QString LockMinMax("LockMinMax");
const QString LogScale("LogScale"); const QString LogScale("LogScale");
} // namespace Tag } // namespace Tag
namespace Attrib {
const QString value("value");
}
} // namespace } // namespace
BasicAxisItem::BasicAxisItem(QObject* parent) BasicAxisItem::BasicAxisItem(QObject* parent)
...@@ -112,69 +104,72 @@ void BasicAxisItem::setVisible(bool b) ...@@ -112,69 +104,72 @@ void BasicAxisItem::setVisible(bool b)
emit axisVisibilityChanged(); emit axisVisibilityChanged();
} }
void BasicAxisItem::writeTo(QXmlStreamWriter* writer) const void BasicAxisItem::writeTo(QXmlStreamWriter* w) const
{ {
XML::writeAttribute(w, XML::Attrib::version, uint(1));
// visibility // visibility
writer->writeStartElement(Tag::IsVisible); w->writeStartElement(Tag::IsVisible);
XML::writeAttribute(writer, Attrib::value, m_visible); XML::writeAttribute(w, XML::Attrib::value, m_visible);
writer->writeEndElement(); w->writeEndElement();
// nbins // nbins
writer->writeStartElement(Tag::Nbins); w->writeStartElement(Tag::Nbins);
XML::writeAttribute(writer, Attrib::value, m_nbins); XML::writeAttribute(w, XML::Attrib::value, m_nbins);
writer->writeEndElement(); w->writeEndElement();
// min // min
writer->writeStartElement(Tag::MinDeg); w->writeStartElement(Tag::MinDeg);
XML::writeAttribute(writer, Attrib::value, m_minDeg); XML::writeAttribute(w, XML::Attrib::value, m_minDeg);
writer->writeEndElement(); w->writeEndElement();
// max // max
writer->writeStartElement(Tag::MaxDeg); w->writeStartElement(Tag::MaxDeg);
XML::writeAttribute(writer, Attrib::value, m_maxDeg); XML::writeAttribute(w, XML::Attrib::value, m_maxDeg);
writer->writeEndElement(); w->writeEndElement();
// title // title
writer->writeStartElement(Tag::Title); w->writeStartElement(Tag::Title);
XML::writeAttribute(writer, Attrib::value, m_title); XML::writeAttribute(w, XML::Attrib::value, m_title);
writer->writeEndElement(); w->writeEndElement();
} }
void BasicAxisItem::readFrom(QXmlStreamReader* reader) void BasicAxisItem::readFrom(QXmlStreamReader* r)
{ {
while (reader->readNextStartElement()) const uint version = XML::readUIntAttribute(r, XML::Attrib::version);
readBasicTags(reader); Q_UNUSED(version)
}
void BasicAxisItem::readBasicTags(QXmlStreamReader* reader) while (r->readNextStartElement()) {
{ QString tag = r->name().toString();
// visibility
if (reader->name() == Tag::IsVisible) {
XML::readAttribute(reader, Attrib::value, &m_visible);
XML::gotoEndElementOfTag(reader, Tag::IsVisible);
// nbins // visibility?
} else if (reader->name() == Tag::Nbins) { if (tag == Tag::IsVisible) {
XML::readAttribute(reader, Attrib::value, &m_nbins); XML::readAttribute(r, XML::Attrib::value, &m_visible);
XML::gotoEndElementOfTag(reader, Tag::Nbins); XML::gotoEndElementOfTag(r, tag);
// min // nbins
} else if (reader->name() == Tag::MinDeg) { } else if (tag == Tag::Nbins) {
XML::readAttribute(reader, Attrib::value, &m_minDeg); XML::readAttribute(r, XML::Attrib::value, &m_nbins);
XML::gotoEndElementOfTag(reader, Tag::MinDeg); XML::gotoEndElementOfTag(r, tag);
// max // min
} else if (reader->name() == Tag::MaxDeg) { } else if (tag == Tag::MinDeg) {
XML::readAttribute(reader, Attrib::value, &m_maxDeg); XML::readAttribute(r, XML::Attrib::value, &m_minDeg);
XML::gotoEndElementOfTag(reader, Tag::MaxDeg); XML::gotoEndElementOfTag(r, tag);
// title // max
} else if (reader->name() == Tag::Title) { } else if (tag == Tag::MaxDeg) {
XML::readAttribute(reader, Attrib::value, &m_title); XML::readAttribute(r, XML::Attrib::value, &m_maxDeg);
XML::gotoEndElementOfTag(reader, Tag::Title); XML::gotoEndElementOfTag(r, tag);
} else // title
reader->skipCurrentElement(); } else if (tag == Tag::Title) {
XML::readAttribute(r, XML::Attrib::value, &m_title);
XML::gotoEndElementOfTag(r, tag);
} else
r->skipCurrentElement();
}
} }
// ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- //
...@@ -186,39 +181,51 @@ AmplitudeAxisItem::AmplitudeAxisItem(QObject* parent) ...@@ -186,39 +181,51 @@ AmplitudeAxisItem::AmplitudeAxisItem(QObject* parent)
{ {
} }
void AmplitudeAxisItem::writeTo(QXmlStreamWriter* writer) const void AmplitudeAxisItem::writeTo(QXmlStreamWriter* w) const
{ {
BasicAxisItem::writeTo(writer); XML::writeAttribute(w, XML::Attrib::version, uint(1));
// parameters from base class
w->writeStartElement(Tag::BaseData);
BasicAxisItem::writeTo(w);
w->writeEndElement();
// lock min max // lock min max
writer->writeStartElement(Tag::LockMinMax); w->writeStartElement(Tag::LockMinMax);
XML::writeAttribute(writer, Attrib::value, m_lockMinMax); XML::writeAttribute(w, XML::Attrib::value, m_lockMinMax);
writer->writeEndElement(); w->writeEndElement();
// log scale // log scale
writer->writeStartElement(Tag::LogScale); w->writeStartElement(Tag::LogScale);
XML::writeAttribute(writer, Attrib::value, m_logScale); XML::writeAttribute(w, XML::Attrib::value, m_logScale);
writer->writeEndElement(); w->writeEndElement();
} }
void AmplitudeAxisItem::readFrom(QXmlStreamReader* reader) void AmplitudeAxisItem::readFrom(QXmlStreamReader* r)
{ {
while (reader->readNextStartElement()) { const uint version = XML::readUIntAttribute(r, XML::Attrib::version);
Q_UNUSED(version)
while (r->readNextStartElement()) {
QString tag = r->name().toString();
// visibility // parameters from base class
if (reader->name() == Tag::LockMinMax) { if (tag == Tag::BaseData) {
XML::readAttribute(reader, Attrib::value, &m_lockMinMax); BasicAxisItem::readFrom(r);
XML::gotoEndElementOfTag(reader, Tag::LockMinMax); XML::gotoEndElementOfTag(r, tag);
// visibility
} else if (tag == Tag::LockMinMax) {
XML::readAttribute(r, XML::Attrib::value, &m_lockMinMax);
XML::gotoEndElementOfTag(r, tag);
// title // title
} else if (reader->name() == Tag::LogScale) { } else if (tag == Tag::LogScale) {
XML::readAttribute(reader, Attrib::value, &m_logScale); XML::readAttribute(r, XML::Attrib::value, &m_logScale);
XML::gotoEndElementOfTag(reader, Tag::LogScale); XML::gotoEndElementOfTag(r, tag);
// members from base class } else
} else { r->skipCurrentElement();
BasicAxisItem::readBasicTags(reader);
}
} }
} }
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
#define BORNAGAIN_GUI_MODEL_DEVICE_AXESITEMS_H #define BORNAGAIN_GUI_MODEL_DEVICE_AXESITEMS_H
#include <QObject> #include <QObject>
#include <QXmlStreamWriter>
class IAxis; class IAxis;
class QXmlStreamReader;
class QXmlStreamWriter;
class BasicAxisItem : public QObject { class BasicAxisItem : public QObject {
Q_OBJECT Q_OBJECT
...@@ -28,11 +27,8 @@ public: ...@@ -28,11 +27,8 @@ public:
explicit BasicAxisItem(QObject* parent = nullptr); explicit BasicAxisItem(QObject* parent = nullptr);
~BasicAxisItem() override; ~BasicAxisItem() override;
virtual void writeTo(QXmlStreamWriter* writer) const; virtual void writeTo(QXmlStreamWriter* w) const;
virtual void readFrom(QXmlStreamReader* reader); virtual void readFrom(QXmlStreamReader* r);
protected:
void readBasicTags(QXmlStreamReader* reader);
public: public:
virtual std::unique_ptr<IAxis> createAxis(double scale) const; virtual std::unique_ptr<IAxis> createAxis(double scale) const;
...@@ -81,8 +77,8 @@ class AmplitudeAxisItem : public BasicAxisItem { ...@@ -81,8 +77,8 @@ class AmplitudeAxisItem : public BasicAxisItem {
public: public:
explicit AmplitudeAxisItem(QObject* parent = nullptr); explicit AmplitudeAxisItem(QObject* parent = nullptr);
void writeTo(QXmlStreamWriter* writer) const override; void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* reader) override; void readFrom(QXmlStreamReader* r) override;
bool isLogScale() const; bool isLogScale() const;
void setLogScale(bool value); void setLogScale(bool value);
......
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