TablesPage is now CatalogInspector and is now a module.

This commit is contained in:
eelke 2019-01-06 10:11:48 +01:00
parent d3c85722c7
commit 3e4917428d
7 changed files with 101 additions and 45 deletions

View file

@ -1,4 +1,4 @@
#include "TablesPage.h" #include "CatalogInspector.h"
#include "ui_TablesPage.h" #include "ui_TablesPage.h"
#include "catalog/PgAttribute.h" #include "catalog/PgAttribute.h"
@ -10,6 +10,7 @@
#include "ConstraintModel.h" #include "ConstraintModel.h"
#include "IconColumnDelegate.h" #include "IconColumnDelegate.h"
#include "IndexModel.h" #include "IndexModel.h"
#include "OpenDatabase.h"
#include "PgLabItemDelegate.h" #include "PgLabItemDelegate.h"
#include "PropertiesPage.h" #include "PropertiesPage.h"
#include "ResultTableModelUtil.h" #include "ResultTableModelUtil.h"
@ -22,7 +23,7 @@
#include <unordered_set> #include <unordered_set>
#include "plugin_support/IPluginContentWidgetContext.h" #include "plugin_support/IPluginContentWidgetContext.h"
TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent) CatalogInspector::CatalogInspector(IPluginContentWidgetContext *context_, QWidget *parent)
: PluginContentWidget(context_, parent) : PluginContentWidget(context_, parent)
, ui(new Ui::TablesPage) , ui(new Ui::TablesPage)
{ {
@ -61,24 +62,24 @@ TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent)
// --------------- // ---------------
// Table selection // Table selection
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this, connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&TablesPage::tableListTable_currentRowChanged); &CatalogInspector::tableListTable_currentRowChanged);
connect(m_tablesModel, &QAbstractItemModel::layoutChanged, connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
this, &TablesPage::tableListTable_layoutChanged); this, &CatalogInspector::tableListTable_layoutChanged);
//layoutChanged(const QList<QPersistentModelIndex> &parents = ..., QAbstractItemModel::LayoutChangeHint hint = ...) //layoutChanged(const QList<QPersistentModelIndex> &parents = ..., QAbstractItemModel::LayoutChangeHint hint = ...)
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TablesPage::constraintsTable_selectionChanged); &CatalogInspector::constraintsTable_selectionChanged);
connect(ui->constraintsTable->model(), &QAbstractItemModel::modelReset, this, connect(ui->constraintsTable->model(), &QAbstractItemModel::modelReset, this,
&TablesPage::constraintsTable_modelReset); &CatalogInspector::constraintsTable_modelReset);
// React to changes in de selected indexes, does not trigger when model is reset // React to changes in de selected indexes, does not trigger when model is reset
connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&TablesPage::indexesTable_selectionChanged); &CatalogInspector::indexesTable_selectionChanged);
// Capture model reset independently // Capture model reset independently
connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this, connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this,
&TablesPage::indexesTable_modelReset); &CatalogInspector::indexesTable_modelReset);
// Non designer based code // Non designer based code
// - Columns page // - Columns page
@ -102,12 +103,15 @@ TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent)
// Force focus on columns tab by default // Force focus on columns tab by default
ui->twDetails->setCurrentIndex(0); ui->twDetails->setCurrentIndex(0);
auto db = context_->getObject<OpenDatabase>();
setCatalog(db->catalog());
retranslateUi(false); retranslateUi(false);
} }
void TablesPage::retranslateUi(bool all) void CatalogInspector::retranslateUi(bool all)
{ {
if (all) if (all)
ui->retranslateUi(this); ui->retranslateUi(this);
@ -123,12 +127,12 @@ void TablesPage::retranslateUi(bool all)
} }
TablesPage::~TablesPage() CatalogInspector::~CatalogInspector()
{ {
delete ui; delete ui;
} }
void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat) void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
{ {
m_catalog = cat; m_catalog = cat;
m_tablesModel->setCatalog(cat); m_tablesModel->setCatalog(cat);
@ -142,13 +146,28 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
highlighter->setTypes(*cat->types()); highlighter->setTypes(*cat->types());
} }
void TablesPage::setNamespaceFilter(TablesTableModel::NamespaceFilter filter) void CatalogInspector::setNamespaceFilter(TablesTableModel::NamespaceFilter filter)
{ {
m_tablesModel->setNamespaceFilter(filter); m_tablesModel->setNamespaceFilter(filter);
QString hint = "Catalog instpector";
QString caption = "Inspector";
switch (filter) {
case TablesTableModel::PgCatalog:
hint += " - pg_catalog";
caption = "pg_catalog";
break;
case TablesTableModel::InformationSchema:
hint += " - information_schema";
caption = "information_schema";
break;
default:
break;
}
context()->setCaption(this, caption, hint);
} }
void TablesPage::tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous) void CatalogInspector::tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{ {
if (current.row() != previous.row()) { if (current.row() != previous.row()) {
if (current.isValid()) { if (current.isValid()) {
@ -161,7 +180,7 @@ void TablesPage::tableListTable_currentRowChanged(const QModelIndex &current, co
} }
void TablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint ) void CatalogInspector::tableListTable_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint )
{ {
auto&& index = ui->tableListTable->selectionModel()->currentIndex(); auto&& index = ui->tableListTable->selectionModel()->currentIndex();
if (index.isValid()) { if (index.isValid()) {
@ -173,7 +192,7 @@ void TablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex>
} }
void TablesPage::selectedTableChanged(const std::optional<PgClass> &table) void CatalogInspector::selectedTableChanged(const std::optional<PgClass> &table)
{ {
m_columnsPage->setData(m_catalog, table); m_columnsPage->setData(m_catalog, table);
@ -189,7 +208,7 @@ void TablesPage::selectedTableChanged(const std::optional<PgClass> &table)
updateSqlTab(table); updateSqlTab(table);
} }
void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) void CatalogInspector::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{ {
const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes(); const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes();
std::unordered_set<int> rijen; std::unordered_set<int> rijen;
@ -206,12 +225,12 @@ void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selec
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates); ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
} }
void TablesPage::constraintsTable_modelReset() void CatalogInspector::constraintsTable_modelReset()
{ {
ui->constraintSqlEdit->clear(); ui->constraintSqlEdit->clear();
} }
void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) void CatalogInspector::indexesTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{ {
const auto indexes = ui->indexesTable->selectionModel()->selectedIndexes(); const auto indexes = ui->indexesTable->selectionModel()->selectedIndexes();
std::unordered_set<int> rijen; std::unordered_set<int> rijen;
@ -229,12 +248,12 @@ void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected*
} }
void TablesPage::indexesTable_modelReset() void CatalogInspector::indexesTable_modelReset()
{ {
ui->indexSqlEdit->clear(); ui->indexSqlEdit->clear();
} }
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index) void CatalogInspector::on_tableListTable_doubleClicked(const QModelIndex &index)
{ {
PgClass table = m_tablesModel->getTable(index.row()); PgClass table = m_tablesModel->getTable(index.row());
if (table.oid() != InvalidOid) { if (table.oid() != InvalidOid) {
@ -244,7 +263,7 @@ void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
} }
} }
void TablesPage::updateSqlTab(const std::optional<PgClass> &table) void CatalogInspector::updateSqlTab(const std::optional<PgClass> &table)
{ {
if (!table.has_value()) { if (!table.has_value()) {
m_sqlCodePreview->clear(); m_sqlCodePreview->clear();
@ -286,3 +305,31 @@ void TablesPage::updateSqlTab(const std::optional<PgClass> &table)
// //
m_sqlCodePreview->setPlainText(drop_sql % "\n\n" % create_sql); m_sqlCodePreview->setPlainText(drop_sql % "\n\n" % create_sql);
} }
void CatalogInspectorModule::init()
{
registerModuleAction("open",
[this] (IPluginContentWidgetContext* context,
const ModuleActionParameters &params)
{
moduleAction_open(context, params);
});
}
void CatalogInspectorModule::moduleAction_open(
IPluginContentWidgetContext* context,
const ModuleActionParameters &params
)
{
auto ct = new CatalogInspector(context, nullptr);
context->addContentWidget(this, ct);
auto nsf = params.at("namespace-filter").toString();
TablesTableModel::NamespaceFilter filter = TablesTableModel::User;
if (nsf == "pg_catalog") filter = TablesTableModel::PgCatalog;
else if (nsf == "information_schema") filter = TablesTableModel::InformationSchema;
ct->setNamespaceFilter(filter);
}
REGISTER_PLUGIN_MODULE_CAT(CatalogInspectorModule, "Catalog inspector tool",
"pglab.catalog-inspector", "database")

View file

@ -25,13 +25,13 @@ class TriggerPage;
class PgClass; class PgClass;
class SqlCodePreview; class SqlCodePreview;
class TablesPage : public PluginContentWidget class CatalogInspector : public PluginContentWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TablesPage(IPluginContentWidgetContext *context, QWidget *parent = nullptr); explicit CatalogInspector(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
~TablesPage(); ~CatalogInspector();
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat); void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
void setNamespaceFilter(TablesTableModel::NamespaceFilter filter); void setNamespaceFilter(TablesTableModel::NamespaceFilter filter);
@ -62,4 +62,17 @@ private slots:
void on_tableListTable_doubleClicked(const QModelIndex &index); void on_tableListTable_doubleClicked(const QModelIndex &index);
}; };
class CatalogInspectorModule: public PluginModule {
Q_OBJECT
public:
using PluginModule::PluginModule;
void init();
private slots:
private:
void moduleAction_open(IPluginContentWidgetContext* context, const ModuleActionParameters &params);
};
#endif // TABLESPAGE_H #endif // TABLESPAGE_H

View file

@ -138,4 +138,4 @@ void CrudPageModule::moduleAction_open(
} }
REGISTER_PLUGIN_MODULE(CrudPageModule, "CRUD tool", "pglab.crudpage") REGISTER_PLUGIN_MODULE_CAT(CrudPageModule, "CRUD tool", "pglab.crudpage", "database")

