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:
Max Wilfinger
2026-01-08 17:34:12 +01:00
committed by GitHub
parent 8e720d6608
commit 8010b04656
2 changed files with 14 additions and 0 deletions

View File

@@ -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());

View File

@@ -73,6 +73,9 @@ protected:
void drawControl(QStyleOptionSpinBox&);
private:
void showExpression(Number number);
protected:
QLineEdit* lineedit;
QAbstractSpinBox* spinbox;