Gui: add warning to DlgExpressionInput

Warn when binding expression with unit to unit-less properties.
This commit is contained in:
Zheng, Lei
2019-08-30 09:23:19 +08:00
committed by wmayer
parent e8e1a67e50
commit 087349c07a

View File

@@ -139,24 +139,33 @@ void DlgExpressionInput::textChanged(const QString &text)
ui->okBtn->setEnabled(true);
ui->msg->clear();
//set default palette as we may have read text right now
ui->msg->setPalette(ui->okBtn->palette());
NumberExpression * n = Base::freecad_dynamic_cast<NumberExpression>(result.get());
if (n) {
Base::Quantity value = n->getQuantity();
QString msg = value.getUserString();
if(!impliedUnit.isEmpty()) {
if (!value.getUnit().isEmpty() && value.getUnit() != impliedUnit)
throw Base::UnitsMismatchError("Unit mismatch between result and required unit");
value.setUnit(impliedUnit);
} else if (!value.getUnit().isEmpty()) {
msg += QString::fromUtf8(" (Warning: unit discarded)");
QPalette p(ui->msg->palette());
p.setColor(QPalette::WindowText, Qt::red);
ui->msg->setPalette(p);
}
ui->msg->setText(value.getUserString());
ui->msg->setText(msg);
}
else
ui->msg->setText(Base::Tools::fromStdString(result->toString()));
//set default palette as we may have read text right now
ui->msg->setPalette(ui->okBtn->palette());
}
}
catch (Base::Exception & e) {