View file

@ -9,7 +9,6 @@
#include <QTableView> #include <QTableView>
// Pages that should become modules // Pages that should become modules
#include "TablesPage.h"
#include "EditTableWidget.h" #include "EditTableWidget.h"
#include "CodeGenerator.h" #include "CodeGenerator.h"
#include "FunctionsPage.h" #include "FunctionsPage.h"
@ -71,19 +70,10 @@ void DatabaseWindow::catalogLoaded()
auto ctx = context(); auto ctx = context();
ctx->registerObject(m_database); ctx->registerObject(m_database);
auto tt = new TablesPage(ctx, this); for (auto f : { "user", "pg_catalog", "information_schema" })
tt->setCatalog(m_database->catalog()); ctx->moduleAction("pglab.catalog-inspector", "open", {
m_tabWidget->addTab(tt, "Tables"); { "namespace-filter", f }
});
auto pg_cat_tables = new TablesPage(ctx, this);
pg_cat_tables->setNamespaceFilter(TablesTableModel::PgCatalog);
pg_cat_tables->setCatalog(m_database->catalog());
m_tabWidget->addTab(pg_cat_tables, "pg_catalog");
auto info_schema_tables = new TablesPage(ctx, this);
info_schema_tables->setNamespaceFilter(TablesTableModel::InformationSchema);
info_schema_tables->setCatalog(m_database->catalog());
m_tabWidget->addTab(info_schema_tables, "information_schema");
auto functions_page = new FunctionsPage(this); auto functions_page = new FunctionsPage(this);
functions_page->setCatalog(m_database->catalog()); functions_page->setCatalog(m_database->catalog());

