mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
add basic autocompletion for tables and fields to the sql text input
this does only work on full table names, NOT on aliases for a full auto completion to work we need a sqlite parser
This commit is contained in:
47
src/sqltextedit.h
Normal file
47
src/sqltextedit.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef SQLTEXTEDIT_H
|
||||
#define SQLTEXTEDIT_H
|
||||
|
||||
#include <QTextEdit>
|
||||
|
||||
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 QTextEdit
|
||||
{
|
||||
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;
|
||||
|
||||
void clearFieldCompleterModelMap();
|
||||
QAbstractItemModel* addFieldCompleterModel(const QString& tablename, QAbstractItemModel *model);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void focusInEvent(QFocusEvent *e);
|
||||
|
||||
private:
|
||||
QString identifierUnderCursor() const;
|
||||
|
||||
private slots:
|
||||
void insertCompletion(const QString& completion);
|
||||
|
||||
private:
|
||||
QCompleter* m_Completer;
|
||||
QAbstractItemModel* m_defaultCompleterModel;
|
||||
FieldCompleterModelMap m_fieldCompleterMap;
|
||||
};
|
||||
|
||||
#endif // SQLTEXTEDIT_H
|
||||
Reference in New Issue
Block a user