2019-01-06 10:11:48 +01:00
|
|
|
|
#include "CatalogInspector.h"
|
|
|
|
|
|
#include "OpenDatabase.h"
|
2018-10-07 19:40:06 +02:00
|
|
|
|
#include "UserConfiguration.h"
|
2019-02-09 09:49:27 +01:00
|
|
|
|
#include "plugin_support/IPluginContentWidgetContext.h"
|
|
|
|
|
|
#include "widgets/CatalogFunctionsPage.h"
|
|
|
|
|
|
#include "widgets/CatalogSequencesPage.h"
|
|
|
|
|
|
#include "widgets/CatalogTablesPage.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QTabWidget>
|
2018-01-06 21:22:22 +01:00
|
|
|
|
#include <QStringBuilder>
|
2019-02-09 09:49:27 +01:00
|
|
|
|
#include <QVBoxLayout>
|
2018-12-23 08:39:38 +01:00
|
|
|
|
#include <unordered_set>
|
2017-12-10 14:20:45 +01:00
|
|
|
|
|
2019-08-14 09:06:48 +02:00
|
|
|
|
CatalogInspector::CatalogInspector(IPluginContentWidgetContext *context_, PluginModule *module, QWidget *parent)
|
|
|
|
|
|
: PluginContentWidget(context_, module, parent)
|
2017-12-10 08:17:07 +01:00
|
|
|
|
{
|
2019-02-09 09:49:27 +01:00
|
|
|
|
m_tabWidget = new QTabWidget(this);
|
|
|
|
|
|
m_tablesPage = new CatalogTablesPage(this);
|
|
|
|
|
|
m_functionsPage = new CatalogFunctionsPage(this);
|
|
|
|
|
|
m_sequencesPage = new CatalogSequencesPage(this);
|
2018-12-29 10:56:24 +01:00
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
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, "");
|
2018-12-29 10:56:24 +01:00
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
auto db = context_->getObject<OpenDatabase>();
|
|
|
|
|
|
setCatalog(db->catalog());
|
2018-10-07 19:40:06 +02:00
|
|
|
|
retranslateUi(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
void CatalogInspector::retranslateUi(bool all)
|
2018-10-07 19:40:06 +02:00
|
|
|
|
{
|
2019-02-09 09:49:27 +01:00
|
|
|
|
m_tablesPage->retranslateUi(all);
|
2018-11-30 18:41:38 +01:00
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
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));
|
2017-12-12 20:13:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
CatalogInspector::~CatalogInspector()
|
2017-12-12 20:13:53 +01:00
|
|
|
|
{
|
2017-12-10 14:20:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
2017-12-10 14:20:45 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_catalog = cat;
|
2019-02-09 09:49:27 +01:00
|
|
|
|
m_tablesPage->setCatalog(cat);
|
|
|
|
|
|
m_functionsPage->setCatalog(cat);
|
|
|
|
|
|
m_sequencesPage->setCatalog(cat);
|
2017-12-10 08:17:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-09 20:37:34 +01:00
|
|
|
|
void CatalogInspector::setNamespaceFilter(NamespaceFilter filter)
|
2018-12-29 10:56:24 +01:00
|
|
|
|
{
|
2019-02-09 09:49:27 +01:00
|
|
|
|
m_tablesPage->setNamespaceFilter(filter);
|
2019-02-09 20:37:34 +01:00
|
|
|
|
m_functionsPage->setNamespaceFilter(filter);
|
|
|
|
|
|
m_sequencesPage->setNamespaceFilter(filter);
|
2019-01-06 10:11:48 +01:00
|
|
|
|
QString hint = "Catalog instpector";
|
|
|
|
|
|
QString caption = "Inspector";
|
|
|
|
|
|
switch (filter) {
|
2019-02-09 20:37:34 +01:00
|
|
|
|
case NamespaceFilter::PgCatalog:
|
2019-01-06 10:11:48 +01:00
|
|
|
|
hint += " - pg_catalog";
|
|
|
|
|
|
caption = "pg_catalog";
|
|
|
|
|
|
break;
|
2019-02-09 20:37:34 +01:00
|
|
|
|
case NamespaceFilter::InformationSchema:
|
2019-01-06 10:11:48 +01:00
|
|
|
|
hint += " - information_schema";
|
|
|
|
|
|
caption = "information_schema";
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
context()->setCaption(this, caption, hint);
|
2018-12-29 10:56:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-06 10:11:48 +01:00
|
|
|
|
void CatalogInspectorModule::init()
|
|
|
|
|
|
{
|
|
|
|
|
|
registerModuleAction("open",
|
|
|
|
|
|
[this] (IPluginContentWidgetContext* context,
|
|
|
|
|
|
const ModuleActionParameters ¶ms)
|
|
|
|
|
|
{
|
|
|
|
|
|
moduleAction_open(context, params);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CatalogInspectorModule::moduleAction_open(
|
|
|
|
|
|
IPluginContentWidgetContext* context,
|
|
|
|
|
|
const ModuleActionParameters ¶ms
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
2019-08-14 09:06:48 +02:00
|
|
|
|
auto ct = new CatalogInspector(context, this);
|
|
|
|
|
|
context->addContentWidget(ct);
|
2019-01-06 10:11:48 +01:00
|
|
|
|
auto nsf = params.at("namespace-filter").toString();
|
2019-02-09 20:37:34 +01:00
|
|
|
|
NamespaceFilter filter = NamespaceFilter::User;
|
|
|
|
|
|
if (nsf == "pg_catalog") filter = NamespaceFilter::PgCatalog;
|
|
|
|
|
|
else if (nsf == "information_schema") filter = NamespaceFilter::InformationSchema;
|
2019-01-06 10:11:48 +01:00
|
|
|
|
ct->setNamespaceFilter(filter);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
REGISTER_PLUGIN_MODULE_CAT(CatalogInspectorModule, "Catalog inspector tool",
|
|
|
|
|
|
"pglab.catalog-inspector", "database")
|