BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DoubleDescriptor Class Reference

Description

Describes properties of a double value which are necessary to allow GUI representation, editing the value, undo/redo, unit conversion.

By using this class, the underlying data scheme is hidden from the user of the data. This e.g. eases SessionItem migration. The underlying implementation can be a SessionItem, a simple double member, or any other construction to hold a double value. It could also describe a value which is not even represented by an existing double, but is only a calculated value. In this case it might apply that there is no setter possible, which is still allowed as long as care is taken not trying to call the setter.

Note that this class does not provide (implement) a double value, but provide information about a double value. For implementing a double value, please see DoubleProperty.

For easy UI creation, there are functions like GUI:Util::createSpinBox() which take a descriptor and fully initialize the created spin box.

See also
DoubleProperty
GUI:Util::createSpinBox()

Definition at line 49 of file DoubleDescriptor.h.

Collaboration diagram for DoubleDescriptor:
[legend]

Public Member Functions

 DoubleDescriptor ()=default
 
 DoubleDescriptor (const DoubleDescriptor &other)=default
 
 DoubleDescriptor (const QString &label, const double *var, const variant< QString, Unit > &unit)
 
 DoubleDescriptor (const QString &label, const QString &tooltip, function< void(double)> setter, function< double()> getter, const variant< QString, Unit > &unit)
 Operates on any kind of storage (e.g. session items), by using setter/getter methods decimals is set to 3, limits is set to nonnegative. More...
 
 DoubleDescriptor (const QString &label, SessionItem *item, const variant< QString, Unit > &unit)
 Operates on a session item. The settings (like decimals, limits) are taken from the session item. Only for easier migration. Should be removed after SessionItem refactoring. More...
 
 DoubleDescriptor (QString label, QString tooltip, int decimals, const RealLimits &limits, function< void(double)> setter, function< double()> getter, const variant< QString, Unit > &unit)
 Operates on any kind of storage (e.g. session items), by using setter/getter methods. More...
 
 DoubleDescriptor (SessionItem *item, const variant< QString, Unit > &unit)
 Operates on a session item. The settings (like decimals, limits) are taken from the session item. Only for easier migration. Should be removed after SessionItem refactoring. More...
 
 operator double () const
 Return the current value of the handled parameter. More...
 

Public Attributes

int decimals = 0
 numbers of decimals to be shown in an edit control More...
 
function< double()> get = nullptr
 function to get the current value More...
 
QString label
 A label text (short, no trailing colon) More...
 
RealLimits limits
 Limits of the value. More...
 
function< QString()> path = nullptr
 Path describing this value. Used e.g. for undo/redo. More...
 
function< void(double)> set = nullptr
 function to set the value More...
 
QString tooltip
 Tooltip text. More...
 
variant< QString, Unitunit = Unit::unitless
 Unit of the value (internal unit only!) More...
 

Private Member Functions

 DoubleDescriptor (const QString &label, const QString &tooltip, double *var, const variant< QString, Unit > &unit)
 Operates on a double value (e.g a member variable). Decimals is set to 3, limits is set to nonnegative. More...
 
 DoubleDescriptor (const QString &label, const QString &tooltip, int decimals, const RealLimits &limits, double *var, const variant< QString, Unit > &unit)
 Operates on a double value (e.g a member variable). More...
 

Constructor & Destructor Documentation

◆ DoubleDescriptor() [1/9]

DoubleDescriptor::DoubleDescriptor ( const QString &  label,
const QString &  tooltip,
int  decimals,
const RealLimits &  limits,
double *  var,
const variant< QString, Unit > &  unit 
)
private

Operates on a double value (e.g a member variable).

Definition at line 51 of file DoubleDescriptor.cpp.

55  label, tooltip, decimals, limits, [=](double v) { *var = v; }, [=] { return *var; }, unit)
56 {
57 }
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString label
A label text (short, no trailing colon)
RealLimits limits
Limits of the value.
DoubleDescriptor()=default
QString tooltip
Tooltip text.
int decimals
numbers of decimals to be shown in an edit control

