Skip to content
Snippets Groups Projects
Commit 848e4325 authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

ditto for AxisProperty

parent 8b34d335
No related branches found
No related tags found
1 merge request!707Split serializer
...@@ -37,16 +37,18 @@ void AxisProperty::initMax(const QString& label, const QString& tooltip, double ...@@ -37,16 +37,18 @@ void AxisProperty::initMax(const QString& label, const QString& tooltip, double
m_max.init(label, tooltip, value, unit, decimals, limits, "max"); 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); s.assertVersion(0);
m_nbins.rwXML(s); m_nbins.rwXML(s);
m_min.rwXML(s); m_min.rwXML(s);
m_max.rwXML(s); m_max.rwXML(s);
} s.finish(tag);
std::unique_ptr<FixedBinAxis> AxisProperty::createAxis(double scaleFactor) const
{
return std::make_unique<FixedBinAxis>(std::string(), m_nbins, m_min * scaleFactor,
m_max * scaleFactor);
} }
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
//! Creates an axis with empty title //! Creates an axis with empty title
std::unique_ptr<FixedBinAxis> createAxis(double scaleFactor) const; 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 //! Add a member and a getter for an axis property
......
...@@ -264,7 +264,7 @@ void DepthProbeInstrumentItem::serialize(Serializer& s) ...@@ -264,7 +264,7 @@ void DepthProbeInstrumentItem::serialize(Serializer& s)
{ {
s.assertVersion(0); s.assertVersion(0);
s.rwBaseClass<InstrumentItem>("InstrumentItem", this); s.rwBaseClass<InstrumentItem>("InstrumentItem", this);
s.rw("zAxis", m_zAxis); m_zAxis.rwXML(s, "zAxis");
} }
SpecularBeamItem* DepthProbeInstrumentItem::beamItem() const SpecularBeamItem* DepthProbeInstrumentItem::beamItem() const
...@@ -424,7 +424,7 @@ void OffSpecularInstrumentItem::serialize(Serializer& s) ...@@ -424,7 +424,7 @@ void OffSpecularInstrumentItem::serialize(Serializer& s)
{ {
s.assertVersion(0); s.assertVersion(0);
s.rwBaseClass<Instrument2DItem>("Instrument2DItem", this); s.rwBaseClass<Instrument2DItem>("Instrument2DItem", this);
s.rw("alphaAxis", m_alphaAxis); m_alphaAxis.rwXML(s, "alphaAxis");
} }
std::vector<int> OffSpecularInstrumentItem::shape() const std::vector<int> OffSpecularInstrumentItem::shape() const
......
...@@ -49,8 +49,8 @@ void SphericalDetectorItem::serialize(Serializer& s) ...@@ -49,8 +49,8 @@ void SphericalDetectorItem::serialize(Serializer& s)
s.rw<ResolutionFunctionItemCatalog>(m_resolutionFunction); s.rw<ResolutionFunctionItemCatalog>(m_resolutionFunction);
// own members // own members
s.rw("phiAxis", m_phiAxis); m_phiAxis.rwXML(s, "phiAxis" );
s.rw("alphaAxis", m_alphaAxis); m_alphaAxis.rwXML(s, "alphaAxis");
if (s.xmlReader()) if (s.xmlReader())
m_resolutionFunction->setUnit(Unit::degree); m_resolutionFunction->setUnit(Unit::degree);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
// ************************************************************************************************ // ************************************************************************************************
#include "GUI/Model/XML/Serializer.h" #include "GUI/Model/XML/Serializer.h"
#include "GUI/Model/Descriptor/AxisProperty.h"
#include "GUI/Support/Data/XML.h" #include "GUI/Support/Data/XML.h"
#include "GUI/Util/DeserializationException.h" #include "GUI/Util/DeserializationException.h"
#include <QColor> #include <QColor>
...@@ -143,19 +142,6 @@ void Serializer::rw(const QString& tag, R3& val) ...@@ -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) void Serializer::gotoEndElementOfTag(const QString& tag)
{ {
if (m_r->name() != tag) { if (m_r->name() != tag) {
...@@ -198,3 +184,19 @@ void Serializer::assertCurrentToken(QXmlStreamReader::TokenType token) const ...@@ -198,3 +184,19 @@ void Serializer::assertCurrentToken(QXmlStreamReader::TokenType token) const
if (m_r->tokenType() != token) if (m_r->tokenType() != token)
throw DeserializationException::streamError(); 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);
}
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include <functional> #include <functional>
#include <heinz/Vectors3D.h> #include <heinz/Vectors3D.h>
class AxisProperty;
namespace XML { namespace XML {
namespace Tags { namespace Tags {
constexpr auto Id("id"); constexpr auto Id("id");
...@@ -64,8 +62,6 @@ public: ...@@ -64,8 +62,6 @@ public:
void rw(const QString& tag, QByteArray& val); void rw(const QString& tag, QByteArray& val);
void rw(const QString& tag, R3& 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 //! serialize a list with a known and fixed type which is not a base class, but the real class
template <typename T, typename... Args> template <typename T, typename... Args>
void rw(const QString& tag, QVector<T>& vec, Args... argsForConstructor); void rw(const QString& tag, QVector<T>& vec, Args... argsForConstructor);
...@@ -120,6 +116,9 @@ public: ...@@ -120,6 +116,9 @@ public:
void gotoEndElementOfTag(const QString& tag); void gotoEndElementOfTag(const QString& tag);
void assertCurrentTag(const QString& expectedTag) const; void assertCurrentTag(const QString& expectedTag) const;
void start(const QString& tag);
void finish(const QString& tag);
private: private:
void goToStartElementOfTag(const QString& tag); void goToStartElementOfTag(const QString& tag);
void assertCurrentToken(QXmlStreamReader::TokenType token) const; void assertCurrentToken(QXmlStreamReader::TokenType token) const;
......
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