diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index d40f0f02b0..47dee6eb71 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -554,7 +554,7 @@ void QuantitySpinBox::userInput(const QString & text) if (keyboardTracking()) { d->cached = res; - handlePendingEmit(); + handlePendingEmit(false); } else { d->cached = res; @@ -585,18 +585,19 @@ void QuantitySpinBox::openFormulaDialog() Q_EMIT showFormulaDialog(true); } -void QuantitySpinBox::handlePendingEmit() +void QuantitySpinBox::handlePendingEmit(bool updateUnit /* = true */) { - updateFromCache(true); + updateFromCache(true, updateUnit); } -void QuantitySpinBox::updateFromCache(bool notify) +void QuantitySpinBox::updateFromCache(bool notify, bool updateUnit /* = true */) { Q_D(QuantitySpinBox); if (d->pendingEmit) { double factor; const Base::Quantity& res = d->cached; - QString text = getUserString(res, factor, d->unitStr); + auto tmpUnit(d->unitStr); + QString text = getUserString(res, factor, updateUnit ? d->unitStr : tmpUnit); d->unitValue = res.getValue() / factor; d->quantity = res; @@ -782,7 +783,8 @@ void QuantitySpinBox::stepBy(int steps) else if (val < d->minimum) val = d->minimum; - lineEdit()->setText(QString::fromUtf8("%L1 %2").arg(val).arg(d->unitStr)); + Quantity quant(val, d->unitStr); + updateText(quant); updateFromCache(true); update(); selectNumber(); diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h index 49872e3b70..9131692d52 100644 --- a/src/Gui/QuantitySpinBox.h +++ b/src/Gui/QuantitySpinBox.h @@ -138,7 +138,7 @@ public Q_SLOTS: protected Q_SLOTS: void userInput(const QString & text); - void handlePendingEmit(); + void handlePendingEmit(bool updateUnit = true); protected: virtual void setExpression(std::shared_ptr expr); @@ -156,7 +156,7 @@ protected: private: void validateInput(); void updateText(const Base::Quantity&); - void updateFromCache(bool); + void updateFromCache(bool notify, bool updateUnit = true); QString getUserString(const Base::Quantity& val, double& factor, QString& unitString) const; QString getUserString(const Base::Quantity& val) const;