First version of multiple SQL scripts support in main window

Allow multiple SQL scripts in different tabs in the SQL tab of the main
window.

Auto completion support is still missing, the rest is working fine.
This commit is contained in:
Martin Kleusberg
2013-05-02 21:15:23 +02:00
parent 909d435ec6
commit 23d929ec0e
9 changed files with 266 additions and 166 deletions

62
src/SqlExecutionArea.cpp Normal file
View File

@@ -0,0 +1,62 @@
#include "SqlExecutionArea.h"
#include "sqltextedit.h"
#include "ExtendedTableWidget.h"
#include "SQLiteSyntaxHighlighter.h"
#include "sqlitetablemodel.h"
#include "sqlitedb.h"
#include "PreferencesDialog.h"
#include <QLabel>
#include <QSplitter>
#include <QVBoxLayout>
SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* db) :
QFrame(parent)
{
// Create widgets
splitter = new QSplitter(Qt::Vertical, this);
editor = new SqlTextEdit(this);
table = new ExtendedTableWidget(this);
errors = new QLabel(this);
// Set up widgets
QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);
font.setPointSize(8);
editor->setFont(font);
highlighter = new SQLiteSyntaxHighlighter(editor->document());
model = new SqliteTableModel(this, db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
table->setModel(model);
// Build layout
splitter->addWidget(editor);
splitter->addWidget(table);
layout = new QVBoxLayout(this);
layout->addWidget(splitter);
layout->addWidget(errors);
setLayout(layout);
}
void SqlExecutionArea::setTableNames(const QStringList& tables)
{
highlighter->setTableNames(tables);
}
QString SqlExecutionArea::getSql() const
{
return editor->toPlainText().trimmed();
}
QString SqlExecutionArea::getSelectedSql() const
{
return editor->textCursor().selectedText().trimmed();
}
void SqlExecutionArea::finishExecution(const QString& result)
{
errors->setText(result);
table->resizeColumnsToContents();
}