forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqltextedit.h
67 lines (53 loc) · 1.78 KB
/
sqltextedit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef SQLTEXTEDIT_H
#define SQLTEXTEDIT_H
#include <QPlainTextEdit>
class QCompleter;
class QAbstractItemModel;
/**
* @brief The SqlTextEdit class
* With basic table and fieldname auto completion.
* This class is based on the Qt custom completion example.
*/
class SqlTextEdit : public QPlainTextEdit
{
Q_OBJECT
public:
explicit SqlTextEdit(QWidget *parent = 0);
virtual ~SqlTextEdit();
void setCompleter(QCompleter* completer);
QCompleter* completer() const;
void setDefaultCompleterModel(QAbstractItemModel* model);
// map that associates table -> field model
typedef QMap<QString,QAbstractItemModel*> FieldCompleterModelMap;
QAbstractItemModel* addFieldCompleterModel(const QString& tablename, QAbstractItemModel *model);
void insertFieldCompleterModels(const FieldCompleterModelMap& fieldmap);
protected:
void keyPressEvent(QKeyEvent *e);
void focusInEvent(QFocusEvent *e);
void resizeEvent(QResizeEvent* event);
void dropEvent(QDropEvent* e);
void lineNumberAreaPaintEvent(QPaintEvent* event);
int lineNumberAreaWidth();
private:
class LineNumberArea : public QWidget
{
public:
LineNumberArea(SqlTextEdit *editor) : QWidget(editor), parent(editor) {}
QSize sizeHint() const;
protected:
void paintEvent(QPaintEvent* event);
SqlTextEdit* parent;
};
LineNumberArea* lineNumberArea;
QString identifierUnderCursor() const;
private slots:
void insertCompletion(const QString& completion);
void highlightCurrentLine();
void updateLineNumberAreaWidth();
void updateLineNumberArea(const QRect& rect, int dy);
private:
QCompleter* m_Completer;
QAbstractItemModel* m_defaultCompleterModel;
FieldCompleterModelMap m_fieldCompleterMap;
};
#endif // SQLTEXTEDIT_H