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

Description

Definition at line 20 of file ScientificSpinBox.h.

Inheritance diagram for ScientificSpinBox:
[legend]
Collaboration diagram for ScientificSpinBox:
[legend]

Signals

void valueChanged (double value)
 

Public Member Functions

 ScientificSpinBox (QWidget *parent=nullptr)
 
 ~ScientificSpinBox () override
 
int decimals () const
 
void fixup (QString &) const override
 
double maximum () const
 
double minimum () const
 
void setDecimals (int)
 
void setMaximum (double max)
 
void setMinimum (double min)
 
void setSingleStep (double step)
 
void setValue (double val)
 
double singleStep () const
 
QSize sizeHint () const override
 
void stepBy (int steps) override
 
QValidator::State validate (QString &, int &) const override
 
double value () const
 

Static Public Member Functions

static double round (double val, int decimals)
 
static double toDouble (QString text, const QDoubleValidator &validator, double min, double max, double default_value)
 
static QString toString (double val, int decimal_points)
 

Protected Member Functions

QAbstractSpinBox::StepEnabled stepEnabled () const override
 

Properties

double value
 

Private Member Functions

bool inRange (double val) const
 
void updateText ()
 
void updateValue ()
 

Private Attributes

int m_decimals
 
double m_max
 
double m_min
 
double m_step
 
QDoubleValidator m_validator
 
double m_value
 

Constructor & Destructor Documentation

◆ ScientificSpinBox()

ScientificSpinBox::ScientificSpinBox ( QWidget *  parent = nullptr)

Definition at line 30 of file ScientificSpinBox.cpp.

31  : QDoubleSpinBox(parent)
32  , m_value(0.0)
33  , m_min(-max_val)
34  , m_max(max_val)
35  , m_step(1.0)
36  , m_decimals(3)
37 {
38  QLocale locale;
39  locale.setNumberOptions(QLocale::RejectGroupSeparator);
40  m_validator.setLocale(locale);
41  m_validator.setNotation(QDoubleValidator::ScientificNotation);
42 
43  connect(this, &QAbstractSpinBox::editingFinished, this, &ScientificSpinBox::updateValue);
44 }
QDoubleValidator m_validator

References m_validator, and updateValue().

Here is the call graph for this function:

◆ ~ScientificSpinBox()

ScientificSpinBox::~ScientificSpinBox ( )
overridedefault

Member Function Documentation

◆ decimals()

int ScientificSpinBox::decimals ( ) const

Definition at line 120 of file ScientificSpinBox.cpp.

121 {
122  return m_decimals;
123 }

References m_decimals.

Referenced by round().

◆ fixup()

void ScientificSpinBox::fixup ( QString &  ) const
inlineoverride

Definition at line 47 of file ScientificSpinBox.h.

47 {}

◆ inRange()

bool ScientificSpinBox::inRange ( double  val) const
private

Definition at line 170 of file ScientificSpinBox.cpp.

171 {
172  return val >= m_min && val <= m_max;
173 }

References m_max, and m_min.

Referenced by stepBy().

◆ maximum()

double ScientificSpinBox::maximum ( ) const

Definition at line 100 of file ScientificSpinBox.cpp.

101 {
102  return m_max;
103 }

References m_max.

◆ minimum()

double ScientificSpinBox::minimum ( ) const

Definition at line 88 of file ScientificSpinBox.cpp.

89 {
90  return m_min;
91 }

References m_min.

◆ round()

double ScientificSpinBox::round ( double  val,
int  decimals 
)
static

Definition at line 153 of file ScientificSpinBox.cpp.

154 {
155  return QString::number(val, 'e', decimals).toDouble();
156 }

References decimals().

Referenced by setValue(), and stepBy().

Here is the call graph for this function:

◆ setDecimals()

void ScientificSpinBox::setDecimals ( int  val)

Definition at line 112 of file ScientificSpinBox.cpp.

113 {
114  if (val <= 0)
115  return;
116  m_decimals = val;
117  setValue(m_value);
118 }
void setValue(double val)

References m_decimals, m_value, and setValue().

Referenced by ParameterTuningDelegate::createEditor(), and ScientificSpinBoxEditor::setDecimals().

Here is the call graph for this function:

◆ setMaximum()

void ScientificSpinBox::setMaximum ( double  max)

Definition at line 105 of file ScientificSpinBox.cpp.

106 {
107  m_max = max;
108  if (m_value > m_max)
109  setValue(m_max);
110 }

References m_max, m_value, and setValue().

Referenced by ParameterTuningDelegate::createEditor(), and ScientificSpinBoxEditor::setLimits().

Here is the call graph for this function:

◆ setMinimum()

void ScientificSpinBox::setMinimum ( double  min)

Definition at line 93 of file ScientificSpinBox.cpp.

94 {
95  m_min = min;
96  if (m_value < m_min)
97  setValue(m_min);
98 }

References m_min, m_value, and setValue().

Referenced by ParameterTuningDelegate::createEditor(), and ScientificSpinBoxEditor::setLimits().

Here is the call graph for this function:

◆ setSingleStep()

void ScientificSpinBox::setSingleStep ( double  step)

◆ setValue()

void ScientificSpinBox::setValue ( double  val)

Definition at line 63 of file ScientificSpinBox.cpp.

64 {
65  double old_val = m_value;
66  m_value = round(val, m_decimals);
67  updateText();
68  if (std::abs(old_val - m_value) > min_val)
69  emit valueChanged(m_value);
70 }
static double round(double val, int decimals)
void valueChanged(double value)

