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

Description

Class for representing a double value, its attributes and its accessors.

Contained attributes are

  • the value itself
  • label: a label of e.g. a spin box
  • tooltip: tooltip for e.g. a spin box
  • unit: unit of this value (not the representation on UI, but the unit of the contained value). Use this to show the unit in the UI as well as allow a representation in a different unit (e.g. Angstrom instead of nanometer)
  • decimals: how many decimals shall be shown in a spin box
  • limits: which limits shall be set in a spin box or other validator
  • persistent tag: a name to serialize this property. Do not change this tag if it was already used for serialization, otherwise you may break backward compatibility of project reading.
  • uid: a unique id which represents this property. This is used for linking to this property, also when serializing the link. Right now, this uid is a UUID. It could also be refactored and changed to a simple (e.g. integer) id which is always unique throughout one project.

This property class supports also the descriptor mechanism by directly returning a DoubleDescriptor. This descriptor contains all the relevant information taken from this class, and provides a getter and a setter to the contained value.

See also
DoubleDescriptor

Definition at line 44 of file DoubleProperty.h.

Collaboration diagram for DoubleProperty:
[legend]

Public Member Functions

unsigned decimals () const
 Number of decimals to be shown in an edit field. More...
 
DoubleDescriptor descriptor () const
 Return a descriptor (information provider) for this double property. More...
 
double get () const
 The contained value. More...
 
void init (const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, const QString &persistentTag)
 
void init (const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, int decimals, const RealLimits &limits, const QString &persistentTag)
 
bool isInitialized () const
 True if one of the init methods has been called (checks for a valid uid). More...
 
 operator double () const
 Cast to the contained double value. More...
 
 operator DoubleDescriptor () const
 Cast to a descriptor (information provider) More...
 
QString persistentTag () const
 Persistent tag for serializing. More...
 
void set (double d)
 Set the contained value. More...
 
void setDecimals (unsigned decimals)
 Set number of decimals to be shown in an edit field. More...
 
void setLimits (const RealLimits &limits)
 Set the limits. More...
 
void setTooltip (const QString &tooltip)
 Set the tooltip. More...
 
void setUid (const QString &uid)
 Set the unique id of this double property. More...
 
void setUnit (const variant< QString, Unit > &unit)
 Set the unit. More...
 
QString uid () const
 Unique id of this double property. More...
 

Private Attributes

unsigned m_decimals = 3
 Number of decimals to be shown in an edit field. More...
 
DoubleDescriptor m_descriptor
 descriptor, holding more attributes like label, tooltip etc. More...
 
QString m_persistentTag
 Persistent tag for serializing. More...
 
QString m_uid
 Unique id of this double property. More...
 
double m_value = 0.0
 Current value. More...
 

Member Function Documentation

◆ decimals()

unsigned DoubleProperty::decimals ( ) const
inline

Number of decimals to be shown in an edit field.

Definition at line 77 of file DoubleProperty.h.

77 { return m_decimals; }
unsigned m_decimals
Number of decimals to be shown in an edit field.

References m_decimals.

Referenced by init(), Serialize::rwProperty(), and setDecimals().

◆ descriptor()

DoubleDescriptor DoubleProperty::descriptor ( ) const
inline

Return a descriptor (information provider) for this double property.

Definition at line 53 of file DoubleProperty.h.

53 { return m_descriptor; }
DoubleDescriptor m_descriptor
descriptor, holding more attributes like label, tooltip etc.

References m_descriptor.

◆ get()

double DoubleProperty::get ( ) const
inline

The contained value.

Definition at line 65 of file DoubleProperty.h.

65 { return m_value; }
double m_value
Current value.

References m_value.

Referenced by Serialize::rwProperty().

◆ init() [1/2]

void DoubleProperty::init ( const QString &  label,
const QString &  tooltip,
double  value,
const variant< QString, Unit > &  unit,
const QString &  persistentTag 
)

◆ init() [2/2]

void DoubleProperty::init ( const QString &  label,
const QString &  tooltip,
double  value,
const variant< QString, Unit > &  unit,
int  decimals,
const RealLimits &  limits,
const QString &  persistentTag 
)

Definition at line 26 of file DoubleProperty.cpp.

29 {
30  m_value = value;
33  m_uid = QUuid::createUuid().toString(QUuid::WithoutBraces);
34 
35  m_descriptor.label = label;
36  m_descriptor.tooltip = tooltip;
38  m_descriptor.limits = limits;
39  m_descriptor.unit = unit;
40  m_descriptor.set = [=](double v) { m_value = v; };
41  m_descriptor.get = [=] { return m_value; };
42  m_descriptor.path = [=] { return m_uid; };
43 }
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.
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.
QString m_uid
Unique id of this double property.
unsigned decimals() const
Number of decimals to be shown in an edit field.
QString m_persistentTag
Persistent tag for serializing.

