From 7300865c77cf2a4a6dc93f3ae6fa5b2540739c18 Mon Sep 17 00:00:00 2001 From: eelke Date: Fri, 8 Apr 2022 20:16:42 +0200 Subject: [PATCH] Switched DatabaseWindow to using the form designer. --- pglab/DatabaseWindow.cpp | 591 +++++++++++++++------------------------ pglab/DatabaseWindow.h | 122 ++++---- pglab/DatabaseWindow.ui | 327 ++++++++++++++++++++++ pglab/pglab.pro | 1 + 4 files changed, 604 insertions(+), 437 deletions(-) create mode 100644 pglab/DatabaseWindow.ui diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index 2676f3d..95c7512 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -1,4 +1,5 @@ #include "DatabaseWindow.h" +#include "ui_DatabaseWindow.h" #include "util.h" #include "crud/CrudTab.h" #include "widgets/CatalogTablesPage.h" @@ -28,41 +29,40 @@ namespace pg = Pgsql; DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent) : QMainWindow(parent) + , ui(new Ui::DatabaseWindow) , m_masterController(master) { - m_tabWidget = new QTabWidget(this); - m_tabWidget->setObjectName("m_tabWidget"); - setCentralWidget(m_tabWidget); + ui->setupUi(this); - connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, &DatabaseWindow::m_tabWidget_tabCloseRequested); - connect(m_tabWidget, &QTabWidget::currentChanged, this, &DatabaseWindow::m_tabWidget_currentChanged); - - createActions(); - initMenus(); + connect(ui->mainTabs, &QTabWidget::tabCloseRequested, this, &DatabaseWindow::mainTabCloseRequested); + connect(ui->mainTabs, &QTabWidget::currentChanged, this, &DatabaseWindow::currentMainTabChanged); setAcceptDrops(true); } -DatabaseWindow::~DatabaseWindow() = default; +DatabaseWindow::~DatabaseWindow() +{ + delete ui; +} void DatabaseWindow::addPage(QWidget* page, QString caption) { - m_tabWidget->addTab(page, caption); - m_tabWidget->setCurrentWidget(page); + ui->mainTabs->addTab(page, caption); + ui->mainTabs->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); + auto index = ui->mainTabs->indexOf(widget); + ui->mainTabs->setTabText(index, caption); + ui->mainTabs->setTabToolTip(index, hint); } void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname) { - auto index = m_tabWidget->indexOf(widget); + auto index = ui->mainTabs->indexOf(widget); auto n = ":/icons/16x16/" + iconname; - m_tabWidget->setTabIcon(index, QIcon(n)); + ui->mainTabs->setTabIcon(index, QIcon(n)); } void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr dbres) @@ -74,22 +74,24 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptrcurrentWidget(); + auto widget = ui->mainTabs->currentWidget(); auto qt = dynamic_cast(widget); return qt; } CrudTab *DatabaseWindow::GetActiveCrud() { - auto widget = m_tabWidget->currentWidget(); + auto widget = ui->mainTabs->currentWidget(); auto ct = dynamic_cast(widget); return ct; } void DatabaseWindow::closeEvent(QCloseEvent *event) { - for (int idx = 0; idx < m_tabWidget->count(); ++idx) { - if (!canCloseTab(idx)) { + for (int idx = 0; idx < ui->mainTabs->count(); ++idx) + { + if (!canCloseTab(idx)) + { event->ignore(); return; } @@ -99,166 +101,44 @@ void DatabaseWindow::closeEvent(QCloseEvent *event) void DatabaseWindow::setConfig(const ConnectionConfig &config) { m_config = config; - try { + try + { QString title = "pglab - "; title += m_config.name(); setWindowTitle(title); auto cfg = m_config; auto qthis = QPointer(this); - QtConcurrent::run([cfg] { - return OpenDatabase::createOpenDatabase(cfg); - }).then(qApp, [qthis](OpenDatabase::OpenDatabaseSPtr db) { - if (qthis) { - qthis.data()->catalogLoaded(db); + QtConcurrent::run([cfg] + { + return OpenDatabase::createOpenDatabase(cfg); } - }); + ).then(qApp, [qthis](OpenDatabase::OpenDatabaseSPtr db) + { + if (qthis) + qthis.data()->catalogLoaded(db); + } + ); - } catch (std::runtime_error &ex) { + } + catch (std::runtime_error &ex) + { QMessageBox::critical(this, "Error reading database", QString::fromUtf8(ex.what())); - close(); } } -QAction* DatabaseWindow::createAction(QString iconname, QString caption, void (DatabaseWindow::*func)()) -{ - QIcon icon; - icon.addFile(iconname, QSize(), QIcon::Normal, QIcon::On); - QAction *action = new QAction(icon, caption, this); - connect(action, &QAction::triggered, this, func); - return action; -} - -QAction* DatabaseWindow::createAction(QString caption, void (DatabaseWindow::*func)()) -{ - QAction *action = new QAction(caption, this); - connect(action, &QAction::triggered, this, func); - return action; -} - -void DatabaseWindow::createActions() -{ - actionAbout = createAction(":/icons/about.png", tr("About"), &DatabaseWindow::actionAbout_triggered); - actionCancelQuery = createAction(":/icons/script_delete.png", tr("Cancel query"), &DatabaseWindow::actionCancelQuery_triggered); - actionClose = createAction(":/icons/page_white_delete.png", tr("Close"), &DatabaseWindow::actionClose_triggered); - actionCopy = createAction(":/icons/page_white_copy.png", tr("Copy"), &DatabaseWindow::actionCopy_triggered); - actionCopyAsCString = createAction(":/icons/token_shortland_character.png", tr("Copy as C string"), &DatabaseWindow::actionCopyAsCString_triggered); - actionCopyAsRawCppString = createAction(":/icons/token_shortland_character.png", tr("Copy as raw C++-string"), &DatabaseWindow::actionCopyAsRawCppString_triggered); - actionExecuteQuery = createAction(":/icons/script_go.png", tr("Execute query"), &DatabaseWindow::actionExecuteQuery_triggered); - actionExplain = createAction(":/icons/lightbulb_off.png", tr("Explain"), &DatabaseWindow::actionExplain_triggered); - actionExplainAnalyze = createAction(":/icons/lightbulb.png", tr("Explain analyze"), &DatabaseWindow::actionExplainAnalyze_triggered); - actionExportData = createAction(":/icons/table_save.png", tr("Export data"), &DatabaseWindow::actionExportData_triggered); - actionGenerateCode = createAction(tr("Generate code"), &DatabaseWindow::actionGenerateCode_triggered); - actionInspectInformationSchema = createAction(":/icons/page_white_add.png", tr("Inspect information_schema"), &DatabaseWindow::actionInspectInformationSchema_triggered); - actionInspectPgCatalog = createAction(":/icons/page_white_add.png", tr("Inspect pg_catalog"), &DatabaseWindow::actionInspectPgCatalog_triggered); - actionInspectUserSchemas = createAction(":/icons/page_white_add.png", tr("Inspect user schemas"), &DatabaseWindow::actionInspectUserSchemas_triggered); - actionServerInspector = createAction(":/icons/page_white_add.png", tr("Inspect server"), &DatabaseWindow::actionServerInspector_triggered); - actionNewSql = createAction(":/icons/new_query_tab.png", tr("New Query"), &DatabaseWindow::actionNewSql_triggered); - actionOpenSql = createAction(":/icons/folder.png", tr("Open Query"), &DatabaseWindow::actionOpenSql_triggered); - actionSaveSql = createAction(":/icons/script_save.png", tr("Save Query"), &DatabaseWindow::actionSaveSql_triggered); - actionPasteLangString = createAction(tr("Paste lang string"), &DatabaseWindow::actionPasteLangString_triggered); - actionRefreshCatalog = createAction(tr("Refresh"), &DatabaseWindow::actionRefreshCatalog_triggered); - actionRefreshCrud = createAction(tr("Refresh"), &DatabaseWindow::actionRefreshCrud_triggered); - actionSaveSqlAs = createAction(tr("Save query as"), &DatabaseWindow::actionSaveSqlAs_triggered); - actionSaveCopyOfSqlAs = createAction(tr("Save copy of query as"), &DatabaseWindow::actionSaveCopyOfSqlAs_triggered); - actionShowConnectionManager = createAction(tr("Show connection manager"), &DatabaseWindow::actionShowConnectionManager_triggered); - - actionClose->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W)); - actionCopy->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C)); - actionCopyAsCString->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C)); - actionExecuteQuery->setShortcut(QKeySequence(Qt::Key_F5)); - actionExplain->setShortcut(QKeySequence(Qt::Key_F7)); - actionExplainAnalyze->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_F7)); - actionNewSql->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); - actionOpenSql->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O)); - actionSaveSql->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); -} - - -void DatabaseWindow::initMenus() -{ - auto mb = new QMenuBar(this); - menuFile = mb->addMenu(tr("File")); - menuFile->addActions({ - actionNewSql, - actionOpenSql, - seperator(), - actionSaveSql, - actionSaveSqlAs, - actionSaveCopyOfSqlAs, - seperator(), - actionExportData, - seperator(), - actionClose - }); - - menuEdit = mb->addMenu(tr("Edit")); - menuEdit->addActions({ - actionCopy, - actionCopyAsCString, - actionCopyAsRawCppString, - // standard Paste missing Ctrl+V works however by default - actionPasteLangString, - actionGenerateCode - }); - - menuQuery = mb->addMenu(tr("Query")); - menuQuery->addActions({ - actionExecuteQuery, - actionExplain, - actionExplainAnalyze, - actionCancelQuery - }); - - menuCatalog = mb->addMenu(tr("Catalog")); - menuCatalog->addActions({ - actionRefreshCatalog - }); - - menuCrud = mb->addMenu(tr("CRUD")); - menuCrud->addActions({ - actionRefreshCrud - }); - - menuWindow = mb->addMenu(tr("Window")); - menuWindow->addActions({ - actionInspectUserSchemas, - actionInspectPgCatalog, - actionInspectInformationSchema, - actionServerInspector, - seperator(), - actionShowConnectionManager - }); - - - menuHelp = mb->addMenu(tr("Help")); - menuHelp->addActions({ - seperator(), - actionAbout - }); - - setMenuBar(mb); -} - -QAction *DatabaseWindow::seperator() -{ - auto ac = new QAction(this); - ac->setSeparator(true); - return ac; -} - void DatabaseWindow::newCreateTablePage() { auto w = new EditTableWidget(m_database, this); - m_tabWidget->addTab(w, "Create table"); + ui->mainTabs->addTab(w, "Create table"); } void DatabaseWindow::newCrudPage(Oid tableoid) { CrudTab *ct = new CrudTab(this, this); - ct->addAction(actionRefreshCrud); + ct->addAction(ui->actionRefreshCrud); addPage(ct, "crud"); ct->setConfig(tableoid); } @@ -269,7 +149,7 @@ void DatabaseWindow::newCatalogInspectorPage(QString caption, NamespaceFilter fi return; // would be better if we queued the operation for later auto ct = new CatalogInspector(m_database, this); - ct->addAction(actionRefreshCatalog); + ct->addAction(ui->actionRefreshCatalog); addPage(ct, caption); ct->setNamespaceFilter(filter); @@ -288,44 +168,48 @@ void DatabaseWindow::closeTab(int index) if (index < 0) return; - if (canCloseTab(index)) { - QWidget *widget = m_tabWidget->widget(index); - m_tabWidget->removeTab(index); + if (canCloseTab(index)) + { + QWidget *widget = ui->mainTabs->widget(index); + ui->mainTabs->removeTab(index); delete widget; } } bool DatabaseWindow::canCloseTab(int index) const { - QWidget *widget = m_tabWidget->widget(index); + QWidget *widget = ui->mainTabs->widget(index); auto mp = dynamic_cast(widget); - if (mp) { + if (mp) return mp->CanClose(true); - } + return true; } void DatabaseWindow::openSqlFile(QString file_name) { - if ( ! file_name.isEmpty()) { + if (!file_name.isEmpty()) + { auto *ct = new QueryTool(this, this); - if (ct->load(file_name)) { - ct->addAction(actionExecuteQuery); + if (ct->load(file_name)) + { + ct->addAction(ui->actionExecute_query); addPage(ct, ct->title()); } - else { + else delete ct; - } } - } void DatabaseWindow::catalogLoaded(OpenDatabase::OpenDatabaseSPtr db) { - try { + try + { m_database = db; - actionNewSql_triggered(); - } catch (const OpenDatabaseException &ex) { + on_actionNew_Query_triggered(); + } + catch (const OpenDatabaseException &ex) + { QMessageBox::critical(this, "Error reading database", ex.text()); close(); } @@ -336,222 +220,49 @@ void DatabaseWindow::tableSelected(Oid tableoid) newCrudPage(tableoid); } - -void DatabaseWindow::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::actionCancelQuery_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) { - query_tool->cancel(); - } -} - -void DatabaseWindow::actionClose_triggered() -{ - m_tabWidget->tabCloseRequested(m_tabWidget->currentIndex()); -} - -void DatabaseWindow::actionCopy_triggered() -{ - QWidget *w = QApplication::focusWidget(); - if (w == nullptr) - return; - - QTableView *tv = dynamic_cast(w); - if (tv) - copySelectionToClipboard(tv); - else - InvokeCopyIfPresent(w); -} - void DatabaseWindow::InvokeCopyIfPresent(QWidget *w) { const QMetaObject *meta = w->metaObject(); int i = meta->indexOfMethod("copy()"); - if (i != -1) { + if (i != -1) + { QMetaMethod method = meta->method(i); method.invoke(w, Qt::AutoConnection); } } -void DatabaseWindow::actionCopyAsCString_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->copyQueryAsCString(); -} - -void DatabaseWindow::actionCopyAsRawCppString_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->copyQueryAsRawCppString(); -} - -void DatabaseWindow::actionExecuteQuery_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->execute(); -} - -void DatabaseWindow::actionExplain_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->explain(false); -} - -void DatabaseWindow::actionExplainAnalyze_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->explain(true); -} - -void DatabaseWindow::actionExportData_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->exportData(); -} - -void DatabaseWindow::actionGenerateCode_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->generateCode(); -} - -void DatabaseWindow::actionInspectInformationSchema_triggered() -{ - newCatalogInspectorPage("information_schema", NamespaceFilter::InformationSchema); -} - -void DatabaseWindow::actionInspectPgCatalog_triggered() -{ - newCatalogInspectorPage("pg_catalog", NamespaceFilter::PgCatalog); -} - -void DatabaseWindow::actionInspectUserSchemas_triggered() -{ - newCatalogInspectorPage("Schema", NamespaceFilter::User); -} - -void DatabaseWindow::actionServerInspector_triggered() -{ - newServerInspectorPage(); -} - -void DatabaseWindow::actionNewSql_triggered() -{ - auto *ct = new QueryTool(this, this); - ct->addAction(actionExecuteQuery); - addPage(ct, "new"); - ct->newdoc(); -} - -void DatabaseWindow::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)")); - openSqlFile(file_name); -} - -void DatabaseWindow::actionPasteLangString_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->pasteLangString(); -} - -void DatabaseWindow::actionRefreshCatalog_triggered() -{ - m_database->refresh(); -} - -void DatabaseWindow::actionRefreshCrud_triggered() -{ - auto crud = GetActiveCrud(); - if (crud) - crud->refresh(); -} - -void DatabaseWindow::actionSaveSql_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->save(); -} - -void DatabaseWindow::actionSaveSqlAs_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->saveAs(); -} - -void DatabaseWindow::actionSaveCopyOfSqlAs_triggered() -{ - auto query_tool = GetActiveQueryTool(); - if (query_tool) - query_tool->saveCopyAs(); -} - -void DatabaseWindow::actionShowConnectionManager_triggered() -{ - m_masterController->connectionController()->showConnectionManager(); -} - -void DatabaseWindow::m_tabWidget_tabCloseRequested(int index) +void DatabaseWindow::mainTabCloseRequested(int index) { closeTab(index); } -void DatabaseWindow::m_tabWidget_currentChanged(int) +void DatabaseWindow::currentMainTabChanged(int) { - auto widget = m_tabWidget->currentWidget(); + auto widget = ui->mainTabs->currentWidget(); auto qt = dynamic_cast(widget); auto ct = dynamic_cast(widget); auto ci = dynamic_cast(widget); - menuQuery->menuAction()->setVisible(qt != nullptr); - menuCatalog->menuAction()->setVisible(ci != nullptr); - menuCrud->menuAction()->setVisible(ct != nullptr); + ui->menuQuery->menuAction()->setVisible(qt != nullptr); + ui->menuCatalog->menuAction()->setVisible(ci != nullptr); + ui->menuCRUD->menuAction()->setVisible(ct != nullptr); } 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); + int i = ui->mainTabs->indexOf(widget); + if (i >= 0) + { + ui->mainTabs->setTabText(i, title); + ui->mainTabs->setTabToolTip(i, hint); } } void DatabaseWindow::setIconForWidget(QWidget *widget, QIcon icon) { - int i = m_tabWidget->indexOf(widget); + int i = ui->mainTabs->indexOf(widget); if (i >= 0) - m_tabWidget->setTabIcon(i, icon); + ui->mainTabs->setTabIcon(i, icon); } @@ -574,9 +285,163 @@ void DatabaseWindow::dragEnterEvent(QDragEnterEvent *event) void DatabaseWindow::dropEvent(QDropEvent *event) { - foreach (const QUrl &url, event->mimeData()->urls()) { + foreach (const QUrl &url, event->mimeData()->urls()) + { QString file_name = url.toLocalFile(); qDebug() << "Dropped file:" << file_name; openSqlFile(file_name); } } + + + +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_actionCancel_query_triggered() +{ + CallOnActiveQueryTool(&QueryTool::cancel); +} + + +void DatabaseWindow::on_actionClose_triggered() +{ + ui->mainTabs->tabCloseRequested(ui->mainTabs->currentIndex()); +} + + +void DatabaseWindow::on_actionCopy_triggered() +{ + QWidget *w = QApplication::focusWidget(); + if (w == nullptr) + return; + + QTableView *tv = dynamic_cast(w); + if (tv) + copySelectionToClipboard(tv); + else + InvokeCopyIfPresent(w); +} + + +void DatabaseWindow::on_actionCopy_as_C_string_triggered() +{ + CallOnActiveQueryTool(&QueryTool::copyQueryAsCString); +} + +void DatabaseWindow::on_actionCopy_as_raw_C_string_triggered() +{ + CallOnActiveQueryTool(&QueryTool::copyQueryAsRawCppString); +} + +void DatabaseWindow::on_actionExecute_query_triggered() +{ + CallOnActiveQueryTool(&QueryTool::execute); +} + +void DatabaseWindow::on_actionExplain_triggered() +{ + CallOnActiveQueryTool(&QueryTool::explain, false); +} + +void DatabaseWindow::on_actionExplain_analyze_triggered() +{ + CallOnActiveQueryTool(&QueryTool::explain, true); +} + +void DatabaseWindow::on_actionExport_data_triggered() +{ + CallOnActiveQueryTool(&QueryTool::exportData); +} + +void DatabaseWindow::on_actionGenerate_code_triggered() +{ + CallOnActiveQueryTool(&QueryTool::generateCode); +} + +void DatabaseWindow::on_actionInspect_information_schema_triggered() +{ + newCatalogInspectorPage("information_schema", NamespaceFilter::InformationSchema); +} + +void DatabaseWindow::on_actionInspect_pg_catalog_triggered() +{ + newCatalogInspectorPage("pg_catalog", NamespaceFilter::PgCatalog); +} + +void DatabaseWindow::on_actionInspect_user_schemas_triggered() +{ + newCatalogInspectorPage("Schema", NamespaceFilter::User); +} + +void DatabaseWindow::on_actionInspect_server_triggered() +{ + newServerInspectorPage(); +} + +void DatabaseWindow::on_actionNew_Query_triggered() +{ + auto *ct = new QueryTool(this, this); + ct->addAction(ui->actionExecute_query); + addPage(ct, "new"); + ct->newdoc(); + +} + +void DatabaseWindow::on_actionOpen_Query_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)")); + openSqlFile(file_name); +} + +void DatabaseWindow::on_actionSave_Query_triggered() +{ + CallOnActiveQueryTool(&QueryTool::save); +} + +void DatabaseWindow::on_actionPaste_lang_string_triggered() +{ + CallOnActiveQueryTool(&QueryTool::pasteLangString); +} + +void DatabaseWindow::on_actionRefreshCatalog_triggered() +{ + m_database->refresh(); +} + +void DatabaseWindow::on_actionRefreshCrud_triggered() +{ + CallOnActiveCrud(&CrudTab::refresh); +} + +void DatabaseWindow::on_actionSave_query_as_triggered() +{ + CallOnActiveQueryTool(&QueryTool::saveAs); +} + +void DatabaseWindow::on_actionSave_copy_of_query_as_triggered() +{ + CallOnActiveQueryTool(&QueryTool::saveCopyAs); +} + +void DatabaseWindow::on_actionShow_connection_manager_triggered() +{ + m_masterController->connectionController()->showConnectionManager(); +} diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index 3b66326..fff4646 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -9,6 +9,9 @@ #include #include +namespace Ui { + class DatabaseWindow; +} namespace Pgsql { class Connection; } @@ -53,56 +56,13 @@ protected: virtual void closeEvent(QCloseEvent *event) override; private: - QTabWidget *m_tabWidget = nullptr; - QToolBar *m_mainToolBar = nullptr; + Ui::DatabaseWindow *ui; ConnectionConfig m_config; std::shared_ptr m_database; MasterController *m_masterController; - // Standard menu's - QMenu *m_fileMenu = nullptr; - - // Standard actions - QAction *actionAbout = nullptr; - QAction *actionCancelQuery = nullptr; - QAction *actionClose = nullptr; - QAction *actionCopy = nullptr; - QAction *actionCopyAsCString = nullptr; - QAction *actionCopyAsRawCppString = nullptr; - QAction *actionExecuteQuery = nullptr; - QAction *actionExplain = nullptr; - QAction *actionExplainAnalyze = nullptr; - QAction *actionExportData = nullptr; - QAction *actionGenerateCode = nullptr; - QAction *actionInspectInformationSchema = nullptr; ///< Create or switch to pgcatalog tab - QAction *actionInspectPgCatalog = nullptr; ///< Create or switch to pgcatalog tab - QAction *actionInspectUserSchemas = nullptr; ///< Create or switch to pgcatalog tab - QAction *actionServerInspector = nullptr; - QAction *actionNewSql = nullptr; - QAction *actionOpenSql = nullptr; - QAction *actionPasteLangString = nullptr; - QAction *actionRefreshCatalog = nullptr; - QAction *actionRefreshCrud = nullptr; - QAction *actionSaveSql = nullptr; - QAction *actionSaveSqlAs = nullptr; - QAction *actionSaveCopyOfSqlAs = nullptr; - QAction *actionShowConnectionManager = nullptr; - - QMenu *menuEdit = nullptr; - QMenu *menuFile = nullptr; - QMenu *menuHelp = nullptr; - QMenu *menuQuery = nullptr; - QMenu *menuCatalog = nullptr; - QMenu *menuCrud = nullptr; - QMenu *menuWindow = nullptr; - - void createActions(); - void initMenus(); - - QAction* seperator(); - void newCreateTablePage(); void newCrudPage(Oid tableoid); void newCatalogInspectorPage(QString caption, NamespaceFilter filter); @@ -115,41 +75,37 @@ private: /// If it has it invokes this method using reflection. static void InvokeCopyIfPresent(QWidget *w); - QAction* createAction(QString icon, QString caption, void (DatabaseWindow::*func)()); - QAction* createAction(QString caption, void (DatabaseWindow::*func)()); - private slots: void catalogLoaded(OpenDatabase::OpenDatabaseSPtr db); void tableSelected(Oid tableoid); + void mainTabCloseRequested(int index); + void currentMainTabChanged(int index); - void actionAbout_triggered(); - void actionCancelQuery_triggered(); - void actionClose_triggered(); - void actionCopy_triggered(); - void actionCopyAsCString_triggered(); - void actionCopyAsRawCppString_triggered(); - void actionExecuteQuery_triggered(); - void actionExplain_triggered(); - void actionExplainAnalyze_triggered(); - void actionExportData_triggered(); - void actionGenerateCode_triggered(); - void actionInspectInformationSchema_triggered(); - void actionInspectPgCatalog_triggered(); - void actionInspectUserSchemas_triggered(); - void actionServerInspector_triggered(); - void actionNewSql_triggered(); - void actionOpenSql_triggered(); - void actionPasteLangString_triggered(); - void actionRefreshCatalog_triggered(); - void actionRefreshCrud_triggered(); - void actionSaveSql_triggered(); - void actionSaveSqlAs_triggered(); - void actionSaveCopyOfSqlAs_triggered(); - void actionShowConnectionManager_triggered(); - void m_tabWidget_tabCloseRequested(int index); - void m_tabWidget_currentChanged(int index); + void on_actionAbout_triggered(); + void on_actionCancel_query_triggered(); + void on_actionClose_triggered(); + void on_actionCopy_triggered(); + void on_actionCopy_as_C_string_triggered(); + void on_actionCopy_as_raw_C_string_triggered(); + void on_actionExecute_query_triggered(); + void on_actionExplain_triggered(); + void on_actionExplain_analyze_triggered(); + void on_actionExport_data_triggered(); + void on_actionGenerate_code_triggered(); + void on_actionInspect_information_schema_triggered(); + void on_actionInspect_pg_catalog_triggered(); + void on_actionInspect_user_schemas_triggered(); + void on_actionInspect_server_triggered(); + void on_actionNew_Query_triggered(); + void on_actionOpen_Query_triggered(); + void on_actionSave_Query_triggered(); + void on_actionPaste_lang_string_triggered(); + void on_actionRefreshCatalog_triggered(); + void on_actionRefreshCrud_triggered(); + void on_actionSave_query_as_triggered(); + void on_actionSave_copy_of_query_as_triggered(); + void on_actionShow_connection_manager_triggered(); - // IDatabaseWindow interface public: virtual void setTitleForWidget(QWidget *widget, QString title, QString hint) override; virtual void setIconForWidget(QWidget *widget, QIcon icon) override; @@ -160,6 +116,24 @@ public: protected: virtual void dragEnterEvent(QDragEnterEvent *event) override; virtual void dropEvent(QDropEvent *event) override; + +private: + + template + void CallOnActiveQueryTool(T (QueryTool::*Func)(Params...), Params... args) + { + auto query_tool = GetActiveQueryTool(); + if (query_tool) + (query_tool->*Func)(&args...); + } + + template + void CallOnActiveCrud(T (CrudTab::*Func)(Params...), Params... args) + { + auto crud = GetActiveCrud(); + if (crud) + (crud->*Func)(&args...); + } }; #endif // MAINWINDOW_H diff --git a/pglab/DatabaseWindow.ui b/pglab/DatabaseWindow.ui new file mode 100644 index 0000000..2560e24 --- /dev/null +++ b/pglab/DatabaseWindow.ui @@ -0,0 +1,327 @@ + + + DatabaseWindow + + + + 0 + 0 + 1260 + 732 + + + + pglab + + + + + + + -1 + + + + + + + + + 0 + 0 + 1260 + 29 + + + + + File + + + + + + + + + + + + + + + Edit + + + + + + + + + + Query + + + + + + + + + Catalog + + + + + + CRUD + + + + + + View + + + + + + + + + + + Help + + + + + + + + + + + + + + + :/icons/about.png:/icons/about.png + + + About + + + + + + :/icons/script_delete.png:/icons/script_delete.png + + + Cancel query + + + + + + :/icons/page_white_delete.png:/icons/page_white_delete.png + + + Close + + + Ctrl+W + + + + + + :/icons/page_white_copy.png:/icons/page_white_copy.png + + + Copy + + + Ctrl+C + + + + + + :/icons/token_shortland_character.png:/icons/token_shortland_character.png + + + Copy as C string + + + Ctrl+Shift+C + + + + + + :/icons/token_shortland_character.png:/icons/token_shortland_character.png + + + Copy as raw C++-string + + + + + + :/icons/script_go.png:/icons/script_go.png + + + Execute query + + + F5 + + + + + + :/icons/lightbulb_off.png:/icons/lightbulb_off.png + + + Explain + + + F7 + + + + + + :/icons/lightbulb.png:/icons/lightbulb.png + + + Explain analyze + + + Shift+F7 + + + + + + :/icons/table_save.png:/icons/table_save.png + + + Export data + + + + + Generate code + + + + + + :/icons/page_white_add.png:/icons/page_white_add.png + + + Inspect information_schema + + + + + + :/icons/page_white_add.png:/icons/page_white_add.png + + + Inspect pg_catalog + + + + + + :/icons/page_white_add.png:/icons/page_white_add.png + + + Inspect user schemas + + + + + + :/icons/page_white_add.png:/icons/page_white_add.png + + + Inspect server + + + + + + :/icons/new_query_tab.png:/icons/new_query_tab.png + + + New Query + + + Ctrl+N + + + + + + :/icons/folder.png:/icons/folder.png + + + Open Query + + + Ctrl+O + + + + + + :/icons/script_save.png:/icons/script_save.png + + + Save Query + + + Ctrl+S + + + + + Paste lang string + + + + + Refresh + + + + + Refresh + + + + + Save query as + + + + + Save copy of query as + + + + + Show connection manager + + + + + + + + diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 241c979..76c1517 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -172,6 +172,7 @@ CustomDataRole.h \ FORMS += \ ConnectionManagerWindow.ui \ CreateDatabaseDialog.ui \ + DatabaseWindow.ui \ TuplesResultWidget.ui \ QueryTab.ui \ ProcessStdioWidget.ui \