Skip to content

Commit

Permalink
UnitsCalculator fixes
Browse files Browse the repository at this point in the history
- missing initial value
- missing check for invalid units starting with 'e'
  • Loading branch information
donovaly authored and wwmayer committed Dec 20, 2019
1 parent af011da commit 0754965
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Gui/DlgUnitsCalculatorImp.cpp
Expand Up @@ -80,6 +80,7 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WindowFlags fl )
ui->unitsBox->addItem(it->getTypeString());
}

ui->quantitySpinBox->setValue(1.0);
ui->quantitySpinBox->setUnit(units.front());
}

Expand All @@ -106,8 +107,11 @@ void DlgUnitsCalculator::textChanged(QString unit)

void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant)
{
// first check the unit, if it is invalid, getTypeString() outputs an empty string
if (Base::Unit(ui->UnitInput->text()).getTypeString().isEmpty()) {
// first check the unit, if it is invalid, getTypeString() outputs an empty string
// explicitly check for "ee" like in "eeV" because this would trigger an exception in Base::Unit
// since it expects then a scientific notation number like "1e3"
if ( (ui->UnitInput->text().mid(0, 2) == QString::fromLatin1("ee")) ||
Base::Unit(ui->UnitInput->text()).getTypeString().isEmpty()) {
ui->ValueOutput->setText(tr("unknown unit: ") + ui->UnitInput->text());
ui->pushButton_Copy->setEnabled(false);
} else { // the unit is valid
Expand Down

0 comments on commit 0754965

Please sign in to comment.