BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UIntProperty.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/UIntProperty.cpp
6 //! @brief Implements class UIntProperty
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 UIntProperty::init(const QString& label, const QString& tooltip, uint value,
21  const variant<QString, Unit>& unit, const QString& persistentTag)
22 {
23  init(label, tooltip, value, unit, RealLimits::nonnegative(), persistentTag);
24 }
25 
26 void UIntProperty::init(const QString& label, const QString& tooltip, uint value,
27  const variant<QString, Unit>& unit, const RealLimits& limits,
28  const QString& persistentTag)
29 {
30  m_value = value;
32  m_uid = QUuid::createUuid().toString();
33 
34  m_descriptor.label = label;
35  m_descriptor.tooltip = tooltip;
36  m_descriptor.limits = limits;
37  m_descriptor.unit = unit;
38  m_descriptor.set = [=](double v) { m_value = v; };
39  m_descriptor.get = [=] { return m_value; };
40  m_descriptor.path = [=] { return m_uid; };
41 }
42 
43 
45 {
46  if (QXmlStreamWriter* w = s.xmlWriter()) {
47  w->writeStartElement(d.persistentTag());
50  w->writeEndElement();
51  } else if (QXmlStreamReader* r = s.xmlReader()) {
52  r->readNextStartElement();
54  d.set(r->attributes().value(XML::Tags::Value).toUInt());
55  d.setUid(r->attributes().value(XML::Tags::Id).toString());
57  } else
58  ASSERT(0);
59 }
Defines class Streamer.
Defines class UIntProperty.
Defines.
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
QString label
A label text (short, no trailing colon)
function< void(uint)> set
function to set the value
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString tooltip
Tooltip text.
RealLimits limits
Limits of the value.
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
function< uint()> get
function to get the current value
Class for representing a uint value, its attributes and its accessors.
Definition: UIntProperty.h:39
void setUid(const QString &uid)
Definition: UIntProperty.h:55
QString persistentTag() const
Definition: UIntProperty.h:53
uint get() const
Definition: UIntProperty.h:51
void set(uint d)
Definition: UIntProperty.h:50
UIntDescriptor m_descriptor
Definition: UIntProperty.h:62
QString m_uid
Definition: UIntProperty.h:60
QString m_persistentTag
Definition: UIntProperty.h:59
void init(const QString &label, const QString &tooltip, uint value, const variant< QString, Unit > &unit, const QString &persistentTag)
QString uid() const
Definition: UIntProperty.h:54
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")