2018-12-28 12:55:11 +01:00
|
|
|
|
#include "DatabaseWindow.h"
|
2019-01-01 14:34:14 +01:00
|
|
|
|
//#include "ui_DatabaseWindow.h"
|
2017-12-10 14:20:45 +01:00
|
|
|
|
#include "TablesPage.h"
|
2018-11-25 09:06:01 +01:00
|
|
|
|
#include "FunctionsPage.h"
|
2018-12-28 08:51:02 +01:00
|
|
|
|
#include "SequencesPage.h"
|
2017-08-23 13:27:23 +02:00
|
|
|
|
#include "QueryTab.h"
|
2017-01-21 18:16:57 +01:00
|
|
|
|
#include "util.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include "plugin_support/PluginContentWidget.h"
|
2019-01-01 14:34:14 +01:00
|
|
|
|
#include "plugin_support/PluginContentWidgetContextBase.h"
|
2018-09-18 11:53:19 +02:00
|
|
|
|
#include "CodeGenerator.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
#include "MasterController.h"
|
2017-12-28 07:23:20 +01:00
|
|
|
|
#include "ScopeGuard.h"
|
2018-12-15 20:27:40 +01:00
|
|
|
|
#include "EditTableWidget.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include "TaskExecutor.h"
|
2019-01-01 14:34:14 +01:00
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
#include <QMenuBar>
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QMetaMethod>
|
|
|
|
|
|
#include <QMetaObject>
|
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
|
#include <QTextTable>
|
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
#include <algorithm>
|
2017-01-08 15:16:16 +01:00
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
namespace pg = Pgsql;
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
namespace DatabaseWindow_details {
|
|
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
class DatabaseWindowContentContext: public PluginContentWidgetContextBase {
|
2018-12-29 18:59:54 +01:00
|
|
|
|
public:
|
|
|
|
|
|
explicit DatabaseWindowContentContext(DatabaseWindow *window)
|
|
|
|
|
|
: m_window(window)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) override
|
|
|
|
|
|
{
|
|
|
|
|
|
m_window->setTabCaptionForWidget(content, caption, hint);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setIcon(PluginContentWidget *content, const QString &iconname) override
|
|
|
|
|
|
{
|
|
|
|
|
|
m_window->setTabIcon(content, iconname);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<OpenDatabase> getDatabase() override
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_window->getDatabase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void showStatusMessage(const QString &msg) override
|
|
|
|
|
|
{
|
|
|
|
|
|
m_window->statusBar()->showMessage(msg);
|
|
|
|
|
|
}
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
|
|
|
|
|
void addContentWidget(PluginContentWidget *widget) override
|
|
|
|
|
|
{
|
|
|
|
|
|
m_window->addPage(widget, "");
|
|
|
|
|
|
}
|
2018-12-29 18:59:54 +01:00
|
|
|
|
private:
|
|
|
|
|
|
DatabaseWindow *m_window;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
using namespace DatabaseWindow_details;
|
|
|
|
|
|
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2019-01-01 11:15:16 +01:00
|
|
|
|
LMainWindow::LMainWindow(QWidget *parent)
|
2018-12-30 15:46:15 +01:00
|
|
|
|
: QMainWindow(parent)
|
2019-01-01 11:15:16 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_fileMenu = new QMenu("File T", this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LMainWindow::initModuleMenus()
|
|
|
|
|
|
{
|
|
|
|
|
|
menuBar()->addMenu(m_fileMenu);
|
|
|
|
|
|
addModuleMenuActions();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LMainWindow::addModuleMenuActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto reg = PluginRegister::getInstance();
|
|
|
|
|
|
auto mods = reg->modules();
|
|
|
|
|
|
for (auto && mod : mods) {
|
|
|
|
|
|
auto items = mod.second->menuActions();
|
|
|
|
|
|
for (auto && item : items) {
|
|
|
|
|
|
addMenuAction(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LMainWindow::addMenuAction(const MenuAction &ma)
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug() << "add action " << ma.text();
|
|
|
|
|
|
//auto ac =
|
|
|
|
|
|
m_fileMenu->addAction(ma.icon(), ma.text(),
|
|
|
|
|
|
[ma, this] ()
|
|
|
|
|
|
{
|
|
|
|
|
|
ma.perform(m_context);
|
|
|
|
|
|
},
|
|
|
|
|
|
ma.shortCut());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// auto ac = new QAction(this);
|
|
|
|
|
|
// ac->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
|
|
|
|
|
: LMainWindow(parent)
|
2019-01-01 14:34:14 +01:00
|
|
|
|
// , ui(new Ui::DatabaseWindow)
|
2017-02-01 18:01:02 +01:00
|
|
|
|
, m_masterController(master)
|
2016-12-26 16:06:55 +01:00
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
// ui->setupUi(this);
|
|
|
|
|
|
// ui->tabWidget->setDocumentMode(true);
|
|
|
|
|
|
|
|
|
|
|
|
// auto centralWidget = new QWidget(this);
|
|
|
|
|
|
// auto verticalLayout_3 = new QVBoxLayout(centralWidget);
|
|
|
|
|
|
// verticalLayout_3->setSpacing(4);
|
|
|
|
|
|
// verticalLayout_3->setContentsMargins(4, 4, 4, 4);
|
|
|
|
|
|
|
|
|
|
|
|
m_tabWidget = new QTabWidget(this);
|
|
|
|
|
|
m_tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
|
|
|
|
|
|
m_tabWidget->setDocumentMode(true);
|
|
|
|
|
|
// verticalLayout_3->addWidget(m_tabWidget);
|
|
|
|
|
|
|
|
|
|
|
|
setCentralWidget(m_tabWidget);
|
|
|
|
|
|
|
2019-01-04 18:29:22 +01:00
|
|
|
|
createActions();
|
|
|
|
|
|
|
2019-01-01 14:34:14 +01:00
|
|
|
|
auto menuBar = new QMenuBar(this);
|
|
|
|
|
|
setMenuBar(menuBar);
|
|
|
|
|
|
|
|
|
|
|
|
m_mainToolBar = new QToolBar(this);
|
2019-01-04 18:29:22 +01:00
|
|
|
|
m_mainToolBar->addAction(m_closeAction);
|
2019-01-01 14:34:14 +01:00
|
|
|
|
addToolBar(Qt::TopToolBarArea, m_mainToolBar);
|
|
|
|
|
|
|
|
|
|
|
|
auto statusBar = new QStatusBar(this);
|
|
|
|
|
|
setStatusBar(statusBar);
|
2018-12-30 15:46:15 +01:00
|
|
|
|
|
2019-01-01 11:15:16 +01:00
|
|
|
|
m_context = new DatabaseWindowContentContext(this);
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
DatabaseWindow::~DatabaseWindow()
|
2017-01-06 07:23:40 +01:00
|
|
|
|
{
|
2018-12-29 18:59:54 +01:00
|
|
|
|
delete m_context;
|
2019-01-01 14:34:14 +01:00
|
|
|
|
// delete ui;
|
2017-01-06 07:23:40 +01:00
|
|
|
|
}
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2019-01-04 18:29:22 +01:00
|
|
|
|
void DatabaseWindow::createActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
{
|
|
|
|
|
|
auto action = m_closeAction = new QAction(this);
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
|
icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On);
|
|
|
|
|
|
action->setIcon(icon);
|
|
|
|
|
|
connect(m_closeAction, &QAction::triggered, this, &DatabaseWindow::actionClose_triggered);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
QueryTab* DatabaseWindow::newSqlPage()
|
2017-01-21 18:16:57 +01:00
|
|
|
|
{
|
2018-12-29 18:59:54 +01:00
|
|
|
|
QueryTab *qt = new QueryTab(m_context);
|
2017-01-25 06:54:21 +01:00
|
|
|
|
qt->newdoc();
|
2018-04-21 14:36:33 +02:00
|
|
|
|
qt->focusEditor();
|
2018-12-30 15:44:05 +01:00
|
|
|
|
addPage(qt, "Tab");
|
2017-01-22 08:50:41 +01:00
|
|
|
|
return qt;
|
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
|
|
|
|
{
|
2018-12-29 18:59:54 +01:00
|
|
|
|
auto cgtab = new CodeGenerator(m_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
|
|
|
|
QueryTab *DatabaseWindow::GetActiveQueryTab()
|
2017-01-21 18:16:57 +01:00
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
QWidget *widget = m_tabWidget->currentWidget();
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
|
|
|
|
|
|
return qt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
//SCOPE_EXIT { loadFuture = {}; };
|
|
|
|
|
|
m_database = loadWatcher.future().result();
|
2017-12-25 15:33:10 +01:00
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
auto tt = new TablesPage(m_context, 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
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
auto pg_cat_tables = new TablesPage(m_context, 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
|
|
|
|
|
2018-12-31 15:20:55 +01:00
|
|
|
|
auto info_schema_tables = new TablesPage(m_context, 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
|
|
|
|
|
2017-12-19 18:17:41 +01:00
|
|
|
|
newSqlPage();
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionLoad_SQL_triggered()
|
2017-01-09 07:39:09 +01:00
|
|
|
|
{
|
2017-01-22 08:50:41 +01:00
|
|
|
|
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()) {
|
|
|
|
|
|
QueryTab* qt = newSqlPage();
|
|
|
|
|
|
qt->load(file_name);
|
2017-01-09 07:39:09 +01:00
|
|
|
|
}
|
2017-01-22 08:50:41 +01:00
|
|
|
|
|
2017-01-09 07:39:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionSave_SQL_triggered()
|
2017-01-21 08:09:12 +01:00
|
|
|
|
{
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->save();
|
2017-01-21 08:09:12 +01:00
|
|
|
|
}
|
2017-01-21 08:19:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionSave_SQL_as_triggered()
|
2017-01-21 08:19:47 +01:00
|
|
|
|
{
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->saveAs();
|
2017-01-21 08:19:47 +01:00
|
|
|
|
}
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2017-01-21 08:19:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionSave_copy_of_SQL_as_triggered()
|
2017-01-21 08:19:47 +01:00
|
|
|
|
{
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->saveCopyAs();
|
2017-01-09 07:39:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionExport_data_triggered()
|
2017-01-09 07:39:09 +01:00
|
|
|
|
{
|
2017-02-05 13:35:41 +01:00
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
|
|
|
|
|
|
QString file_name = QFileDialog::getSaveFileName(this,
|
|
|
|
|
|
tr("Export data"), home_dir, tr("CSV file (*.csv)"));
|
2017-01-09 07:39:09 +01:00
|
|
|
|
|
2017-02-05 13:35:41 +01:00
|
|
|
|
tab->exportData(file_name);
|
|
|
|
|
|
}
|
2017-01-09 07:39:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-04 18:29:22 +01:00
|
|
|
|
void DatabaseWindow::actionClose_triggered()
|
2017-01-09 07:39:09 +01:00
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
on_tabWidget_tabCloseRequested(m_tabWidget->currentIndex());
|
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(
|
2018-12-29 18:59:54 +01:00
|
|
|
|
"Copyrights 2016-2018, 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::closeEvent(QCloseEvent* /*event*/)
|
2017-01-19 17:48:44 +01:00
|
|
|
|
{
|
2017-01-21 18:16:57 +01:00
|
|
|
|
// TODO collect which files need saving
|
2017-02-20 06:43:33 +01:00
|
|
|
|
// std::vector<QString> files_to_save;
|
|
|
|
|
|
// int n = ui->tabWidget->count();
|
|
|
|
|
|
// for (int i = 0; i < n; ++i) {
|
|
|
|
|
|
// QWidget *w = ui->tabWidget->widget(i);
|
|
|
|
|
|
// QueryTab *qt = dynamic_cast<QueryTab*>(w);
|
|
|
|
|
|
// if (qt) {
|
|
|
|
|
|
// if (qt->isChanged()) {
|
|
|
|
|
|
// files_to_save.push_back(qt->fileName());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2017-02-19 17:41:05 +01:00
|
|
|
|
|
2017-02-20 06:43:33 +01:00
|
|
|
|
// QString s;
|
|
|
|
|
|
// for (const auto& e : files_to_save) {
|
|
|
|
|
|
// s += e + "\n";
|
|
|
|
|
|
// }
|
2017-02-19 17:41:05 +01:00
|
|
|
|
|
2017-02-20 06:43:33 +01:00
|
|
|
|
// QMessageBox msgBox;
|
|
|
|
|
|
// msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
|
// msgBox.setText("The following documents need to be saved");
|
|
|
|
|
|
// msgBox.setInformativeText(s);
|
|
|
|
|
|
// msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
|
|
|
|
// msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
|
// //int ret =
|
|
|
|
|
|
// msgBox.exec();
|
2017-02-19 17:41:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-01-19 17:48:44 +01:00
|
|
|
|
}
|
2017-01-21 08:09:12 +01:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::showEvent(QShowEvent *event)
|
2017-01-21 08:09:12 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (!event->spontaneous()) {
|
2017-01-21 18:16:57 +01:00
|
|
|
|
// m_queryTextChanged = false;
|
2017-01-21 08:09:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
event->accept();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionNew_SQL_triggered()
|
2017-01-21 18:16:57 +01:00
|
|
|
|
{
|
2017-12-10 14:20:45 +01:00
|
|
|
|
newSqlPage();
|
2017-01-22 08:50:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-14 20:24:41 +02:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_tabWidget_tabCloseRequested(int index)
|
2017-01-22 08:50:41 +01:00
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
QWidget *widget = m_tabWidget->widget(index);
|
2018-12-29 18:59:54 +01:00
|
|
|
|
PluginContentWidget *plg_page = dynamic_cast<PluginContentWidget*>(widget);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
if (plg_page) {
|
|
|
|
|
|
if (plg_page->canClose()) {
|
|
|
|
|
|
removePage(plg_page);
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->removeTab(index);
|
|
|
|
|
|
delete plg_page;
|
2018-05-14 20:24:41 +02:00
|
|
|
|
}
|
2017-01-22 08:50:41 +01:00
|
|
|
|
}
|
2018-05-14 20:24:41 +02:00
|
|
|
|
else {
|
|
|
|
|
|
// old behaviour shouldn't be needed any more when all pages have been migrated
|
|
|
|
|
|
// to PlgPage
|
|
|
|
|
|
QueryTab *qt = dynamic_cast<QueryTab*>(widget);
|
|
|
|
|
|
if (qt && qt->canClose()) {
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->removeTab(index);
|
|
|
|
|
|
delete qt;
|
2018-05-14 20:24:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
else if (index > 0) {
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->removeTab(index);
|
|
|
|
|
|
delete widget;
|
2018-05-14 20:24:41 +02:00
|
|
|
|
}
|
2019-01-01 14:34:14 +01:00
|
|
|
|
|
2018-04-10 20:21:50 +02:00
|
|
|
|
}
|
2017-01-21 18:16:57 +01:00
|
|
|
|
}
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
2017-02-01 18:01:02 +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
|
|
|
|
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionCopy_as_C_string_triggered()
|
2017-02-05 08:23:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
// Find which edit is active, copy the selected text or all text if no selection present
|
|
|
|
|
|
// Put quote's around each line and add escapes.
|
|
|
|
|
|
|
|
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->copyQueryAsCString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-05 16:02:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionCopy_as_raw_Cpp_string_triggered()
|
2017-10-05 16:02:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->copyQueryAsRawCppString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-14 20:24:41 +02:00
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void DatabaseWindow::addToolBarButtonsForPage(PluginContentWidget *page)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
std::vector<QAction*> actions = page->getToolbarActions();
|
|
|
|
|
|
QList<QAction*> list;
|
|
|
|
|
|
for (auto act : actions) {
|
|
|
|
|
|
list.append(act);
|
|
|
|
|
|
}
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_mainToolBar->addActions(list);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void DatabaseWindow::removeToolBarButtonsForPage(PluginContentWidget *page)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
std::vector<QAction*> actions = page->getToolbarActions();
|
|
|
|
|
|
for (auto act : actions) {
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_mainToolBar->removeAction(act);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void DatabaseWindow::addPage(PluginContentWidget* page, QString caption)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->addTab(page, caption);
|
|
|
|
|
|
m_tabWidget->setCurrentWidget(page);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
|
|
|
|
|
|
//addToolBarButtonsForPage(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void DatabaseWindow::removePage(PluginContentWidget *)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_tabWidget_currentChanged(int index)
|
2018-05-14 20:24:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
// remove buttons of old page
|
|
|
|
|
|
if (m_previousPage) {
|
|
|
|
|
|
removeToolBarButtonsForPage(m_previousPage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add buttons of new page
|
2018-12-29 18:59:54 +01:00
|
|
|
|
PluginContentWidget * page = nullptr;
|
2018-05-14 20:24:41 +02:00
|
|
|
|
if (index >= 0) {
|
2019-01-01 14:34:14 +01:00
|
|
|
|
QWidget *widget = m_tabWidget->widget(index);
|
2018-12-29 18:59:54 +01:00
|
|
|
|
page = dynamic_cast<PluginContentWidget*>(widget);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
if (page) {
|
|
|
|
|
|
addToolBarButtonsForPage(page);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
m_previousPage = page;
|
|
|
|
|
|
}
|
2018-09-18 11:53:19 +02:00
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
void DatabaseWindow::on_actionGenerate_code_triggered()
|
2018-09-18 11:53:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
QueryTab *tab = GetActiveQueryTab();
|
|
|
|
|
|
if (tab) {
|
|
|
|
|
|
tab->generateCode();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-12-29 18:59:54 +01:00
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint)
|
|
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
auto index = m_tabWidget->indexOf(widget);
|
|
|
|
|
|
m_tabWidget->setTabText(index, caption);
|
|
|
|
|
|
m_tabWidget->setTabToolTip(index, hint);
|
2018-12-29 18:59:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname)
|
|
|
|
|
|
{
|
2019-01-01 14:34:14 +01:00
|
|
|
|
auto index = m_tabWidget->indexOf(widget);
|
2018-12-29 18:59:54 +01:00
|
|
|
|
auto n = ":/icons/16x16/" + iconname;
|
2019-01-01 14:34:14 +01:00
|
|
|
|
m_tabWidget->setTabIcon(index, QIcon(n));
|
2018-12-29 18:59:54 +01:00
|
|
|
|
}
|