From 6fdf631fac25193b5c94e67874765d9e7399e7c0 Mon Sep 17 00:00:00 2001 From: eelke Date: Fri, 16 Aug 2019 10:49:38 +0200 Subject: [PATCH] Make double clicking on table in CatalogInspector open crud for selected table/view. --- pglab/CatalogInspector.cpp | 5 ++++ pglab/CatalogInspector.h | 2 ++ pglab/CrudTab.cpp | 37 ++++------------------------- pglab/CrudTab.h | 4 +++- pglab/DatabaseWindow.cpp | 36 ++++++++++++++++++++-------- pglab/DatabaseWindow.h | 4 ++++ pglab/widgets/CatalogTablesPage.cpp | 8 +++---- pglab/widgets/CatalogTablesPage.h | 4 ++++ 8 files changed, 53 insertions(+), 47 deletions(-) diff --git a/pglab/CatalogInspector.cpp b/pglab/CatalogInspector.cpp index 3435d08..1cfaae2 100644 --- a/pglab/CatalogInspector.cpp +++ b/pglab/CatalogInspector.cpp @@ -75,3 +75,8 @@ void CatalogInspector::setNamespaceFilter(NamespaceFilter filter) } // context()->setCaption(this, caption, hint); } + +CatalogTablesPage *CatalogInspector::tablesPage() +{ + return m_tablesPage; +} diff --git a/pglab/CatalogInspector.h b/pglab/CatalogInspector.h index d0ca4dc..7b72cbd 100644 --- a/pglab/CatalogInspector.h +++ b/pglab/CatalogInspector.h @@ -20,6 +20,8 @@ public: void setCatalog(std::shared_ptr cat); void setNamespaceFilter(NamespaceFilter filter); + + CatalogTablesPage *tablesPage(); private: QTabWidget *m_tabWidget = nullptr; CatalogTablesPage *m_tablesPage = nullptr; diff --git a/pglab/CrudTab.cpp b/pglab/CrudTab.cpp index 8953bf2..8d940d3 100644 --- a/pglab/CrudTab.cpp +++ b/pglab/CrudTab.cpp @@ -14,13 +14,14 @@ #include -CrudTab::CrudTab(std::shared_ptr open_database, QWidget *parent) +CrudTab::CrudTab(IDatabaseWindow *context, QWidget *parent) : QWidget(parent) + , m_context(context) , ui(new Ui::CrudTab) { ui->setupUi(this); - m_db = open_database; + m_db = context->openDatabase(); SetTableViewDefault(ui->tableView); @@ -50,6 +51,7 @@ void CrudTab::setConfig(Oid oid) //std::shared_ptr db, const PgCla { m_table = *m_db->catalog()->classes()->getByKey(oid); m_crudModel->setConfig(m_db, *m_table); + m_context->setTitleForWidget(this, m_table->objectName(), ""); } void CrudTab::refresh() @@ -116,33 +118,4 @@ void CrudTab::initActions() } } -//QList CrudTab::actions() -//{ -// return { m_refreshAction }; -//} - - -//void CrudPageModule::init() -//{ -// registerModuleAction("open", -// [this] (IPluginContentWidgetContext* context, -// const ModuleActionParameters ¶ms) -// { -// moduleAction_open(context, params); -// }); -//} - -//void CrudPageModule::moduleAction_open( -// IPluginContentWidgetContext* context, -// const ModuleActionParameters ¶ms -// ) -//{ -// // create new widget for specified table -// // hand widget to context for display -// CrudTab *ct = new CrudTab(context, this); -// context->addContentWidget(ct); // maybe CrudTab should do this -// ct->setConfig(params.at("oid").toUInt()); - -//} - -//REGISTER_PLUGIN_MODULE_CAT(CrudPageModule, "CRUD tool", "pglab.crudpage", "database") +// TODO refresh action diff --git a/pglab/CrudTab.h b/pglab/CrudTab.h index 961eaaf..f9db78b 100644 --- a/pglab/CrudTab.h +++ b/pglab/CrudTab.h @@ -2,6 +2,7 @@ #define CRUDTAB_H #include "catalog/PgClass.h" +#include "IDatabaseWindow.h" #include #include #include @@ -16,7 +17,7 @@ class CrudModel; class CrudTab : public QWidget { Q_OBJECT public: - explicit CrudTab(std::shared_ptr open_database, QWidget *parent = nullptr); + explicit CrudTab(IDatabaseWindow *context, QWidget *parent = nullptr); ~CrudTab() override; void setConfig(Oid oid); @@ -24,6 +25,7 @@ public slots: void refresh(); private: Ui::CrudTab *ui; + IDatabaseWindow *m_context; std::shared_ptr m_db; std::optional m_table; diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index e1b4d76..0ffe171 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -1,5 +1,7 @@ #include "DatabaseWindow.h" #include "util.h" +#include "CrudTab.h" +#include "widgets/CatalogTablesPage.h" #include "OpenDatabase.h" #include "MasterController.h" #include "TaskExecutor.h" @@ -14,7 +16,6 @@ #include #include "EditTableWidget.h" -#include "CatalogInspector.h" #include "CodeGenerator.h" #include "QueryTool.h" @@ -65,6 +66,13 @@ void DatabaseWindow::newCreateTablePage() m_tabWidget->addTab(w, "Create table"); } +void DatabaseWindow::newCrudPage(Oid tableoid) +{ + CrudTab *ct = new CrudTab(this, this); + addPage(ct, "crud"); + ct->setConfig(tableoid); +} + void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr dbres) { // TODO should this call be this direct or should it go through module system @@ -288,6 +296,15 @@ QAction *DatabaseWindow::seperator() return ac; } +void DatabaseWindow::createCatalogInspector(QString caption, NamespaceFilter filter) +{ + auto ct = new CatalogInspector(m_database, this); + addPage(ct, caption); + ct->setNamespaceFilter(filter); + + connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected); + +} void DatabaseWindow::catalogLoaded() @@ -307,6 +324,11 @@ void DatabaseWindow::catalogLoaded() } } +void DatabaseWindow::tableSelected(Oid tableoid) +{ + newCrudPage(tableoid); +} + void DatabaseWindow::on_actionAbout_triggered() { @@ -414,23 +436,17 @@ void DatabaseWindow::on_actionClose_triggered() void DatabaseWindow::on_actionInspectInformationSchema_triggered() { - auto ct = new CatalogInspector(m_database, this); - addPage(ct, "information_schema"); - ct->setNamespaceFilter(NamespaceFilter::InformationSchema); + createCatalogInspector("information_schema", NamespaceFilter::InformationSchema); } void DatabaseWindow::on_actionInspectPgCatalog_triggered() { - auto ct = new CatalogInspector(m_database, this); - addPage(ct, "pg_catalog"); - ct->setNamespaceFilter(NamespaceFilter::PgCatalog); + createCatalogInspector("pg_catalog", NamespaceFilter::PgCatalog); } void DatabaseWindow::on_actionInspectUserSchemas_triggered() { - auto ct = new CatalogInspector(m_database, this); - addPage(ct, "Schema"); - ct->setNamespaceFilter(NamespaceFilter::User); + createCatalogInspector("Schema", NamespaceFilter::User); } void DatabaseWindow::on_actionNewSql_triggered() diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index 5bd4573..0d1e215 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include "ConnectionConfig.h" +#include "CatalogInspector.h" #include "OpenDatabase.h" #include "Pgsql_Connection.h" #include "ControllableTask.h" @@ -106,13 +107,16 @@ private: QFutureWatcher loadWatcher; void newCreateTablePage(); + void newCrudPage(Oid tableoid); void createActions(); void initMenus(); QAction* seperator(); + void createCatalogInspector(QString caption, NamespaceFilter filter); private slots: void catalogLoaded(); + void tableSelected(Oid tableoid); // void tabWidget_tabCloseRequested(int index); // void tabWidget_currentChanged(int index); diff --git a/pglab/widgets/CatalogTablesPage.cpp b/pglab/widgets/CatalogTablesPage.cpp index a38992d..1bc7460 100644 --- a/pglab/widgets/CatalogTablesPage.cpp +++ b/pglab/widgets/CatalogTablesPage.cpp @@ -75,6 +75,9 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent) connect(m_tablesModel, &QAbstractItemModel::layoutChanged, this, &CatalogTablesPage::tableListTable_layoutChanged); + + connect(m_tableView, &QTableView::doubleClicked, + this, &CatalogTablesPage::on_tableListTable_doubleClicked); } void CatalogTablesPage::retranslateUi(bool /*all*/) @@ -136,13 +139,10 @@ void CatalogTablesPage::tableListTable_layoutChanged(const QListmapToSource(index).row(); PgClass table = m_tablesModel->getTable(row); if (table.oid() != InvalidOid) { -// context()->moduleAction("pglab.crudpage", "open", { -// { "oid", table.oid() } -// }); + tableSelected(table.oid()); } } diff --git a/pglab/widgets/CatalogTablesPage.h b/pglab/widgets/CatalogTablesPage.h index 4272143..b1a82de 100644 --- a/pglab/widgets/CatalogTablesPage.h +++ b/pglab/widgets/CatalogTablesPage.h @@ -6,6 +6,7 @@ #include #include #include +#include "Pgsql_oids.h" class CatalogConstraintPage; class CatalogIndexPage; @@ -32,6 +33,9 @@ public: void setNamespaceFilter(NamespaceFilter filter); void retranslateUi(bool all = true); + +signals: + void tableSelected(Oid tableoid); private: PgLabTableView *m_tableView = nullptr; TablesTableModel* m_tablesModel = nullptr;