References DoubleDescriptor::decimals, decimals(), DoubleDescriptor::get, DoubleDescriptor::label, DoubleDescriptor::limits, m_decimals, m_descriptor, m_persistentTag, m_uid, m_value, DoubleDescriptor::path, persistentTag(), DoubleDescriptor::set, DoubleDescriptor::tooltip, and DoubleDescriptor::unit.

Here is the call graph for this function:

◆ isInitialized()

bool DoubleProperty::isInitialized ( ) const

True if one of the init methods has been called (checks for a valid uid).

Definition at line 60 of file DoubleProperty.cpp.

61 {
62  return !m_uid.isEmpty();
63 }

References m_uid.

◆ operator double()

DoubleProperty::operator double ( ) const
inline

Cast to the contained double value.

Definition at line 59 of file DoubleProperty.h.

59 { return m_value; }

References m_value.

◆ operator DoubleDescriptor()

DoubleProperty::operator DoubleDescriptor ( ) const
inline

Cast to a descriptor (information provider)

Definition at line 56 of file DoubleProperty.h.

56 { return m_descriptor; }

References m_descriptor.

◆ persistentTag()

QString DoubleProperty::persistentTag ( ) const
inline

Persistent tag for serializing.

Definition at line 68 of file DoubleProperty.h.

68 { return m_persistentTag; }

References m_persistentTag.

Referenced by init(), and Serialize::rwProperty().

◆ set()

◆ setDecimals()

void DoubleProperty::setDecimals ( unsigned  decimals)
inline

Set number of decimals to be shown in an edit field.

Definition at line 80 of file DoubleProperty.h.

80 { m_decimals = decimals; }

References decimals(), and m_decimals.

Referenced by Serialize::rwProperty().

Here is the call graph for this function:

◆ setLimits()

void DoubleProperty::setLimits ( const RealLimits &  limits)

Set the limits.

Definition at line 55 of file DoubleProperty.cpp.

56 {
57  m_descriptor.limits = limits;
58 }

References DoubleDescriptor::limits, and m_descriptor.

◆ setTooltip()

void DoubleProperty::setTooltip ( const QString &  tooltip)

Set the tooltip.

Definition at line 45 of file DoubleProperty.cpp.

46 {
47  m_descriptor.tooltip = tooltip;
48 }

References m_descriptor, and DoubleDescriptor::tooltip.

◆ setUid()

void DoubleProperty::setUid ( const QString &  uid)
inline

Set the unique id of this double property.

Definition at line 74 of file DoubleProperty.h.

74 { m_uid = uid; }
QString uid() const
Unique id of this double property.

References m_uid, and uid().

Referenced by Serialize::rwProperty().

Here is the call graph for this function:

◆ setUnit()

void DoubleProperty::setUnit ( const variant< QString, Unit > &  unit)

Set the unit.

Definition at line 50 of file DoubleProperty.cpp.

51 {
52  m_descriptor.unit = unit;
53 }

References m_descriptor, and DoubleDescriptor::unit.

◆ uid()

QString DoubleProperty::uid ( ) const
inline

Unique id of this double property.

Definition at line 71 of file DoubleProperty.h.

71 { return m_uid; }

References m_uid.

Referenced by Serialize::rwProperty(), setUid(), and ParticleLayoutItem::totalDensity().

Member Data Documentation

◆ m_decimals

unsigned DoubleProperty::m_decimals = 3
private

Number of decimals to be shown in an edit field.

Definition at line 96 of file DoubleProperty.h.

Referenced by decimals(), init(), and setDecimals().

◆ m_descriptor

DoubleDescriptor DoubleProperty::m_descriptor
private

descriptor, holding more attributes like label, tooltip etc.

Definition at line 99 of file DoubleProperty.h.

Referenced by descriptor(), init(), operator DoubleDescriptor(), setLimits(), setTooltip(), and setUnit().

◆ m_persistentTag

QString DoubleProperty::m_persistentTag
private

Persistent tag for serializing.

Definition at line 97 of file DoubleProperty.h.

Referenced by init(), and persistentTag().

◆ m_uid

QString DoubleProperty::m_uid
private

Unique id of this double property.

Definition at line 98 of file DoubleProperty.h.

Referenced by init(), isInitialized(), setUid(), and uid().

◆ m_value

double DoubleProperty::m_value = 0.0
private

Current value.

Definition at line 95 of file DoubleProperty.h.

Referenced by get(), init(), operator double(), and set().


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