From af01b32c076b417ed854633d4d350882b71df818 Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de> Date: Mon, 5 Dec 2022 12:30:47 +0100 Subject: [PATCH] SelectionProperty: rwSelected is a class method now --- GUI/Model/Descriptor/SelectionProperty.h | 40 +++++-------------- GUI/Model/Device/BeamAngleItems.cpp | 4 +- GUI/Model/Device/BeamItems.cpp | 2 +- GUI/Model/Device/BeamWavelengthItem.cpp | 2 +- GUI/Model/Device/InstrumentItems.cpp | 4 +- GUI/Model/Device/RectangularDetectorItem.cpp | 2 +- .../Device/SpecularBeamInclinationItem.cpp | 2 +- GUI/Model/Device/SphericalDetectorItem.cpp | 2 +- GUI/Model/Sample/CompoundItem.cpp | 2 +- GUI/Model/Sample/InterferenceItems.cpp | 16 ++++---- GUI/Model/Sample/MesocrystalItem.cpp | 6 +-- GUI/Model/Sample/ParticleItem.cpp | 4 +- GUI/Model/Sample/ParticleLayoutItem.cpp | 2 +- 13 files changed, 35 insertions(+), 53 deletions(-) diff --git a/GUI/Model/Descriptor/SelectionProperty.h b/GUI/Model/Descriptor/SelectionProperty.h index ac88f3c3637..7871e93bd5e 100644 --- a/GUI/Model/Descriptor/SelectionProperty.h +++ b/GUI/Model/Descriptor/SelectionProperty.h @@ -148,6 +148,17 @@ public: //! Persistent tag for serializing. QString persistentTag() const { return m_persistentTag; } + template <typename... ArgsForCreation> + void rwSelected(Streamer& s, ArgsForCreation... argsForCreation) + { + if (QXmlStreamWriter* w = s.xmlWriter()) { + s.write<Catalog>(persistentTag(), m_p); + } else if (QXmlStreamReader* r = s.xmlReader()) { + CatalogedType* p = nullptr; + s.read<Catalog>(persistentTag(), p, argsForCreation...); + set(p); + } + } private: template <typename... ArgsForCreation> @@ -184,33 +195,4 @@ private: std::function<void(CatalogedType* newItem, const CatalogedType* oldItem)> m_initializer; }; -// Extends namespace defined in GUI/Model/XML/Serialize.h -namespace Serialize { - -//! Serializes an item from a catalog. -//! Passes optional arguments to the constructor. -template <typename Catalog, typename... ArgsForCreation> -void rwSelected(Streamer& s, SelectionProperty<Catalog>& d, - ArgsForCreation... argsForCreation); - -} // namespace Serialize - -// ************************************************************************************************ -// Template implementation -// ************************************************************************************************ - -template <typename Catalog, typename... ArgsForCreation> -void Serialize::rwSelected(Streamer& s, SelectionProperty<Catalog>& d, - ArgsForCreation... argsForCreation) -{ - if (QXmlStreamWriter* w = s.xmlWriter()) { - typename Catalog::CatalogedType* p = d.get(); - s.write<Catalog>(d.persistentTag(), p); - } else if (QXmlStreamReader* r = s.xmlReader()) { - typename Catalog::CatalogedType* p = nullptr; - s.read<Catalog>(d.persistentTag(), p, argsForCreation...); - d.set(p); - } -} - #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H diff --git a/GUI/Model/Device/BeamAngleItems.cpp b/GUI/Model/Device/BeamAngleItems.cpp index 469cfc6435d..822a2aac087 100644 --- a/GUI/Model/Device/BeamAngleItems.cpp +++ b/GUI/Model/Device/BeamAngleItems.cpp @@ -25,7 +25,7 @@ BeamAzimuthalAngleItem::BeamAzimuthalAngleItem() void BeamAzimuthalAngleItem::serialize(Streamer& s) { s.assertVersion(0); - Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution); + m_distribution.rwSelected(s); if (s.xmlReader()) { m_distribution->setLimits(RealLimits::limited(-90.0, 90.0)); @@ -73,7 +73,7 @@ BeamInclinationAngleItem::BeamInclinationAngleItem() void BeamInclinationAngleItem::serialize(Streamer& s) { s.assertVersion(0); - Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution); + m_distribution.rwSelected(s); if (s.xmlReader()) { m_distribution->setLimits(RealLimits::limited(-90.0, 90.0)); diff --git a/GUI/Model/Device/BeamItems.cpp b/GUI/Model/Device/BeamItems.cpp index c5ecd34ecc0..d39fd13c809 100644 --- a/GUI/Model/Device/BeamItems.cpp +++ b/GUI/Model/Device/BeamItems.cpp @@ -142,7 +142,7 @@ void SpecularBeamItem::serialize(Streamer& s) { s.assertVersion(0); Serialize::rwBaseClass<BeamItem>(s, "BeamItem", this); - Serialize::rwSelected<FootprintItemCatalog>(s, m_footprint); + m_footprint.rwSelected(s); } double SpecularBeamItem::getInclinationAngle() const diff --git a/GUI/Model/Device/BeamWavelengthItem.cpp b/GUI/Model/Device/BeamWavelengthItem.cpp index 13d6c52ff94..a18b20e0e3c 100644 --- a/GUI/Model/Device/BeamWavelengthItem.cpp +++ b/GUI/Model/Device/BeamWavelengthItem.cpp @@ -57,7 +57,7 @@ BeamWavelengthItem::BeamWavelengthItem(bool onlySymmetricDistributions) void BeamWavelengthItem::serialize(Streamer& s) { s.assertVersion(0); - Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution); + m_distribution.rwSelected(s); if (s.xmlReader()) { m_distribution->setLimits(RealLimits::positive()); diff --git a/GUI/Model/Device/InstrumentItems.cpp b/GUI/Model/Device/InstrumentItems.cpp index 7d80ce77c71..f699a69b58a 100644 --- a/GUI/Model/Device/InstrumentItems.cpp +++ b/GUI/Model/Device/InstrumentItems.cpp @@ -171,7 +171,7 @@ void InstrumentItem::serialize(Streamer& s) m_analyzerDirection.rwProperty(s, Tag::AnalyzerDirection); Serialize::rwProperty(s, Tag::AnalyzerEfficiency, m_analyzerEfficiency); Serialize::rwProperty(s, Tag::AnalyzerTotalTransmission, m_analyzerTotalTransmission); - Serialize::rwSelected<BackgroundItemCatalog>(s, m_backgroundItem); + m_backgroundItem.rwSelected(s); Serialize::rwClass(s, Tag::Beam, *m_beamItem); } @@ -357,7 +357,7 @@ void Instrument2DItem::serialize(Streamer& s) { s.assertVersion(0); Serialize::rwBaseClass<InstrumentItem>(s, "InstrumentItem", this); - Serialize::rwSelected<DetectorItemCatalog>(s, m_detectorItem); + m_detectorItem.rwSelected(s); } DetectorItem* Instrument2DItem::detectorItem() const diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp index 054f034370f..9b4abbaa8f9 100644 --- a/GUI/Model/Device/RectangularDetectorItem.cpp +++ b/GUI/Model/Device/RectangularDetectorItem.cpp @@ -119,7 +119,7 @@ void RectangularDetectorItem::serialize(Streamer& s) s.assertVersion(0); // base class members Serialize::rwClass(s, Tag::Masks, m_maskItems); - Serialize::rwSelected<ResolutionFunctionItemCatalog>(s, m_resolutionFunction); + m_resolutionFunction.rwSelected(s); // own members Serialize::rwValue(s, Tag::XSize, m_xSize); diff --git a/GUI/Model/Device/SpecularBeamInclinationItem.cpp b/GUI/Model/Device/SpecularBeamInclinationItem.cpp index d9e77cc388b..70e6c94e1cd 100644 --- a/GUI/Model/Device/SpecularBeamInclinationItem.cpp +++ b/GUI/Model/Device/SpecularBeamInclinationItem.cpp @@ -78,7 +78,7 @@ SpecularBeamInclinationItem::SpecularBeamInclinationItem(const InstrumentItem* o void SpecularBeamInclinationItem::serialize(Streamer& s) { s.assertVersion(0); - Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution); + m_distribution.rwSelected(s); Serialize::rwValue(s, "currentAxisIsUniformAxis", m_currentAxisIsUniformAxis); // r/w axes diff --git a/GUI/Model/Device/SphericalDetectorItem.cpp b/GUI/Model/Device/SphericalDetectorItem.cpp index 78a60c28bf1..695e671a01d 100644 --- a/GUI/Model/Device/SphericalDetectorItem.cpp +++ b/GUI/Model/Device/SphericalDetectorItem.cpp @@ -47,7 +47,7 @@ void SphericalDetectorItem::serialize(Streamer& s) s.assertVersion(0); // base class members Serialize::rwClass(s, "masks", m_maskItems); - Serialize::rwSelected<ResolutionFunctionItemCatalog>(s, m_resolutionFunction); + m_resolutionFunction.rwSelected(s); // own members m_phiAxis.rwAxisProperty(s, "phiAxis"); diff --git a/GUI/Model/Sample/CompoundItem.cpp b/GUI/Model/Sample/CompoundItem.cpp index de853876023..73a27a50edb 100644 --- a/GUI/Model/Sample/CompoundItem.cpp +++ b/GUI/Model/Sample/CompoundItem.cpp @@ -55,7 +55,7 @@ void CompoundItem::serialize(Streamer& s) s.assertVersion(0); Serialize::rwProperty(s, Tag::Abundance, m_abundance); m_position.rwProperty(s, Tag::Position); - Serialize::rwSelected<RotationItemCatalog>(s, m_rotation); + m_rotation.rwSelected(s); Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, Tag::Particles, m_particles, m_materials); } diff --git a/GUI/Model/Sample/InterferenceItems.cpp b/GUI/Model/Sample/InterferenceItems.cpp index ef06223cf22..9bad9effd45 100644 --- a/GUI/Model/Sample/InterferenceItems.cpp +++ b/GUI/Model/Sample/InterferenceItems.cpp @@ -75,7 +75,7 @@ void Interference1DLatticeItem::serialize(Streamer& s) Serialize::rwProperty(s, Tag::PositionVariance, m_positionVariance); Serialize::rwProperty(s, Tag::Length, m_length); Serialize::rwProperty(s, Tag::RotationAngle, m_rotationAngle); - Serialize::rwSelected<Profile1DItemCatalog>(s, m_decayFunction); + m_decayFunction.rwSelected(s); } // --------------------------------------------------------------------------------------------- // @@ -114,8 +114,8 @@ void Interference2DLatticeItem::serialize(Streamer& s) s.assertVersion(0); Serialize::rwProperty(s, Tag::PositionVariance, m_positionVariance); Serialize::rwValue(s, Tag::IntegrateOverXi, m_xiIntegration); - Serialize::rwSelected<Lattice2DItemCatalog>(s, m_latticeType); - Serialize::rwSelected<Profile2DItemCatalog>(s, m_decayFunction); + m_latticeType.rwSelected(s); + m_decayFunction.rwSelected(s); } // --------------------------------------------------------------------------------------------- // @@ -155,12 +155,12 @@ void Interference2DParacrystalItem::serialize(Streamer& s) s.assertVersion(0); Serialize::rwProperty(s, Tag::PositionVariance, m_positionVariance); Serialize::rwValue(s, Tag::IntegrateOverXi, m_xiIntegration); - Serialize::rwSelected<Lattice2DItemCatalog>(s, m_latticeType); + m_latticeType.rwSelected(s); Serialize::rwProperty(s, Tag::DampingLength, m_dampingLength); Serialize::rwProperty(s, Tag::DomainSize1, m_domainSize1); Serialize::rwProperty(s, Tag::DomainSize2, m_domainSize2); - Serialize::rwSelected<Profile2DItemCatalog>(s, m_pdf1); - Serialize::rwSelected<Profile2DItemCatalog>(s, m_pdf2); + m_pdf1.rwSelected(s); + m_pdf2.rwSelected(s); } // --------------------------------------------------------------------------------------------- // @@ -187,7 +187,7 @@ void InterferenceFinite2DLatticeItem::serialize(Streamer& s) s.assertVersion(0); Serialize::rwProperty(s, Tag::PositionVariance, m_positionVariance); Serialize::rwValue(s, Tag::IntegrateOverXi, m_xiIntegration); - Serialize::rwSelected<Lattice2DItemCatalog>(s, m_latticeType); + m_latticeType.rwSelected(s); Serialize::rwValue(s, Tag::DomainSize1, m_domainSize1); Serialize::rwValue(s, Tag::DomainSize1, m_domainSize2); } @@ -252,5 +252,5 @@ void InterferenceRadialParacrystalItem::serialize(Streamer& s) Serialize::rwProperty(s, Tag::DampingLength, m_dampingLength); Serialize::rwProperty(s, Tag::DomainSize, m_domainSize); Serialize::rwProperty(s, Tag::Kappa, m_kappa); - Serialize::rwSelected<Profile1DItemCatalog>(s, m_pdf); + m_pdf.rwSelected(s); } diff --git a/GUI/Model/Sample/MesocrystalItem.cpp b/GUI/Model/Sample/MesocrystalItem.cpp index dd3d56576b9..08463a49771 100644 --- a/GUI/Model/Sample/MesocrystalItem.cpp +++ b/GUI/Model/Sample/MesocrystalItem.cpp @@ -66,12 +66,12 @@ void MesocrystalItem::serialize(Streamer& s) s.assertVersion(0); Serialize::rwProperty(s, Tag::Abundance, m_abundance); m_position.rwProperty(s, Tag::Position); - Serialize::rwSelected<RotationItemCatalog>(s, m_rotation); + m_rotation.rwSelected(s); m_vectorA.rwProperty(s, Tag::VectorA); m_vectorB.rwProperty(s, Tag::VectorB); m_vectorC.rwProperty(s, Tag::VectorC); - Serialize::rwSelected<FormFactorItemCatalog>(s, m_outerShape); - Serialize::rwSelected<ItemWithParticlesCatalog>(s, m_basisParticle, m_materials); + m_outerShape.rwSelected(s); + m_basisParticle.rwSelected(s, m_materials); } std::unique_ptr<Mesocrystal> MesocrystalItem::createMesocrystal() const diff --git a/GUI/Model/Sample/ParticleItem.cpp b/GUI/Model/Sample/ParticleItem.cpp index 624fdd51300..89ef002bc30 100644 --- a/GUI/Model/Sample/ParticleItem.cpp +++ b/GUI/Model/Sample/ParticleItem.cpp @@ -52,8 +52,8 @@ void ParticleItem::serialize(Streamer& s) Serialize::rwValue(s, "MaterialIdentifier", m_materialIdentifier); Serialize::rwProperty(s, Tag::Abundance, m_abundance); m_position.rwProperty(s, Tag::Position); - Serialize::rwSelected<RotationItemCatalog>(s, m_rotation); - Serialize::rwSelected<FormFactorItemCatalog>(s, m_formFactor); + m_rotation.rwSelected(s); + m_formFactor.rwSelected(s); } std::unique_ptr<Particle> ParticleItem::createParticle() const diff --git a/GUI/Model/Sample/ParticleLayoutItem.cpp b/GUI/Model/Sample/ParticleLayoutItem.cpp index dc5258987f1..2264993232b 100644 --- a/GUI/Model/Sample/ParticleLayoutItem.cpp +++ b/GUI/Model/Sample/ParticleLayoutItem.cpp @@ -116,6 +116,6 @@ void ParticleLayoutItem::serialize(Streamer& s) { s.assertVersion(0); Serialize::rwProperty(s, Tag::OwnDensity, m_ownDensity); - Serialize::rwSelected<InterferenceItemCatalog>(s, m_interference); + m_interference.rwSelected(s); Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, Tag::Particles, m_particles, m_materials); } -- GitLab