MCPcopy Create free account
hub / github.com/KDE/labplot / validateExpression

Method validateExpression

src/frontend/widgets/ExpressionTextEdit.cpp:124–144  ·  view source on GitHub ↗

! * \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 */

Source from the content-addressed store, hash-verified

122 * \param force forces the validation and highlighting when no text changes were made, used when new parameters/variables were provided
123 */
124void 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 ###############################

Callers

nothing calls this directly

Calls 4

setToolTipFunction · 0.85
QStringClass · 0.50
isValidMethod · 0.45
errorMessageMethod · 0.45

Tested by

no test coverage detected