2018-12-28 12:55:11 +01:00
|
|
|
|
#include "DatabaseWindow.h"
|
2019-01-05 11:12:47 +01:00
|
|
|
|
#include "plugin_support/IPluginContentWidgetContext.h"
|
2017-01-21 18:16:57 +01:00
|
|
|
|
#include "util.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
#include "MasterController.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include "TaskExecutor.h"
|
2019-01-01 14:34:14 +01:00
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QMetaMethod>
|
2019-01-06 08:17:37 +01:00
|
|
|
|
#include <QTableView>
|
|
|
|
|
|
|
|
|
|
|
|
// Pages that should become modules
|
|
|
|
|
|
#include "TablesPage.h"
|
|
|
|
|
|
#include "EditTableWidget.h"
|
|
|
|
|
|
#include "CodeGenerator.h"
|
|
|
|
|
|
#include "FunctionsPage.h"
|
|
|
|
|
|
#include "SequencesPage.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)
|
|
|
|
|
|
: LMainWindow(parent)
|
|
|
|
|
|
|
|
|
|
|
|
, 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
|
|
|
|
|
|
|
|
|
|
initModuleMenus();
|
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
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::newCreateTablePage()
|
2018-12-15 20:27:40 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto w = new EditTableWidget(m_database, this);
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(w, "Create table");
|
2018-12-15 20:27:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
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-01-05 11:12:47 +01:00
|
|
|
|
auto cgtab = new CodeGenerator(context(), this);
|
2018-11-25 09:05:01 +01:00
|
|
|
|
cgtab->Init(m_database->catalog(), query, dbres);
|
2018-09-18 11:53:19 +02:00
|
|
|
|
addPage(cgtab, "Codegen");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 - ";
|
|
|
|
|
|
title += m_config.name().c_str();
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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();
|
2019-01-05 11:12:47 +01:00
|
|
|
|
auto ctx = context();
|
|
|
|
|
|
ctx->registerObject(m_database);
|
2017-12-25 15:33:10 +01:00
|
|
|
|
|
2019-01-05 11:12:47 +01:00
|
|
|
|
auto tt = new TablesPage(ctx, this);
|
2018-11-25 09:05:01 +01:00
|
|
|
|
tt->setCatalog(m_database->catalog());
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(tt, "Tables");
|
2017-12-19 18:17:41 +01:00
|
|
|
|
|
2019-01-05 11:12:47 +01:00
|
|
|
|
auto pg_cat_tables = new TablesPage(ctx, this);
|
2018-12-29 10:56:24 +01:00
|
|
|
|
pg_cat_tables->setNamespaceFilter(TablesTableModel::PgCatalog);
|
|
|
|
|
|
pg_cat_tables->setCatalog(m_database->catalog());
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(pg_cat_tables, "pg_catalog");
|
2018-12-29 10:56:24 +01:00
|
|
|
|
|
2019-01-05 11:12:47 +01:00
|
|
|
|
auto info_schema_tables = new TablesPage(ctx, this);
|
2018-12-29 10:56:24 +01:00
|
|
|
|
info_schema_tables->setNamespaceFilter(TablesTableModel::InformationSchema);
|
|
|
|
|
|
info_schema_tables->setCatalog(m_database->catalog());
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(info_schema_tables, "information_schema");
|
2018-12-29 10:56:24 +01:00
|
|
|
|
|
2018-11-25 09:06:01 +01:00
|
|
|
|
auto functions_page = new FunctionsPage(this);
|
|
|
|
|
|
functions_page->setCatalog(m_database->catalog());
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(functions_page, "Functions");
|
2018-01-09 20:39:43 +01:00
|
|
|
|
|
2018-12-28 08:51:02 +01:00
|
|
|
|
auto sequences_page = new SequencesPage(this);
|
|
|
|
|
|
sequences_page->setCatalog(m_database->catalog());
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(sequences_page, "Sequences");
|
2018-12-28 08:51:02 +01:00
|
|
|
|
|
2018-12-15 20:27:40 +01:00
|
|
|
|
newCreateTablePage();
|
2017-12-19 18:17:41 +01:00
|
|
|
|
} catch (std::runtime_error &ex) {
|
2017-12-19 19:06:36 +01:00
|
|
|
|
QMessageBox::critical(this, "Error reading database",
|
|
|
|
|
|
QString::fromUtf8(ex.what()));
|
|
|
|
|
|
|
|
|
|
|
|
close();
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
2017-01-15 21:01:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-09 07:39:09 +01: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
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionShow_connection_manager_triggered()
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_masterController->showConnectionManager();
|
|
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionCopy_triggered()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
// What should be copied?
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
int i = meta->indexOfSlot("copy");
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|