21 const double upper_switch = 100;
22 const double lower_switch = 0.1;
23 const double min_val = std::numeric_limits<double>::min();
24 const double max_val = std::numeric_limits<double>::max();
26 bool useExponentialNotation(
double val);
31 : QDoubleSpinBox(parent)
39 locale.setNumberOptions(QLocale::RejectGroupSeparator);
41 m_validator.setNotation(QDoubleValidator::ScientificNotation);
68 if (std::abs(old_val -
m_value) > min_val)
134 QString result = useExponentialNotation(val) ? QString::number(val,
'e', decimal_points)
135 : QString::number(val,
'f', decimal_points);
137 return result.replace(QRegExp(
"(\\.?0+)?((e{1}[\\+|-]{1})(0+)?([1-9]{1}.*))?$"),
"\\3\\5");
141 double max,
double default_value)
144 if (validator.validate(text, pos) == QValidator::Acceptable) {
145 double new_val = validator.locale().toDouble(text);
146 if (std::abs(new_val) < min_val)
148 return new_val >= min && new_val <= max ? new_val : default_value;
150 return default_value;
155 return QString::number(val,
'e',
decimals).toDouble();
160 return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled;
166 if (new_text != text())
167 lineEdit()->setText(new_text);
177 bool useExponentialNotation(
double val)
179 const double abs_val = std::abs(val);
181 if (abs_val <= min_val)
184 return abs_val >= upper_switch || abs_val < lower_switch;
Defines class ScientificSpinBox.
ScientificSpinBox(QWidget *parent=nullptr)
void stepBy(int steps) override
static double toDouble(QString text, const QDoubleValidator &validator, double min, double max, double default_value)
void setMaximum(double max)
QSize sizeHint() const override
void setMinimum(double min)
~ScientificSpinBox() override
void setValue(double val)
void setSingleStep(double step)
QDoubleValidator m_validator
static double round(double val, int decimals)
bool inRange(double val) const
QAbstractSpinBox::StepEnabled stepEnabled() const override
static QString toString(double val, int decimal_points)
void valueChanged(double value)
double singleStep() const