Add tab with namespaces (schema's)
This commit is contained in:
parent
8dd13d103e
commit
1df8455af5
7 changed files with 171 additions and 18 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "UserConfiguration.h"
|
#include "UserConfiguration.h"
|
||||||
#include "widgets/CatalogFunctionsPage.h"
|
#include "widgets/CatalogFunctionsPage.h"
|
||||||
|
#include "widgets/CatalogNamespacePage.h"
|
||||||
#include "widgets/CatalogSequencesPage.h"
|
#include "widgets/CatalogSequencesPage.h"
|
||||||
#include "widgets/CatalogTablesPage.h"
|
#include "widgets/CatalogTablesPage.h"
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ CatalogInspector::CatalogInspector(std::shared_ptr<OpenDatabase> open_database,
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
m_tabWidget = new QTabWidget(this);
|
m_tabWidget = new QTabWidget(this);
|
||||||
|
m_namespacePage = new CatalogNamespacePage(this);
|
||||||
m_tablesPage = new CatalogTablesPage(this);
|
m_tablesPage = new CatalogTablesPage(this);
|
||||||
m_functionsPage = new CatalogFunctionsPage(this);
|
m_functionsPage = new CatalogFunctionsPage(this);
|
||||||
m_sequencesPage = new CatalogSequencesPage(this);
|
m_sequencesPage = new CatalogSequencesPage(this);
|
||||||
|
|
@ -22,6 +24,7 @@ CatalogInspector::CatalogInspector(std::shared_ptr<OpenDatabase> open_database,
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
layout->addWidget(m_tabWidget);
|
layout->addWidget(m_tabWidget);
|
||||||
|
m_tabWidget->addTab(m_namespacePage, "");
|
||||||
m_tabWidget->addTab(m_tablesPage, "");
|
m_tabWidget->addTab(m_tablesPage, "");
|
||||||
m_tabWidget->addTab(m_functionsPage, "");
|
m_tabWidget->addTab(m_functionsPage, "");
|
||||||
m_tabWidget->addTab(m_sequencesPage, "");
|
m_tabWidget->addTab(m_sequencesPage, "");
|
||||||
|
|
@ -34,6 +37,8 @@ void CatalogInspector::retranslateUi(bool all)
|
||||||
{
|
{
|
||||||
m_tablesPage->retranslateUi(all);
|
m_tablesPage->retranslateUi(all);
|
||||||
|
|
||||||
|
m_tabWidget->setTabText(m_tabWidget->indexOf(m_namespacePage),
|
||||||
|
QApplication::translate("CatalogInspector", "Schemas", nullptr));
|
||||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_tablesPage),
|
m_tabWidget->setTabText(m_tabWidget->indexOf(m_tablesPage),
|
||||||
QApplication::translate("CatalogInspector", "Tables", nullptr));
|
QApplication::translate("CatalogInspector", "Tables", nullptr));
|
||||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_functionsPage),
|
m_tabWidget->setTabText(m_tabWidget->indexOf(m_functionsPage),
|
||||||
|
|
@ -49,6 +54,7 @@ CatalogInspector::~CatalogInspector()
|
||||||
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||||
{
|
{
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
|
m_namespacePage->setCatalog(cat);
|
||||||
m_tablesPage->setCatalog(cat);
|
m_tablesPage->setCatalog(cat);
|
||||||
m_functionsPage->setCatalog(cat);
|
m_functionsPage->setCatalog(cat);
|
||||||
m_sequencesPage->setCatalog(cat);
|
m_sequencesPage->setCatalog(cat);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
class CatalogFunctionsPage;
|
class CatalogFunctionsPage;
|
||||||
class CatalogSequencesPage;
|
class CatalogSequencesPage;
|
||||||
class CatalogTablesPage;
|
class CatalogTablesPage;
|
||||||
|
class CatalogNamespacePage;
|
||||||
class OpenDatabase;
|
class OpenDatabase;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
class QTabWidget;
|
class QTabWidget;
|
||||||
|
|
@ -24,6 +25,7 @@ public:
|
||||||
CatalogTablesPage *tablesPage();
|
CatalogTablesPage *tablesPage();
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_tabWidget = nullptr;
|
QTabWidget *m_tabWidget = nullptr;
|
||||||
|
CatalogNamespacePage *m_namespacePage = nullptr;
|
||||||
CatalogTablesPage *m_tablesPage = nullptr;
|
CatalogTablesPage *m_tablesPage = nullptr;
|
||||||
CatalogFunctionsPage *m_functionsPage = nullptr;
|
CatalogFunctionsPage *m_functionsPage = nullptr;
|
||||||
CatalogSequencesPage *m_sequencesPage = nullptr;
|
CatalogSequencesPage *m_sequencesPage = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace NamespaceItemModel_impl {
|
||||||
virtual Qt::CheckState getCheckState() const = 0;
|
virtual Qt::CheckState getCheckState() const = 0;
|
||||||
virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0;
|
virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0;
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const = 0;
|
virtual QVariant data(const QModelIndex &index, int role) const = 0;
|
||||||
|
virtual int columnCount() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
class GroupNode;
|
class GroupNode;
|
||||||
|
|
@ -45,16 +46,29 @@ namespace NamespaceItemModel_impl {
|
||||||
emit model->dataChanged(index.parent(), index.parent());
|
emit model->dataChanged(index.parent(), index.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant data(const QModelIndex &/*index*/, int role) const override
|
QVariant data(const QModelIndex &index, int role) const override
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
v = ns.objectName();
|
switch (index.column()) {
|
||||||
|
case NamespaceItemModel::ColNamespaceName:
|
||||||
|
return ns.objectName();
|
||||||
|
case NamespaceItemModel::ColOwner:
|
||||||
|
return ns.ownerName();
|
||||||
|
case NamespaceItemModel::ColAcl:
|
||||||
|
return ns.aclString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (role == Qt::CheckStateRole) {
|
else if (role == Qt::CheckStateRole) {
|
||||||
v = getCheckState();
|
if (index.column() == 0)
|
||||||
|
return getCheckState();
|
||||||
}
|
}
|
||||||
return v;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int columnCount() const override
|
||||||
|
{
|
||||||
|
return NamespaceItemModel::ColCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (const LeafNode &rhs) const
|
bool operator < (const LeafNode &rhs) const
|
||||||
|
|
@ -62,12 +76,11 @@ namespace NamespaceItemModel_impl {
|
||||||
return ns.objectName() < rhs.ns.objectName();
|
return ns.objectName() < rhs.ns.objectName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupNode: public Node {
|
class GroupNode: public Node {
|
||||||
public:
|
public:
|
||||||
using LeafVec = std::vector<std::shared_ptr<LeafNode>>;
|
using LeafVec = QVector<std::shared_ptr<LeafNode>>;
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
LeafVec leaves;
|
LeafVec leaves;
|
||||||
|
|
@ -120,16 +133,25 @@ namespace NamespaceItemModel_impl {
|
||||||
emit model->dataChanged(model->index(0, 0, index), model->index(leaves.size(), 0, index));
|
emit model->dataChanged(model->index(0, 0, index), model->index(leaves.size(), 0, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant data(const QModelIndex &/*index*/, int role) const override
|
QVariant data(const QModelIndex &index, int role) const override
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
v = name;
|
switch (index.column()) {
|
||||||
|
case NamespaceItemModel::ColNamespaceName:
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(role == Qt::CheckStateRole) {
|
else if(role == Qt::CheckStateRole) {
|
||||||
v = getCheckState();
|
if (index.column() == 0)
|
||||||
|
return getCheckState();
|
||||||
}
|
}
|
||||||
return v;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int columnCount() const override
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -164,6 +186,21 @@ void NamespaceItemModel::init(std::shared_ptr<const PgNamespaceContainer> ns)
|
||||||
e->checked = true;
|
e->checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NamespaceItemModel::setEnableCheckboxes(bool enable)
|
||||||
|
{
|
||||||
|
if (m_enableCheckboxes != enable) {
|
||||||
|
beginResetModel();
|
||||||
|
SCOPE_EXIT { endResetModel(); };
|
||||||
|
m_enableCheckboxes = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NamespaceItemModel::isEnableCheckboxes() const
|
||||||
|
{
|
||||||
|
return m_enableCheckboxes;
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex NamespaceItemModel::index(int row, int column,
|
QModelIndex NamespaceItemModel::index(int row, int column,
|
||||||
const QModelIndex &parent) const
|
const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
|
@ -192,8 +229,9 @@ QModelIndex NamespaceItemModel::parent(const QModelIndex &index) const
|
||||||
auto ln = dynamic_cast<LeafNode*>(n);
|
auto ln = dynamic_cast<LeafNode*>(n);
|
||||||
if (ln) { // leafnode
|
if (ln) { // leafnode
|
||||||
auto grp = ln->parent.lock(); // Get the parent group
|
auto grp = ln->parent.lock(); // Get the parent group
|
||||||
auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list
|
// auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list
|
||||||
int row = fr - groups.begin(); // calculate index ie row
|
// int row = fr - groups.begin(); // calculate index ie row
|
||||||
|
int row = groups.indexOf(grp);
|
||||||
result = createIndex(row, 0, grp.get()); // return index
|
result = createIndex(row, 0, grp.get()); // return index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +254,11 @@ int NamespaceItemModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
int NamespaceItemModel::columnCount(const QModelIndex &/*index*/) const
|
int NamespaceItemModel::columnCount(const QModelIndex &/*index*/) const
|
||||||
{
|
{
|
||||||
return 1;
|
// if (index.isValid()) {
|
||||||
|
// auto *n = static_cast<Node*>(index.internalPointer());
|
||||||
|
// return n->columnCount();
|
||||||
|
// }
|
||||||
|
return ColCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant NamespaceItemModel::data(const QModelIndex &index, int role) const
|
QVariant NamespaceItemModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
@ -234,7 +276,8 @@ bool NamespaceItemModel::setData(const QModelIndex &index,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto *n = static_cast<Node*>(index.internalPointer());
|
auto *n = static_cast<Node*>(index.internalPointer());
|
||||||
n->setChecked(this, index, value == Qt::Checked);
|
if (index.column() == 0)
|
||||||
|
n->setChecked(this, index, value == Qt::Checked);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -242,7 +285,23 @@ bool NamespaceItemModel::setData(const QModelIndex &index,
|
||||||
Qt::ItemFlags NamespaceItemModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags NamespaceItemModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
if (index.column() == 0 && m_enableCheckboxes)
|
||||||
|
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QVariant NamespaceItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation == Qt::Horizontal) {
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch (section) {
|
||||||
|
case ColNamespaceName: return tr("Name");
|
||||||
|
case ColOwner: return tr("Owner");
|
||||||
|
case ColAcl: return tr("ACL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
#define NAMESPACEITEMMODEL_H
|
#define NAMESPACEITEMMODEL_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QVector>
|
||||||
#include "catalog/PgNamespace.h"
|
#include "catalog/PgNamespace.h"
|
||||||
#include <vector>
|
//#include <vector>
|
||||||
#include <iterator>
|
//#include <iterator>
|
||||||
|
|
||||||
namespace NamespaceItemModel_impl {
|
namespace NamespaceItemModel_impl {
|
||||||
|
|
||||||
|
|
@ -20,7 +21,17 @@ class NamespaceItemModel: public QAbstractItemModel {
|
||||||
public:
|
public:
|
||||||
NamespaceItemModel(QObject *parent = 0);
|
NamespaceItemModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
enum Columns {
|
||||||
|
ColNamespaceName,
|
||||||
|
ColOwner,
|
||||||
|
ColAcl,
|
||||||
|
|
||||||
|
ColCount
|
||||||
|
};
|
||||||
|
|
||||||
void init(std::shared_ptr<const PgNamespaceContainer> ns);
|
void init(std::shared_ptr<const PgNamespaceContainer> ns);
|
||||||
|
void setEnableCheckboxes(bool enable);
|
||||||
|
bool isEnableCheckboxes() const;
|
||||||
|
|
||||||
virtual QModelIndex index(int row, int column,
|
virtual QModelIndex index(int row, int column,
|
||||||
const QModelIndex &parent = QModelIndex()) const override;
|
const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
@ -33,9 +44,14 @@ public:
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using GroupVec = std::vector<std::shared_ptr<NamespaceItemModel_impl::GroupNode>>;
|
using GroupVec = QVector<std::shared_ptr<NamespaceItemModel_impl::GroupNode>>;
|
||||||
|
|
||||||
GroupVec groups;
|
GroupVec groups;
|
||||||
|
bool m_enableCheckboxes = true;
|
||||||
|
|
||||||
|
// QAbstractItemModel interface
|
||||||
|
public:
|
||||||
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAMESPACEITEMMODEL_H
|
#endif // NAMESPACEITEMMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ PropertyProxyModel.cpp \
|
||||||
QueryTool.cpp \
|
QueryTool.cpp \
|
||||||
CatalogInspector.cpp \
|
CatalogInspector.cpp \
|
||||||
widgets/CatalogIndexPage.cpp \
|
widgets/CatalogIndexPage.cpp \
|
||||||
|
widgets/CatalogNamespacePage.cpp \
|
||||||
widgets/CatalogPageBase.cpp \
|
widgets/CatalogPageBase.cpp \
|
||||||
widgets/CatalogConstraintPage.cpp \
|
widgets/CatalogConstraintPage.cpp \
|
||||||
widgets/CatalogTablesPage.cpp \
|
widgets/CatalogTablesPage.cpp \
|
||||||
|
|
@ -151,6 +152,7 @@ CustomDataRole.h \
|
||||||
QueryTool.h \
|
QueryTool.h \
|
||||||
CatalogInspector.h \
|
CatalogInspector.h \
|
||||||
widgets/CatalogIndexPage.h \
|
widgets/CatalogIndexPage.h \
|
||||||
|
widgets/CatalogNamespacePage.h \
|
||||||
widgets/CatalogPageBase.h \
|
widgets/CatalogPageBase.h \
|
||||||
widgets/CatalogConstraintPage.h \
|
widgets/CatalogConstraintPage.h \
|
||||||
widgets/CatalogTablesPage.h \
|
widgets/CatalogTablesPage.h \
|
||||||
|
|
|
||||||
32
pglab/widgets/CatalogNamespacePage.cpp
Normal file
32
pglab/widgets/CatalogNamespacePage.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include "CatalogNamespacePage.h"
|
||||||
|
#include <QTreeView>
|
||||||
|
#include "NamespaceItemModel.h"
|
||||||
|
#include "SqlCodePreview.h"
|
||||||
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
|
|
||||||
|
CatalogNamespacePage::CatalogNamespacePage(QWidget *parent)
|
||||||
|
: QSplitter(Qt::Horizontal, parent)
|
||||||
|
, m_namespaceTree(new QTreeView(this))
|
||||||
|
, m_model(new NamespaceItemModel(this))
|
||||||
|
{
|
||||||
|
m_namespaceTree->setModel(m_model);
|
||||||
|
m_definitionView = new SqlCodePreview(this);
|
||||||
|
|
||||||
|
addWidget(m_namespaceTree);
|
||||||
|
addWidget(m_definitionView);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CatalogNamespacePage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||||
|
{
|
||||||
|
m_catalog = cat;
|
||||||
|
m_model->setEnableCheckboxes(false);
|
||||||
|
m_model->init(cat->namespaces());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CatalogNamespacePage::retranslateUi()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
36
pglab/widgets/CatalogNamespacePage.h
Normal file
36
pglab/widgets/CatalogNamespacePage.h
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef CATALOGNAMESPACEPAGE_H
|
||||||
|
#define CATALOGNAMESPACEPAGE_H
|
||||||
|
|
||||||
|
#include "widgets/CatalogPageBase.h"
|
||||||
|
|
||||||
|
class QTreeView;
|
||||||
|
class NamespaceItemModel;
|
||||||
|
class PgDatabaseCatalog;
|
||||||
|
class SqlCodePreview;
|
||||||
|
|
||||||
|
|
||||||
|
class CatalogNamespacePage : public QSplitter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit CatalogNamespacePage(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTreeView *m_namespaceTree = nullptr;
|
||||||
|
SqlCodePreview *m_definitionView = nullptr;
|
||||||
|
NamespaceItemModel *m_model = nullptr;
|
||||||
|
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||||
|
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||||
|
|
||||||
|
void retranslateUi();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CATALOGNAMESPACEPAGE_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue