BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ScientificSpinBox Class Reference
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
 
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
 

Detailed Description

Definition at line 20 of file ScientificSpinBox.h.

Constructor & Destructor Documentation

◆ ScientificSpinBox()

ScientificSpinBox::ScientificSpinBox ( QWidget *  parent = nullptr)

Definition at line 28 of file ScientificSpinBox.cpp.

29  : QAbstractSpinBox(parent)
30  , m_value(0.0)
31  , m_min(-max_val)
32  , m_max(max_val)
33  , m_step(1.0)
34  , m_decimals(3)
35 {
36  QLocale locale;
37  locale.setNumberOptions(QLocale::RejectGroupSeparator);
38  m_validator.setLocale(locale);
39  m_validator.setNotation(QDoubleValidator::ScientificNotation);
40 
41  connect(this, &QAbstractSpinBox::editingFinished, this, &ScientificSpinBox::updateValue);
42 }
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 108 of file ScientificSpinBox.cpp.

109 {
110  return m_decimals;
111 }

References m_decimals.

Referenced by round().

◆ fixup()

void ScientificSpinBox::fixup ( QString &  ) const
inlineoverride

Definition at line 45 of file ScientificSpinBox.h.

45 {}

◆ inRange()

bool ScientificSpinBox::inRange ( double  val) const
private

Definition at line 158 of file ScientificSpinBox.cpp.

159 {
160  return val >= m_min && val <= m_max;
161 }

References m_max, and m_min.

Referenced by stepBy().

◆ maximum()

double ScientificSpinBox::maximum ( ) const

Definition at line 88 of file ScientificSpinBox.cpp.

89 {
90  return m_max;
91 }

References m_max.

◆ minimum()

double ScientificSpinBox::minimum ( ) const

Definition at line 76 of file ScientificSpinBox.cpp.

77 {
78  return m_min;
79 }

References m_min.

◆ round()

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

Definition at line 141 of file ScientificSpinBox.cpp.

142 {
143  return QString::number(val, 'e', decimals).toDouble();
144 }

References decimals().

Referenced by setValue(), and stepBy().

Here is the call graph for this function:

◆ setDecimals()

void ScientificSpinBox::setDecimals ( int  val)

Definition at line 100 of file ScientificSpinBox.cpp.

101 {
102  if (val <= 0)
103  return;
104  m_decimals = val;
105  setValue(m_value);
106 }
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 93 of file ScientificSpinBox.cpp.

94 {
95  m_max = max;
96  if (m_value > m_max)
97  setValue(m_max);
98 }

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 81 of file ScientificSpinBox.cpp.

82 {
83  m_min = min;
84  if (m_value < m_min)
85  setValue(m_min);
86 }

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 51 of file ScientificSpinBox.cpp.

52 {
53  double old_val = m_value;
54  m_value = round(val, m_decimals);
55  updateText();
56  if (std::abs(old_val - m_value) > min_val)
57  emit valueChanged(m_value);
58 }
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(), CsvImportTable::setMultiplierFields(), ParameterTuningDelegate::sliderValueChanged(), stepBy(), and updateValue().

Here is the call graph for this function:

◆ singleStep()

double ScientificSpinBox::singleStep ( ) const

Definition at line 66 of file ScientificSpinBox.cpp.

67 {
68  return m_step;
69 }

References m_step.

◆ stepBy()

void ScientificSpinBox::stepBy ( int  steps)
override

Definition at line 113 of file ScientificSpinBox.cpp.

114 {
115  double new_val = round(m_value + m_step * steps, m_decimals);
116  if (inRange(new_val))
117  setValue(new_val);
118 }
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 146 of file ScientificSpinBox.cpp.

147 {
148  return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled;
149 }

◆ toDouble()

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

Definition at line 128 of file ScientificSpinBox.cpp.

130 {
131  int pos = 0;
132  if (validator.validate(text, pos) == QValidator::Acceptable) {
133  double new_val = validator.locale().toDouble(text);
134  if (std::abs(new_val) < min_val)
135  new_val = 0.0;
136  return new_val >= min && new_val <= max ? new_val : default_value;
137  }
138  return default_value;
139 }

Referenced by updateValue().

◆ toString()

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

Definition at line 120 of file ScientificSpinBox.cpp.

121 {
122  QString result = useExponentialNotation(val) ? QString::number(val, 'e', decimal_points)
123  : QString::number(val, 'f', decimal_points);
124 
125  return result.replace(QRegExp("(\\.?0+)?((e{1}[\\+|-]{1})(0+)?([1-9]{1}.*))?$"), "\\3\\5");
126 }

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

◆ updateText()

void ScientificSpinBox::updateText ( )
private

Definition at line 151 of file ScientificSpinBox.cpp.

152 {
153  QString new_text = toString(m_value, m_decimals);
154  if (new_text != text())
155  lineEdit()->setText(new_text);
156 }
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 60 of file ScientificSpinBox.cpp.

61 {
62  double new_val = toDouble(text(), m_validator, m_min, m_max, m_value);
63  setValue(new_val);
64 }
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 44 of file ScientificSpinBox.h.

44 { return QValidator::Acceptable; }

◆ value()

double ScientificSpinBox::value ( ) const

Definition at line 46 of file ScientificSpinBox.cpp.

47 {
48  return m_value;
49 }

References m_value.

◆ valueChanged

Member Data Documentation

◆ m_decimals

int ScientificSpinBox::m_decimals
private

Definition at line 65 of file ScientificSpinBox.h.

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

◆ m_max

double ScientificSpinBox::m_max
private

Definition at line 63 of file ScientificSpinBox.h.

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

◆ m_min

double ScientificSpinBox::m_min
private

Definition at line 63 of file ScientificSpinBox.h.

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

◆ m_step

double ScientificSpinBox::m_step
private

Definition at line 64 of file ScientificSpinBox.h.

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

◆ m_validator

QDoubleValidator ScientificSpinBox::m_validator
private

Definition at line 66 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: