22 const double upper_switch = 1000;
23 const double lower_switch = 0.1;
24 const double min_val = std::numeric_limits<double>::min();
25 const double max_val = std::numeric_limits<double>::max();
27 bool useExponentialNotation(
double val);
33 : QAbstractSpinBox(parent)
41 locale.setNumberOptions(QLocale::RejectGroupSeparator);
43 m_validator.setNotation(QDoubleValidator::ScientificNotation);
62 if (std::abs(old_val -
m_value) > min_val)
128 QString result = useExponentialNotation(val) ? QString::number(val,
'e', decimal_points)
129 : QString::number(val,
'f', decimal_points);
131 return result.replace(QRegExp(
"(\\.?0+)?((e{1}[\\+|-]{1})(0+)?([1-9]{1}.*))?$"),
"\\3\\5");
135 double max,
double default_value)
138 if (validator.validate(text, pos) == QValidator::Acceptable) {
139 double new_val = validator.locale().toDouble(text);
140 if (std::abs(new_val) < min_val)
142 return new_val >= min && new_val <= max ? new_val : default_value;
144 return default_value;
149 char notation = useExponentialNotation(val) ?
'e' :
'f';
150 return QString::number(val, notation,
decimals).toDouble();
155 return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled;
161 if (new_text != text())
162 lineEdit()->setText(new_text);
171 bool useExponentialNotation(
double val)
173 const double abs_val = std::abs(val);
175 if (abs_val <= min_val)
178 return abs_val >= upper_switch || abs_val < lower_switch;
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)
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)
double singleStep() const
void valueChanged(double value)
const int default_double_decimals
materialitems.h Collection of materials to populate MaterialModel.