add posibility to use a unit schema other then the system schema to represent a quantity
This commit is contained in:
@@ -231,6 +231,7 @@ end:
|
||||
double maximum;
|
||||
double minimum;
|
||||
double singleStep;
|
||||
std::unique_ptr<Base::UnitsSchema> scheme;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -373,7 +374,7 @@ void Gui::QuantitySpinBox::onChange()
|
||||
std::stringstream s;
|
||||
s << value->getValue();
|
||||
|
||||
lineEdit()->setText(value->getQuantity().getUserString());
|
||||
lineEdit()->setText(getUserString(value->getQuantity()));
|
||||
setReadOnly(true);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
@@ -488,7 +489,7 @@ void QuantitySpinBox::updateText(const Quantity &quant)
|
||||
Q_D(QuantitySpinBox);
|
||||
|
||||
double dFactor;
|
||||
QString txt = quant.getUserString(dFactor,d->unitStr);
|
||||
QString txt = getUserString(quant, dFactor, d->unitStr);
|
||||
d->unitValue = quant.getValue()/dFactor;
|
||||
lineEdit()->setText(txt);
|
||||
}
|
||||
@@ -566,7 +567,7 @@ void QuantitySpinBox::userInput(const QString & text)
|
||||
}
|
||||
|
||||
double factor;
|
||||
res.getUserString(factor,d->unitStr);
|
||||
getUserString(res, factor, d->unitStr);
|
||||
d->unitValue = res.getValue()/factor;
|
||||
d->quantity = res;
|
||||
|
||||
@@ -697,6 +698,44 @@ void QuantitySpinBox::setDecimals(int v)
|
||||
updateText(d->quantity);
|
||||
}
|
||||
|
||||
void QuantitySpinBox::setSchema(const Base::UnitSystem& s)
|
||||
{
|
||||
Q_D(QuantitySpinBox);
|
||||
d->scheme = Base::UnitsApi::createSchema(s);
|
||||
updateText(d->quantity);
|
||||
}
|
||||
|
||||
void QuantitySpinBox::clearSchema()
|
||||
{
|
||||
Q_D(QuantitySpinBox);
|
||||
d->scheme = nullptr;
|
||||
updateText(d->quantity);
|
||||
}
|
||||
|
||||
QString QuantitySpinBox::getUserString(const Base::Quantity& val, double& factor, QString& unitString) const
|
||||
{
|
||||
Q_D(const QuantitySpinBox);
|
||||
if (d->scheme) {
|
||||
return val.getUserString(d->scheme.get(), factor, unitString);
|
||||
}
|
||||
else {
|
||||
return val.getUserString(factor, unitString);
|
||||
}
|
||||
}
|
||||
|
||||
QString QuantitySpinBox::getUserString(const Base::Quantity& val) const
|
||||
{
|
||||
Q_D(const QuantitySpinBox);
|
||||
if (d->scheme) {
|
||||
double factor;
|
||||
QString unitString;
|
||||
return val.getUserString(d->scheme.get(), factor, unitString);
|
||||
}
|
||||
else {
|
||||
return val.getUserString();
|
||||
}
|
||||
}
|
||||
|
||||
QAbstractSpinBox::StepEnabled QuantitySpinBox::stepEnabled() const
|
||||
{
|
||||
Q_D(const QuantitySpinBox);
|
||||
@@ -827,7 +866,7 @@ QString QuantitySpinBox::textFromValue(const Base::Quantity& value) const
|
||||
{
|
||||
double factor;
|
||||
QString unitStr;
|
||||
QString str = value.getUserString(factor, unitStr);
|
||||
QString str = getUserString(value, factor, unitStr);
|
||||
if (qAbs(value.getValue()) >= 1000.0) {
|
||||
str.remove(locale().groupSeparator());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user