View file

@ -82,4 +82,4 @@ void QueryToolModule::menuAction_open(IPluginContentWidgetContext* context)
} }
} }
REGISTER_PLUGIN_MODULE(QueryToolModule, "Query tool", "pglab.querytool") REGISTER_PLUGIN_MODULE_CAT(QueryToolModule, "Query tool", "pglab.querytool", "database")

View file

@ -48,7 +48,6 @@ SOURCES += main.cpp\
ResultTableModelUtil.cpp \ ResultTableModelUtil.cpp \
BaseTableModel.cpp \ BaseTableModel.cpp \
QueryParamListController.cpp \ QueryParamListController.cpp \
TablesPage.cpp \
TablesTableModel.cpp \ TablesTableModel.cpp \
ColumnTableModel.cpp \ ColumnTableModel.cpp \
NamespaceFilterWidget.cpp \ NamespaceFilterWidget.cpp \
@ -91,7 +90,8 @@ PropertyProxyModel.cpp \
plugin_support/LMainWindow.cpp \ plugin_support/LMainWindow.cpp \
plugin_support/LWidgetAction.cpp \ plugin_support/LWidgetAction.cpp \
QueryTool.cpp \ QueryTool.cpp \
QueryToolModule.cpp QueryToolModule.cpp \
CatalogInspector.cpp
HEADERS += \ HEADERS += \
QueryResultModel.h \ QueryResultModel.h \
@ -115,7 +115,6 @@ HEADERS += \
ResultTableModelUtil.h \ ResultTableModelUtil.h \
BaseTableModel.h \ BaseTableModel.h \
QueryParamListController.h \ QueryParamListController.h \
TablesPage.h \
TablesTableModel.h \ TablesTableModel.h \
ColumnTableModel.h \ ColumnTableModel.h \
NamespaceFilterWidget.h \ NamespaceFilterWidget.h \
@ -162,7 +161,8 @@ CustomDataRole.h \
plugin_support/LMainWindow.h \ plugin_support/LMainWindow.h \
plugin_support/LWidgetAction.h \ plugin_support/LWidgetAction.h \
QueryTool.h \ QueryTool.h \
QueryToolModule.h QueryToolModule.h \
CatalogInspector.h
FORMS += \ FORMS += \
ConnectionManagerWindow.ui \ ConnectionManagerWindow.ui \

View file

@ -60,9 +60,10 @@ private:
template <typename T> template <typename T>
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident) std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident, QString category={})
{ {
auto module = std::make_shared<T>(std::move(name), std::move(ident)); auto module = std::make_shared<T>(std::move(name), std::move(ident));
module->setDisplayCategory(category);
PluginRegister::getInstance()->registerModule(module); PluginRegister::getInstance()->registerModule(module);
return std::move(module); return std::move(module);
@ -73,5 +74,10 @@ std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\ std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
(name, ident);} (name, ident);}
#define REGISTER_PLUGIN_MODULE_CAT(module, name, ident, category) \
namespace {\
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
(name, ident, category);}
#endif // PLUGIN_SUPPORTPLUGINMODULE_H #endif // PLUGIN_SUPPORTPLUGINMODULE_H