References m_decimals, m_value, round(), updateText(), and valueChanged().

Referenced by ParameterTuningDelegate::createEditor(), ScientificSpinBoxEditor::initEditor(), setDecimals(), setMaximum(), setMinimum(), ParameterTuningDelegate::sliderValueChanged(), stepBy(), and updateValue().

Here is the call graph for this function:

◆ singleStep()

double ScientificSpinBox::singleStep ( ) const

Definition at line 78 of file ScientificSpinBox.cpp.

79 {
80  return m_step;
81 }

References m_step.

◆ sizeHint()

QSize ScientificSpinBox::sizeHint ( ) const
override

Definition at line 48 of file ScientificSpinBox.cpp.

49 {
50  // The following is somehow a hack to get a reasonable sizeHint. Implementation could/should be
51  // re-thought
52  QDoubleSpinBox d;
53  d.setRange(m_min, m_max);
54  d.setDecimals(m_decimals);
55  return d.sizeHint();
56 }

References m_decimals, m_max, and m_min.

◆ stepBy()

void ScientificSpinBox::stepBy ( int  steps)
override

Definition at line 125 of file ScientificSpinBox.cpp.

126 {
127  double new_val = round(m_value + m_step * steps, m_decimals);
128  if (inRange(new_val))
129  setValue(new_val);
130 }
bool inRange(double val) const

References inRange(), m_decimals, m_step, m_value, round(), and setValue().

Here is the call graph for this function:

◆ stepEnabled()

QAbstractSpinBox::StepEnabled ScientificSpinBox::stepEnabled ( ) const
overrideprotected

Definition at line 158 of file ScientificSpinBox.cpp.

159 {
160  return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled;
161 }

◆ toDouble()

double ScientificSpinBox::toDouble ( QString  text,
const QDoubleValidator &  validator,
double  min,
double  max,
double  default_value 
)
static

Definition at line 140 of file ScientificSpinBox.cpp.

142 {
143  int pos = 0;
144  if (validator.validate(text, pos) == QValidator::Acceptable) {
145  double new_val = validator.locale().toDouble(text);
146  if (std::abs(new_val) < min_val)
147  new_val = 0.0;
148  return new_val >= min && new_val <= max ? new_val : default_value;
149  }
150  return default_value;
151 }

Referenced by updateValue().

◆ toString()

QString ScientificSpinBox::toString ( double  val,
int  decimal_points 
)
static

Definition at line 132 of file ScientificSpinBox.cpp.

133 {
134  QString result = useExponentialNotation(val) ? QString::number(val, 'e', decimal_points)
135  : QString::number(val, 'f', decimal_points);
136 
137  return result.replace(QRegExp("(\\.?0+)?((e{1}[\\+|-]{1})(0+)?([1-9]{1}.*))?$"), "\\3\\5");
138 }

Referenced by ParameterTuningDelegate::paint(), GUI::View::PropertyEditorFactory::toString(), and updateText().

◆ updateText()

void ScientificSpinBox::updateText ( )
private

Definition at line 163 of file ScientificSpinBox.cpp.

164 {
165  QString new_text = toString(m_value, m_decimals);
166  if (new_text != text())
167  lineEdit()->setText(new_text);
168 }
static QString toString(double val, int decimal_points)

References m_decimals, m_value, and toString().

Referenced by setValue().

Here is the call graph for this function:

◆ updateValue()

void ScientificSpinBox::updateValue ( )
private

Definition at line 72 of file ScientificSpinBox.cpp.

73 {
74  double new_val = toDouble(text(), m_validator, m_min, m_max, m_value);
75  setValue(new_val);
76 }
static double toDouble(QString text, const QDoubleValidator &validator, double min, double max, double default_value)

References m_max, m_min, m_validator, m_value, setValue(), and toDouble().

Referenced by ScientificSpinBox().

Here is the call graph for this function:

◆ validate()

QValidator::State ScientificSpinBox::validate ( QString &  ,
int &   
) const
inlineoverride

Definition at line 46 of file ScientificSpinBox.h.

46 { return QValidator::Acceptable; }

◆ value()

double ScientificSpinBox::value ( ) const

Definition at line 58 of file ScientificSpinBox.cpp.

59 {
60  return m_value;
61 }

References m_value.

◆ valueChanged

Member Data Documentation

◆ m_decimals

int ScientificSpinBox::m_decimals
private

Definition at line 67 of file ScientificSpinBox.h.

Referenced by decimals(), setDecimals(), setValue(), sizeHint(), stepBy(), and updateText().

◆ m_max

double ScientificSpinBox::m_max
private

Definition at line 65 of file ScientificSpinBox.h.

Referenced by inRange(), maximum(), setMaximum(), sizeHint(), and updateValue().

◆ m_min

double ScientificSpinBox::m_min
private

Definition at line 65 of file ScientificSpinBox.h.

Referenced by inRange(), minimum(), setMinimum(), sizeHint(), and updateValue().

◆ m_step

double ScientificSpinBox::m_step
private

Definition at line 66 of file ScientificSpinBox.h.

Referenced by setSingleStep(), singleStep(), and stepBy().

◆ m_validator

QDoubleValidator ScientificSpinBox::m_validator
private

Definition at line 68 of file ScientificSpinBox.h.

Referenced by ScientificSpinBox(), and updateValue().

◆ m_value

double ScientificSpinBox::m_value
private

Property Documentation

◆ value

double ScientificSpinBox::value
readwrite

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