@@ -30,10 +30,15 @@ constexpr const int ScientificSpinBox::log10_steps_in_range_;
3030ScientificSpinBox::ScientificSpinBox (QWidget* parent, int decimals):
3131 QAbstractSpinBox(parent),
3232 decimals_(decimals) {
33+ connect (this , SIGNAL (editingFinished ()), this , SLOT (updateValueFromText ()));
3334 const auto font = QFontDatabase::systemFont (QFontDatabase::GeneralFont);
3435 const auto family = font.family ();
3536}
3637
38+ void ScientificSpinBox::updateValueFromText () {
39+ setValue (valueFromText (text ()));
40+ }
41+
3742QSize ScientificSpinBox::sizeHint () const {
3843 const auto char_width = fontMetrics ().averageCharWidth ();
3944 // +1 for number sign, +1 for integer part, +1 for decimal point, + decimals() for decimals,
@@ -48,8 +53,11 @@ QSize ScientificSpinBox::minimumSizeHint() const {
4853}
4954
5055void ScientificSpinBox::setValue (double value) {
56+ const auto old_text = textFromValue (value_);
5157 const auto new_text = textFromValue (value);
52- if (new_text == text ()) return ;
58+ if ((new_text == old_text) && (new_text == text ())) {
59+ return ;
60+ }
5361 value_ = valueFromText (new_text);
5462 lineEdit ()->setText (new_text);
5563 emit valueChanged (value_);
@@ -90,15 +98,15 @@ double ScientificSpinBox::valueFromText(const QString& text) const {
9098}
9199
92100QValidator::State ScientificSpinBox::validate (QString& text, int &) const {
93- const auto decimal_point = QString (locale ().decimalPoint ());
94- const auto e = QString (locale ().exponential ());
95- const auto minus = QString (locale ().negativeSign ());
96- const auto plus = QString (locale ().positiveSign ());
97101 bool ok = false ;
98102 locale ().toDouble (text, &ok);
99103 if (ok) {
100104 return QValidator::Acceptable;
101105 }
106+ const auto decimal_point = QString (locale ().decimalPoint ());
107+ const auto e = QString (locale ().exponential ());
108+ const auto minus = QString (locale ().negativeSign ());
109+ const auto plus = QString (locale ().positiveSign ());
102110 if (text.isEmpty ()) {
103111 return QValidator::Intermediate;
104112 }
0 commit comments