TablesPage is now CatalogInspector and is now a module.
This commit is contained in:
parent
d3c85722c7
commit
3e4917428d
7 changed files with 101 additions and 45 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "TablesPage.h"
|
||||
#include "CatalogInspector.h"
|
||||
#include "ui_TablesPage.h"
|
||||
|
||||
#include "catalog/PgAttribute.h"
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include "ConstraintModel.h"
|
||||
#include "IconColumnDelegate.h"
|
||||
#include "IndexModel.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "PropertiesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
|
|
@ -22,7 +23,7 @@
|
|||
#include <unordered_set>
|
||||
#include "plugin_support/IPluginContentWidgetContext.h"
|
||||
|
||||
TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent)
|
||||
CatalogInspector::CatalogInspector(IPluginContentWidgetContext *context_, QWidget *parent)
|
||||
: PluginContentWidget(context_, parent)
|
||||
, ui(new Ui::TablesPage)
|
||||
{
|
||||
|
|
@ -61,24 +62,24 @@ TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent)
|
|||
// ---------------
|
||||
// Table selection
|
||||
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&TablesPage::tableListTable_currentRowChanged);
|
||||
&CatalogInspector::tableListTable_currentRowChanged);
|
||||
|
||||
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
|
||||
this, &TablesPage::tableListTable_layoutChanged);
|
||||
this, &CatalogInspector::tableListTable_layoutChanged);
|
||||
|
||||
//layoutChanged(const QList<QPersistentModelIndex> &parents = ..., QAbstractItemModel::LayoutChangeHint hint = ...)
|
||||
|
||||
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||
&TablesPage::constraintsTable_selectionChanged);
|
||||
&CatalogInspector::constraintsTable_selectionChanged);
|
||||
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
|
||||
connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||
&TablesPage::indexesTable_selectionChanged);
|
||||
&CatalogInspector::indexesTable_selectionChanged);
|
||||
// Capture model reset independently
|
||||
connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this,
|
||||
&TablesPage::indexesTable_modelReset);
|
||||
&CatalogInspector::indexesTable_modelReset);
|
||||
|
||||
// Non designer based code
|
||||
// - Columns page
|
||||
|
|
@ -102,12 +103,15 @@ TablesPage::TablesPage(IPluginContentWidgetContext *context_, QWidget *parent)
|
|||
|
||||
// Force focus on columns tab by default
|
||||
ui->twDetails->setCurrentIndex(0);
|
||||
auto db = context_->getObject<OpenDatabase>();
|
||||
|
||||
setCatalog(db->catalog());
|
||||
|
||||
retranslateUi(false);
|
||||
}
|
||||
|
||||
|
||||
void TablesPage::retranslateUi(bool all)
|
||||
void CatalogInspector::retranslateUi(bool all)
|
||||
{
|
||||
if (all)
|
||||
ui->retranslateUi(this);
|
||||
|
|
@ -123,12 +127,12 @@ void TablesPage::retranslateUi(bool all)
|
|||
|
||||
}
|
||||
|
||||
TablesPage::~TablesPage()
|
||||
CatalogInspector::~CatalogInspector()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_tablesModel->setCatalog(cat);
|
||||
|
|
@ -142,13 +146,28 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
|||
highlighter->setTypes(*cat->types());
|
||||
}
|
||||
|
||||
void TablesPage::setNamespaceFilter(TablesTableModel::NamespaceFilter filter)
|
||||
void CatalogInspector::setNamespaceFilter(TablesTableModel::NamespaceFilter 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 ¤t, const QModelIndex &previous)
|
||||
void CatalogInspector::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
if (current.isValid()) {
|
||||
|
|
@ -161,7 +180,7 @@ void TablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, 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();
|
||||
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);
|
||||
|
||||
|
|
@ -189,7 +208,7 @@ void TablesPage::selectedTableChanged(const std::optional<PgClass> &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();
|
||||
std::unordered_set<int> rijen;
|
||||
|
|
@ -206,12 +225,12 @@ void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selec
|
|||
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
|
||||
}
|
||||
|
||||
void TablesPage::constraintsTable_modelReset()
|
||||
void CatalogInspector::constraintsTable_modelReset()
|
||||
{
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
void CatalogInspector::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
PgClass table = m_tablesModel->getTable(index.row());
|
||||
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()) {
|
||||
m_sqlCodePreview->clear();
|
||||
|
|
@ -286,3 +305,31 @@ void TablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
|||
//
|
||||
m_sqlCodePreview->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||
}
|
||||
|
||||
|
||||
void CatalogInspectorModule::init()
|
||||
{
|
||||
registerModuleAction("open",
|
||||
[this] (IPluginContentWidgetContext* context,
|
||||
const ModuleActionParameters ¶ms)
|
||||
{
|
||||
moduleAction_open(context, params);
|
||||
});
|
||||
}
|
||||
|
||||
void CatalogInspectorModule::moduleAction_open(
|
||||
IPluginContentWidgetContext* context,
|
||||
const ModuleActionParameters ¶ms
|
||||
)
|
||||
{
|
||||
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")
|
||||
|
|
@ -25,13 +25,13 @@ class TriggerPage;
|
|||
class PgClass;
|
||||
class SqlCodePreview;
|
||||
|
||||
class TablesPage : public PluginContentWidget
|
||||
class CatalogInspector : public PluginContentWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TablesPage(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
|
||||
~TablesPage();
|
||||
explicit CatalogInspector(IPluginContentWidgetContext *context, QWidget *parent = nullptr);
|
||||
~CatalogInspector();
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(TablesTableModel::NamespaceFilter filter);
|
||||
|
|
@ -62,4 +62,17 @@ private slots:
|
|||
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 ¶ms);
|
||||
};
|
||||
|
||||
|
||||
#endif // TABLESPAGE_H
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include <QTableView>
|
||||
|
||||
// Pages that should become modules
|
||||
#include "TablesPage.h"
|
||||
#include "EditTableWidget.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "FunctionsPage.h"
|
||||
|
|
@ -71,19 +70,10 @@ void DatabaseWindow::catalogLoaded()
|
|||
auto ctx = context();
|
||||
ctx->registerObject(m_database);
|
||||
|
||||
auto tt = new TablesPage(ctx, this);
|
||||
tt->setCatalog(m_database->catalog());
|
||||
m_tabWidget->addTab(tt, "Tables");
|
||||
|
||||
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");
|
||||
for (auto f : { "user", "pg_catalog", "information_schema" })
|
||||
ctx->moduleAction("pglab.catalog-inspector", "open", {
|
||||
{ "namespace-filter", f }
|
||||
});
|
||||
|
||||
auto functions_page = new FunctionsPage(this);
|
||||
functions_page->setCatalog(m_database->catalog());
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ SOURCES += main.cpp\
|
|||
ResultTableModelUtil.cpp \
|
||||
BaseTableModel.cpp \
|
||||
QueryParamListController.cpp \
|
||||
TablesPage.cpp \
|
||||
TablesTableModel.cpp \
|
||||
ColumnTableModel.cpp \
|
||||
NamespaceFilterWidget.cpp \
|
||||
|
|
@ -91,7 +90,8 @@ PropertyProxyModel.cpp \
|
|||
plugin_support/LMainWindow.cpp \
|
||||
plugin_support/LWidgetAction.cpp \
|
||||
QueryTool.cpp \
|
||||
QueryToolModule.cpp
|
||||
QueryToolModule.cpp \
|
||||
CatalogInspector.cpp
|
||||
|
||||
HEADERS += \
|
||||
QueryResultModel.h \
|
||||
|
|
@ -115,7 +115,6 @@ HEADERS += \
|
|||
ResultTableModelUtil.h \
|
||||
BaseTableModel.h \
|
||||
QueryParamListController.h \
|
||||
TablesPage.h \
|
||||
TablesTableModel.h \
|
||||
ColumnTableModel.h \
|
||||
NamespaceFilterWidget.h \
|
||||
|
|
@ -162,7 +161,8 @@ CustomDataRole.h \
|
|||
plugin_support/LMainWindow.h \
|
||||
plugin_support/LWidgetAction.h \
|
||||
QueryTool.h \
|
||||
QueryToolModule.h
|
||||
QueryToolModule.h \
|
||||
CatalogInspector.h
|
||||
|
||||
FORMS += \
|
||||
ConnectionManagerWindow.ui \
|
||||
|
|
|
|||
|
|
@ -60,9 +60,10 @@ private:
|
|||
|
||||
|
||||
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));
|
||||
module->setDisplayCategory(category);
|
||||
|
||||
PluginRegister::getInstance()->registerModule(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>\
|
||||
(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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue