BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DoubleDescriptor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/DoubleDescriptor.cpp
6 //! @brief Implements 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 
18 #include "GUI/Util/Path.h"
19 #include <utility>
20 
21 DoubleDescriptor::DoubleDescriptor(QString label_, QString tooltip_, int decimals_,
22  const RealLimits& limits_, function<void(double)> setter,
23  function<double()> getter, const variant<QString, Unit>& unit_)
24  : label(std::move(label_))
25  , tooltip(std::move(tooltip_))
26  , decimals(decimals_)
27  , limits(limits_)
28  , set(std::move(setter))
29  , get(std::move(getter))
30  , unit(unit_)
31 {
32  // #baLayerEditor the following path creation has to be implemented when SessionItem migration
33  // has finished
34  path = [] { return QString(); };
35 }
36 
37 DoubleDescriptor::DoubleDescriptor(const QString& label, const QString& tooltip,
38  function<void(double)> setter, function<double()> getter,
39  const variant<QString, Unit>& unit)
40  : DoubleDescriptor(label, tooltip, 3, RealLimits::nonnegative(), setter, getter, unit)
41 {
42 }
43 
44 DoubleDescriptor::DoubleDescriptor(const QString& label, const QString& tooltip, double* var,
45  const variant<QString, Unit>& unit)
46  : DoubleDescriptor(label, tooltip, 3, RealLimits::nonnegative(), var, unit)
47 
48 {
49 }
50 
51 DoubleDescriptor::DoubleDescriptor(const QString& label, const QString& tooltip, int decimals,
52  const RealLimits& limits, double* var,
53  const variant<QString, Unit>& unit)
55  label, tooltip, decimals, limits, [=](double v) { *var = v; }, [=] { return *var; }, unit)
56 {
57 }
58 
59 DoubleDescriptor::DoubleDescriptor(const QString& label, const double* var,
60  const variant<QString, Unit>& unit)
62  label, "", 3, RealLimits::nonnegative(), [=](double v) { *const_cast<double*>(var) = v; },
63  [=] { return *var; }, unit)
64 {
65 }
66 
67 DoubleDescriptor::DoubleDescriptor(const QString& label, SessionItem* item,
68  const variant<QString, Unit>& unit)
70  label, item->toolTip(), item->decimals(), item->limits(),
71  [=](double d) { item->setValue(d); }, [=]() { return item->value().toDouble(); }, unit)
72 {
73  path = [=] {
74  ASSERT(item->model()); // if assert, item is not completely initialized
75  return GUI::Util::Path::getPathFromIndex(item->model()->indexOfItem(item));
76  };
77 }
78 
79 DoubleDescriptor::DoubleDescriptor(SessionItem* item, const variant<QString, Unit>& unit)
80  : DoubleDescriptor(item->displayName(), item, unit)
81 {
82 }
83 
84 DoubleDescriptor::operator double() const
85 {
86  return get();
87 }
Defines class DoubleDescriptor.
Defines class Helpers functions.
Defines class SessionItem.
Defines class SessionModel.
Describes properties of a double value which are necessary to allow GUI representation,...
DoubleDescriptor()=default
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
Base class for a GUI data item.
Definition: SessionItem.h:204
bool setValue(QVariant value)
Set value, ensure that variant types match.
QString getPathFromIndex(const QModelIndex &index)
Definition: Path.cpp:144