BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DoubleDescriptor.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/DoubleDescriptor.h
6 //! @brief Defines class DoubleDescriptor
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_DOUBLEDESCRIPTOR_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_DOUBLEDESCRIPTOR_H
17 
18 #include "Fit/Param/RealLimits.h"
19 #include "GUI/Support/Type/Unit.h"
20 #include <QList>
21 #include <QString>
22 #include <functional>
23 #include <variant>
24 
25 class SessionItem;
26 
27 using std::function;
28 using std::variant;
29 
30 //! Describes properties of a double value which are necessary to allow GUI representation, editing
31 //! the value, undo/redo, unit conversion.
32 //!
33 //! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
34 //! eases SessionItem migration. The underlying implementation can be a SessionItem, a simple double
35 //! member, or any other construction to hold a double value.
36 //! It could also describe a value which is not even represented by an existing double, but is only
37 //! a calculated value. In this case it might apply that there is no setter possible, which is still
38 //! allowed as long as care is taken not trying to call the setter.
39 //!
40 //! Note that this class does not provide (*implement*) a double value, but *provide information*
41 //! about a double value. For implementing a double value, please see DoubleProperty.
42 //!
43 //! For easy UI creation, there are functions like GUI:Util::createSpinBox() which take a descriptor
44 //! and fully initialize the created spin box.
45 //!
46 //! \sa DoubleProperty
47 //! \sa GUI:Util::createSpinBox()
48 //!
50 private: // private as long as path initialization is not included in params (to be done after
51  // SessionItem migration)
52  //! Operates on a double value (e.g a member variable).
53  DoubleDescriptor(const QString& label, const QString& tooltip, int decimals,
54  const RealLimits& limits, double* var, const variant<QString, Unit>& unit);
55 
56  //! Operates on a double value (e.g a member variable).
57  //! Decimals is set to 3, limits is set to nonnegative
58  DoubleDescriptor(const QString& label, const QString& tooltip, double* var,
59  const variant<QString, Unit>& unit);
60 
61 public:
62  //! Operates on any kind of storage (e.g. session items), by using setter/getter methods
63  //! decimals is set to 3, limits is set to nonnegative
64  DoubleDescriptor(const QString& label, const QString& tooltip, function<void(double)> setter,
65  function<double()> getter, const variant<QString, Unit>& unit);
66 
67  //! Operates on any kind of storage (e.g. session items), by using setter/getter methods
68  DoubleDescriptor(QString label, QString tooltip, int decimals, const RealLimits& limits,
69  function<void(double)> setter, function<double()> getter,
70  const variant<QString, Unit>& unit);
71 
72  DoubleDescriptor(const QString& label, const double* var, const variant<QString, Unit>& unit);
73 
74  //! Operates on a session item. The settings (like decimals, limits) are taken from the session
75  //! item.
76  //! Only for easier migration. Should be removed after SessionItem refactoring.
77  DoubleDescriptor(const QString& label, SessionItem* item, const variant<QString, Unit>& unit);
78 
79  //! Operates on a session item. The settings (like decimals, limits) are taken from the session
80  //! item.
81  //! Only for easier migration. Should be removed after SessionItem refactoring.
82  DoubleDescriptor(SessionItem* item, const variant<QString, Unit>& unit);
83 
84  DoubleDescriptor() = default;
85 
87 
88 public:
89  //! Return the current value of the handled parameter.
90  operator double() const;
91 
92  QString label; //!< A label text (short, no trailing colon)
93  QString tooltip; //!< Tooltip text
94  int decimals = 0; //!< numbers of decimals to be shown in an edit control
95  RealLimits limits; //!< Limits of the value.
96  function<void(double)> set = nullptr; //!< function to set the value
97  function<double()> get = nullptr; //!< function to get the current value
98  variant<QString, Unit> unit = Unit::unitless; //!< Unit of the value (internal unit only!)
99  function<QString()> path = nullptr; //!< Path describing this value. Used e.g. for undo/redo
100 };
101 
102 using DoubleDescriptors = QList<DoubleDescriptor>;
103 
104 
105 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_DOUBLEDESCRIPTOR_H
QList< DoubleDescriptor > DoubleDescriptors
Defines class Unit.
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
@ unitless
Describes properties of a double value which are necessary to allow GUI representation,...
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString label
A label text (short, no trailing colon)
function< void(double)> set
function to set the value
RealLimits limits
Limits of the value.
DoubleDescriptor()=default
function< double()> get
function to get the current value
QString tooltip
Tooltip text.
int decimals
numbers of decimals to be shown in an edit control
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
DoubleDescriptor(const DoubleDescriptor &other)=default
Base class for a GUI data item.
Definition: SessionItem.h:204