Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
syntax_line_edit.h
1 /* syntax_line_edit.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef SYNTAX_LINE_EDIT_H
11 #define SYNTAX_LINE_EDIT_H
12 
13 #include <QLineEdit>
14 
15 class QCompleter;
16 class QStringListModel;
17 
18 // Autocompletion is partially implemented. Subclasses must:
19 // - Provide buildCompletionList
20 // - Call setCompletionTokenChars
21 
22 class SyntaxLineEdit : public QLineEdit
23 {
24  Q_OBJECT
25  Q_PROPERTY(SyntaxState syntaxState READ syntaxState)
26  Q_ENUMS(SyntaxState)
27 public:
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  QString styleSheet() const;
35  QString deprecatedToken();
36 
37  void setCompleter(QCompleter *c);
38  QCompleter *completer() const { return completer_; }
39 
40 public slots:
41  void setStyleSheet(const QString &style_sheet);
42  // Insert filter text at the current position, adding spaces where needed.
43  void insertFilter(const QString &filter);
44 
45  // Built-in syntax checks. Connect textChanged to these as needed.
46  void checkDisplayFilter(QString filter);
47  void checkFieldName(QString field);
48  void checkCustomColumn(QString fields);
49  void checkInteger(QString number);
50 
51 protected:
52  QCompleter *completer_;
53  QStringListModel *completion_model_;
54  void setCompletionTokenChars(const QString &token_chars) { token_chars_ = token_chars; }
55  bool isComplexFilter(const QString &filter);
56  virtual void buildCompletionList(const QString&) { }
57  // x = Start position, y = length
58  QPoint getTokenUnderCursor();
59 
60  virtual bool event(QEvent *event);
61  void completionKeyPressEvent(QKeyEvent *event);
62  void completionFocusInEvent(QFocusEvent *event);
63  virtual void focusOutEvent(QFocusEvent *event);
64 
65 private:
66  SyntaxState syntax_state_;
67  QString style_sheet_;
68  QString state_style_sheet_;
69  QString syntax_error_message_;
70  QString token_chars_;
71  QColor busy_fg_;
72 
73 private slots:
74  void insertFieldCompletion(const QString &completion_text);
75 
76 signals:
77 
78 };
79 
80 #endif // SYNTAX_LINE_EDIT_H
Definition: syntax_line_edit.h:22