BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UIntProperty.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/UIntProperty.h
6 //! @brief Defines 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 
15 #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_UINTPROPERTY_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_UINTPROPERTY_H
17 
18 #include "Fit/Param/RealLimits.h"
20 #include "GUI/Support/Type/Unit.h"
21 #include <QString>
22 #include <functional>
23 #include <variant>
24 
25 class Streamer;
26 class SessionItem;
27 
28 using std::function;
29 using std::variant;
30 
31 //! Class for representing a uint value, its attributes and its accessors.
32 //!
33 //! For a complete description please refer to the documentation of DoubleProperty. Everything said
34 //! there also applies to this class, of course not for double values but for uint values.
35 //!
36 //! \sa DoubleProperty
37 //! \sa UIntDescriptor
38 //!
39 class UIntProperty {
40 public:
41  void init(const QString& label, const QString& tooltip, uint value,
42  const variant<QString, Unit>& unit, const QString& persistentTag);
43  void init(const QString& label, const QString& tooltip, uint value,
44  const variant<QString, Unit>& unit, const RealLimits& limits,
45  const QString& persistentTag);
46 
48  operator UIntDescriptor() const { return m_descriptor; }
49  operator uint() const { return m_value; }
50  void set(uint d) { m_value = d; }
51  uint get() const { return m_value; }
52 
53  QString persistentTag() const { return m_persistentTag; }
54  QString uid() const { return m_uid; }
55  void setUid(const QString& uid) { m_uid = uid; }
56 
57 private:
58  uint m_value = 0;
59  QString m_persistentTag;
60  QString m_uid;
61 
63 };
64 
65 namespace Serialize {
66 void rwProperty(Streamer& s, UIntProperty& d);
67 } // namespace Serialize
68 
69 //! Add a member, a getter and a bunch of overloaded setters for a UIntProperty
70 #define UINT_PROPERTY(nameLower, nameUpper) \
71 private: \
72  UIntProperty m_##nameLower; \
73  \
74 public: \
75  UIntDescriptor nameLower() const { return m_##nameLower; } \
76  void set##nameUpper(int v) { m_##nameLower.set(v); } \
77  void set##nameUpper(uint v) { m_##nameLower.set(v); } \
78  void set##nameUpper(size_t v) { m_##nameLower.set((int)v); }
79 
80 
81 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_UINTPROPERTY_H
Defines class UIntDescriptor.
Defines class Unit.
Base class for a GUI data item.
Definition: SessionItem.h:204
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
Describes properties of a uint value which are necessary to allow GUI representation,...
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 descriptor() const
Definition: UIntProperty.h:47
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
Functions to serialize various data types.
Definition: SessionItem.h:339
void rwProperty(Streamer &s, DoubleProperty &d)