Needs work for correctly placing the items in menu and on toolbar. Old system still needs to be removed left in place to keep app useable.
131 lines
3.3 KiB
C++
131 lines
3.3 KiB
C++
#include "DatabaseWindow.h"
|
|
#include "plugin_support/IPluginContentWidgetContext.h"
|
|
#include "util.h"
|
|
#include "OpenDatabase.h"
|
|
#include "MasterController.h"
|
|
#include "TaskExecutor.h"
|
|
#include <QApplication>
|
|
#include <QMessageBox>
|
|
#include <QMetaMethod>
|
|
#include <QTableView>
|
|
|
|
// Pages that should become modules
|
|
#include "EditTableWidget.h"
|
|
#include "CodeGenerator.h"
|
|
|
|
namespace pg = Pgsql;
|
|
|
|
|
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
|
: LMainWindow(parent)
|
|
|
|
, m_masterController(master)
|
|
{
|
|
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
|
this, &DatabaseWindow::catalogLoaded);
|
|
|
|
initModuleMenus();
|
|
QMetaObject::connectSlotsByName(this);
|
|
}
|
|
|
|
DatabaseWindow::~DatabaseWindow() = default;
|
|
|
|
void DatabaseWindow::newCreateTablePage()
|
|
{
|
|
auto w = new EditTableWidget(m_database, this);
|
|
m_tabWidget->addTab(w, "Create table");
|
|
}
|
|
|
|
void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
|
{
|
|
// TODO should this call be this direct or should it go through module system
|
|
// yes it should otherwise context cannot properly setup toolbar and menu!!!
|
|
// auto cgtab = new CodeGenerator(context(), pluginModule(), this);
|
|
// cgtab->Init(m_database->catalog(), query, dbres);
|
|
// addPage(cgtab, "Codegen");
|
|
//
|
|
}
|
|
|
|
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
|
{
|
|
m_config = config;
|
|
try {
|
|
QString title = "pglab - ";
|
|
title += m_config.name().c_str();
|
|
setWindowTitle(title);
|
|
|
|
auto f = TaskExecutor::run(new LoadCatalog(m_config));
|
|
loadWatcher.setFuture(f);
|
|
|
|
} catch (std::runtime_error &ex) {
|
|
QMessageBox::critical(this, "Error reading database",
|
|
QString::fromUtf8(ex.what()));
|
|
|
|
close();
|
|
}
|
|
}
|
|
|
|
void DatabaseWindow::catalogLoaded()
|
|
{
|
|
try {
|
|
m_database = loadWatcher.future().result();
|
|
auto ctx = context();
|
|
ctx->registerObject(m_database);
|
|
|
|
for (auto f : { "user", "pg_catalog", "information_schema" })
|
|
ctx->moduleAction("pglab.catalog-inspector", "open", {
|
|
{ "namespace-filter", f }
|
|
});
|
|
|
|
newCreateTablePage();
|
|
} catch (const OpenDatabaseException &ex) {
|
|
QMessageBox::critical(this, "Error reading database", ex.text());
|
|
|
|
close();
|
|
}
|
|
}
|
|
|
|
|
|
void DatabaseWindow::on_actionAbout_triggered()
|
|
{
|
|
QMessageBox::about(this, "pgLab 0.1", tr(
|
|
"Copyrights 2016-2019, Eelke Klein, All Rights Reserved.\n"
|
|
"\n"
|
|
"The program is provided AS IS with NO WARRANTY OF ANY KIND, "
|
|
"INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
|
|
"FOR A PARTICULAR PURPOSE.\n"
|
|
"\n"
|
|
"This program is dynamically linked with Qt 5.12 Copyright (C) 2018 "
|
|
"The Qt Company Ltd. https://www.qt.io/licensing/. \n"
|
|
"\n"
|
|
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
|
"attribution 3.0 license."
|
|
));
|
|
|
|
}
|
|
|
|
void DatabaseWindow::on_actionShow_connection_manager_triggered()
|
|
{
|
|
m_masterController->showConnectionManager();
|
|
}
|
|
|
|
void DatabaseWindow::on_actionCopy_triggered()
|
|
{
|
|
// What should be copied?
|
|
|
|
QWidget *w = QApplication::focusWidget();
|
|
QTableView *tv = dynamic_cast<QTableView*>(w);
|
|
if (tv) {
|
|
copySelectionToClipboard(tv);
|
|
}
|
|
else {
|
|
const QMetaObject *meta = w->metaObject();
|
|
int i = meta->indexOfSlot("copy");
|
|
if (i != -1) {
|
|
QMetaMethod method = meta->method(i);
|
|
method.invoke(w, Qt::AutoConnection);
|
|
}
|
|
}
|
|
}
|
|
|
|
|