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

Method ExpressionTextEdit

src/frontend/widgets/ExpressionTextEdit.cpp:32–58  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

30 \ingroup frontend
31*/
32ExpressionTextEdit::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
60EquationHighlighter* ExpressionTextEdit::highlighter() {
61 return m_highlighter;

Callers

nothing calls this directly

Calls 4

appendMethod · 0.80
functionDescriptionMethod · 0.80
constantDescriptionMethod · 0.80
setWidgetMethod · 0.80

Tested by

no test coverage detected