-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSqlEditor.h
More file actions
36 lines (28 loc) · 1 KB
/
Copy pathSqlEditor.h
File metadata and controls
36 lines (28 loc) · 1 KB
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
#pragma once
#include <QCompleter>
#include <QPlainTextEdit>
#include <QStringList>
// A QPlainTextEdit for raw SQL input that adds inline autocomplete: SQL
// keywords are always suggested, plus table/column names once the schema
// is known (see setSchemaWords). Popup opens automatically while typing
// an identifier, or on demand with Ctrl+Space.
class SqlEditor : public QPlainTextEdit
{
Q_OBJECT
public:
explicit SqlEditor(QWidget* parent = nullptr);
// Replaces the schema-derived part of the completion list (table and
// column names). Built-in SQL keywords are kept regardless.
void setSchemaWords(const QStringList& words);
protected:
void keyPressEvent(QKeyEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
private slots:
void insertCompletion(const QString& completion);
private:
QString textUnderCursor() const;
void updateCompleterModel();
QCompleter* m_completer = nullptr;
QStringList m_keywords;
QStringList m_schemaWords;
};