#include "CatalogInspector.h" #include "OpenDatabase.h" #include "UserConfiguration.h" #include "plugin_support/IPluginContentWidgetContext.h" #include "widgets/CatalogFunctionsPage.h" #include "widgets/CatalogSequencesPage.h" #include "widgets/CatalogTablesPage.h" #include #include #include #include #include CatalogInspector::CatalogInspector(IPluginContentWidgetContext *context_, PluginModule *module, QWidget *parent) : PluginContentWidget(context_, module, parent) { m_tabWidget = new QTabWidget(this); m_tablesPage = new CatalogTablesPage(this); m_functionsPage = new CatalogFunctionsPage(this); m_sequencesPage = new CatalogSequencesPage(this); auto layout = new QVBoxLayout(this); setLayout(layout); layout->addWidget(m_tabWidget); m_tabWidget->addTab(m_tablesPage, ""); m_tabWidget->addTab(m_functionsPage, ""); m_tabWidget->addTab(m_sequencesPage, ""); auto db = context_->getObject(); setCatalog(db->catalog()); retranslateUi(false); } void CatalogInspector::retranslateUi(bool all) { m_tablesPage->retranslateUi(all); m_tabWidget->setTabText(m_tabWidget->indexOf(m_tablesPage), QApplication::translate("CatalogInspector", "Tables", nullptr)); m_tabWidget->setTabText(m_tabWidget->indexOf(m_functionsPage), QApplication::translate("CatalogInspector", "Functions", nullptr)); m_tabWidget->setTabText(m_tabWidget->indexOf(m_sequencesPage), QApplication::translate("CatalogInspector", "Sequences", nullptr)); } CatalogInspector::~CatalogInspector() { } void CatalogInspector::setCatalog(std::shared_ptr cat) { m_catalog = cat; m_tablesPage->setCatalog(cat); m_functionsPage->setCatalog(cat); m_sequencesPage->setCatalog(cat); } void CatalogInspector::setNamespaceFilter(NamespaceFilter filter) { m_tablesPage->setNamespaceFilter(filter); m_functionsPage->setNamespaceFilter(filter); m_sequencesPage->setNamespaceFilter(filter); QString hint = "Catalog instpector"; QString caption = "Inspector"; switch (filter) { case NamespaceFilter::PgCatalog: hint += " - pg_catalog"; caption = "pg_catalog"; break; case NamespaceFilter::InformationSchema: hint += " - information_schema"; caption = "information_schema"; break; default: break; } context()->setCaption(this, caption, hint); } 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, this); context->addContentWidget(ct); auto nsf = params.at("namespace-filter").toString(); NamespaceFilter filter = NamespaceFilter::User; if (nsf == "pg_catalog") filter = NamespaceFilter::PgCatalog; else if (nsf == "information_schema") filter = NamespaceFilter::InformationSchema; ct->setNamespaceFilter(filter); } REGISTER_PLUGIN_MODULE_CAT(CatalogInspectorModule, "Catalog inspector tool", "pglab.catalog-inspector", "database")