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:
Ladislav Michl
2025-09-02 23:17:22 +02:00
parent e7cd72b2e0
commit 01b547912f
10 changed files with 42 additions and 29 deletions

View File

@@ -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();
}

View File

@@ -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: