BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
VectorProperty.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/VectorProperty.cpp
6 //! @brief Implements class VectorProperty
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
18 #include <QUuid>
19 
20 void VectorProperty::init(const QString& label, const QString& tooltip,
21  const variant<QString, Unit>& unit, const QString& persistentTag)
22 {
24  m_uid = QUuid::createUuid().toString();
25 
26  m_descriptor.init(label, tooltip, &m_value, unit);
27  m_descriptor.uid = [this] { return m_uid; };
28 }
29 
30 
32 {
33  if (QXmlStreamWriter* w = s.xmlWriter()) {
34  w->writeStartElement(d.persistentTag());
37  w->writeEndElement();
38  } else if (QXmlStreamReader* r = s.xmlReader()) {
39  r->readNextStartElement();
41  R3 vec;
42  QString uid;
45  d.set(vec);
46  d.setUid(uid);
48  } else
49  ASSERT(0);
50 }
Defines class Streamer.
Defines.
Defines class VectorProperty.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
void gotoEndElementOfTag(const QString &tag)
Definition: Streamer.cpp:39
void assertCurrentTag(const QString &expectedTag) const
Definition: Streamer.cpp:62
QXmlStreamWriter * xmlWriter()
Returns stream writer or nullptr.
Definition: Streamer.h:47
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void init(const QString &_label, const QString &_tooltip, const R3 *vec, const variant< QString, Unit > &_unit)
function< QString()> uid
unique id describing this value. Used e.g. for undo/redo
Holds a 3D vector of type R3 as well as additional info like label, tooltip.
QString m_persistentTag
QString persistentTag() const
void set(const R3 &d)
void setUid(const QString &uid)
void init(const QString &label, const QString &tooltip, const variant< QString, Unit > &unit, const QString &persistentTag)
R3 get() const
QString uid() const
VectorDescriptor m_descriptor
void readAttribute(QXmlStreamReader *reader, const QString &attributeName, double *d)
Definition: UtilXML.cpp:193
void writeUid(QXmlStreamWriter *writer, const QString &id)
Definition: UtilXML.cpp:127
void writeAttribute(QXmlStreamWriter *writer, const QString &attributeName, const QVariant &variant)
Write the variant's value as an attribute.
Definition: UtilXML.cpp:65
void rwProperty(Streamer &s, DoubleProperty &d)
constexpr auto Id("id")
constexpr auto Value("value")