diff --git a/GUI/Model/Descriptor/AxisProperty.cpp b/GUI/Model/Descriptor/AxisProperty.cpp index 1c281bc79ea72fbd695b03e1a6ef53d3d73bcda3..48c5085d3d43853669155ecb2031634237e081bd 100644 --- a/GUI/Model/Descriptor/AxisProperty.cpp +++ b/GUI/Model/Descriptor/AxisProperty.cpp @@ -37,16 +37,18 @@ void AxisProperty::initMax(const QString& label, const QString& tooltip, double m_max.init(label, tooltip, value, unit, decimals, limits, "max"); } -void AxisProperty::serialize(Serializer& s) +std::unique_ptr<FixedBinAxis> AxisProperty::createAxis(double scaleFactor) const +{ + return std::make_unique<FixedBinAxis>(std::string(), m_nbins, m_min * scaleFactor, + m_max * scaleFactor); +} + +void AxisProperty::rwXML(Serializer& s, const QString& tag) { + s.start(tag); s.assertVersion(0); m_nbins.rwXML(s); m_min.rwXML(s); m_max.rwXML(s); -} - -std::unique_ptr<FixedBinAxis> AxisProperty::createAxis(double scaleFactor) const -{ - return std::make_unique<FixedBinAxis>(std::string(), m_nbins, m_min * scaleFactor, - m_max * scaleFactor); + s.finish(tag); } diff --git a/GUI/Model/Descriptor/AxisProperty.h b/GUI/Model/Descriptor/AxisProperty.h index c2748e43f60ef747ceb91ce4ee1aebaad6c9c8f5..4e56875bf4c6a2de35b68474dbf19bd18d757cdb 100644 --- a/GUI/Model/Descriptor/AxisProperty.h +++ b/GUI/Model/Descriptor/AxisProperty.h @@ -56,7 +56,7 @@ public: //! Creates an axis with empty title std::unique_ptr<FixedBinAxis> createAxis(double scaleFactor) const; - void rwXML(Serializer& s); + void rwXML(Serializer& s, const QString& tag); }; //! Add a member and a getter for an axis property diff --git a/GUI/Model/Device/InstrumentItems.cpp b/GUI/Model/Device/InstrumentItems.cpp index beea9f85368cfb6930bebd0453310d4b04c30df9..30606b3c14e93b53056120d5a9c5124d34f6a51d 100644 --- a/GUI/Model/Device/InstrumentItems.cpp +++ b/GUI/Model/Device/InstrumentItems.cpp @@ -264,7 +264,7 @@ void DepthProbeInstrumentItem::serialize(Serializer& s) { s.assertVersion(0); s.rwBaseClass<InstrumentItem>("InstrumentItem", this); - s.rw("zAxis", m_zAxis); + m_zAxis.rwXML(s, "zAxis"); } SpecularBeamItem* DepthProbeInstrumentItem::beamItem() const @@ -424,7 +424,7 @@ void OffSpecularInstrumentItem::serialize(Serializer& s) { s.assertVersion(0); s.rwBaseClass<Instrument2DItem>("Instrument2DItem", this); - s.rw("alphaAxis", m_alphaAxis); + m_alphaAxis.rwXML(s, "alphaAxis"); } std::vector<int> OffSpecularInstrumentItem::shape() const diff --git a/GUI/Model/Device/SphericalDetectorItem.cpp b/GUI/Model/Device/SphericalDetectorItem.cpp index 5287688a4daa8d69f52393fcbcf007bf4cac543a..73835e895ab268a1238a1e614c9fbbb3b8baa8c0 100644 --- a/GUI/Model/Device/SphericalDetectorItem.cpp +++ b/GUI/Model/Device/SphericalDetectorItem.cpp @@ -49,8 +49,8 @@ void SphericalDetectorItem::serialize(Serializer& s) s.rw<ResolutionFunctionItemCatalog>(m_resolutionFunction); // own members - s.rw("phiAxis", m_phiAxis); - s.rw("alphaAxis", m_alphaAxis); + m_phiAxis.rwXML(s, "phiAxis" ); + m_alphaAxis.rwXML(s, "alphaAxis"); if (s.xmlReader()) m_resolutionFunction->setUnit(Unit::degree); diff --git a/GUI/Model/XML/Serializer.cpp b/GUI/Model/XML/Serializer.cpp index fde02d22e6255c9ddbaea3a02e798416f4280e55..ba3c3f7dd9c9ec633ebb50226068a78a0a13ba1e 100644 --- a/GUI/Model/XML/Serializer.cpp +++ b/GUI/Model/XML/Serializer.cpp @@ -13,7 +13,6 @@ // ************************************************************************************************ #include "GUI/Model/XML/Serializer.h" -#include "GUI/Model/Descriptor/AxisProperty.h" #include "GUI/Support/Data/XML.h" #include "GUI/Util/DeserializationException.h" #include <QColor> @@ -143,19 +142,6 @@ void Serializer::rw(const QString& tag, R3& val) } } -void Serializer::rw(const QString& tag, AxisProperty& d) -{ - if (m_w) { - m_w->writeStartElement(tag); - d.serialize(*this); - m_w->writeEndElement(); - } else { - goToStartElementOfTag(tag); - d.serialize(*this); - gotoEndElementOfTag(tag); - } -} - void Serializer::gotoEndElementOfTag(const QString& tag) { if (m_r->name() != tag) { @@ -198,3 +184,19 @@ void Serializer::assertCurrentToken(QXmlStreamReader::TokenType token) const if (m_r->tokenType() != token) throw DeserializationException::streamError(); } + +void Serializer::start(const QString& tag) +{ + if (m_w) + m_w->writeStartElement(tag); + else + goToStartElementOfTag(tag); +} + +void Serializer::finish(const QString& tag) +{ + if (m_w) + m_w->writeEndElement(); + else + gotoEndElementOfTag(tag); +} diff --git a/GUI/Model/XML/Serializer.h b/GUI/Model/XML/Serializer.h index 2998c51a77b27f24777ef403ec91c67c49b5d7af..fa1e425d2346e12d19ecde17072a4cce669b1de4 100644 --- a/GUI/Model/XML/Serializer.h +++ b/GUI/Model/XML/Serializer.h @@ -20,8 +20,6 @@ #include <functional> #include <heinz/Vectors3D.h> -class AxisProperty; - namespace XML { namespace Tags { constexpr auto Id("id"); @@ -64,8 +62,6 @@ public: void rw(const QString& tag, QByteArray& val); void rw(const QString& tag, R3& val); - void rw(const QString& tag, AxisProperty& d); - //! serialize a list with a known and fixed type which is not a base class, but the real class template <typename T, typename... Args> void rw(const QString& tag, QVector<T>& vec, Args... argsForConstructor); @@ -120,6 +116,9 @@ public: void gotoEndElementOfTag(const QString& tag); void assertCurrentTag(const QString& expectedTag) const; + void start(const QString& tag); + void finish(const QString& tag); + private: void goToStartElementOfTag(const QString& tag); void assertCurrentToken(QXmlStreamReader::TokenType token) const;