3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef SYNTAX_LINE_EDIT_H
23 #define SYNTAX_LINE_EDIT_H
28 class QStringListModel;
30 // Autocompletion is partially implemented. Subclasses must:
31 // - Provide buildCompletionList
32 // - Call setCompletionTokenChars
34 class SyntaxLineEdit : public QLineEdit
37 Q_PROPERTY(SyntaxState syntaxState READ syntaxState)
40 explicit SyntaxLineEdit(QWidget *parent = 0);
41 enum SyntaxState { Empty, Invalid, Deprecated, Valid };
43 SyntaxState syntaxState() const { return syntax_state_; }
44 void setSyntaxState(SyntaxState state = Empty);
45 QString syntaxErrorMessage();
46 QString styleSheet() const;
47 QString deprecatedToken();
49 void setCompleter(QCompleter *c);
50 QCompleter *completer() const { return completer_; }
53 void setStyleSheet(const QString &style_sheet);
54 // Insert filter text at the current position, adding spaces where needed.
55 void insertFilter(const QString &filter);
57 // Built-in syntax checks. Connect textChanged to these as needed.
58 void checkDisplayFilter(QString filter);
59 void checkFieldName(QString field);
60 void checkCustomColumn(QString fields);
61 void checkInteger(QString number);
64 QCompleter *completer_;
65 QStringListModel *completion_model_;
66 void setCompletionTokenChars(const QString &token_chars) { token_chars_ = token_chars; }
67 bool isComplexFilter(const QString &filter);
68 virtual void buildCompletionList(const QString&) { }
69 // x = Start position, y = length
70 QPoint getTokenUnderCursor();
72 void completionKeyPressEvent(QKeyEvent *event);
73 void completionFocusInEvent(QFocusEvent *event);
76 SyntaxState syntax_state_;
78 QString state_style_sheet_;
79 QString deprecated_token_;
80 QString syntax_error_message_;
84 void insertFieldCompletion(const QString &completion_text);
90 #endif // SYNTAX_LINE_EDIT_H