! * \brief Validates the current expression if the text was changed and highlights the text field if the expression is invalid. * \param force forces the validation and highlighting when no text changes were made, used when new parameters/variables were provided */
| 122 | * \param force forces the validation and highlighting when no text changes were made, used when new parameters/variables were provided |
| 123 | */ |
| 124 | void ExpressionTextEdit::validateExpression(bool force) { |
| 125 | // check whether the expression was changed or only the formatting |
| 126 | QString text = toPlainText().simplified(); |
| 127 | bool textChanged{(text != m_currentExpression) ? true : false}; |
| 128 | |
| 129 | if (textChanged || force) { |
| 130 | auto parser = ExpressionParser::getInstance(); |
| 131 | m_isValid = parser->isValid(text, m_variables); |
| 132 | if (!m_isValid) { |
| 133 | setToolTip(parser->errorMessage()); |
| 134 | SET_WARNING_STYLE(this) |
| 135 | } else { |
| 136 | setToolTip(QStringLiteral("")); |
| 137 | setStyleSheet(QString()); |
| 138 | } |
| 139 | |
| 140 | m_currentExpression = std::move(text); |
| 141 | } |
| 142 | if (textChanged) |
| 143 | Q_EMIT expressionChanged(); |
| 144 | } |
| 145 | |
| 146 | // ############################################################################## |
| 147 | // #################################### Events ############################### |
nothing calls this directly
no test coverage detected