BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UIntDescriptor.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/UIntDescriptor.h
6 //! @brief Defines class UIntDescriptor
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_UINTDESCRIPTOR_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_UINTDESCRIPTOR_H
17 
18 #include "Fit/Param/RealLimits.h"
19 #include "GUI/Support/Type/Unit.h"
20 #include <QString>
21 #include <functional>
22 #include <variant>
23 
24 class SessionItem;
25 
26 using std::function;
27 using std::variant;
28 
29 
30 //! Describes properties of a uint 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 uint
35 //! member, or any other construction to hold a uint value.
37 public:
38  UIntDescriptor() = default;
39  //! Operates on a session item. The settings (like limits) are taken from the session
40  //! item.
41  //! Only for easier migration. Should be removed after SessionItem refactoring.
42  UIntDescriptor(SessionItem* item, const variant<QString, Unit>& unit);
43 
44  //! Operates on a session item. The settings (like limits) are taken from the session
45  //! item.
46  //! Only for easier migration. Should be removed after SessionItem refactoring.
47  UIntDescriptor(const QString& label, SessionItem* item, const variant<QString, Unit>& unit);
48 
49  UIntDescriptor(const QString& label, const uint* var, const variant<QString, Unit>& unit);
50 
51 private:
52  //! Operates on any kind of storage (e.g. session items), by using setter/getter methods
53  UIntDescriptor(QString label, QString tooltip, const RealLimits& limits,
54  function<void(uint)> setter, function<uint()> getter,
55  const variant<QString, Unit>& unit);
56 
57  //! Operates on any kind of storage (e.g. session items), by using setter/getter methods
58  //! limits is set to nonnegative
59  UIntDescriptor(const QString& label, const QString& tooltip, function<void(uint)> setter,
60  function<uint()> getter, const variant<QString, Unit>& unit);
61 
62 public:
63  //! Return the current value of the handled parameter.
64  operator uint() const;
65 
66  QString label; //!< A label text (short, no trailing colon)
67  QString tooltip; //!< Tooltip text
68  RealLimits limits; //!< Limits of the value.
69  function<void(uint)> set = nullptr; //!< function to set the value
70  function<uint()> get = nullptr; //!< function to get the current value
71  variant<QString, Unit> unit = Unit::unitless; //!< Unit of the value (internal unit only!)
72  function<QString()> path = nullptr; //!< Path describing this value. Used e.g. for undo/redo
73 };
74 
75 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_UINTDESCRIPTOR_H
Defines class Unit.
@ unitless
Base class for a GUI data item.
Definition: SessionItem.h:204
Describes properties of a uint value which are necessary to allow GUI representation,...
QString label
A label text (short, no trailing colon)
UIntDescriptor()=default
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