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:
Peinthor Rene
2013-02-14 17:32:54 +01:00
parent 158e35ae65
commit ba34c1e986
5 changed files with 330 additions and 3 deletions

47
src/sqltextedit.h Normal file
View 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