BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UIntDescriptor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/UIntDescriptor.cpp
6 //! @brief Implements 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 
16 
18 #include <utility>
19 
20 UIntDescriptor::UIntDescriptor(const QString& label, SessionItem* item,
21  const variant<QString, Unit>& unit)
23  label, item->toolTip(), item->limits(), [=](int d) { item->setValue(d); },
24  [=]() { return item->value().toInt(); }, unit)
25 {
26 }
27 
28 UIntDescriptor::UIntDescriptor(SessionItem* item, const variant<QString, Unit>& unit)
29  : UIntDescriptor(item->displayName(), item, unit)
30 {
31 }
32 
33 UIntDescriptor::UIntDescriptor(const QString& label, const QString& tooltip,
34  function<void(uint)> setter, function<uint()> getter,
35  const variant<QString, Unit>& unit)
36  : UIntDescriptor(label, tooltip, RealLimits::nonnegative(), setter, getter, unit)
37 {
38 }
39 
40 UIntDescriptor::UIntDescriptor(QString label, QString tooltip, const RealLimits& limits,
41  function<void(uint)> setter, function<uint()> getter,
42  const variant<QString, Unit>& unit)
43  : label(std::move(label))
44  , tooltip(std::move(tooltip))
45  , limits(limits)
46  , set(std::move(setter))
47  , get(std::move(getter))
48  , unit(unit)
49 {
50 }
51 
52 UIntDescriptor::UIntDescriptor(const QString& label, const uint* var,
53  const variant<QString, Unit>& unit)
55  label, "", RealLimits::nonnegative(), [=](uint v) { *const_cast<uint*>(var) = v; },
56  [=] { return *var; }, unit)
57 {
58 }
59 
60 UIntDescriptor::operator uint() const
61 {
62  return get();
63 }
Defines class SessionItem.
Defines class UIntDescriptor.
Base class for a GUI data item.
Definition: SessionItem.h:204
bool setValue(QVariant value)
Set value, ensure that variant types match.
Describes properties of a uint value which are necessary to allow GUI representation,...
UIntDescriptor()=default