Move syntax highlighter objects to SqlTextEdit class

Any SqlTextEdit object has its SQL syntax highlighter anyway, so it
makes sense to move the syntax highlighter object inside the text edit
class instead of maintining somewhere else. This hopefully makes the
code a bit easier to maintain.
This commit is contained in:
Martin Kleusberg
2014-11-09 12:20:02 +01:00
parent 7cfd80621e
commit f257f9248e
6 changed files with 12 additions and 27 deletions
+2 -15
View File
@@ -47,8 +47,6 @@ MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent),
ui(new Ui::MainWindow),
m_browseTableModel(new SqliteTableModel(this, &db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt())),
sqliteHighlighterLogUser(0),
sqliteHighlighterLogApp(0),
editWin(new EditDialog(this)),
gotoValidator(new QIntValidator(0, 0, this))
{
@@ -274,8 +272,8 @@ void MainWindow::populateStructure()
return;
QStringList tblnames = db.getBrowsableObjectNames();
sqliteHighlighterLogUser->setTableNames(tblnames);
sqliteHighlighterLogApp->setTableNames(tblnames);
ui->editLogUser->syntaxHighlighter()->setTableNames(tblnames);
ui->editLogApplication->syntaxHighlighter()->setTableNames(tblnames);
// setup models for sqltextedit autocomplete
completerModelTables.setRowCount(tblnames.count());
@@ -957,14 +955,6 @@ void MainWindow::openPreferences()
reloadSettings();
}
void MainWindow::createSyntaxHighlighters()
{
delete sqliteHighlighterLogApp;
delete sqliteHighlighterLogUser;
sqliteHighlighterLogApp = new SQLiteSyntaxHighlighter(ui->editLogApplication->document());
sqliteHighlighterLogUser = new SQLiteSyntaxHighlighter(ui->editLogUser->document());
}
//******************************************************************
//** Tree Events
//******************************************************************
@@ -1343,9 +1333,6 @@ void MainWindow::reloadSettings()
sqlArea->getEditor()->setFont(font);
}
// Create the syntax highlighters
createSyntaxHighlighters();
// Set font for SQL logs
ui->editLogApplication->setFont(logfont);
ui->editLogUser->setFont(logfont);
-5
View File
@@ -10,7 +10,6 @@
class QDragEnterEvent;
class EditDialog;
class SQLiteSyntaxHighlighter;
class QStandardItemModel;
class QIntValidator;
class QLabel;
@@ -75,9 +74,6 @@ private:
QLabel* statusEncodingLabel;
QLabel* statusEncryptionLabel;
SQLiteSyntaxHighlighter* sqliteHighlighterLogUser;
SQLiteSyntaxHighlighter* sqliteHighlighterLogApp;
DbStructureModel* dbStructureModel;
enum { MaxRecentFiles = 5 };
@@ -159,7 +155,6 @@ private slots:
void savePragmas();
void mainTabSelected( int tabindex );
void browseTableHeaderClicked(int logicalindex);
void createSyntaxHighlighters();
unsigned int openSqlTab(bool resetCounter = false);
void closeSqlTab(int index, bool force = false);
void openSqlFile();
+1 -4
View File
@@ -26,9 +26,6 @@ SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* _db) :
logfont.setPointSize(PreferencesDialog::getSettingsValue("log", "fontsize").toInt());
ui->editErrors->setFont(logfont);
// Create syntax highlighter
highlighter = new SQLiteSyntaxHighlighter(ui->editEditor->document());
// Create model
model = new SqliteTableModel(this, db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
ui->tableResult->setModel(model);
@@ -47,7 +44,7 @@ SqlExecutionArea::~SqlExecutionArea()
void SqlExecutionArea::setTableNames(const QStringList& tables)
{
highlighter->setTableNames(tables);
ui->editEditor->syntaxHighlighter()->setTableNames(tables);
}
QString SqlExecutionArea::getSql() const
-2
View File
@@ -5,7 +5,6 @@
#include <QWidget>
class SQLiteSyntaxHighlighter;
class SqliteTableModel;
class DBBrowserDB;
class QMenu;
@@ -39,7 +38,6 @@ public slots:
private:
DBBrowserDB* db;
Ui::SqlExecutionArea* ui;
SQLiteSyntaxHighlighter* highlighter;
SqliteTableModel* model;
QMenu* menuPopupSave;
};
+5 -1
View File
@@ -1,5 +1,6 @@
#include "sqltextedit.h"
#include "PreferencesDialog.h"
#include "SQLiteSyntaxHighlighter.h"
#include <QKeyEvent>
#include <QAbstractItemView>
@@ -11,7 +12,7 @@
#include <QMimeData>
SqlTextEdit::SqlTextEdit(QWidget* parent) :
QPlainTextEdit(parent), m_Completer(0), m_defaultCompleterModel(0)
QPlainTextEdit(parent), m_defaultCompleterModel(0)
{
// basic auto completer for sqliteedit
m_Completer = new QCompleter(this);
@@ -26,6 +27,9 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) :
font.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt());
setFont(font);
// Create syntax highlighter
m_syntaxHighlighter = new SQLiteSyntaxHighlighter(document());
// Create line number area
lineNumberArea = new LineNumberArea(this);
+4
View File
@@ -5,6 +5,7 @@
class QCompleter;
class QAbstractItemModel;
class SQLiteSyntaxHighlighter;
/**
* @brief The SqlTextEdit class
@@ -28,6 +29,8 @@ public:
QAbstractItemModel* addFieldCompleterModel(const QString& tablename, QAbstractItemModel *model);
void insertFieldCompleterModels(const FieldCompleterModelMap& fieldmap);
SQLiteSyntaxHighlighter* syntaxHighlighter() { return m_syntaxHighlighter; }
protected:
void keyPressEvent(QKeyEvent *e);
void focusInEvent(QFocusEvent *e);
@@ -62,6 +65,7 @@ private:
QCompleter* m_Completer;
QAbstractItemModel* m_defaultCompleterModel;
FieldCompleterModelMap m_fieldCompleterMap;
SQLiteSyntaxHighlighter* m_syntaxHighlighter;
};
#endif // SQLTEXTEDIT_H