◆ DoubleDescriptor() [2/9]

DoubleDescriptor::DoubleDescriptor ( const QString &  label,
const QString &  tooltip,
double *  var,
const variant< QString, Unit > &  unit 
)
private

Operates on a double value (e.g a member variable). Decimals is set to 3, limits is set to nonnegative.

Definition at line 44 of file DoubleDescriptor.cpp.

46  : DoubleDescriptor(label, tooltip, 3, RealLimits::nonnegative(), var, unit)
47 
48 {
49 }

◆ DoubleDescriptor() [3/9]

DoubleDescriptor::DoubleDescriptor ( const QString &  label,
const QString &  tooltip,
function< void(double)>  setter,
function< double()>  getter,
const variant< QString, Unit > &  unit 
)

Operates on any kind of storage (e.g. session items), by using setter/getter methods decimals is set to 3, limits is set to nonnegative.

Definition at line 37 of file DoubleDescriptor.cpp.

40  : DoubleDescriptor(label, tooltip, 3, RealLimits::nonnegative(), setter, getter, unit)
41 {
42 }

◆ DoubleDescriptor() [4/9]

DoubleDescriptor::DoubleDescriptor ( QString  label,
QString  tooltip,
int  decimals,
const RealLimits &  limits,
function< void(double)>  setter,
function< double()>  getter,
const variant< QString, Unit > &  unit 
)

Operates on any kind of storage (e.g. session items), by using setter/getter methods.

Definition at line 21 of file DoubleDescriptor.cpp.

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 }
function< void(double)> set
function to set the value
function< double()> get
function to get the current value
function< QString()> path
Path describing this value. Used e.g. for undo/redo.

References path.

◆ DoubleDescriptor() [5/9]

DoubleDescriptor::DoubleDescriptor ( const QString &  label,
const double *  var,
const variant< QString, Unit > &  unit 
)

Definition at line 59 of file DoubleDescriptor.cpp.

62  label, "", 3, RealLimits::nonnegative(), [=](double v) { *const_cast<double*>(var) = v; },
63  [=] { return *var; }, unit)
64 {
65 }

◆ DoubleDescriptor() [6/9]

DoubleDescriptor::DoubleDescriptor ( const QString &  label,
SessionItem item,
const variant< QString, Unit > &  unit 
)

Operates on a session item. The settings (like decimals, limits) are taken from the session item. Only for easier migration. Should be removed after SessionItem refactoring.

Definition at line 67 of file DoubleDescriptor.cpp.

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
76  };
77 }
int decimals() const
QString toolTip() const
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:60
RealLimits limits() const
QModelIndex indexOfItem(SessionItem *item) const
QString getPathFromIndex(const QModelIndex &index)
Definition: Path.cpp:144

References SessionItem::setValue().

Here is the call graph for this function:

◆ DoubleDescriptor() [7/9]

DoubleDescriptor::DoubleDescriptor ( SessionItem item,
const variant< QString, Unit > &  unit 
)

Operates on a session item. The settings (like decimals, limits) are taken from the session item. Only for easier migration. Should be removed after SessionItem refactoring.

Definition at line 79 of file DoubleDescriptor.cpp.

80  : DoubleDescriptor(item->displayName(), item, unit)
81 {
82 }
QString displayName() const
Get display name of item, append index if ambigue.

◆ DoubleDescriptor() [8/9]

DoubleDescriptor::DoubleDescriptor ( )
default

◆ DoubleDescriptor() [9/9]

DoubleDescriptor::DoubleDescriptor ( const DoubleDescriptor other)
default

Member Function Documentation

◆ operator double()

DoubleDescriptor::operator double ( ) const

Return the current value of the handled parameter.

Definition at line 84 of file DoubleDescriptor.cpp.

85 {
86  return get();
87 }

Member Data Documentation

◆ decimals

int DoubleDescriptor::decimals = 0

◆ get

◆ label

◆ limits

◆ path

◆ set

◆ tooltip

◆ unit


The documentation for this class was generated from the following files: