mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-08 04:49:58 -05:00
SqlExecutionArea: Use Qt Designer for layout design
This commit is contained in:
+22
-31
@@ -1,44 +1,30 @@
|
|||||||
#include "SqlExecutionArea.h"
|
#include "SqlExecutionArea.h"
|
||||||
|
#include "ui_SqlExecutionArea.h"
|
||||||
#include "sqltextedit.h"
|
#include "sqltextedit.h"
|
||||||
#include "ExtendedTableWidget.h"
|
#include "ExtendedTableWidget.h"
|
||||||
#include "SQLiteSyntaxHighlighter.h"
|
#include "SQLiteSyntaxHighlighter.h"
|
||||||
#include "sqlitetablemodel.h"
|
#include "sqlitetablemodel.h"
|
||||||
#include "sqlitedb.h"
|
#include "sqlitedb.h"
|
||||||
#include "PreferencesDialog.h"
|
#include "PreferencesDialog.h"
|
||||||
#include <QLabel>
|
|
||||||
#include <QSplitter>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* db) :
|
SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* db) :
|
||||||
QFrame(parent)
|
QWidget(parent),
|
||||||
|
ui(new Ui::SqlExecutionArea)
|
||||||
{
|
{
|
||||||
// Create widgets
|
// Create UI
|
||||||
splitter = new QSplitter(Qt::Vertical, this);
|
ui->setupUi(this);
|
||||||
editor = new SqlTextEdit(this);
|
|
||||||
table = new ExtendedTableWidget(this);
|
|
||||||
errors = new QLabel(this);
|
|
||||||
|
|
||||||
// Set up widgets
|
// Create syntax highlighter
|
||||||
QFont font("Monospace");
|
highlighter = new SQLiteSyntaxHighlighter(ui->editEditor->document());
|
||||||
font.setStyleHint(QFont::TypeWriter);
|
|
||||||
font.setPointSize(8);
|
|
||||||
editor->setFont(font);
|
|
||||||
|
|
||||||
highlighter = new SQLiteSyntaxHighlighter(editor->document());
|
|
||||||
|
|
||||||
|
// Create model
|
||||||
model = new SqliteTableModel(this, db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
|
model = new SqliteTableModel(this, db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
|
||||||
table->setModel(model);
|
ui->tableResult->setModel(model);
|
||||||
table->setEditTriggers(ExtendedTableWidget::NoEditTriggers);
|
}
|
||||||
|
|
||||||
// Build layout
|
SqlExecutionArea::~SqlExecutionArea()
|
||||||
splitter->addWidget(editor);
|
{
|
||||||
splitter->addWidget(table);
|
delete ui;
|
||||||
|
|
||||||
layout = new QVBoxLayout(this);
|
|
||||||
layout->addWidget(splitter);
|
|
||||||
layout->addWidget(errors);
|
|
||||||
|
|
||||||
setLayout(layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlExecutionArea::setTableNames(const QStringList& tables)
|
void SqlExecutionArea::setTableNames(const QStringList& tables)
|
||||||
@@ -48,16 +34,21 @@ void SqlExecutionArea::setTableNames(const QStringList& tables)
|
|||||||
|
|
||||||
QString SqlExecutionArea::getSql() const
|
QString SqlExecutionArea::getSql() const
|
||||||
{
|
{
|
||||||
return editor->toPlainText().trimmed();
|
return ui->editEditor->toPlainText().trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SqlExecutionArea::getSelectedSql() const
|
QString SqlExecutionArea::getSelectedSql() const
|
||||||
{
|
{
|
||||||
return editor->textCursor().selectedText().trimmed();
|
return ui->editEditor->textCursor().selectedText().trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlExecutionArea::finishExecution(const QString& result)
|
void SqlExecutionArea::finishExecution(const QString& result)
|
||||||
{
|
{
|
||||||
errors->setText(result);
|
ui->labelErrors->setText(result);
|
||||||
table->resizeColumnsToContents();
|
ui->tableResult->resizeColumnsToContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
SqlTextEdit* SqlExecutionArea::getEditor()
|
||||||
|
{
|
||||||
|
return ui->editEditor;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-16
@@ -1,43 +1,38 @@
|
|||||||
#ifndef __SQLEXECUTIONAREA_H__
|
#ifndef __SQLEXECUTIONAREA_H__
|
||||||
#define __SQLEXECUTIONAREA_H__
|
#define __SQLEXECUTIONAREA_H__
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QWidget>
|
||||||
#include "sqltextedit.h"
|
#include "sqltextedit.h"
|
||||||
class QSplitter;
|
|
||||||
class SqlTextEdit;
|
|
||||||
class ExtendedTableWidget;
|
|
||||||
class QLabel;
|
|
||||||
class QVBoxLayout;
|
|
||||||
class SQLiteSyntaxHighlighter;
|
class SQLiteSyntaxHighlighter;
|
||||||
class SqliteTableModel;
|
class SqliteTableModel;
|
||||||
class DBBrowserDB;
|
class DBBrowserDB;
|
||||||
class QStandardItemModel;
|
|
||||||
|
|
||||||
class SqlExecutionArea : public QFrame
|
namespace Ui {
|
||||||
|
class SqlExecutionArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SqlExecutionArea : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SqlExecutionArea(QWidget* parent = 0, DBBrowserDB* db = 0);
|
explicit SqlExecutionArea(QWidget* parent = 0, DBBrowserDB* db = 0);
|
||||||
|
~SqlExecutionArea();
|
||||||
|
|
||||||
QString getSql() const;
|
QString getSql() const;
|
||||||
QString getSelectedSql() const;
|
QString getSelectedSql() const;
|
||||||
|
|
||||||
SqliteTableModel* getModel() { return model; }
|
SqliteTableModel* getModel() { return model; }
|
||||||
SqlTextEdit* getEditor() { return editor; }
|
SqlTextEdit* getEditor();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setTableNames(const QStringList& tables);
|
virtual void setTableNames(const QStringList& tables);
|
||||||
virtual void finishExecution(const QString& result);
|
virtual void finishExecution(const QString& result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* layout;
|
Ui::SqlExecutionArea* ui;
|
||||||
QSplitter* splitter;
|
SQLiteSyntaxHighlighter* highlighter;
|
||||||
SqlTextEdit* editor;
|
SqliteTableModel* model;
|
||||||
SQLiteSyntaxHighlighter* highlighter;
|
|
||||||
ExtendedTableWidget* table;
|
|
||||||
SqliteTableModel* model;
|
|
||||||
QLabel* errors;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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>
|
||||||
+2
-1
@@ -76,7 +76,8 @@ FORMS += \
|
|||||||
PreferencesDialog.ui \
|
PreferencesDialog.ui \
|
||||||
EditDialog.ui \
|
EditDialog.ui \
|
||||||
ExportCsvDialog.ui \
|
ExportCsvDialog.ui \
|
||||||
ImportCsvDialog.ui
|
ImportCsvDialog.ui \
|
||||||
|
SqlExecutionArea.ui
|
||||||
|
|
||||||
LIBPATH_QHEXEDIT=$$PWD/../libs/qhexedit
|
LIBPATH_QHEXEDIT=$$PWD/../libs/qhexedit
|
||||||
LIBPATH_ANTLR=$$PWD/../libs/antlr-2.7.7
|
LIBPATH_ANTLR=$$PWD/../libs/antlr-2.7.7
|
||||||
|
|||||||
Reference in New Issue
Block a user