[Core] Fix unit management in QuantitySpinBox
This commit is contained in:
@@ -554,7 +554,7 @@ void QuantitySpinBox::userInput(const QString & text)
|
|||||||
|
|
||||||
if (keyboardTracking()) {
|
if (keyboardTracking()) {
|
||||||
d->cached = res;
|
d->cached = res;
|
||||||
handlePendingEmit();
|
handlePendingEmit(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
d->cached = res;
|
d->cached = res;
|
||||||
@@ -585,18 +585,19 @@ void QuantitySpinBox::openFormulaDialog()
|
|||||||
Q_EMIT showFormulaDialog(true);
|
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);
|
Q_D(QuantitySpinBox);
|
||||||
if (d->pendingEmit) {
|
if (d->pendingEmit) {
|
||||||
double factor;
|
double factor;
|
||||||
const Base::Quantity& res = d->cached;
|
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->unitValue = res.getValue() / factor;
|
||||||
d->quantity = res;
|
d->quantity = res;
|
||||||
|
|
||||||
@@ -782,7 +783,8 @@ void QuantitySpinBox::stepBy(int steps)
|
|||||||
else if (val < d->minimum)
|
else if (val < d->minimum)
|
||||||
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);
|
updateFromCache(true);
|
||||||
update();
|
update();
|
||||||
selectNumber();
|
selectNumber();
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void userInput(const QString & text);
|
void userInput(const QString & text);
|
||||||
void handlePendingEmit();
|
void handlePendingEmit(bool updateUnit = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setExpression(std::shared_ptr<App::Expression> expr);
|
virtual void setExpression(std::shared_ptr<App::Expression> expr);
|
||||||
@@ -156,7 +156,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void validateInput();
|
void validateInput();
|
||||||
void updateText(const Base::Quantity&);
|
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, double& factor, QString& unitString) const;
|
||||||
QString getUserString(const Base::Quantity& val) const;
|
QString getUserString(const Base::Quantity& val) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user