DlgUnitsCalculatorImp.cpp: some cleanup

This commit is contained in:
donovaly
2019-12-02 02:43:38 +01:00
committed by Yorik van Havre
parent d255744684
commit a82ba07886

View File

@@ -113,15 +113,14 @@ void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant)
ui->ValueOutput->setText(tr("unit mismatch"));
ui->pushButton_Copy->setEnabled(false);
} else { // the unit is valid and has the same type
Base::Quantity inputt = Base::Quantity(1.0, ui->UnitInput->text());
// this gives us e.g. for "1 in" the value '25.4' because 1 in = 25.4 mm
double convertValue = Base::Quantity::parse(QString::fromLatin1("1") + ui->UnitInput->text()).getValue();
// the result is now just input / convertValue because the imput is always in a base unit
// (an input of "1 cm" will immediately be converted to "10 mm" by Gui::InputField from the dialog)
// we got now e.g. for "1 in" the value '25.4' because 1 in = 25.4 mm
// the result is now just quant / convertValue because the input is always in a base unit
// (an input of "1 cm" will immediately be converted to "10 mm" by Gui::InputField of the dialog)
double value = quant.getValue() / convertValue;
// determine how many decimals we will need to avoid an output like "0.00"
// at first use scientific notation, if there is no "e", we can round it to the user-defined decimals
// the user-defined decimals might be too low for cases like "10 um" in "in",
// at first use scientific notation, if there is no "e", we can round it to the user-defined decimals,
// but the user-defined decimals might be too low for cases like "10 um" in "in",
// thus only if value > 0.005 because FC's default are 2 decimals
QString val = QLocale::system().toString(value, 'g');
if (!val.contains(QChar::fromLatin1('e')) && (value > 0.005))