Gui: Handle exception in showValidExpression (#26721)
* Gui: Handle exception in showValidExpression If an exception is raised inside showValidExpression() because the expression cannot be evaluated then handle the exception and show it as invalid expression. This fixes issue: https://github.com/FreeCAD/FreeCAD/issues/26501 --------- Co-authored-by: wwmayer <wmayer@freecad.org>
This commit is contained in:
@@ -91,9 +91,20 @@ void ExpressionSpinBox::showInvalidExpression(const QString& tip)
|
||||
p.setColor(QPalette::Active, QPalette::Text, Qt::red);
|
||||
lineedit->setPalette(p);
|
||||
iconLabel->setToolTip(tip);
|
||||
iconLabel->setPixmap(getIcon(":/icons/button_invalid.svg", QSize(iconHeight, iconHeight)));
|
||||
}
|
||||
|
||||
void ExpressionSpinBox::showValidExpression(ExpressionSpinBox::Number number)
|
||||
{
|
||||
try {
|
||||
showExpression(number);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
showInvalidExpression(QString::fromUtf8(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionSpinBox::showExpression(Number number)
|
||||
{
|
||||
std::unique_ptr<Expression> result(getExpression()->eval());
|
||||
auto* value = freecad_cast<NumberExpression*>(result.get());
|
||||
|
||||
@@ -73,6 +73,9 @@ protected:
|
||||
|
||||
void drawControl(QStyleOptionSpinBox&);
|
||||
|
||||
private:
|
||||
void showExpression(Number number);
|
||||
|
||||
protected:
|
||||
QLineEdit* lineedit;
|
||||
QAbstractSpinBox* spinbox;
|
||||
|
||||
Reference in New Issue
Block a user