! \class ExpressionTextEdit \brief Provides a widget for defining mathematical expressions Supports syntax-highlighting and completion. Modified version of https://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.html \ingroup frontend */
| 30 | \ingroup frontend |
| 31 | */ |
| 32 | ExpressionTextEdit::ExpressionTextEdit(QWidget* parent) |
| 33 | : KTextEdit(parent) |
| 34 | , m_highlighter(new EquationHighlighter(this)) { |
| 35 | QStringList list = ExpressionParser::getInstance()->functions(); |
| 36 | // append description |
| 37 | for (auto& s : list) |
| 38 | s.append(ExpressionParser::functionArgumentString(s, XYEquationCurve::EquationType::Cartesian) + QStringLiteral(" - ") |
| 39 | + ExpressionParser::getInstance()->functionDescription(s)); |
| 40 | QStringList constants = ExpressionParser::getInstance()->constants(); |
| 41 | for (auto& s : constants) { |
| 42 | if (s != QLatin1String("...")) |
| 43 | s.append(QStringLiteral(" - ") + ExpressionParser::getInstance()->constantDescription(s)); |
| 44 | } |
| 45 | list.append(constants); |
| 46 | |
| 47 | setTabChangesFocus(true); |
| 48 | |
| 49 | m_completer = new QCompleter(list, this); |
| 50 | m_completer->setWidget(this); |
| 51 | m_completer->setCompletionMode(QCompleter::PopupCompletion); |
| 52 | |
| 53 | connect(m_completer, QOverload<const QString&>::of(&QCompleter::activated), this, &ExpressionTextEdit::insertCompletion); |
| 54 | connect(this, &ExpressionTextEdit::textChanged, this, [=]() { |
| 55 | validateExpression(); |
| 56 | }); |
| 57 | connect(this, &ExpressionTextEdit::cursorPositionChanged, m_highlighter, &EquationHighlighter::rehighlight); |
| 58 | } |
| 59 | |
| 60 | EquationHighlighter* ExpressionTextEdit::highlighter() { |
| 61 | return m_highlighter; |
nothing calls this directly
no test coverage detected