Moved QueryParamListController to its own translation unit.
This commit is contained in:
parent
3a13b7ffb4
commit
3bf1ef4fe0
5 changed files with 88 additions and 75 deletions
49
pglab/QueryParamListController.cpp
Normal file
49
pglab/QueryParamListController.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "QueryParamListController.h"
|
||||||
|
#include "OpenDatabase.h"
|
||||||
|
#include "PgDatabaseCatalogue.h"
|
||||||
|
#include "PgTypeContainer.h"
|
||||||
|
#include <QTableView>
|
||||||
|
|
||||||
|
|
||||||
|
QueryParamListController::QueryParamListController(QTableView *tv,
|
||||||
|
OpenDatabase *opendb, QWidget *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, paramTableView(tv)
|
||||||
|
, m_openDatabase(opendb)
|
||||||
|
{
|
||||||
|
if (opendb) {
|
||||||
|
m_typeDelegate.setTypeSelectionModel(opendb->typeSelectionModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
paramTableView->setModel(&m_paramList);
|
||||||
|
paramTableView->setItemDelegateForColumn(1, &m_typeDelegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pgsql::Params QueryParamListController::params() const
|
||||||
|
{
|
||||||
|
Pgsql::Params params;
|
||||||
|
auto types = m_openDatabase->catalogue()->types();
|
||||||
|
for (auto e : m_paramList) {
|
||||||
|
Oid oid = types->getByName(e.type).oid;
|
||||||
|
params.add(e.value, oid);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QueryParamListController::empty() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return m_paramList.rowCount() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueryParamListController::on_addParam()
|
||||||
|
{
|
||||||
|
m_paramList.insertRows(m_paramList.rowCount(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueryParamListController::on_removeParam()
|
||||||
|
{
|
||||||
|
auto rc = m_paramList.rowCount();
|
||||||
|
if (rc > 0)
|
||||||
|
m_paramList.removeRows(rc-1, 1);
|
||||||
|
}
|
||||||
29
pglab/QueryParamListController.h
Normal file
29
pglab/QueryParamListController.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef QUERYPARAMLISTCONTROLLER_H
|
||||||
|
#define QUERYPARAMLISTCONTROLLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "ParamListModel.h"
|
||||||
|
#include "ParamTypeDelegate.h"
|
||||||
|
#include "Pgsql_Params.h"
|
||||||
|
|
||||||
|
class QTableView;
|
||||||
|
class OpenDatabase;
|
||||||
|
|
||||||
|
class QueryParamListController : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QueryParamListController(QTableView *tv, OpenDatabase *opendb, QWidget *parent);
|
||||||
|
|
||||||
|
Pgsql::Params params() const;
|
||||||
|
bool empty() const;
|
||||||
|
public slots:
|
||||||
|
void on_addParam();
|
||||||
|
void on_removeParam();
|
||||||
|
private:
|
||||||
|
QTableView *paramTableView;
|
||||||
|
OpenDatabase *m_openDatabase;
|
||||||
|
ParamListModel m_paramList;
|
||||||
|
ParamTypeDelegate m_typeDelegate;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QUERYPARAMLISTCONTROLLER_H
|
||||||
|
|
@ -15,54 +15,11 @@
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "PgTypeContainer.h"
|
|
||||||
#include "PgDatabaseCatalogue.h"
|
#include "PgDatabaseCatalogue.h"
|
||||||
|
#include "QueryParamListController.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "GlobalIoService.h"
|
#include "GlobalIoService.h"
|
||||||
|
|
||||||
QueryParamListController::QueryParamListController(QTableView *tv,
|
|
||||||
OpenDatabase *opendb, QWidget *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, paramTableView(tv)
|
|
||||||
, m_openDatabase(opendb)
|
|
||||||
{
|
|
||||||
if (opendb) {
|
|
||||||
m_typeDelegate.setTypeSelectionModel(opendb->typeSelectionModel());
|
|
||||||
}
|
|
||||||
|
|
||||||
paramTableView->setModel(&m_paramList);
|
|
||||||
paramTableView->setItemDelegateForColumn(1, &m_typeDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pgsql::Params QueryParamListController::params() const
|
|
||||||
{
|
|
||||||
Pgsql::Params params;
|
|
||||||
auto types = m_openDatabase->catalogue()->types();
|
|
||||||
for (auto e : m_paramList) {
|
|
||||||
Oid oid = types->getByName(e.type).oid;
|
|
||||||
params.add(e.value, oid);
|
|
||||||
}
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QueryParamListController::empty() const
|
|
||||||
{
|
|
||||||
|
|
||||||
return m_paramList.rowCount() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QueryParamListController::on_addParam()
|
|
||||||
{
|
|
||||||
m_paramList.insertRows(m_paramList.rowCount(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QueryParamListController::on_removeParam()
|
|
||||||
{
|
|
||||||
auto rc = m_paramList.rowCount();
|
|
||||||
if (rc > 0)
|
|
||||||
m_paramList.removeRows(rc-1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -295,21 +252,15 @@ bool QueryTab::continueWithoutSavingWarning()
|
||||||
bool QueryTab::saveSqlTo(const QString &filename)
|
bool QueryTab::saveSqlTo(const QString &filename)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
QFileInfo fileinfo(filename);
|
||||||
|
|
||||||
|
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream.setCodec("utf-8");
|
stream.setCodec("utf-8");
|
||||||
QString text = ui->queryEdit->toPlainText();
|
QString text = ui->queryEdit->toPlainText();
|
||||||
stream << text;
|
stream << text;
|
||||||
/*
|
|
||||||
QTextDocument *doc = ui->queryEdit->document();
|
|
||||||
QTextBlock block = doc->firstBlock();
|
|
||||||
while (stream.status() == QTextStream::Ok && block.isValid()) {
|
|
||||||
QString plain = block.text();
|
|
||||||
stream << plain << "\n";
|
|
||||||
block = block.next();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
stream.flush();
|
stream.flush();
|
||||||
if (stream.status() == QTextStream::Ok) {
|
if (stream.status() == QTextStream::Ok) {
|
||||||
|
|
@ -320,6 +271,7 @@ bool QueryTab::saveSqlTo(const QString &filename)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString QueryTab::promptUserForSaveSqlFilename()
|
QString QueryTab::promptUserForSaveSqlFilename()
|
||||||
{
|
{
|
||||||
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
#define QUERYTAB_H
|
#define QUERYTAB_H
|
||||||
|
|
||||||
#include "ASyncDBConnection.h"
|
#include "ASyncDBConnection.h"
|
||||||
#include "ParamListModel.h"
|
|
||||||
#include "ParamTypeDelegate.h"
|
|
||||||
#include "QueryResultModel.h"
|
#include "QueryResultModel.h"
|
||||||
#include "QueryExplainModel.h"
|
#include "QueryExplainModel.h"
|
||||||
#include "stopwatch.h"
|
#include "stopwatch.h"
|
||||||
|
|
@ -26,24 +24,7 @@ class QueryResultModel;
|
||||||
class QueryExplainModel;
|
class QueryExplainModel;
|
||||||
class PgTypeContainer;
|
class PgTypeContainer;
|
||||||
class OpenDatabase;
|
class OpenDatabase;
|
||||||
|
class QueryParamListController;
|
||||||
class QueryParamListController : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
QueryParamListController(QTableView *tv, OpenDatabase *opendb, QWidget *parent);
|
|
||||||
|
|
||||||
Pgsql::Params params() const;
|
|
||||||
bool empty() const;
|
|
||||||
public slots:
|
|
||||||
void on_addParam();
|
|
||||||
void on_removeParam();
|
|
||||||
private:
|
|
||||||
QTableView *paramTableView;
|
|
||||||
OpenDatabase *m_openDatabase;
|
|
||||||
ParamListModel m_paramList;
|
|
||||||
ParamTypeDelegate m_typeDelegate;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class QueryTab : public QWidget {
|
class QueryTab : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ PgDatabaseCatalogue.cpp \
|
||||||
GlobalIoService.cpp \
|
GlobalIoService.cpp \
|
||||||
CodeBuilderConfiguration.cpp \
|
CodeBuilderConfiguration.cpp \
|
||||||
ResultTableModelUtil.cpp \
|
ResultTableModelUtil.cpp \
|
||||||
BaseTableModel.cpp
|
BaseTableModel.cpp \
|
||||||
|
QueryParamListController.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
|
|
@ -111,7 +112,8 @@ PgDatabaseCatalogue.h \
|
||||||
GlobalIoService.h \
|
GlobalIoService.h \
|
||||||
CodeBuilderConfiguration.h \
|
CodeBuilderConfiguration.h \
|
||||||
ResultTableModelUtil.h \
|
ResultTableModelUtil.h \
|
||||||
BaseTableModel.h
|
BaseTableModel.h \
|
||||||
|
QueryParamListController.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
DatabaseWindow.ui \
|
DatabaseWindow.ui \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue