Sequence and Function pages are now properly filtered on namespace.
This commit is contained in:
parent
7ca671a078
commit
f2808de613
17 changed files with 136 additions and 48 deletions
|
|
@ -56,17 +56,19 @@ void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
|||
m_sequencesPage->setCatalog(cat);
|
||||
}
|
||||
|
||||
void CatalogInspector::setNamespaceFilter(TablesTableModel::NamespaceFilter filter)
|
||||
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 TablesTableModel::PgCatalog:
|
||||
case NamespaceFilter::PgCatalog:
|
||||
hint += " - pg_catalog";
|
||||
caption = "pg_catalog";
|
||||
break;
|
||||
case TablesTableModel::InformationSchema:
|
||||
case NamespaceFilter::InformationSchema:
|
||||
hint += " - information_schema";
|
||||
caption = "information_schema";
|
||||
break;
|
||||
|
|
@ -94,9 +96,9 @@ void CatalogInspectorModule::moduleAction_open(
|
|||
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;
|
||||
NamespaceFilter filter = NamespaceFilter::User;
|
||||
if (nsf == "pg_catalog") filter = NamespaceFilter::PgCatalog;
|
||||
else if (nsf == "information_schema") filter = NamespaceFilter::InformationSchema;
|
||||
ct->setNamespaceFilter(filter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "TablesTableModel.h"
|
||||
#include "NamespaceFilter.h"
|
||||
#include "plugin_support/PluginContentWidget.h"
|
||||
#include "plugin_support/PluginModule.h"
|
||||
|
||||
class CatalogFunctionsPage;
|
||||
class CatalogSequencesPage;
|
||||
class CatalogTablesPage;
|
||||
class PgDatabaseCatalog;
|
||||
class QTabWidget;
|
||||
|
||||
class CatalogInspector : public PluginContentWidget {
|
||||
|
|
@ -19,7 +20,7 @@ public:
|
|||
~CatalogInspector();
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(TablesTableModel::NamespaceFilter filter);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
private:
|
||||
QTabWidget *m_tabWidget = nullptr;
|
||||
CatalogTablesPage *m_tablesPage = nullptr;
|
||||
|
|
|
|||
8
pglab/NamespaceFilter.h
Normal file
8
pglab/NamespaceFilter.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef NAMESPACEFILTER_H
|
||||
#define NAMESPACEFILTER_H
|
||||
|
||||
enum class NamespaceFilter {
|
||||
User, PgCatalog, InformationSchema
|
||||
};
|
||||
|
||||
#endif // NAMESPACEFILTER_H
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "catalog/PgProcContainer.h"
|
||||
#include "catalog/PgLanguageContainer.h"
|
||||
#include "catalog/PgNamespace.h"
|
||||
#include "CustomDataRole.h"
|
||||
|
||||
ProcTableModel::ProcTableModel(QObject *parent)
|
||||
|
|
@ -27,17 +28,48 @@ QVariant ProcTableModel::headerData(int section, Qt::Orientation orientation, in
|
|||
|
||||
void ProcTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void ProcTableModel::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_namespaceFilter = filter;
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void ProcTableModel::reloadData()
|
||||
{
|
||||
if (!m_catalog)
|
||||
return;
|
||||
|
||||
beginResetModel();
|
||||
|
||||
m_catalog = cat;
|
||||
m_procs = cat->procs();
|
||||
auto && procs = m_catalog->procs();
|
||||
m_procs.clear();
|
||||
for (auto&& p : *procs) {
|
||||
bool add = false;
|
||||
switch (m_namespaceFilter) {
|
||||
case NamespaceFilter::User:
|
||||
add = !p.ns().isSystemCatalog();
|
||||
break;
|
||||
case NamespaceFilter::PgCatalog:
|
||||
add = p.ns().objectName() == "pg_catalog";
|
||||
break;
|
||||
case NamespaceFilter::InformationSchema:
|
||||
add = p.ns().objectName() == "information_schema";
|
||||
break;
|
||||
}
|
||||
if (add)
|
||||
m_procs.push_back(p);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ProcTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_procs ? static_cast<int>(m_procs->count()) : 0;
|
||||
return static_cast<int>(m_procs.size());
|
||||
}
|
||||
|
||||
int ProcTableModel::columnCount(const QModelIndex &) const
|
||||
|
|
@ -60,7 +92,7 @@ QVariant ProcTableModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
PgProc ProcTableModel::proc(int row) const
|
||||
{
|
||||
return m_procs->getByIdx(row);
|
||||
return m_procs.at(static_cast<size_t>(row));
|
||||
}
|
||||
|
||||
Oid ProcTableModel::getType(int ) const
|
||||
|
|
@ -77,7 +109,7 @@ Oid ProcTableModel::getType(int ) const
|
|||
|
||||
QVariant ProcTableModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
auto&& t = m_procs->getByIdx(index.row());
|
||||
auto&& t = m_procs.at(static_cast<size_t>(index.row()));
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.objectName();
|
||||
case NamespaceCol: return t.nsName();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef PROCTABLEMODEL_H
|
||||
#define PROCTABLEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include "catalog/PgClass.h"
|
||||
#include "catalog/PgProc.h"
|
||||
#include "NamespaceFilter.h"
|
||||
#include <QAbstractTableModel>
|
||||
#include <memory>
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
|
|
@ -34,6 +35,7 @@ public:
|
|||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
|
@ -44,8 +46,10 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::shared_ptr<const PgProcContainer> m_procs;
|
||||
NamespaceFilter m_namespaceFilter = NamespaceFilter::User;
|
||||
std::vector<PgProc> m_procs;
|
||||
|
||||
void reloadData();
|
||||
Oid getType(int column) const;
|
||||
QVariant getData(const QModelIndex &index) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "SequenceModel.h"
|
||||
#include "catalog/PgDatabaseCatalog.h"
|
||||
#include "catalog/PgNamespace.h"
|
||||
#include "catalog/PgSequenceContainer.h"
|
||||
|
||||
SequenceModel::SequenceModel(QObject * parent)
|
||||
|
|
@ -31,22 +32,53 @@ QVariant SequenceModel::headerData(int section, Qt::Orientation orientation, int
|
|||
|
||||
void SequenceModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void SequenceModel::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_namespaceFilter = filter;
|
||||
reloadData();
|
||||
}
|
||||
|
||||
void SequenceModel::reloadData()
|
||||
{
|
||||
if (!m_catalog)
|
||||
return;
|
||||
|
||||
beginResetModel();
|
||||
|
||||
m_catalog = cat;
|
||||
m_sequences = cat->sequences();
|
||||
auto && seqs = m_catalog->sequences();
|
||||
m_sequences.clear();
|
||||
for (auto&& s : *seqs) {
|
||||
bool add = false;
|
||||
switch (m_namespaceFilter) {
|
||||
case NamespaceFilter::User:
|
||||
add = !s.ns().isSystemCatalog();
|
||||
break;
|
||||
case NamespaceFilter::PgCatalog:
|
||||
add = s.ns().objectName() == "pg_catalog";
|
||||
break;
|
||||
case NamespaceFilter::InformationSchema:
|
||||
add = s.ns().objectName() == "information_schema";
|
||||
break;
|
||||
}
|
||||
if (add)
|
||||
m_sequences.push_back(s);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
PgSequence SequenceModel::sequence(int row) const
|
||||
{
|
||||
return m_sequences->getByIdx(row);
|
||||
return m_sequences.at(static_cast<size_t>(row));
|
||||
}
|
||||
|
||||
int SequenceModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_sequences ? static_cast<int>(m_sequences->count()) : 0;
|
||||
return static_cast<int>(m_sequences.size());
|
||||
}
|
||||
|
||||
int SequenceModel::columnCount(const QModelIndex &) const
|
||||
|
|
@ -56,11 +88,11 @@ int SequenceModel::columnCount(const QModelIndex &) const
|
|||
|
||||
QVariant SequenceModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_sequences)
|
||||
if (m_sequences.empty())
|
||||
return {};
|
||||
|
||||
int row = index.row();
|
||||
auto && seq = m_sequences->getByIdx(row);
|
||||
auto && seq = m_sequences.at(static_cast<size_t>(row));
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (index.column()) {
|
||||
case NameCol: return seq.objectName();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef SEQUENCEMODEL_H
|
||||
#define SEQUENCEMODEL_H
|
||||
|
||||
#include "NamespaceFilter.h"
|
||||
#include <QAbstractTableModel>
|
||||
//#include "catalog/PgClass.h"
|
||||
#include "catalog/PgSequence.h"
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ public:
|
|||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
void SequenceModel::setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
|
@ -42,7 +43,10 @@ public:
|
|||
PgSequence sequence(int row) const;
|
||||
private:
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::shared_ptr<const PgSequenceContainer> m_sequences;
|
||||
std::vector<PgSequence> m_sequences;
|
||||
NamespaceFilter m_namespaceFilter = NamespaceFilter::User;
|
||||
|
||||
void reloadData();
|
||||
};
|
||||
|
||||
#endif // SEQUENCEMODEL_H
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ void TablesTableModel::reloadData()
|
|||
if (e.kind == RelKind::Table || e.kind == RelKind::View
|
||||
|| e.kind == RelKind::MaterializedView || e.kind == RelKind::ForeignTable) {
|
||||
switch (m_namespaceFilter) {
|
||||
case TablesTableModel::User:
|
||||
case NamespaceFilter::User:
|
||||
add = !e.ns().isSystemCatalog();
|
||||
break;
|
||||
case TablesTableModel::PgCatalog:
|
||||
case NamespaceFilter::PgCatalog:
|
||||
add = e.ns().objectName() == "pg_catalog";
|
||||
break;
|
||||
case TablesTableModel::InformationSchema:
|
||||
case NamespaceFilter::InformationSchema:
|
||||
add = e.ns().objectName() == "information_schema";
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define TABLESTABLEMODEL_H
|
||||
|
||||
#include "BaseTableModel.h"
|
||||
#include "NamespaceFilter.h"
|
||||
#include "catalog/PgClass.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
@ -25,9 +26,6 @@ public:
|
|||
|
||||
TablesTableModel(QObject *parent);
|
||||
|
||||
enum NamespaceFilter {
|
||||
User, PgCatalog, InformationSchema
|
||||
};
|
||||
void setNamespaceFilter(NamespaceFilter nsf);
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ private:
|
|||
using t_Tables = std::vector<PgClass>;
|
||||
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
NamespaceFilter m_namespaceFilter = User;
|
||||
NamespaceFilter m_namespaceFilter = NamespaceFilter::User;
|
||||
t_Tables m_tables;
|
||||
|
||||
void reloadData();
|
||||
|
|
|
|||
|
|
@ -170,7 +170,8 @@ CustomDataRole.h \
|
|||
widgets/CatalogConstraintPage.h \
|
||||
widgets/CatalogTablesPage.h \
|
||||
widgets/CatalogFunctionsPage.h \
|
||||
widgets/CatalogSequencesPage.h
|
||||
widgets/CatalogSequencesPage.h \
|
||||
NamespaceFilter.h
|
||||
|
||||
FORMS += \
|
||||
ConnectionManagerWindow.ui \
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ CatalogFunctionsPage::CatalogFunctionsPage(QWidget *parent)
|
|||
m_functionTable->setModel(m_sortFilterProxy);
|
||||
m_functionTable->setSortingEnabled(true);
|
||||
m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_functionTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogFunctionsPage::functionTable_currentRowChanged);
|
||||
|
|
@ -60,6 +61,11 @@ void CatalogFunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> c
|
|||
m_functionTable->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_model->setNamespaceFilter(filter);
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include "NamespaceFilter.h"
|
||||
|
||||
class PgLabTableView;
|
||||
class PgDatabaseCatalog;
|
||||
|
|
@ -19,6 +20,7 @@ public:
|
|||
explicit CatalogFunctionsPage(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
|
|||
m_sequenceTable->setModel(m_sortFilterProxy);
|
||||
m_sequenceTable->setSortingEnabled(true);
|
||||
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_sequenceTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(m_sequenceTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogSequencesPage::sequenceTable_currentRowChanged);
|
||||
|
|
@ -42,6 +43,11 @@ void CatalogSequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> c
|
|||
m_sequenceTable->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_model->setNamespaceFilter(filter);
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SEQUENCESPAGES_H
|
||||
#define SEQUENCESPAGES_H
|
||||
|
||||
#include "NamespaceFilter.h"
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
|
@ -18,6 +19,7 @@ public:
|
|||
CatalogSequencesPage(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
public slots:
|
||||
|
||||
void sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "PropertiesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "TablesTableModel.h"
|
||||
#include "TriggerPage.h"
|
||||
#include "catalog/PgIndexContainer.h"
|
||||
#include "catalog/PgTriggerContainer.h"
|
||||
|
|
@ -101,7 +102,7 @@ void CatalogTablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
|||
m_triggerPage->setCatalog(cat);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::setNamespaceFilter(TablesTableModel::NamespaceFilter filter)
|
||||
void CatalogTablesPage::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_tablesModel->setNamespaceFilter(filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef CATALOGTABLESPAGE_H
|
||||
#define CATALOGTABLESPAGE_H
|
||||
|
||||
#include "NamespaceFilter.h"
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include "TablesTableModel.h"
|
||||
#include <optional>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class CatalogConstraintPage;
|
||||
class CatalogIndexPage;
|
||||
|
|
@ -27,7 +29,7 @@ public:
|
|||
explicit CatalogTablesPage(QWidget * parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(TablesTableModel::NamespaceFilter filter);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -30,12 +30,6 @@ void operator<<(RelKind &s, const Pgsql::Value &v);
|
|||
|
||||
class PgClass: public PgNamespaceObject {
|
||||
public:
|
||||
|
||||
// Oid oid = InvalidOid;
|
||||
// QString name;
|
||||
// Oid relnamespace = InvalidOid;
|
||||
// QString relnamespace_name; // Transient, cached value from relnamespace
|
||||
// bool system_namespace = false; // Transient, cached value from relnamespace
|
||||
Oid type = InvalidOid;
|
||||
Oid oftype = InvalidOid;
|
||||
//Oid owner = InvalidOid;
|
||||
|
|
@ -56,15 +50,8 @@ public:
|
|||
|
||||
using PgNamespaceObject::PgNamespaceObject;
|
||||
|
||||
// virtual QString objectName() const override;
|
||||
|
||||
// bool operator==(Oid _oid) const { return oid == _oid; }
|
||||
// bool operator==(const QString &n) const { return objectName() == n; }
|
||||
// bool operator<(Oid _oid) const { return oid < _oid; }
|
||||
// bool operator<(const PgClass &rhs) const { return oid < rhs.oid; }
|
||||
|
||||
QString kindString() const;
|
||||
QString createSql() const;
|
||||
QString createSql() const override;
|
||||
QString typeName() const override;
|
||||
QString aclAllPattern() const override;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue