From f0e5488ce008eb7b0367cb13d154d533ee1aad10 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 10 Apr 2021 14:27:04 +0200 Subject: [PATCH] List of databases and roles moved to a "Server tab" within the database window. Opened by selecting "Inspect Server" from the menu. --- pglab/CodeGenerator.cpp | 13 +++++++ pglab/CodeGenerator.h | 3 ++ pglab/DatabaseWindow.cpp | 25 +++++++++++-- pglab/DatabaseWindow.h | 3 ++ pglab/PgLabTableViewHelper.h | 40 +++++++++++++++++++++ pglab/pglab.pro | 7 ++++ pglab/serverinspector/DatabasesPage.cpp | 32 +++++++++++++++++ pglab/serverinspector/DatabasesPage.h | 28 +++++++++++++++ pglab/serverinspector/RolesPage.cpp | 23 ++++++++++++ pglab/serverinspector/RolesPage.h | 26 ++++++++++++++ pglab/serverinspector/ServerInspector.cpp | 44 +++++++++++++++++++++++ pglab/serverinspector/ServerInspector.h | 29 +++++++++++++++ 12 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 pglab/PgLabTableViewHelper.h create mode 100644 pglab/serverinspector/DatabasesPage.cpp create mode 100644 pglab/serverinspector/DatabasesPage.h create mode 100644 pglab/serverinspector/RolesPage.cpp create mode 100644 pglab/serverinspector/RolesPage.h create mode 100644 pglab/serverinspector/ServerInspector.cpp create mode 100644 pglab/serverinspector/ServerInspector.h diff --git a/pglab/CodeGenerator.cpp b/pglab/CodeGenerator.cpp index 207dff4..3842035 100644 --- a/pglab/CodeGenerator.cpp +++ b/pglab/CodeGenerator.cpp @@ -5,18 +5,31 @@ #include "UserConfiguration.h" #include +class CodeGeneratorViewModel { +public: + QProperty StructName; + +private: + +}; + CodeGenerator::CodeGenerator(QWidget *parent) : QWidget(parent) , ui(new Ui::CodeGenerator) + , Model(new CodeGeneratorViewModel) { ui->setupUi(this); ui->generatedCodeEditor->setFont(UserConfiguration::instance()->codeFont()); ui->generatedCodeEditor->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + + + auto v = Model->StructName.onValueChanged([this]() { ui->structNameEdit->setText(Model->StructName); }); } CodeGenerator::~CodeGenerator() { + delete Model; delete ui; } diff --git a/pglab/CodeGenerator.h b/pglab/CodeGenerator.h index 9c3e716..a82f5f9 100644 --- a/pglab/CodeGenerator.h +++ b/pglab/CodeGenerator.h @@ -9,6 +9,7 @@ class CodeGenerator; } class PgDatabaseCatalog; +class CodeGeneratorViewModel; class CodeGenerator : public QWidget { Q_OBJECT @@ -23,6 +24,8 @@ private slots: private: Ui::CodeGenerator *ui; + CodeGeneratorViewModel *Model; + std::shared_ptr m_catalog; QString m_query; std::shared_ptr m_dbres; diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index 6b7db85..4398541 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -21,6 +21,7 @@ #include "EditTableWidget.h" #include "CodeGenerator.h" #include "QueryTool.h" +#include namespace pg = Pgsql; @@ -202,6 +203,12 @@ void DatabaseWindow::createActions() auto action = actionInspectInformationSchema = new QAction(icon, tr("Inspect information_schema"), this); action->setObjectName("actionInspectInformationSchema"); } + { + QIcon icon; + icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On); + auto action = actionServerInspector = new QAction(icon, tr("Inspect server"), this); + action->setObjectName("actionServerInspector"); + } { QIcon icon; icon.addFile(QString::fromUtf8(":/icons/page_white_add.png"), QSize(), QIcon::Normal, QIcon::On); @@ -320,6 +327,7 @@ void DatabaseWindow::initMenus() actionInspectUserSchemas, actionInspectPgCatalog, actionInspectInformationSchema, + actionServerInspector, seperator(), actionShowConnectionManager }); @@ -363,7 +371,15 @@ void DatabaseWindow::newCatalogInspectorPage(QString caption, NamespaceFilter fi addPage(ct, caption); ct->setNamespaceFilter(filter); - connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected); + connect(ct->tablesPage(), &CatalogTablesPage::tableSelected, this, &DatabaseWindow::tableSelected); +} + +void DatabaseWindow::newServerInspectorPage() +{ + auto si = new ServerInspector(m_database, this); +// si->addAction(actionRefreshCatalog); + addPage(si, tr("Server")); + } void DatabaseWindow::closeTab(int index) @@ -520,7 +536,12 @@ void DatabaseWindow::on_actionInspectPgCatalog_triggered() void DatabaseWindow::on_actionInspectUserSchemas_triggered() { - newCatalogInspectorPage("Schema", NamespaceFilter::User); + newCatalogInspectorPage("Schema", NamespaceFilter::User); +} + +void DatabaseWindow::on_actionServerInspector_triggered() +{ + newServerInspectorPage(); } void DatabaseWindow::on_actionNewSql_triggered() diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index df1ae70..424f7f9 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -81,6 +81,7 @@ private: 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; @@ -125,6 +126,7 @@ private: void newCreateTablePage(); void newCrudPage(Oid tableoid); void newCatalogInspectorPage(QString caption, NamespaceFilter filter); + void newServerInspectorPage(); void closeTab(int index); private slots: void catalogLoaded(); @@ -146,6 +148,7 @@ private slots: void on_actionInspectInformationSchema_triggered(); void on_actionInspectPgCatalog_triggered(); void on_actionInspectUserSchemas_triggered(); + void on_actionServerInspector_triggered(); void on_actionNewSql_triggered(); void on_actionOpenSql_triggered(); void on_actionPasteLangString_triggered(); diff --git a/pglab/PgLabTableViewHelper.h b/pglab/PgLabTableViewHelper.h new file mode 100644 index 0000000..4529ce8 --- /dev/null +++ b/pglab/PgLabTableViewHelper.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include "PgLabTableView.h" + +template +class PgLabTableViewHelper { +public: + PgLabTableViewHelper(QWidget * parent) + { + m_tableView = new PgLabTableView(parent); + + m_dataModel = new TableModel(parent); + m_sortFilter = new QSortFilterProxyModel(parent); + m_sortFilter->setSourceModel(m_dataModel); + m_tableView->setModel(m_dataModel); + m_tableView->setSortingEnabled(true); + } + + PgLabTableView *tableView() const + { + return m_tableView; + } + + TableModel *dataModel() const + { + return m_dataModel; + } + + QSortFilterProxyModel *sortFilter() const + { + return m_sortFilter; + } + +private: + PgLabTableView *m_tableView = nullptr; + TableModel *m_dataModel = nullptr; + QSortFilterProxyModel *m_sortFilter = nullptr; +}; diff --git a/pglab/pglab.pro b/pglab/pglab.pro index e201e68..2d8608b 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -36,6 +36,9 @@ SOURCES += main.cpp\ ConnectionManagerWindow.cpp \ ConnectionListModel.cpp \ SslModeModel.cpp \ + serverinspector/DatabasesPage.cpp \ + serverinspector/RolesPage.cpp \ + serverinspector/ServerInspector.cpp \ stopwatch.cpp \ TuplesResultWidget.cpp \ BackupDialog.cpp \ @@ -101,12 +104,16 @@ HEADERS += \ NotificationModel.h \ NotificationService.h \ PgDumpOutputHighlighter.h \ + PgLabTableViewHelper.h \ QueryResultModel.h \ QueryExplainModel.h \ CreateDatabaseDialog.h \ ConnectionManagerWindow.h \ ConnectionListModel.h \ SslModeModel.h \ + serverinspector/DatabasesPage.h \ + serverinspector/RolesPage.h \ + serverinspector/ServerInspector.h \ stopwatch.h \ TuplesResultWidget.h \ BackupDialog.h \ diff --git a/pglab/serverinspector/DatabasesPage.cpp b/pglab/serverinspector/DatabasesPage.cpp new file mode 100644 index 0000000..04ad732 --- /dev/null +++ b/pglab/serverinspector/DatabasesPage.cpp @@ -0,0 +1,32 @@ +#include "DatabasesPage.h" + +#include "DatabasesTableModel.h" +#include "catalog/PgDatabaseCatalog.h" +#include "PgLabTableView.h" + + +DatabasesPage::DatabasesPage(QWidget * parent) + : QSplitter(Qt::Horizontal, parent) + , m_databasesTableView(this) +{ + auto tv = m_databasesTableView.tableView(); + tv->setSelectionMode(QAbstractItemView::SingleSelection); + + m_detailsTabs = new QTabWidget(this); + + addWidget(tv); + addWidget(m_detailsTabs); +} + +void DatabasesPage::setCatalog(std::shared_ptr cat) +{ + m_catalog = cat; + m_databasesTableView.dataModel()->setDatabaseList(cat); + m_databasesTableView.tableView()->resizeColumnsToContents(); +} + + + + + + diff --git a/pglab/serverinspector/DatabasesPage.h b/pglab/serverinspector/DatabasesPage.h new file mode 100644 index 0000000..1e5f824 --- /dev/null +++ b/pglab/serverinspector/DatabasesPage.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +#include "PgLabTableViewHelper.h" + +class DatabasesTableModel; +class PgDatabaseCatalog; +class PgLabTableView; +class QSortFilterProxyModel; + +class DatabasesPage: public QSplitter { +public: + explicit DatabasesPage(QWidget * parent = nullptr); + + void setCatalog(std::shared_ptr cat); + + void retranslateUi(bool all = true); + +private: + PgLabTableViewHelper m_databasesTableView; + QTabWidget *m_detailsTabs = nullptr; + + std::shared_ptr m_catalog; + +}; + diff --git a/pglab/serverinspector/RolesPage.cpp b/pglab/serverinspector/RolesPage.cpp new file mode 100644 index 0000000..da28a53 --- /dev/null +++ b/pglab/serverinspector/RolesPage.cpp @@ -0,0 +1,23 @@ +#include "RolesPage.h" +#include "catalog/PgDatabaseCatalog.h" +#include "RolesTableModel.h" + +RolesPage::RolesPage(QWidget * parent) + : QSplitter(Qt::Horizontal, parent) + , m_rolesTableView(this) +{ + auto tv = m_rolesTableView.tableView(); + tv->setSelectionMode(QAbstractItemView::SingleSelection); + + m_detailsTabs = new QTabWidget(this); + + addWidget(tv); + addWidget(m_detailsTabs); +} + +void RolesPage::setCatalog(std::shared_ptr cat) +{ + m_catalog = cat; + m_rolesTableView.dataModel()->setRoleList(cat->authIds()); + m_rolesTableView.tableView()->resizeColumnsToContents(); +} diff --git a/pglab/serverinspector/RolesPage.h b/pglab/serverinspector/RolesPage.h new file mode 100644 index 0000000..6461525 --- /dev/null +++ b/pglab/serverinspector/RolesPage.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "PgLabTableViewHelper.h" + +class RolesTableModel; +class PgDatabaseCatalog; +class PgLabTableView; +class QSortFilterProxyModel; + + +class RolesPage: public QSplitter { +public: + RolesPage(QWidget * parent = nullptr); + + void setCatalog(std::shared_ptr cat); +private: + PgLabTableViewHelper m_rolesTableView; + QTabWidget *m_detailsTabs = nullptr; + + std::shared_ptr m_catalog; + +}; + diff --git a/pglab/serverinspector/ServerInspector.cpp b/pglab/serverinspector/ServerInspector.cpp new file mode 100644 index 0000000..791fa91 --- /dev/null +++ b/pglab/serverinspector/ServerInspector.cpp @@ -0,0 +1,44 @@ +#include "ServerInspector.h" +#include "DatabasesPage.h" +#include "OpenDatabase.h" +#include "RolesPage.h" + +#include +#include + +ServerInspector::ServerInspector(std::shared_ptr open_database, QWidget *parent) + : QWidget(parent) +{ + m_databasesPage = new DatabasesPage(this); + m_rolesPage = new RolesPage(this); + + m_tabWidget = new QTabWidget(this); + m_tabWidget->addTab(m_databasesPage, tr("Databases")); + m_tabWidget->addTab(m_rolesPage, tr("Roles")); + + auto layout = new QVBoxLayout(this); + setLayout(layout); + layout->addWidget(m_tabWidget); + + setCatalog(open_database->catalog()); + retranslateUi(false); +} + + +void ServerInspector::setCatalog(std::shared_ptr cat) +{ + m_catalog = cat; + m_databasesPage->setCatalog(cat); + m_rolesPage->setCatalog(cat); +// m_tablesPage->setCatalog(cat); +// m_functionsPage->setCatalog(cat); +// m_sequencesPage->setCatalog(cat); + // m_typesPage->setCatalog(cat); +} + +void ServerInspector::retranslateUi(bool ) +{ +// m_tabWidget->setTabText(m_tabWidget->indexOf(m_namespacePage), +// QApplication::translate("CatalogInspector", "Schemas", nullptr)); + +} diff --git a/pglab/serverinspector/ServerInspector.h b/pglab/serverinspector/ServerInspector.h new file mode 100644 index 0000000..ac6c552 --- /dev/null +++ b/pglab/serverinspector/ServerInspector.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +class DatabasesPage; +class OpenDatabase; +class PgDatabaseCatalog; +class QTabWidget; +class RolesPage; + + +class ServerInspector : public QWidget { + Q_OBJECT +public: + explicit ServerInspector(std::shared_ptr open_database, QWidget *parent = nullptr); + + void setCatalog(std::shared_ptr cat); +private: + QTabWidget *m_tabWidget = nullptr; + + DatabasesPage *m_databasesPage = nullptr; + RolesPage *m_rolesPage = nullptr; + + std::shared_ptr m_catalog; + + void retranslateUi(bool all = true); +}; +