Base: QuantityFormat: avoid storing formatting defaults
User defined precision and fractional inch are stored on QuantityFormat construction making changes persistent to object life time. Change that so until not explicitely overriden, user defined values are always returned. Co-authored-by: Matthias Danner <28687794+matthiasdanner@users.noreply.github.com>
This commit is contained in:
@@ -69,7 +69,7 @@ protected:
|
||||
UnitsApi::setSchema(name);
|
||||
Quantity quantity {value, unit};
|
||||
QuantityFormat format = quantity.getFormat();
|
||||
format.precision = precision;
|
||||
format.setPrecision(precision);
|
||||
quantity.setFormat(format);
|
||||
return quantity.getSafeUserString();
|
||||
}
|
||||
|
||||
@@ -51,18 +51,18 @@ private Q_SLOTS:
|
||||
{
|
||||
auto quant = qsb->value();
|
||||
auto format = quant.getFormat();
|
||||
format.precision = 7;
|
||||
format.setPrecision(7);
|
||||
quant.setFormat(format);
|
||||
|
||||
qsb->setValue(quant);
|
||||
|
||||
auto val1 = qsb->value();
|
||||
QCOMPARE(val1.getFormat().precision, 7);
|
||||
QCOMPARE(val1.getFormat().getPrecision(), 7);
|
||||
|
||||
// format shouldn't change after setting a double
|
||||
qsb->setValue(3.5);
|
||||
auto val2 = qsb->value();
|
||||
QCOMPARE(val2.getFormat().precision, 7);
|
||||
QCOMPARE(val2.getFormat().getPrecision(), 7);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user