Gui: support of range checks in DlgExpressionInput
This commit is contained in:
@@ -111,6 +111,45 @@ DlgExpressionInput::~DlgExpressionInput()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NumberRange::setRange(double min, double max)
|
||||
{
|
||||
minimum = min;
|
||||
maximum = max;
|
||||
defined = true;
|
||||
}
|
||||
|
||||
void NumberRange::clearRange()
|
||||
{
|
||||
defined = false;
|
||||
}
|
||||
|
||||
void NumberRange::throwIfOutOfRange(const Base::Quantity& value) const
|
||||
{
|
||||
if (!defined)
|
||||
return;
|
||||
|
||||
if (value.getValue() < minimum || value.getValue() > maximum) {
|
||||
Base::Quantity minVal(minimum, value.getUnit());
|
||||
Base::Quantity maxVal(maximum, value.getUnit());
|
||||
QString valStr = value.getUserString();
|
||||
QString minStr = minVal.getUserString();
|
||||
QString maxStr = maxVal.getUserString();
|
||||
QString error = QString::fromLatin1("Value out of range (%1 out of [%2, %3])").arg(valStr, minStr, maxStr);
|
||||
|
||||
throw Base::ValueError(error.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void DlgExpressionInput::setRange(double minimum, double maximum)
|
||||
{
|
||||
numberRange.setRange(minimum, maximum);
|
||||
}
|
||||
|
||||
void DlgExpressionInput::clearRange()
|
||||
{
|
||||
numberRange.clearRange();
|
||||
}
|
||||
|
||||
QPoint DlgExpressionInput::expressionPosition() const
|
||||
{
|
||||
return ui->expression->pos();
|
||||
@@ -179,10 +218,13 @@ void DlgExpressionInput::textChanged(const QString &text)
|
||||
ui->msg->setPalette(p);
|
||||
}
|
||||
|
||||
numberRange.throwIfOutOfRange(value);
|
||||
|
||||
ui->msg->setText(msg);
|
||||
}
|
||||
else
|
||||
else {
|
||||
ui->msg->setText(Base::Tools::fromStdString(result->toString()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user