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 syntaxState()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); completer()38 QCompleter *completer() const { return completer_; } 39 void allowCompletion(bool enabled); 40 41 public slots: 42 void setStyleSheet(const QString &style_sheet); 43 // Insert filter text at the current position, adding spaces where needed. 44 void insertFilter(const QString &filter); 45 46 // Built-in syntax checks. Connect textChanged to these as needed. 47 bool checkDisplayFilter(QString filter); 48 void checkFieldName(QString field); 49 void checkCustomColumn(QString fields); 50 void checkInteger(QString number); 51 52 protected: 53 QCompleter *completer_; 54 QStringListModel *completion_model_; setCompletionTokenChars(const QString & token_chars)55 void setCompletionTokenChars(const QString &token_chars) { token_chars_ = token_chars; } 56 bool isComplexFilter(const QString &filter); buildCompletionList(const QString &)57 virtual void buildCompletionList(const QString&) { } 58 // x = Start position, y = length 59 QPoint getTokenUnderCursor(); 60 61 virtual bool event(QEvent *event); 62 void completionKeyPressEvent(QKeyEvent *event); 63 void completionFocusInEvent(QFocusEvent *event); 64 virtual void focusOutEvent(QFocusEvent *event); 65 virtual void paintEvent(QPaintEvent *event); 66 67 private: 68 SyntaxState syntax_state_; 69 QString style_sheet_; 70 QString state_style_sheet_; 71 QString syntax_error_message_; 72 QString token_chars_; 73 bool completion_enabled_; 74 75 private slots: 76 void insertFieldCompletion(const QString &completion_text); 77 78 signals: 79 80 }; 81 82 #endif // SYNTAX_LINE_EDIT_H 83