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

XML::writeChosen with template paremeters B, C

parent ec4a7aca
No related branches found
No related tags found
1 merge request!2696PolyItem -> PolyPtr, with BaseItem as separate template parameter
...@@ -40,7 +40,7 @@ RegionOfInterestItem* MasksSet::regionOfInterestItem() const ...@@ -40,7 +40,7 @@ RegionOfInterestItem* MasksSet::regionOfInterestItem() const
void MasksSet::writeTo(QXmlStreamWriter* w) const void MasksSet::writeTo(QXmlStreamWriter* w) const
{ {
for (const MaskItem* t : *this) for (const MaskItem* t : *this)
XML::writeChosen<MaskCatalog>(t, w, Tag::Mask); XML::writeChosen<MaskItem, MaskCatalog>(t, w, Tag::Mask);
} }
void MasksSet::readFrom(QXmlStreamReader* r) void MasksSet::readFrom(QXmlStreamReader* r)
......
...@@ -63,7 +63,7 @@ void CompoundItem::writeTo(QXmlStreamWriter* w) const ...@@ -63,7 +63,7 @@ void CompoundItem::writeTo(QXmlStreamWriter* w) const
{ {
XML::writeBaseElement<ItemWithParticles>(w, XML::Tag::BaseData, this); XML::writeBaseElement<ItemWithParticles>(w, XML::Tag::BaseData, this);
for (auto* t : m_particles) for (auto* t : m_particles)
XML::writeChosen<ParticleCatalog>(t, w, Tag::Particle); XML::writeChosen<ItemWithParticles, ParticleCatalog>(t, w, Tag::Particle);
XML::writeTaggedValue(w, Tag::ExpandCompoundGroupbox, expandCompound); XML::writeTaggedValue(w, Tag::ExpandCompoundGroupbox, expandCompound);
} }
......
...@@ -101,7 +101,7 @@ void ParticleLayoutItem::writeTo(QXmlStreamWriter* w) const ...@@ -101,7 +101,7 @@ void ParticleLayoutItem::writeTo(QXmlStreamWriter* w) const
m_own_density.writeTo2(w, Tag::OwnDensity); m_own_density.writeTo2(w, Tag::OwnDensity);
XML::writeTaggedElement(w, Tag::InterferenceFunction, m_interference); XML::writeTaggedElement(w, Tag::InterferenceFunction, m_interference);
for (auto* t : m_particles) for (auto* t : m_particles)
XML::writeChosen<ParticleCatalog>(t, w, Tag::Particle); XML::writeChosen<ItemWithParticles, ParticleCatalog>(t, w, Tag::Particle);
XML::writeTaggedValue(w, Tag::ExpandLayoutGroupbox, expandParticleLayout); XML::writeTaggedValue(w, Tag::ExpandLayoutGroupbox, expandParticleLayout);
XML::writeTaggedValue(w, Tag::ExpandInterferenceGroupbox, expandInterference); XML::writeTaggedValue(w, Tag::ExpandInterferenceGroupbox, expandInterference);
} }
......
...@@ -30,7 +30,7 @@ InstrumentsSet::~InstrumentsSet() = default; ...@@ -30,7 +30,7 @@ InstrumentsSet::~InstrumentsSet() = default;
void InstrumentsSet::writeTo(QXmlStreamWriter* w) const void InstrumentsSet::writeTo(QXmlStreamWriter* w) const
{ {
for (const InstrumentItem* t : *this) for (const InstrumentItem* t : *this)
XML::writeChosen<InstrumentCatalog>(t, w, Tag::Instrument); XML::writeChosen<InstrumentItem, InstrumentCatalog>(t, w, Tag::Instrument);
XML::writeTaggedValue(w, Tag::CurrentIndex, (int)currentIndex()); XML::writeTaggedValue(w, Tag::CurrentIndex, (int)currentIndex());
} }
......
...@@ -125,21 +125,21 @@ typename C::BaseItem* readChosen(QXmlStreamReader* r, const QString& tag, Args.. ...@@ -125,21 +125,21 @@ typename C::BaseItem* readChosen(QXmlStreamReader* r, const QString& tag, Args..
return t; return t;
} }
template <typename C> void writeItemTo(const typename C::BaseItem* t, QXmlStreamWriter* w) template <typename B, typename C> void writeItemTo(const B* t, QXmlStreamWriter* w)
{ {
const uint typeIndex = static_cast<uint>(C::type(t)); const uint typeIndex = static_cast<uint>(C::type(t));
XML::writeAttribute(w, XML::Attrib::type, typeIndex); writeAttribute(w, Attrib::type, typeIndex);
// The next line allows to see the name of item type in XML. May be skipped while reading. // The next line allows to see the name of item type in XML. May be skipped while reading.
XML::writeAttribute(w, XML::Attrib::kind, C::uiInfo(C::type(t)).menuEntry); writeAttribute(w, Attrib::kind, C::uiInfo(C::type(t)).menuEntry);
if (t) if (t)
t->writeTo(w); t->writeTo(w);
} }
template <typename C> template <typename B, typename C>
void writeChosen(const typename C::BaseItem* t, QXmlStreamWriter* w, const QString& tag) void writeChosen(const B* t, QXmlStreamWriter* w, const QString& tag)
{ {
w->writeStartElement(tag); w->writeStartElement(tag);
XML::writeItemTo<C>(t, w); writeItemTo<B, C>(t, w);
w->writeEndElement(); w->writeEndElement();
} }
......
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