Wireshark 4.5.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
18// Autocompletion is partially implemented. Subclasses must:
19// - Provide buildCompletionList
20// - Call setCompletionTokenChars
21
22class SyntaxLineEdit : public QLineEdit
23{
24 Q_OBJECT
25 Q_PROPERTY(SyntaxState syntaxState READ syntaxState)
26 Q_ENUMS(SyntaxState)
27public:
28 explicit SyntaxLineEdit(QWidget *parent = 0);
29 enum SyntaxState { Empty, Busy, Invalid, Deprecated, Valid };
30
31 SyntaxState syntaxState() const { return syntax_state_; }
32 void setSyntaxState(SyntaxState state = Empty);
33 QString syntaxErrorMessage();
34 // Error message with filter expression and location error.
35 QString syntaxErrorMessageFull();
36 QString styleSheet() const;
37 QString deprecatedToken();
38
39 void setCompleter(QCompleter *c);
40 QCompleter *completer() const { return completer_; }
41 void allowCompletion(bool enabled);
42
43 static QString createSyntaxErrorMessageFull(const QString &filter,
44 const QString &err_msg,
45 qsizetype loc_start, size_t loc_length);
46
47public slots:
48 void setStyleSheet(const QString &style_sheet);
49 // Insert filter text at the current position, adding spaces where needed.
50 void insertFilter(const QString &filter);
51
52 // Built-in syntax checks. Connect textChanged to these as needed.
53 bool checkDisplayFilter(QString filter);
54 void checkFieldName(QString field);
55 void checkCustomColumn(QString fields);
56 void checkInteger(QString number);
57
58protected:
59 QCompleter *completer_;
60 QStringListModel *completion_model_;
61 void setCompletionTokenChars(const QString &token_chars) { token_chars_ = token_chars; }
62 bool isComplexFilter(const QString &filter);
63 virtual void buildCompletionList(const QString &field_word, const QString &preamble) { Q_UNUSED(field_word); Q_UNUSED(preamble); }
64 // x = Start position, y = length
65 QPoint getTokenUnderCursor();
66 // Returns (preamble, token)
67 QStringList splitLineUnderCursor();
68
69 virtual bool event(QEvent *event);
70 void completionKeyPressEvent(QKeyEvent *event);
71 void completionFocusInEvent(QFocusEvent *event);
72 virtual void focusOutEvent(QFocusEvent *event);
73 virtual void paintEvent(QPaintEvent *event);
74
75private:
76 SyntaxState syntax_state_;
77 QString style_sheet_;
78 QString state_style_sheet_;
79 QString syntax_error_message_;
80 QString syntax_error_message_full_;
81 QString token_chars_;
82 bool completion_enabled_;
83
84private slots:
85 void insertFieldCompletion(const QString &completion_text);
86
87signals:
88
89};
90
91#endif // SYNTAX_LINE_EDIT_H
Definition syntax_line_edit.h:23