2018-12-28 12:55:11 +01:00
|
|
|
|
#include "DatabaseWindow.h"
|
2017-01-21 18:16:57 +01:00
|
|
|
|
#include "util.h"
|
2019-08-16 10:49:38 +02:00
|
|
|
|
#include "CrudTab.h"
|
|
|
|
|
|
#include "widgets/CatalogTablesPage.h"
|
2019-01-29 19:41:27 +01:00
|
|
|
|
#include "OpenDatabase.h"
|
2019-10-06 13:52:45 +02:00
|
|
|
|
#include "catalog/PgDatabaseCatalog.h"
|
2019-08-24 20:47:32 +02:00
|
|
|
|
#include "ConnectionController.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
#include "MasterController.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include "TaskExecutor.h"
|
2019-08-15 16:18:47 +02:00
|
|
|
|
#include <QAction>
|
2019-01-01 14:34:14 +01:00
|
|
|
|
#include <QApplication>
|
2019-08-15 16:18:47 +02:00
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
#include <QMenuBar>
|
2019-01-01 14:34:14 +01:00
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QMetaMethod>
|
2019-08-15 16:18:47 +02:00
|
|
|
|
#include <QStandardPaths>
|
2019-08-16 08:29:27 +02:00
|
|
|
|
#include <QStatusBar>
|
2019-01-06 08:17:37 +01:00
|
|
|
|
#include <QTableView>
|
|
|
|
|
|
|
|
|
|
|
|
#include "EditTableWidget.h"
|
|
|
|
|
|
#include "CodeGenerator.h"
|
2019-08-15 16:18:47 +02:00
|
|
|
|
#include "QueryTool.h"
|
2017-01-08 15:16:16 +01:00
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
namespace pg = Pgsql;
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
2019-01-05 09:49:12 +01:00
|
|
|
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
2019-08-15 16:18:47 +02:00
|
|
|
|
: QMainWindow(parent)
|
2019-01-05 09:49:12 +01:00
|
|
|
|
, m_masterController(master)
|
|
|
|
|
|
{
|
2018-12-30 15:46:15 +01:00
|
|
|
|
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
|
|
|
|
|
this, &DatabaseWindow::catalogLoaded);
|
2019-01-01 11:15:16 +01:00
|
|
|
|
|
2019-08-15 16:18:47 +02:00
|
|
|
|
m_tabWidget = new QTabWidget(this);
|
2019-08-16 10:49:59 +02:00
|
|
|
|
m_tabWidget->setObjectName("m_tabWidget");
|
2019-08-15 16:18:47 +02:00
|
|
|
|
setCentralWidget(m_tabWidget);
|
|
|
|
|
|
|
|
|
|
|
|
createActions();
|
|
|
|
|
|
initMenus();
|
|
|
|
|
|
|
2019-01-01 14:34:14 +01:00
|
|
|
|
QMetaObject::connectSlotsByName(this);
|
2016-12-26 16:06:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-05 11:12:47 +01:00
|
|
|
|
DatabaseWindow::~DatabaseWindow() = default;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2019-08-15 16:18:47 +02:00
|
|
|
|
void DatabaseWindow::addPage(QWidget* page, QString caption)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_tabWidget->addTab(page, caption);
|
|
|
|
|
|
m_tabWidget->setCurrentWidget(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto index = m_tabWidget->indexOf(widget);
|
|
|
|
|
|
m_tabWidget->setTabText(index, caption);
|
|
|
|
|
|
m_tabWidget->setTabToolTip(index, hint);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto index = m_tabWidget->indexOf(widget);
|
|
|
|
|
|
auto n = ":/icons/16x16/" + iconname;
|
|
|
|
|
|
m_tabWidget->setTabIcon(index, QIcon(n));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
2018-09-18 11:53:19 +02:00
|
|
|
|
{
|
2019-08-19 10:05:05 +02:00
|
|
|
|
auto cgtab = new CodeGenerator(this);
|
|
|
|
|
|
cgtab->Init(m_database->catalog(), query, dbres);
|
|
|
|
|
|
addPage(cgtab, "Codegen");
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QueryTool *DatabaseWindow::GetActiveQueryTool()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto widget = m_tabWidget->currentWidget();
|
|
|
|
|
|
auto qt = dynamic_cast<QueryTool*>(widget);
|
|
|
|
|
|
return qt;
|
2018-09-18 11:53:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 07:31:48 +02:00
|
|
|
|
CrudTab *DatabaseWindow::GetActiveCrud()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto widget = m_tabWidget->currentWidget();
|
|
|
|
|
|
auto ct = dynamic_cast<CrudTab*>(widget);
|
|
|
|
|
|
return ct;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
2017-01-15 21:01:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_config = config;
|
2017-12-19 18:17:41 +01:00
|
|
|
|
try {
|
|
|
|
|
|
QString title = "pglab - ";
|
2019-09-16 19:24:39 +02:00
|
|
|
|
title += m_config.name();
|
2017-12-19 18:17:41 +01:00
|
|
|
|
setWindowTitle(title);
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
auto f = TaskExecutor::run(new LoadCatalog(m_config));
|
|
|
|
|
|
loadWatcher.setFuture(f);
|
|
|
|
|
|
|
2017-12-25 15:33:10 +01:00
|
|
|
|
} catch (std::runtime_error &ex) {
|
|
|
|
|
|
QMessageBox::critical(this, "Error reading database",
|
|
|
|
|
|
QString::fromUtf8(ex.what()));
|
|
|
|
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 16:18:47 +02:00
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::createActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/about.png"), QSize(), QIcon::Normal, QIcon::On);
|
2019-08-15 16:38:01 +02:00
|
|
|
|
auto action = actionAbout = new QAction(icon, tr("About"), this);
|
|
|
|
|
|
action->setObjectName("actionAbout");
|
2019-08-15 16:18:47 +02:00
|
|
|
|
}
|
2019-08-16 08:27:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/script_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionCancelQuery = new QAction(icon, tr("Cancel query"), this);
|
|
|
|
|
|
action->setObjectName("actionCancelQuery");
|
|
|
|
|
|
}
|
2019-08-15 16:18:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionClose = new QAction(icon, tr("Close"), this);
|
2019-08-15 16:38:01 +02:00
|
|
|
|
action->setObjectName("actionClose");
|
2019-08-15 16:18:47 +02:00
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
|
|
|
|
|
|
}
|
2019-08-15 19:32:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_copy.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionCopy = new QAction(icon, tr("Copy"), this);
|
|
|
|
|
|
action->setObjectName("actionCopy");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionCopyAsCString = new QAction(icon, tr("Copy as C string"), this);
|
|
|
|
|
|
action->setObjectName("actionCopyAsCString");
|
2019-08-19 11:38:04 +02:00
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionCopyAsRawCppString = new QAction(icon, tr("Copy as raw C++-string"), this);
|
|
|
|
|
|
action->setObjectName("actionCopyAsRawCppString");
|
2019-08-19 11:38:04 +02:00
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
2019-08-16 07:23:18 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/script_go.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionExecuteQuery = new QAction(icon, tr("Execute query"), this);
|
|
|
|
|
|
action->setObjectName("actionExecuteQuery");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F5));
|
2019-10-13 07:31:48 +02:00
|
|
|
|
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2019-08-16 07:23:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/lightbulb_off.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionExplain = new QAction(icon, tr("Explain"), this);
|
|
|
|
|
|
action->setObjectName("actionExplain");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F7));
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/lightbulb.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionExplainAnalyze = new QAction(icon, tr("Explain analyze"), this);
|
|
|
|
|
|
action->setObjectName("actionExplainAnalyze");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F7));
|
|
|
|
|
|
}
|
2019-08-15 19:32:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/table_save.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionExportData = new QAction(icon, tr("Export data"), this);
|
|
|
|
|
|
action->setObjectName("actionExportData");
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
auto action = actionGenerateCode = new QAction(tr("Generate code"), this);
|
|
|
|
|
|
action->setObjectName("actionGenerateCode");
|
|
|
|
|
|
}
|
2019-08-15 16:38:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionInspectInformationSchema = new QAction(icon, tr("Inspect information_schema"), this);
|
|
|
|
|
|
action->setObjectName("actionInspectInformationSchema");
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionInspectPgCatalog = new QAction(icon, tr("Inspect pg_catalog"), this);
|
|
|
|
|
|
action->setObjectName("actionInspectPgCatalog");
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionInspectUserSchemas = new QAction(icon, tr("Inspect user schemas"), this);
|
|
|
|
|
|
action->setObjectName("actionInspectUserSchemas");
|
|
|
|
|
|
}
|
2019-08-15 16:18:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/new_query_tab.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionNewSql = new QAction(icon, tr("New Query"), this);
|
2019-08-15 16:38:01 +02:00
|
|
|
|
action->setObjectName("actionNewSql");
|
2019-08-15 16:18:47 +02:00
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionOpenSql = new QAction(icon, tr("Open Query"), this);
|
2019-08-15 16:38:01 +02:00
|
|
|
|
action->setObjectName("actionOpenSql");
|
2019-08-15 16:18:47 +02:00
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
|
|
|
|
|
}
|
2019-08-19 11:38:04 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
//icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionPasteLangString = new QAction(icon, tr("Paste lang string"), this);
|
|
|
|
|
|
action->setObjectName("actionPasteLangString");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V));
|
|
|
|
|
|
}
|
2019-10-06 13:52:45 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
auto action = actionRefreshCatalog = new QAction(icon, tr("Refresh"), this);
|
2019-10-13 07:31:48 +02:00
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F5));
|
|
|
|
|
|
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
2019-10-06 13:52:45 +02:00
|
|
|
|
action->setObjectName("actionRefreshCatalog");
|
|
|
|
|
|
}
|
2019-10-13 07:31:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto action = actionRefreshCrud = new QAction(QIcon(), tr("Refresh"), this);
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::Key_F5));
|
|
|
|
|
|
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
|
|
|
|
|
action->setObjectName("actionRefreshCrud");
|
|
|
|
|
|
}
|
2019-08-15 19:32:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
auto action = actionSaveSql = new QAction(icon, tr("Save query"), this);
|
|
|
|
|
|
action->setObjectName("actionSaveSql");
|
|
|
|
|
|
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
auto action = actionSaveSqlAs = new QAction(tr("Save query as"), this);
|
|
|
|
|
|
action->setObjectName("actionSaveSqlAs");
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
auto action = actionSaveCopyOfSqlAs = new QAction(tr("Save copy of query as"), this);
|
|
|
|
|
|
action->setObjectName("actionSaveCopyOfSqlAs");
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
auto action = actionShowConnectionManager = new QAction(tr("Show connection manager"), this);
|
|
|
|
|
|
action->setObjectName("actionShowConnectionManager");
|
|
|
|
|
|
}
|
2019-08-15 16:18:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
|
2019-08-15 16:18:47 +02:00
|
|
|
|
void DatabaseWindow::initMenus()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto mb = new QMenuBar(this);
|
|
|
|
|
|
menuFile = mb->addMenu(tr("File"));
|
|
|
|
|
|
menuFile->addActions({
|
2019-08-15 19:32:33 +02:00
|
|
|
|
actionNewSql,
|
|
|
|
|
|
actionOpenSql,
|
|
|
|
|
|
seperator(),
|
|
|
|
|
|
actionSaveSql,
|
|
|
|
|
|
actionSaveSqlAs,
|
|
|
|
|
|
actionSaveCopyOfSqlAs,
|
|
|
|
|
|
seperator(),
|
|
|
|
|
|
actionExportData,
|
|
|
|
|
|
seperator(),
|
|
|
|
|
|
actionClose
|
2019-08-15 16:18:47 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2019-08-15 20:15:13 +02:00
|
|
|
|
menuEdit = mb->addMenu(tr("Edit"));
|
2019-08-15 19:32:33 +02:00
|
|
|
|
menuEdit->addActions({
|
|
|
|
|
|
actionCopy,
|
|
|
|
|
|
actionCopyAsCString,
|
|
|
|
|
|
actionCopyAsRawCppString,
|
2019-08-19 11:38:04 +02:00
|
|
|
|
// standard Paste missing Ctrl+V works however by default
|
|
|
|
|
|
actionPasteLangString,
|
2019-08-15 19:32:33 +02:00
|
|
|
|
actionGenerateCode
|
|
|
|
|
|
});
|
2019-08-15 20:15:13 +02:00
|
|
|
|
|
2019-08-16 07:23:18 +02:00
|
|
|
|
menuQuery = mb->addMenu(tr("Query"));
|
|
|
|
|
|
menuQuery->addActions({
|
|
|
|
|
|
actionExecuteQuery,
|
|
|
|
|
|
actionExplain,
|
2019-08-16 08:27:05 +02:00
|
|
|
|
actionExplainAnalyze,
|
|
|
|
|
|
actionCancelQuery
|
2019-08-16 07:23:18 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2019-10-06 13:52:45 +02:00
|
|
|
|
menuCatalog = mb->addMenu(tr("Catalog"));
|
|
|
|
|
|
menuCatalog->addActions({
|
|
|
|
|
|
actionRefreshCatalog
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-10-13 07:31:48 +02:00
|
|
|
|
menuCrud = mb->addMenu(tr("CRUD"));
|
|
|
|
|
|
menuCrud->addActions({
|
|
|
|
|
|
actionRefreshCrud
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
menuWindow = mb->addMenu(tr("Window"));
|
|
|
|
|
|
menuWindow->addActions({
|
2019-08-15 20:15:13 +02:00
|
|
|
|
actionInspectUserSchemas,
|
|
|
|
|
|
actionInspectPgCatalog,
|
|
|
|
|
|
actionInspectInformationSchema,
|
|
|
|
|
|
seperator(),
|
2019-08-15 19:32:33 +02:00
|
|
|
|
actionShowConnectionManager
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-15 16:18:47 +02:00
|
|
|
|
menuHelp = mb->addMenu(tr("Help"));
|
|
|
|
|
|
menuHelp->addActions({
|
2019-08-15 19:32:33 +02:00
|
|
|
|
seperator(),
|
|
|
|
|
|
actionAbout
|
2019-08-15 16:18:47 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
setMenuBar(mb);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
QAction *DatabaseWindow::seperator()
|
2019-08-15 16:18:47 +02:00
|
|
|
|
{
|
2019-08-15 19:32:33 +02:00
|
|
|
|
auto ac = new QAction(this);
|
|
|
|
|
|
ac->setSeparator(true);
|
|
|
|
|
|
return ac;
|
2019-08-15 16:18:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 07:31:48 +02:00
|
|
|
|
void DatabaseWindow::newCreateTablePage()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto w = new EditTableWidget(m_database, this);
|
|
|
|
|
|
m_tabWidget->addTab(w, "Create table");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::newCrudPage(Oid tableoid)
|
|
|
|
|
|
{
|
|
|
|
|
|
CrudTab *ct = new CrudTab(this, this);
|
|
|
|
|
|
ct->addAction(actionRefreshCrud);
|
|
|
|
|
|
addPage(ct, "crud");
|
|
|
|
|
|
ct->setConfig(tableoid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::newCatalogInspectorPage(QString caption, NamespaceFilter filter)
|
2019-08-16 10:49:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
auto ct = new CatalogInspector(m_database, this);
|
2019-10-13 07:31:48 +02:00
|
|
|
|
ct->addAction(actionRefreshCatalog);
|
|
|
|
|
|
|
2019-08-16 10:49:38 +02:00
|
|
|
|
addPage(ct, caption);
|
|
|
|
|
|
ct->setNamespaceFilter(filter);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected);
|
|
|
|
|
|
}
|
2019-08-15 16:38:01 +02:00
|
|
|
|
|
2019-08-16 10:49:59 +02:00
|
|
|
|
void DatabaseWindow::closeTab(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *widget = m_tabWidget->widget(index);
|
|
|
|
|
|
|
|
|
|
|
|
auto qt = dynamic_cast<QueryTool*>(widget);
|
|
|
|
|
|
if (qt && qt->canClose()) {
|
|
|
|
|
|
m_tabWidget->removeTab(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (index >= 0) {
|
|
|
|
|
|
m_tabWidget->removeTab(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-08-15 16:18:47 +02:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::catalogLoaded()
|
2017-12-25 15:33:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
try {
|
2018-12-30 15:46:15 +01:00
|
|
|
|
m_database = loadWatcher.future().result();
|
2017-12-25 15:33:10 +01:00
|
|
|
|
|
2019-08-19 10:05:05 +02:00
|
|
|
|
// for (auto f : { "user", "pg_catalog", "information_schema" }) {
|
|
|
|
|
|
// // TODO open inspector windows
|
|
|
|
|
|
// }
|
|
|
|
|
|
// newCreateTablePage();
|
|
|
|
|
|
on_actionNewSql_triggered();
|
2019-01-29 19:41:27 +01:00
|
|
|
|
} catch (const OpenDatabaseException &ex) {
|
|
|
|
|
|
QMessageBox::critical(this, "Error reading database", ex.text());
|
2017-12-19 19:06:36 +01:00
|
|
|
|
close();
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
2017-01-15 21:01:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 10:49:38 +02:00
|
|
|
|
void DatabaseWindow::tableSelected(Oid tableoid)
|
|
|
|
|
|
{
|
|
|
|
|
|
newCrudPage(tableoid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionAbout_triggered()
|
2017-01-09 07:39:09 +01:00
|
|
|
|
{
|
2017-02-01 18:01:02 +01:00
|
|
|
|
QMessageBox::about(this, "pgLab 0.1", tr(
|
2019-01-05 11:12:47 +01:00
|
|
|
|
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
"\n"
|
2017-12-28 09:20:42 +01:00
|
|
|
|
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
|
|
|
|
|
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
2017-02-01 18:01:02 +01:00
|
|
|
|
"FOR A PARTICULAR PURPOSE.\n"
|
|
|
|
|
|
"\n"
|
2018-12-29 18:59:54 +01:00
|
|
|
|
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
|
2017-02-04 11:55:49 +01:00
|
|
|
|
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
"\n"
|
|
|
|
|
|
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
2017-12-19 19:55:12 +01:00
|
|
|
|
"attribution 3.0 license."
|
2017-02-01 18:01:02 +01:00
|
|
|
|
));
|
|
|
|
|
|
|
2017-01-09 07:39:09 +01:00
|
|
|
|
}
|
2017-01-13 19:09:58 +01:00
|
|
|
|
|
2019-08-16 08:27:05 +02:00
|
|
|
|
void DatabaseWindow::on_actionCancelQuery_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 10:49:59 +02:00
|
|
|
|
void DatabaseWindow::on_actionClose_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionCopy_triggered()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
QWidget *w = QApplication::focusWidget();
|
|
|
|
|
|
QTableView *tv = dynamic_cast<QTableView*>(w);
|
|
|
|
|
|
if (tv) {
|
|
|
|
|
|
copySelectionToClipboard(tv);
|
|
|
|
|
|
}
|
2017-02-05 08:23:06 +01:00
|
|
|
|
else {
|
|
|
|
|
|
const QMetaObject *meta = w->metaObject();
|
2019-10-05 16:41:14 +02:00
|
|
|
|
int i = meta->indexOfMethod("copy()");
|
2017-02-05 08:23:06 +01:00
|
|
|
|
if (i != -1) {
|
|
|
|
|
|
QMetaMethod method = meta->method(i);
|
|
|
|
|
|
method.invoke(w, Qt::AutoConnection);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
2017-02-05 08:23:06 +01:00
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
void DatabaseWindow::on_actionCopyAsCString_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->copyQueryAsCString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionCopyAsRawCppString_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->copyQueryAsRawCppString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 07:23:18 +02:00
|
|
|
|
void DatabaseWindow::on_actionExecuteQuery_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionExplain_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->explain(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionExplainAnalyze_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->explain(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
void DatabaseWindow::on_actionExportData_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->exportData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionGenerateCode_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->generateCode();
|
2019-08-19 10:05:05 +02:00
|
|
|
|
//newCodeGenPage
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionInspectInformationSchema_triggered()
|
|
|
|
|
|
{
|
2019-10-13 07:31:48 +02:00
|
|
|
|
newCatalogInspectorPage("information_schema", NamespaceFilter::InformationSchema);
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionInspectPgCatalog_triggered()
|
|
|
|
|
|
{
|
2019-10-13 07:31:48 +02:00
|
|
|
|
newCatalogInspectorPage("pg_catalog", NamespaceFilter::PgCatalog);
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionInspectUserSchemas_triggered()
|
|
|
|
|
|
{
|
2019-10-13 07:31:48 +02:00
|
|
|
|
newCatalogInspectorPage("Schema", NamespaceFilter::User);
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionNewSql_triggered()
|
|
|
|
|
|
{
|
2019-08-16 08:29:27 +02:00
|
|
|
|
auto *ct = new QueryTool(this, this);
|
2019-10-13 07:31:48 +02:00
|
|
|
|
ct->addAction(actionExecuteQuery);
|
2019-12-03 19:08:13 +01:00
|
|
|
|
addPage(ct, "new");
|
2019-08-15 19:32:33 +02:00
|
|
|
|
ct->newdoc();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionOpenSql_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
|
|
|
|
|
QString file_name = QFileDialog::getOpenFileName(this,
|
|
|
|
|
|
tr("Open sql query"), home_dir, tr("SQL files (*.sql *.txt)"));
|
|
|
|
|
|
if ( ! file_name.isEmpty()) {
|
2019-08-16 08:29:27 +02:00
|
|
|
|
auto *ct = new QueryTool(this, this);
|
2019-08-15 19:32:33 +02:00
|
|
|
|
if (ct->load(file_name)) {
|
2019-12-03 19:08:13 +01:00
|
|
|
|
ct->addAction(actionExecuteQuery);
|
|
|
|
|
|
addPage(ct, ct->title());
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
delete ct;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-19 11:38:04 +02:00
|
|
|
|
void DatabaseWindow::on_actionPasteLangString_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->pasteLangString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-06 13:52:45 +02:00
|
|
|
|
void DatabaseWindow::on_actionRefreshCatalog_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_database->refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 07:31:48 +02:00
|
|
|
|
void DatabaseWindow::on_actionRefreshCrud_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto crud = GetActiveCrud();
|
|
|
|
|
|
if (crud) {
|
|
|
|
|
|
crud->refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-15 19:32:33 +02:00
|
|
|
|
void DatabaseWindow::on_actionSaveSql_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->save();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionSaveSqlAs_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->saveAs();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionSaveCopyOfSqlAs_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto query_tool = GetActiveQueryTool();
|
|
|
|
|
|
if (query_tool) {
|
|
|
|
|
|
query_tool->saveCopyAs();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::on_actionShowConnectionManager_triggered()
|
|
|
|
|
|
{
|
2019-08-19 10:05:05 +02:00
|
|
|
|
m_masterController->connectionController()->showConnectionManager();
|
2019-08-15 19:32:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 10:49:59 +02:00
|
|
|
|
void DatabaseWindow::on_m_tabWidget_tabCloseRequested(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
closeTab(index);
|
|
|
|
|
|
}
|
2019-08-16 08:29:27 +02:00
|
|
|
|
|
2019-10-13 07:31:48 +02:00
|
|
|
|
void DatabaseWindow::on_m_tabWidget_currentChanged(int)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto widget = m_tabWidget->currentWidget();
|
|
|
|
|
|
auto qt = dynamic_cast<QueryTool*>(widget);
|
|
|
|
|
|
auto ct = dynamic_cast<CrudTab*>(widget);
|
|
|
|
|
|
auto ci = dynamic_cast<CatalogInspector*>(widget);
|
|
|
|
|
|
|
|
|
|
|
|
menuQuery->menuAction()->setVisible(qt != nullptr);
|
|
|
|
|
|
menuCatalog->menuAction()->setVisible(ci != nullptr);
|
|
|
|
|
|
menuCrud->menuAction()->setVisible(ct != nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-16 08:29:27 +02:00
|
|
|
|
void DatabaseWindow::setTitleForWidget(QWidget *widget, QString title, QString hint)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i = m_tabWidget->indexOf(widget);
|
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
|
m_tabWidget->setTabText(i, title);
|
|
|
|
|
|
m_tabWidget->setTabToolTip(i, hint);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::setIconForWidget(QWidget *widget, QIcon icon)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i = m_tabWidget->indexOf(widget);
|
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
|
m_tabWidget->setTabIcon(i, icon);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<OpenDatabase> DatabaseWindow::openDatabase()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_database;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::showStatusBarMessage(QString message)
|
|
|
|
|
|
{
|
|
|
|
|
|
statusBar()->showMessage(message);
|
|
|
|
|
|
}
|