Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
syntax_line_edit.h
Go to the documentation of this file.
1
10#ifndef SYNTAX_LINE_EDIT_H
11#define SYNTAX_LINE_EDIT_H
12
13#include <QLineEdit>
14
15class QCompleter;
16class QStringListModel;
17
27class SyntaxLineEdit : public QLineEdit
28{
29 Q_OBJECT
30 Q_PROPERTY(SyntaxState syntaxState READ syntaxState)
31 Q_ENUMS(SyntaxState)
32
33public:
38 explicit SyntaxLineEdit(QWidget *parent = 0);
39
50
55 SyntaxState syntaxState() const { return syntax_state_; }
56
61 void setSyntaxState(SyntaxState state = Empty);
62
67 QString syntaxErrorMessage();
68
74 QString syntaxErrorMessageFull();
75
80 QString styleSheet() const;
81
86 QString deprecatedToken();
87
92 void setCompleter(QCompleter *c);
93
98 QCompleter *completer() const { return completer_; }
99
104 void allowCompletion(bool enabled);
105
115 static QString createSyntaxErrorMessageFull(const QString &filter,
116 const QString &err_msg,
117 qsizetype loc_start,
118 size_t loc_length);
119
120public slots:
125 void setStyleSheet(const QString &style_sheet);
126
132 void insertFilter(const QString &filter);
133
140 bool checkDisplayFilter(QString filter);
141
146 void checkFieldName(QString field);
147
153 void checkCustomColumn(QString fields);
154
159 void checkInteger(QString number);
160
161protected:
162 QCompleter *completer_;
163 QStringListModel *completion_model_;
171 void setCompletionTokenChars(const QString &token_chars) { token_chars_ = token_chars; }
172
179 bool isComplexFilter(const QString &filter);
180
187 virtual void buildCompletionList(const QString &field_word, const QString &preamble)
188 {
189 Q_UNUSED(field_word);
190 Q_UNUSED(preamble);
191 }
192
197 QPoint getTokenUnderCursor();
198
203 QStringList splitLineUnderCursor();
204
210 virtual bool event(QEvent *event);
211
217 void completionKeyPressEvent(QKeyEvent *event);
218
223 void completionFocusInEvent(QFocusEvent *event);
224
229 virtual void focusOutEvent(QFocusEvent *event);
230
235 virtual void paintEvent(QPaintEvent *event);
236
237private:
238 SyntaxState syntax_state_;
239 QString style_sheet_;
240 QString state_style_sheet_;
241 QString syntax_error_message_;
242 QString syntax_error_message_full_;
243 QString token_chars_;
244 bool completion_enabled_;
246private slots:
251 void insertFieldCompletion(const QString &completion_text);
252
253signals:
254};
255
256#endif // SYNTAX_LINE_EDIT_H
QLineEdit subclass that adds syntax-state colouring, error messaging, and partial token-based autocom...
Definition syntax_line_edit.h:28
QString deprecatedToken()
Returns the deprecated token string when the state is Deprecated.
QPoint getTokenUnderCursor()
Returns the start position and length of the token under the cursor.
Definition syntax_line_edit.cpp:508
SyntaxState syntaxState() const
Returns the current syntax validation state.
Definition syntax_line_edit.h:55
virtual void focusOutEvent(QFocusEvent *event)
Hides the completer popup when the widget loses focus.
Definition syntax_line_edit.cpp:388
static QString createSyntaxErrorMessageFull(const QString &filter, const QString &err_msg, qsizetype loc_start, size_t loc_length)
Builds a full syntax error message string combining the filter expression with a location-annotated e...
Definition syntax_line_edit.cpp:110
virtual bool event(QEvent *event)
Intercepts Tab and other keys to trigger or dismiss the completer.
Definition syntax_line_edit.cpp:295
void completionKeyPressEvent(QKeyEvent *event)
Handles key press events while the completer popup is visible, forwarding navigation keys to the popu...
Definition syntax_line_edit.cpp:333
void completionFocusInEvent(QFocusEvent *event)
Triggers a completion refresh when the widget gains focus.
Definition syntax_line_edit.cpp:381
bool isComplexFilter(const QString &filter)
Returns true if filter contains operators or structure that make it too complex for token-level autoc...
Definition syntax_line_edit.cpp:279
bool checkDisplayFilter(QString filter)
Validates filter as a Wireshark display filter and updates the syntax state and error message accordi...
Definition syntax_line_edit.cpp:154
QStringList splitLineUnderCursor()
Splits the line at the cursor into the preamble and the current token.
Definition syntax_line_edit.cpp:528
QString syntaxErrorMessage()
Returns a short, human-readable description of the current syntax error.
Definition syntax_line_edit.cpp:100
void setSyntaxState(SyntaxState state=Empty)
Sets the syntax state and updates the widget's style sheet to reflect it.
Definition syntax_line_edit.cpp:77
void insertFilter(const QString &filter)
Inserts filter text at the cursor position, adding surrounding spaces where necessary to keep the exp...
Definition syntax_line_edit.cpp:136
QString syntaxErrorMessageFull()
Returns a full error message that includes the filter expression and the location of the error within...
Definition syntax_line_edit.cpp:105
QStringListModel * completion_model_
Definition syntax_line_edit.h:163
QString styleSheet() const
Returns the base style sheet, excluding any state-driven overrides.
Definition syntax_line_edit.cpp:127
QCompleter * completer_
Definition syntax_line_edit.h:162
void checkCustomColumn(QString fields)
Validates fields as a custom-column field expression and updates the syntax state.
Definition syntax_line_edit.cpp:225
SyntaxState
Visual and semantic state of the text currently in the editor.
Definition syntax_line_edit.h:43
@ Busy
Definition syntax_line_edit.h:45
@ Deprecated
Definition syntax_line_edit.h:47
@ Invalid
Definition syntax_line_edit.h:46
@ Valid
Definition syntax_line_edit.h:48
@ Empty
Definition syntax_line_edit.h:44
void setCompletionTokenChars(const QString &token_chars)
Sets the characters that may appear in a completion token (e.g. letters, digits, underscores,...
Definition syntax_line_edit.h:171
QCompleter * completer() const
Returns the currently installed completer.
Definition syntax_line_edit.h:98
void checkFieldName(QString field)
Validates field as a protocol field name and updates the syntax state.
Definition syntax_line_edit.cpp:210
virtual void paintEvent(QPaintEvent *event)
Paints the widget, overlaying a state-appropriate background colour.
Definition syntax_line_edit.cpp:401
void setStyleSheet(const QString &style_sheet)
Sets the base style sheet; the state-driven style is composited on top.
Definition syntax_line_edit.cpp:131
void allowCompletion(bool enabled)
Enables or disables autocompletion without removing the completer.
Definition syntax_line_edit.cpp:72
virtual void buildCompletionList(const QString &field_word, const QString &preamble)
Builds the list of completion candidates based on the current token and filter context....
Definition syntax_line_edit.h:187
void checkInteger(QString number)
Validates number as a well-formed integer and updates the syntax state.
Definition syntax_line_edit.cpp:263
void setCompleter(QCompleter *c)
Installs a QCompleter for token-based autocompletion.
Definition syntax_line_edit.cpp:49