mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
SqlExecutionArea: Use Qt Designer for layout design
This commit is contained in:
@@ -1,44 +1,30 @@
|
||||
#include "SqlExecutionArea.h"
|
||||
#include "ui_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)
|
||||
QWidget(parent),
|
||||
ui(new Ui::SqlExecutionArea)
|
||||
{
|
||||
// Create widgets
|
||||
splitter = new QSplitter(Qt::Vertical, this);
|
||||
editor = new SqlTextEdit(this);
|
||||
table = new ExtendedTableWidget(this);
|
||||
errors = new QLabel(this);
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
|
||||
// Set up widgets
|
||||
QFont font("Monospace");
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
font.setPointSize(8);
|
||||
editor->setFont(font);
|
||||
|
||||
highlighter = new SQLiteSyntaxHighlighter(editor->document());
|
||||
// Create syntax highlighter
|
||||
highlighter = new SQLiteSyntaxHighlighter(ui->editEditor->document());
|
||||
|
||||
// Create model
|
||||
model = new SqliteTableModel(this, db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
|
||||
table->setModel(model);
|
||||
table->setEditTriggers(ExtendedTableWidget::NoEditTriggers);
|
||||
ui->tableResult->setModel(model);
|
||||
}
|
||||
|
||||
// Build layout
|
||||
splitter->addWidget(editor);
|
||||
splitter->addWidget(table);
|
||||
|
||||
layout = new QVBoxLayout(this);
|
||||
layout->addWidget(splitter);
|
||||
layout->addWidget(errors);
|
||||
|
||||
setLayout(layout);
|
||||
SqlExecutionArea::~SqlExecutionArea()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SqlExecutionArea::setTableNames(const QStringList& tables)
|
||||
@@ -48,16 +34,21 @@ void SqlExecutionArea::setTableNames(const QStringList& tables)
|
||||
|
||||
QString SqlExecutionArea::getSql() const
|
||||
{
|
||||
return editor->toPlainText().trimmed();
|
||||
return ui->editEditor->toPlainText().trimmed();
|
||||
}
|
||||
|
||||
QString SqlExecutionArea::getSelectedSql() const
|
||||
{
|
||||
return editor->textCursor().selectedText().trimmed();
|
||||
return ui->editEditor->textCursor().selectedText().trimmed();
|
||||
}
|
||||
|
||||
void SqlExecutionArea::finishExecution(const QString& result)
|
||||
{
|
||||
errors->setText(result);
|
||||
table->resizeColumnsToContents();
|
||||
ui->labelErrors->setText(result);
|
||||
ui->tableResult->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
SqlTextEdit* SqlExecutionArea::getEditor()
|
||||
{
|
||||
return ui->editEditor;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
#ifndef __SQLEXECUTIONAREA_H__
|
||||
#define __SQLEXECUTIONAREA_H__
|
||||
|
||||
#include <QFrame>
|
||||
#include <QWidget>
|
||||
#include "sqltextedit.h"
|
||||
class QSplitter;
|
||||
class SqlTextEdit;
|
||||
class ExtendedTableWidget;
|
||||
class QLabel;
|
||||
class QVBoxLayout;
|
||||
class SQLiteSyntaxHighlighter;
|
||||
class SqliteTableModel;
|
||||
class DBBrowserDB;
|
||||
class QStandardItemModel;
|
||||
|
||||
class SqlExecutionArea : public QFrame
|
||||
namespace Ui {
|
||||
class SqlExecutionArea;
|
||||
}
|
||||
|
||||
class SqlExecutionArea : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SqlExecutionArea(QWidget* parent = 0, DBBrowserDB* db = 0);
|
||||
~SqlExecutionArea();
|
||||
|
||||
QString getSql() const;
|
||||
QString getSelectedSql() const;
|
||||
|
||||
SqliteTableModel* getModel() { return model; }
|
||||
SqlTextEdit* getEditor() { return editor; }
|
||||
SqlTextEdit* getEditor();
|
||||
|
||||
public slots:
|
||||
virtual void setTableNames(const QStringList& tables);
|
||||
virtual void finishExecution(const QString& result);
|
||||
|
||||
private:
|
||||
QVBoxLayout* layout;
|
||||
QSplitter* splitter;
|
||||
SqlTextEdit* editor;
|
||||
SQLiteSyntaxHighlighter* highlighter;
|
||||
ExtendedTableWidget* table;
|
||||
SqliteTableModel* model;
|
||||
QLabel* errors;
|
||||
Ui::SqlExecutionArea* ui;
|
||||
SQLiteSyntaxHighlighter* highlighter;
|
||||
SqliteTableModel* model;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
60
src/SqlExecutionArea.ui
Normal file
60
src/SqlExecutionArea.ui
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SqlExecutionArea</class>
|
||||
<widget class="QWidget" name="SqlExecutionArea">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>434</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="SqlTextEdit" name="editEditor">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Monospace</family>
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="ExtendedTableWidget" name="tableResult">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelErrors">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>SqlTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>sqltextedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ExtendedTableWidget</class>
|
||||
<extends>QTableWidget</extends>
|
||||
<header>ExtendedTableWidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -76,7 +76,8 @@ FORMS += \
|
||||
PreferencesDialog.ui \
|
||||
EditDialog.ui \
|
||||
ExportCsvDialog.ui \
|
||||
ImportCsvDialog.ui
|
||||
ImportCsvDialog.ui \
|
||||
SqlExecutionArea.ui
|
||||
|
||||
LIBPATH_QHEXEDIT=$$PWD/../libs/qhexedit
|
||||
LIBPATH_ANTLR=$$PWD/../libs/antlr-2.7.7
|
||||
|
||||
Reference in New Issue
Block a user