From 1a208a6a2d3c14fc39fb9a8e07e227f86b101d02 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 13 Oct 2019 07:31:48 +0200 Subject: [PATCH] Crud page has now reload action. F5 key is bound to the execute query, reload catalog and reload crud actions. By using addAction to add these actions to the relevant pages the ambiguity of the shortcut is resolved. --- pglab/CrudTab.cpp | 13 ------- pglab/CrudTab.h | 16 -------- pglab/DatabaseWindow.cpp | 80 +++++++++++++++++++++++++++++++--------- pglab/DatabaseWindow.h | 13 +++++-- 4 files changed, 71 insertions(+), 51 deletions(-) diff --git a/pglab/CrudTab.cpp b/pglab/CrudTab.cpp index 8d940d3..a7c6591 100644 --- a/pglab/CrudTab.cpp +++ b/pglab/CrudTab.cpp @@ -106,16 +106,3 @@ void CrudTab::headerCustomContextMenu(const QPoint &pos) auto horizontal_header = ui->tableView->horizontalHeader(); menu->popup(horizontal_header->mapToGlobal(pos)); } - -void CrudTab::initActions() -{ - - { - auto ac = new QAction(QIcon(":/icons/script_go.png"), tr("Refresh"), this); - ac->setShortcut(QKeySequence(Qt::Key_F5)); - connect(ac, &QAction::triggered, this, &CrudTab::refresh); - m_refreshAction = ac; - } -} - -// TODO refresh action diff --git a/pglab/CrudTab.h b/pglab/CrudTab.h index f9db78b..640d3fe 100644 --- a/pglab/CrudTab.h +++ b/pglab/CrudTab.h @@ -31,29 +31,13 @@ private: std::optional m_table; CrudModel *m_crudModel = nullptr; - QAction *m_refreshAction = nullptr; void initActions(); -// virtual QList actions() override; - private slots: void on_actionRemove_rows_triggered(); void headerCustomContextMenu(const QPoint &pos); }; -//class CrudPageModule: public PluginModule { -// Q_OBJECT -//public: -// using PluginModule::PluginModule; - -// void init(); -//private slots: - -//private: - -// void moduleAction_open(IPluginContentWidgetContext* context, const ModuleActionParameters ¶ms); -//}; - #endif // CRUDTAB_H diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index 2cee827..92ae164 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -63,19 +63,6 @@ void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname) m_tabWidget->setTabIcon(index, QIcon(n)); } -void DatabaseWindow::newCreateTablePage() -{ - auto w = new EditTableWidget(m_database, this); - 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) { auto cgtab = new CodeGenerator(this); @@ -90,6 +77,13 @@ QueryTool *DatabaseWindow::GetActiveQueryTool() return qt; } +CrudTab *DatabaseWindow::GetActiveCrud() +{ + auto widget = m_tabWidget->currentWidget(); + auto ct = dynamic_cast(widget); + return ct; +} + void DatabaseWindow::setConfig(const ConnectionConfig &config) { m_config = config; @@ -158,6 +152,7 @@ void DatabaseWindow::createActions() auto action = actionExecuteQuery = new QAction(icon, tr("Execute query"), this); action->setObjectName("actionExecuteQuery"); action->setShortcut(QKeySequence(Qt::Key_F5)); + action->setShortcutContext(Qt::WidgetWithChildrenShortcut); } { QIcon icon; @@ -225,8 +220,16 @@ void DatabaseWindow::createActions() { QIcon icon; auto action = actionRefreshCatalog = new QAction(icon, tr("Refresh"), this); + action->setShortcut(QKeySequence(Qt::Key_F5)); + action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setObjectName("actionRefreshCatalog"); } + { + auto action = actionRefreshCrud = new QAction(QIcon(), tr("Refresh"), this); + action->setShortcut(QKeySequence(Qt::Key_F5)); + action->setShortcutContext(Qt::WidgetWithChildrenShortcut); + action->setObjectName("actionRefreshCrud"); + } { QIcon icon; icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On); @@ -289,6 +292,11 @@ void DatabaseWindow::initMenus() actionRefreshCatalog }); + menuCrud = mb->addMenu(tr("CRUD")); + menuCrud->addActions({ + actionRefreshCrud + }); + menuWindow = mb->addMenu(tr("Window")); menuWindow->addActions({ actionInspectUserSchemas, @@ -315,14 +323,29 @@ QAction *DatabaseWindow::seperator() return ac; } -void DatabaseWindow::createCatalogInspector(QString caption, NamespaceFilter filter) +void DatabaseWindow::newCreateTablePage() +{ + auto w = new EditTableWidget(m_database, this); + m_tabWidget->addTab(w, "Create table"); +} + +void DatabaseWindow::newCrudPage(Oid tableoid) +{ + CrudTab *ct = new CrudTab(this, this); + ct->addAction(actionRefreshCrud); + addPage(ct, "crud"); + ct->setConfig(tableoid); +} + +void DatabaseWindow::newCatalogInspectorPage(QString caption, NamespaceFilter filter) { auto ct = new CatalogInspector(m_database, this); + ct->addAction(actionRefreshCatalog); + addPage(ct, caption); ct->setNamespaceFilter(filter); connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected); - } void DatabaseWindow::closeTab(int index) @@ -467,22 +490,23 @@ void DatabaseWindow::on_actionGenerateCode_triggered() void DatabaseWindow::on_actionInspectInformationSchema_triggered() { - createCatalogInspector("information_schema", NamespaceFilter::InformationSchema); + newCatalogInspectorPage("information_schema", NamespaceFilter::InformationSchema); } void DatabaseWindow::on_actionInspectPgCatalog_triggered() { - createCatalogInspector("pg_catalog", NamespaceFilter::PgCatalog); + newCatalogInspectorPage("pg_catalog", NamespaceFilter::PgCatalog); } void DatabaseWindow::on_actionInspectUserSchemas_triggered() { - createCatalogInspector("Schema", NamespaceFilter::User); + newCatalogInspectorPage("Schema", NamespaceFilter::User); } void DatabaseWindow::on_actionNewSql_triggered() { auto *ct = new QueryTool(this, this); + ct->addAction(actionExecuteQuery); addPage(ct, "query"); ct->newdoc(); } @@ -516,6 +540,14 @@ void DatabaseWindow::on_actionRefreshCatalog_triggered() m_database->refresh(); } +void DatabaseWindow::on_actionRefreshCrud_triggered() +{ + auto crud = GetActiveCrud(); + if (crud) { + crud->refresh(); + } +} + void DatabaseWindow::on_actionSaveSql_triggered() { auto query_tool = GetActiveQueryTool(); @@ -550,6 +582,18 @@ void DatabaseWindow::on_m_tabWidget_tabCloseRequested(int index) closeTab(index); } +void DatabaseWindow::on_m_tabWidget_currentChanged(int) +{ + auto widget = m_tabWidget->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); +} + void DatabaseWindow::setTitleForWidget(QWidget *widget, QString title, QString hint) { int i = m_tabWidget->indexOf(widget); diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index 7e296bd..7a01675 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -15,6 +15,7 @@ namespace Pgsql { class Connection; } +class CrudTab; class MasterController; class QCloseEvent; class OpenDatabase; @@ -48,6 +49,7 @@ public: virtual void newCodeGenPage(QString query, std::shared_ptr dbres) override; QueryTool *GetActiveQueryTool(); + CrudTab *GetActiveCrud(); private: QTabWidget *m_tabWidget = nullptr; QToolBar *m_mainToolBar = nullptr; @@ -79,6 +81,7 @@ private: QAction *actionOpenSql = nullptr; QAction *actionPasteLangString = nullptr; QAction *actionRefreshCatalog = nullptr; + QAction *actionRefreshCrud = nullptr; QAction *actionSaveSql = nullptr; QAction *actionSaveSqlAs = nullptr; QAction *actionSaveCopyOfSqlAs = nullptr; @@ -89,6 +92,7 @@ private: QMenu *menuHelp = nullptr; QMenu *menuQuery = nullptr; QMenu *menuCatalog = nullptr; + QMenu *menuCrud = nullptr; QMenu *menuWindow = nullptr; @@ -109,15 +113,14 @@ private: QFutureWatcher loadWatcher; - void newCreateTablePage(); - void newCrudPage(Oid tableoid); - void createActions(); void initMenus(); QAction* seperator(); - void createCatalogInspector(QString caption, NamespaceFilter filter); + void newCreateTablePage(); + void newCrudPage(Oid tableoid); + void newCatalogInspectorPage(QString caption, NamespaceFilter filter); void closeTab(int index); private slots: void catalogLoaded(); @@ -143,11 +146,13 @@ private slots: void on_actionOpenSql_triggered(); void on_actionPasteLangString_triggered(); void on_actionRefreshCatalog_triggered(); + void on_actionRefreshCrud_triggered(); void on_actionSaveSql_triggered(); void on_actionSaveSqlAs_triggered(); void on_actionSaveCopyOfSqlAs_triggered(); void on_actionShowConnectionManager_triggered(); void on_m_tabWidget_tabCloseRequested(int index); + void on_m_tabWidget_currentChanged(int index); // IDatabaseWindow interface public: -- 2.47.2