Qt: Add missing multi-field column validation
[metze/wireshark/wip.git] / ui / qt / 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  * 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.
11  *
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.
16  *
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.
20  */
21
22 #ifndef SYNTAX_LINE_EDIT_H
23 #define SYNTAX_LINE_EDIT_H
24
25 #include <QLineEdit>
26
27 class QCompleter;
28 class QStringListModel;
29
30 // Autocompletion is partially implemented. Subclasses must:
31 // - Provide buildCompletionList
32 // - Call setCompletionTokenChars
33
34 class SyntaxLineEdit : public QLineEdit
35 {
36     Q_OBJECT
37     Q_PROPERTY(SyntaxState syntaxState READ syntaxState)
38     Q_ENUMS(SyntaxState)
39 public:
40     explicit SyntaxLineEdit(QWidget *parent = 0);
41     enum SyntaxState { Empty, Invalid, Deprecated, Valid };
42
43     SyntaxState syntaxState() const { return syntax_state_; }
44     void setSyntaxState(SyntaxState state = Empty);
45     QString syntaxErrorMessage();
46     QString styleSheet() const;
47     QString deprecatedToken();
48
49     void setCompleter(QCompleter *c);
50     QCompleter *completer() const { return completer_; }
51
52 public slots:
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);
56
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);
62
63 protected:
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();
71
72     void completionKeyPressEvent(QKeyEvent *event);
73     void completionFocusInEvent(QFocusEvent *event);
74
75 private:
76     SyntaxState syntax_state_;
77     QString style_sheet_;
78     QString state_style_sheet_;
79     QString deprecated_token_;
80     QString syntax_error_message_;
81     QString token_chars_;
82
83 private slots:
84     void insertFieldCompletion(const QString &completion_text);
85
86 signals:
87
88 };
89
90 #endif // SYNTAX_LINE_EDIT_H