Reorganization of pgLab project
This commit is contained in:
parent
7300865c77
commit
c71fdc4af7
78 changed files with 204 additions and 148 deletions
46
pglab/catalog/widgets/CatalogConstraintPage.cpp
Normal file
46
pglab/catalog/widgets/CatalogConstraintPage.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "catalog/widgets/CatalogConstraintPage.h"
|
||||
#include "catalog/models/ConstraintModel.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "catalog/delegates/IconColumnDelegate.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QHeaderView>
|
||||
#include <QStringBuilder>
|
||||
|
||||
CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
||||
: CatalogPageBase(parent)
|
||||
{
|
||||
m_constraintModel = new ConstraintModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_constraintModel);
|
||||
|
||||
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
||||
m_tableView->horizontalHeader()->setSortIndicator(ConstraintModel::NameCol, Qt::AscendingOrder);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &CatalogConstraintPage::tableView_selectionChanged);
|
||||
connect(m_constraintModel, &ConstraintModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
}
|
||||
|
||||
void CatalogConstraintPage::catalogSet()
|
||||
{
|
||||
}
|
||||
|
||||
void CatalogConstraintPage::setFilter(const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_constraintModel->setData(m_catalog, cls);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||
{
|
||||
auto rijen = selectedRows();
|
||||
QString drops;
|
||||
QString creates;
|
||||
for (auto rij : rijen) {
|
||||
const PgConstraint constraint = m_constraintModel->constraint(rij);
|
||||
drops += constraint.dropSql() % "\n";
|
||||
creates += constraint.createSql() % "\n";
|
||||
}
|
||||
m_definitionView->setPlainText(drops % "\n" % creates);
|
||||
}
|
||||
29
pglab/catalog/widgets/CatalogConstraintPage.h
Normal file
29
pglab/catalog/widgets/CatalogConstraintPage.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef CATALOGCONSTRAINTPAGE_H
|
||||
#define CATALOGCONSTRAINTPAGE_H
|
||||
|
||||
#include "CatalogPageBase.h"
|
||||
|
||||
class ConstraintModel;
|
||||
class PgClass;
|
||||
class QItemSelection;
|
||||
|
||||
|
||||
class CatalogConstraintPage : public CatalogPageBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogConstraintPage(QWidget *parent = nullptr);
|
||||
|
||||
void setFilter(const std::optional<PgClass> &cls);
|
||||
|
||||
protected:
|
||||
void catalogSet() override;
|
||||
|
||||
private:
|
||||
|
||||
ConstraintModel *m_constraintModel = nullptr;
|
||||
|
||||
private slots:
|
||||
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
};
|
||||
|
||||
#endif // CATALOGCONSTRAINTPAGE_H
|
||||
100
pglab/catalog/widgets/CatalogFunctionsPage.cpp
Normal file
100
pglab/catalog/widgets/CatalogFunctionsPage.cpp
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include "CatalogFunctionsPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabItemDelegate.h"
|
||||
#include "catalog/models/ProcTableModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QApplication>
|
||||
#include "util/PgLabTableView.h"
|
||||
#include <QHeaderView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabWidget>
|
||||
|
||||
CatalogFunctionsPage::CatalogFunctionsPage(QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
// create widgets
|
||||
m_functionTable = new PgLabTableView(this);
|
||||
m_detailTabs = new QTabWidget(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
|
||||
// build widget tree
|
||||
// add top level widgets to splitter
|
||||
addWidget(m_functionTable);
|
||||
addWidget(m_detailTabs);
|
||||
|
||||
// add widgets to detail tabs
|
||||
m_detailTabs->addTab(m_definitionView, "SQL");
|
||||
|
||||
// auto mainLayout = new QVBoxLayout;
|
||||
// mainLayout->addWidget(m_functionTable);
|
||||
// setLayout(mainLayout);
|
||||
|
||||
// Do further initialization of widgets and models
|
||||
m_model = new ProcTableModel(this);
|
||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
m_functionTable->setModel(m_sortFilterProxy);
|
||||
m_functionTable->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
m_functionTable->setSortingEnabled(true);
|
||||
m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_functionTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogFunctionsPage::functionTable_currentRowChanged);
|
||||
connect(m_model, &ProcTableModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::retranslateUi()
|
||||
{
|
||||
auto set_tabtext = [this] (QWidget *widget, QString translation) {
|
||||
m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation);
|
||||
};
|
||||
|
||||
set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr));
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
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()) {
|
||||
if (current.isValid()) {
|
||||
auto source_index = m_sortFilterProxy->mapToSource(current);
|
||||
auto proc = m_model->proc(source_index.row());
|
||||
|
||||
selectedProcChanged(proc);
|
||||
}
|
||||
else
|
||||
selectedProcChanged({});
|
||||
}
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::selectedProcChanged(const std::optional<PgProc> &proc)
|
||||
{
|
||||
updateSqlTab(proc);
|
||||
}
|
||||
|
||||
void CatalogFunctionsPage::updateSqlTab(const std::optional<PgProc> &proc)
|
||||
{
|
||||
if (!proc.has_value()) {
|
||||
m_definitionView->clear();
|
||||
return;
|
||||
}
|
||||
QString create_sql = proc->createSql();
|
||||
|
||||
m_definitionView->setPlainText(create_sql);
|
||||
}
|
||||
43
pglab/catalog/widgets/CatalogFunctionsPage.h
Normal file
43
pglab/catalog/widgets/CatalogFunctionsPage.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef FUNCTIONSPAGE_H
|
||||
#define FUNCTIONSPAGE_H
|
||||
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include "NamespaceFilter.h"
|
||||
|
||||
class PgLabTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class ProcTableModel;
|
||||
class CustomFilterSortModel;
|
||||
class QTabWidget;
|
||||
class SqlCodePreview;
|
||||
class PgProc;
|
||||
|
||||
class CatalogFunctionsPage : public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogFunctionsPage(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
private:
|
||||
PgLabTableView *m_functionTable = nullptr;
|
||||
QTabWidget *m_detailTabs = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
ProcTableModel *m_model = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi();
|
||||
|
||||
void selectedProcChanged(const std::optional<PgProc> &proc);
|
||||
void updateSqlTab(const std::optional<PgProc> &proc);
|
||||
};
|
||||
|
||||
#endif // FUNCTIONSPAGE_H
|
||||
46
pglab/catalog/widgets/CatalogIndexPage.cpp
Normal file
46
pglab/catalog/widgets/CatalogIndexPage.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "catalog/widgets/CatalogIndexPage.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "catalog/models/IndexModel.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QHeaderView>
|
||||
#include <QStringBuilder>
|
||||
#include "catalog/delegates/IconColumnDelegate.h"
|
||||
|
||||
|
||||
CatalogIndexPage::CatalogIndexPage(QWidget *parent)
|
||||
: CatalogPageBase(parent)
|
||||
{
|
||||
m_indexModel = new IndexModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_indexModel);
|
||||
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
||||
m_tableView->horizontalHeader()->setSortIndicator(IndexModel::NameCol, Qt::AscendingOrder);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &CatalogIndexPage::tableView_selectionChanged);
|
||||
connect(m_indexModel, &IndexModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
}
|
||||
|
||||
void CatalogIndexPage::catalogSet()
|
||||
{
|
||||
}
|
||||
|
||||
void CatalogIndexPage::setFilter(const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_indexModel->setData(m_catalog, cls);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogIndexPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||
{
|
||||
auto rijen = selectedRows();
|
||||
QString drops;
|
||||
QString creates;
|
||||
for (auto rij : rijen) {
|
||||
const PgIndex index = m_indexModel->getIndex(rij);
|
||||
drops += index.dropSql() % "\n";
|
||||
creates += index.createSql() % "\n";
|
||||
}
|
||||
m_definitionView->setPlainText(drops % "\n" % creates);
|
||||
}
|
||||
29
pglab/catalog/widgets/CatalogIndexPage.h
Normal file
29
pglab/catalog/widgets/CatalogIndexPage.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef CATALOGINDEXPAGE_H
|
||||
#define CATALOGINDEXPAGE_H
|
||||
|
||||
#include "CatalogPageBase.h"
|
||||
|
||||
class IndexModel;
|
||||
class PgClass;
|
||||
class QItemSelection;
|
||||
|
||||
|
||||
class CatalogIndexPage : public CatalogPageBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogIndexPage(QWidget *parent = nullptr);
|
||||
|
||||
void setFilter(const std::optional<PgClass> &cls);
|
||||
|
||||
protected:
|
||||
void catalogSet() override;
|
||||
|
||||
private:
|
||||
|
||||
IndexModel *m_indexModel = nullptr;
|
||||
|
||||
private slots:
|
||||
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
};
|
||||
|
||||
#endif // CATALOGINDEXPAGE_H
|
||||
94
pglab/catalog/widgets/CatalogInspector.cpp
Normal file
94
pglab/catalog/widgets/CatalogInspector.cpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#include "CatalogInspector.h"
|
||||
#include "OpenDatabase.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "catalog/widgets/CatalogFunctionsPage.h"
|
||||
#include "catalog/widgets/CatalogNamespacePage.h"
|
||||
#include "catalog/widgets/CatalogSequencesPage.h"
|
||||
#include "catalog/widgets/CatalogTablesPage.h"
|
||||
#include "catalog/widgets/CatalogTypesPage.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTabWidget>
|
||||
#include <QStringBuilder>
|
||||
#include <QVBoxLayout>
|
||||
#include <unordered_set>
|
||||
|
||||
CatalogInspector::CatalogInspector(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
// m_namespacePage = new CatalogNamespacePage(this);
|
||||
m_tablesPage = new CatalogTablesPage(open_database, this);
|
||||
m_functionsPage = new CatalogFunctionsPage(this);
|
||||
m_sequencesPage = new CatalogSequencesPage(this);
|
||||
m_typesPage = new CatalogTypesPage(this);
|
||||
|
||||
auto layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_tabWidget);
|
||||
// m_tabWidget->addTab(m_namespacePage, "");
|
||||
m_tabWidget->addTab(m_tablesPage, "");
|
||||
m_tabWidget->addTab(m_functionsPage, "");
|
||||
m_tabWidget->addTab(m_sequencesPage, "");
|
||||
m_tabWidget->addTab(m_typesPage, "");
|
||||
|
||||
setCatalog(open_database->catalog());
|
||||
retranslateUi(false);
|
||||
}
|
||||
|
||||
void CatalogInspector::retranslateUi(bool 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),
|
||||
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));
|
||||
m_tabWidget->setTabText(m_tabWidget->indexOf(m_typesPage),
|
||||
QApplication::translate("CatalogInspector", "Types", nullptr));
|
||||
}
|
||||
|
||||
CatalogInspector::~CatalogInspector()
|
||||
{
|
||||
}
|
||||
|
||||
void CatalogInspector::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
// m_namespacePage->setCatalog(cat);
|
||||
m_tablesPage->setCatalog(cat);
|
||||
m_functionsPage->setCatalog(cat);
|
||||
m_sequencesPage->setCatalog(cat);
|
||||
m_typesPage->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);
|
||||
}
|
||||
|
||||
CatalogTablesPage *CatalogInspector::tablesPage()
|
||||
{
|
||||
return m_tablesPage;
|
||||
}
|
||||
41
pglab/catalog/widgets/CatalogInspector.h
Normal file
41
pglab/catalog/widgets/CatalogInspector.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef TABLESPAGE_H
|
||||
#define TABLESPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "NamespaceFilter.h"
|
||||
|
||||
class CatalogFunctionsPage;
|
||||
class CatalogSequencesPage;
|
||||
class CatalogTablesPage;
|
||||
class CatalogNamespacePage;
|
||||
class CatalogTypesPage;
|
||||
class OpenDatabase;
|
||||
class PgDatabaseCatalog;
|
||||
class QTabWidget;
|
||||
|
||||
class CatalogInspector : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogInspector(std::shared_ptr<OpenDatabase> open_database, QWidget *parent = nullptr);
|
||||
~CatalogInspector();
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
CatalogTablesPage *tablesPage();
|
||||
private:
|
||||
QTabWidget *m_tabWidget = nullptr;
|
||||
// CatalogNamespacePage *m_namespacePage = nullptr;
|
||||
CatalogTablesPage *m_tablesPage = nullptr;
|
||||
CatalogFunctionsPage *m_functionsPage = nullptr;
|
||||
CatalogSequencesPage *m_sequencesPage = nullptr;
|
||||
CatalogTypesPage *m_typesPage = nullptr;
|
||||
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
|
||||
private slots:
|
||||
};
|
||||
|
||||
#endif // TABLESPAGE_H
|
||||
32
pglab/catalog/widgets/CatalogNamespacePage.cpp
Normal file
32
pglab/catalog/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/catalog/widgets/CatalogNamespacePage.h
Normal file
36
pglab/catalog/widgets/CatalogNamespacePage.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef CATALOGNAMESPACEPAGE_H
|
||||
#define CATALOGNAMESPACEPAGE_H
|
||||
|
||||
#include "catalog/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
|
||||
35
pglab/catalog/widgets/CatalogPageBase.cpp
Normal file
35
pglab/catalog/widgets/CatalogPageBase.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "catalog/widgets/CatalogPageBase.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "SqlCodePreview.h"
|
||||
|
||||
CatalogPageBase::CatalogPageBase(QWidget *parent)
|
||||
: QSplitter(Qt::Vertical, parent)
|
||||
{
|
||||
m_tableView = new PgLabTableView(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
addWidget(m_tableView);
|
||||
addWidget(m_definitionView);
|
||||
|
||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||
|
||||
m_tableView->setModel(m_sortFilterProxy);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
}
|
||||
|
||||
void CatalogPageBase::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_definitionView->setCatalog(m_catalog);
|
||||
catalogSet();
|
||||
}
|
||||
|
||||
std::unordered_set<int> CatalogPageBase::selectedRows() const
|
||||
{
|
||||
auto&& indexes = m_tableView->selectionModel()->selectedIndexes();
|
||||
std::unordered_set<int> rijen;
|
||||
for (const auto &e : indexes)
|
||||
rijen.insert(m_sortFilterProxy->mapToSource(e).row());
|
||||
return rijen;
|
||||
}
|
||||
32
pglab/catalog/widgets/CatalogPageBase.h
Normal file
32
pglab/catalog/widgets/CatalogPageBase.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef CATALOGPAGEBASE_H
|
||||
#define CATALOGPAGEBASE_H
|
||||
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <unordered_set>
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
class PgLabTableView;
|
||||
class SqlCodePreview;
|
||||
class CustomFilterSortModel;
|
||||
|
||||
|
||||
class CatalogPageBase : public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CatalogPageBase(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
|
||||
protected:
|
||||
PgLabTableView *m_tableView = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
virtual void catalogSet() {}
|
||||
std::unordered_set<int> selectedRows() const;
|
||||
};
|
||||
|
||||
#endif // CATALOGPAGEBASE_H
|
||||
83
pglab/catalog/widgets/CatalogSequencesPage.cpp
Normal file
83
pglab/catalog/widgets/CatalogSequencesPage.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include "catalog/widgets/CatalogSequencesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabItemDelegate.h"
|
||||
#include "catalog/models/SequenceModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include <QHeaderView>
|
||||
|
||||
CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
m_sequenceTable = new PgLabTableView(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
|
||||
// build widget tree
|
||||
// add top level widgets to splitter
|
||||
addWidget(m_sequenceTable);
|
||||
addWidget(m_definitionView);
|
||||
|
||||
m_model = new SequenceModel(this);
|
||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
m_sequenceTable->setModel(m_sortFilterProxy);
|
||||
m_sequenceTable->horizontalHeader()->setSortIndicator(SequenceModel::NameCol, Qt::AscendingOrder);
|
||||
m_sequenceTable->setSortingEnabled(true);
|
||||
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_sequenceTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(m_sequenceTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogSequencesPage::sequenceTable_currentRowChanged);
|
||||
connect(m_model, &SequenceModel::modelReset,
|
||||
[this] () { selectedSequenceChanged({}); });
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::retranslateUi()
|
||||
{
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
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()) {
|
||||
if (current.isValid()) {
|
||||
auto source_index = m_sortFilterProxy->mapToSource(current);
|
||||
auto proc = m_model->sequence(source_index.row());
|
||||
|
||||
selectedSequenceChanged(proc);
|
||||
}
|
||||
else
|
||||
selectedSequenceChanged({});
|
||||
}
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::selectedSequenceChanged(const std::optional<PgSequence> &seq)
|
||||
{
|
||||
updateSqlTab(seq);
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::updateSqlTab(const std::optional<PgSequence> &seq)
|
||||
{
|
||||
if (!seq.has_value()) {
|
||||
m_definitionView->clear();
|
||||
return;
|
||||
}
|
||||
QString create_sql = seq->createSql();
|
||||
|
||||
m_definitionView->setPlainText(create_sql);
|
||||
}
|
||||
40
pglab/catalog/widgets/CatalogSequencesPage.h
Normal file
40
pglab/catalog/widgets/CatalogSequencesPage.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef SEQUENCESPAGES_H
|
||||
#define SEQUENCESPAGES_H
|
||||
|
||||
#include "NamespaceFilter.h"
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
class PgLabTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class SequenceModel;
|
||||
class CustomFilterSortModel;
|
||||
class SqlCodePreview;
|
||||
class PgSequence;
|
||||
|
||||
class CatalogSequencesPage : public QSplitter {
|
||||
Q_OBJECT
|
||||
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);
|
||||
|
||||
private:
|
||||
PgLabTableView *m_sequenceTable = nullptr;
|
||||
//QTabWidget *m_detailTabs = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
SequenceModel *m_model = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi();
|
||||
void selectedSequenceChanged(const std::optional<PgSequence> &seq);
|
||||
void updateSqlTab(const std::optional<PgSequence> &seq);
|
||||
};
|
||||
|
||||
#endif // SEQUENCESPAGES_H
|
||||
205
pglab/catalog/widgets/CatalogTablesPage.cpp
Normal file
205
pglab/catalog/widgets/CatalogTablesPage.cpp
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
#include "CatalogTablesPage.h"
|
||||
|
||||
#include "catalog/widgets/CatalogConstraintPage.h"
|
||||
#include "catalog/widgets/CatalogIndexPage.h"
|
||||
#include "catalog/widgets/ColumnPage.h"
|
||||
#include "catalog/widgets/DependantsPage.h"
|
||||
#include "PropertiesPage.h"
|
||||
#include "catalog/widgets/TriggerPage.h"
|
||||
#include "catalog/models/ColumnTableModel.h"
|
||||
#include "catalog/models/ConstraintModel.h"
|
||||
#include "catalog/models/TablesTableModel.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "SqlFormattingUtils.h"
|
||||
#include "catalog/PgAttributeContainer.h"
|
||||
#include "catalog/PgIndexContainer.h"
|
||||
#include "catalog/PgTriggerContainer.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QStringBuilder>
|
||||
//#include <QSortFilterProxyModel>
|
||||
#include <QTableWidget>
|
||||
|
||||
CatalogTablesPage::CatalogTablesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
, m_tablesTableView(this, new TablesTableModel(opendatabase, this))
|
||||
{
|
||||
auto tv = m_tablesTableView.tableView();
|
||||
tv->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_detailsTabs = new QTabWidget(this);
|
||||
|
||||
// Populate splitter
|
||||
addWidget(tv);
|
||||
addWidget(m_detailsTabs);
|
||||
|
||||
// - Columns page
|
||||
m_columnsPage = new ColumnPage(this);
|
||||
m_detailsTabs->addTab(m_columnsPage, "");
|
||||
|
||||
// constrainst
|
||||
m_constraintPage = new CatalogConstraintPage(this);
|
||||
m_detailsTabs->addTab(m_constraintPage, "");
|
||||
|
||||
// - Index page
|
||||
m_indexPage = new CatalogIndexPage(this);
|
||||
m_detailsTabs->addTab(m_indexPage, "");
|
||||
|
||||
// - Properties page
|
||||
// m_propertiesPage = new PropertiesPage(this);
|
||||
// m_propertiesPage->setSourceModel(m_tablesTableView.dataModel());
|
||||
// m_detailsTabs->addTab(m_propertiesPage, "");
|
||||
|
||||
// - Trigger page
|
||||
m_triggerPage = new TriggerPage(this);
|
||||
m_detailsTabs->addTab(m_triggerPage, "");
|
||||
|
||||
m_dependentsPage = new DependantsPage(this);
|
||||
m_detailsTabs->addTab(m_dependentsPage, "");
|
||||
|
||||
// SQL tab
|
||||
m_tableSql = new SqlCodePreview(this);
|
||||
m_detailsTabs->addTab(m_tableSql, "");
|
||||
|
||||
// Force focus on columns tab by default
|
||||
m_detailsTabs->setCurrentIndex(0);
|
||||
|
||||
// Signals
|
||||
connect(tv->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogTablesPage::tableListTable_currentRowChanged);
|
||||
|
||||
connect(m_tablesTableView.dataModel(), &QAbstractItemModel::layoutChanged,
|
||||
this, &CatalogTablesPage::tableListTable_layoutChanged);
|
||||
|
||||
connect(tv, &QTableView::doubleClicked,
|
||||
this, &CatalogTablesPage::on_tableListTable_doubleClicked);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::retranslateUi(bool /*all*/)
|
||||
{
|
||||
auto set_tabtext = [this] (QWidget *widget, QString translation) {
|
||||
m_detailsTabs->setTabText(m_detailsTabs->indexOf(widget), translation);
|
||||
};
|
||||
|
||||
set_tabtext(m_columnsPage, QApplication::translate("TablesPage", "Columns", nullptr));
|
||||
set_tabtext(m_constraintPage, QApplication::translate("TablesPage", "Constraints", nullptr));
|
||||
set_tabtext(m_indexPage, QApplication::translate("TablesPage", "Indexes", nullptr));
|
||||
// set_tabtext(m_propertiesPage, QApplication::translate("TablesPage", "Properties", nullptr));
|
||||
set_tabtext(m_triggerPage, QApplication::translate("TablesPage", "Triggers", nullptr));
|
||||
set_tabtext(m_dependentsPage, QApplication::translate("TablesPage", "Dependants", nullptr));
|
||||
set_tabtext(m_tableSql, QApplication::translate("TablesPage", "SQL", nullptr));
|
||||
}
|
||||
|
||||
void CatalogTablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_tablesTableView.setCatalog(cat);
|
||||
|
||||
m_constraintPage->setCatalog(cat);
|
||||
m_indexPage->setCatalog(cat);
|
||||
m_triggerPage->setCatalog(cat);
|
||||
m_dependentsPage->setCatalog(cat);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::setNamespaceFilter(NamespaceFilter filter)
|
||||
{
|
||||
m_tablesTableView.dataModel()->setNamespaceFilter(filter);
|
||||
m_tablesTableView.tableView()->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() == previous.row())
|
||||
return;
|
||||
|
||||
auto table = m_tablesTableView.rowItemForProxyIndex(current);
|
||||
selectedTableChanged(table);
|
||||
}
|
||||
|
||||
|
||||
void CatalogTablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint )
|
||||
{
|
||||
auto table = m_tablesTableView.currentRowItem();
|
||||
selectedTableChanged(table);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
auto row = m_tablesTableView.sortFilter()->mapToSource(index).row();
|
||||
PgClass table = m_tablesTableView.dataModel()->getTable(row);
|
||||
if (table.oid() != InvalidOid) {
|
||||
tableSelected(table.oid());
|
||||
}
|
||||
}
|
||||
|
||||
void CatalogTablesPage::selectedTableChanged(const std::optional<PgClass> &table)
|
||||
{
|
||||
m_columnsPage->setData(m_catalog, table);
|
||||
|
||||
m_constraintPage->setFilter(table);
|
||||
m_indexPage->setFilter(table);
|
||||
m_triggerPage->setFilter(table);
|
||||
m_dependentsPage->setFilter(table);
|
||||
|
||||
updateSqlTab(table);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
||||
{
|
||||
if (!table.has_value()) {
|
||||
m_tableSql->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
QString drop_sql;
|
||||
QString create_sql;
|
||||
// table
|
||||
drop_sql += table->dropSql() % "\n";
|
||||
create_sql += table->createSql() % "\n";
|
||||
// - columns
|
||||
// - constraints
|
||||
// table details (inherits etc)
|
||||
|
||||
// Indexes
|
||||
auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
||||
if (!indexes.empty()) {
|
||||
drop_sql += "-- drop Indexes\n";
|
||||
create_sql += "-- create Indexes\n";
|
||||
for (auto && index : indexes) {
|
||||
drop_sql += index.dropSql() % "\n";
|
||||
create_sql += index.createSql() % "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Triggers
|
||||
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
||||
if (!triggers.empty()) {
|
||||
drop_sql += "-- drop Triggers\n";
|
||||
create_sql += "-- create Triggers\n";
|
||||
for (auto && trg : triggers) {
|
||||
drop_sql += trg.dropSql() % "\n";
|
||||
create_sql += trg.createSql() % "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Privileges
|
||||
create_sql += "-- set Privileges\n";
|
||||
create_sql += table->grantSql() % "\n";
|
||||
|
||||
// Comments
|
||||
create_sql += "-- set Comments table + columns\n";
|
||||
create_sql += table->commentSql() % "\n";
|
||||
|
||||
auto && cols = m_catalog->attributes()->getColumnsForRelation(table->oid());
|
||||
for (auto && col : cols) {
|
||||
if (!col.description.isEmpty()) {
|
||||
create_sql += "COMMENT ON COLUMN " + table->fullyQualifiedQuotedObjectName()
|
||||
+ "." + quoteIdent(col.name) + " IS " + dollarQuoteString(col.description) + ";\n";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||
}
|
||||
66
pglab/catalog/widgets/CatalogTablesPage.h
Normal file
66
pglab/catalog/widgets/CatalogTablesPage.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef CATALOGTABLESPAGE_H
|
||||
#define CATALOGTABLESPAGE_H
|
||||
|
||||
#include "NamespaceFilter.h"
|
||||
#include "catalog/models/TablesTableModel.h"
|
||||
#include "util/PgLabTableViewHelper.h"
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <QAbstractItemModel>
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
class CatalogConstraintPage;
|
||||
class CatalogIndexPage;
|
||||
class ColumnPage;
|
||||
class ColumnTableModel;
|
||||
class ConstraintModel;
|
||||
class DependantsPage;
|
||||
class PgClass;
|
||||
class PgDatabaseCatalog;
|
||||
class PgLabTableView;
|
||||
class PropertiesPage;
|
||||
class QTabWidget;
|
||||
class SqlCodePreview;
|
||||
class QSortFilterProxyModel;
|
||||
class TriggerPage;
|
||||
|
||||
|
||||
class CatalogTablesPage: public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogTablesPage(std::shared_ptr<OpenDatabase> opendatabase, QWidget * parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(NamespaceFilter filter);
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
|
||||
signals:
|
||||
void tableSelected(Oid tableoid);
|
||||
private:
|
||||
PgLabTableViewHelper<TablesTableModel> m_tablesTableView;
|
||||
|
||||
// Details
|
||||
QTabWidget *m_detailsTabs = nullptr;
|
||||
ColumnPage *m_columnsPage = nullptr;
|
||||
CatalogConstraintPage *m_constraintPage = nullptr;
|
||||
CatalogIndexPage *m_indexPage = nullptr;
|
||||
// PropertiesPage *m_propertiesPage = nullptr;
|
||||
TriggerPage *m_triggerPage = nullptr;
|
||||
DependantsPage *m_dependentsPage = nullptr;
|
||||
SqlCodePreview *m_tableSql = nullptr;
|
||||
|
||||
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void selectedTableChanged(const std::optional<PgClass> &table);
|
||||
void updateSqlTab(const std::optional<PgClass> &table);
|
||||
private slots:
|
||||
|
||||
void tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void tableListTable_layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
|
||||
void on_tableListTable_doubleClicked(const QModelIndex &index);
|
||||
|
||||
};
|
||||
|
||||
#endif // CATALOGTABLESPAGE_H
|
||||
80
pglab/catalog/widgets/CatalogTypesPage.cpp
Normal file
80
pglab/catalog/widgets/CatalogTypesPage.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include "CatalogTypesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabItemDelegate.h"
|
||||
#include "catalog/PgType.h"
|
||||
#include "model/TypeSelectionItemModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include <optional>
|
||||
#include <QHeaderView>
|
||||
|
||||
CatalogTypesPage::CatalogTypesPage(QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
m_typeTable = new PgLabTableView(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
|
||||
// build widget tree
|
||||
// add top level widgets to splitter
|
||||
addWidget(m_typeTable);
|
||||
addWidget(m_definitionView);
|
||||
|
||||
m_model = new TypeModel(this);
|
||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
m_typeTable->setModel(m_sortFilterProxy);
|
||||
m_typeTable->horizontalHeader()->setSortIndicator(TypeModel::NameCol, Qt::AscendingOrder);
|
||||
m_typeTable->setSortingEnabled(true);
|
||||
m_typeTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_typeTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(m_typeTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogTypesPage::typeTable_currentRowChanged);
|
||||
connect(m_model, &TypeModel::modelReset,
|
||||
[this] () { selectedTypeChanged({}); });
|
||||
|
||||
retranslateUi();
|
||||
|
||||
}
|
||||
|
||||
void CatalogTypesPage::retranslateUi()
|
||||
{
|
||||
}
|
||||
|
||||
void CatalogTypesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setTypeList(cat->types());
|
||||
m_typeTable->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void CatalogTypesPage::typeTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
if (current.isValid()) {
|
||||
auto source_index = m_sortFilterProxy->mapToSource(current);
|
||||
auto proc = m_model->typ(source_index.row());
|
||||
selectedTypeChanged(proc);
|
||||
}
|
||||
else
|
||||
selectedTypeChanged({});
|
||||
}
|
||||
}
|
||||
|
||||
void CatalogTypesPage::selectedTypeChanged(const std::optional<PgType> &typ)
|
||||
{
|
||||
updateSqlTab(typ);
|
||||
}
|
||||
|
||||
void CatalogTypesPage::updateSqlTab(const std::optional<PgType> &typ)
|
||||
{
|
||||
if (!typ.has_value()) {
|
||||
m_definitionView->clear();
|
||||
return;
|
||||
}
|
||||
QString create_sql = typ->createSql();
|
||||
|
||||
m_definitionView->setPlainText(create_sql);
|
||||
}
|
||||
34
pglab/catalog/widgets/CatalogTypesPage.h
Normal file
34
pglab/catalog/widgets/CatalogTypesPage.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <QSplitter>
|
||||
|
||||
class PgLabTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class TypeModel;
|
||||
class CustomFilterSortModel;
|
||||
class SqlCodePreview;
|
||||
class PgType;
|
||||
|
||||
|
||||
class CatalogTypesPage : public QSplitter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CatalogTypesPage(QWidget *parent = nullptr);
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
public slots:
|
||||
|
||||
void typeTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
private:
|
||||
PgLabTableView *m_typeTable = nullptr;
|
||||
//QTabWidget *m_detailTabs = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
TypeModel *m_model = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi();
|
||||
void selectedTypeChanged(const std::optional<PgType> &seq);
|
||||
void updateSqlTab(const std::optional<PgType> &seq);
|
||||
};
|
||||
|
||||
109
pglab/catalog/widgets/ColumnPage.cpp
Normal file
109
pglab/catalog/widgets/ColumnPage.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#include "catalog/widgets/ColumnPage.h"
|
||||
|
||||
#include "catalog/models/ColumnTableModel.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "SqlFormattingUtils.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "catalog/PgClass.h"
|
||||
#include <QHeaderView>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QStringBuilder>
|
||||
#include <unordered_set>
|
||||
|
||||
ColumnPage::ColumnPage(QWidget *parent)
|
||||
: QSplitter(Qt::Vertical, parent)
|
||||
{
|
||||
m_tableView = new PgLabTableView(this);
|
||||
m_definitionView = new SqlCodePreview(this);
|
||||
addWidget(m_tableView);
|
||||
addWidget(m_definitionView);
|
||||
|
||||
m_columnModel = new ColumnTableModel(this);
|
||||
m_sortFilterProxy = new QSortFilterProxyModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_columnModel);
|
||||
m_tableView->setItemDelegateForColumn(ColumnTableModel::TypeCol, new QStyledItemDelegate(this));
|
||||
m_tableView->setModel(m_sortFilterProxy);
|
||||
m_tableView->horizontalHeader()->setSortIndicator(ColumnTableModel::AttnumCol, Qt::AscendingOrder);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
m_sortFilterProxy->sort(ColumnTableModel::AttnumCol, Qt::AscendingOrder);
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &ColumnPage::tableView_selectionChanged);
|
||||
connect(m_columnModel, &ColumnTableModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
}
|
||||
|
||||
void ColumnPage::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_definitionView->setCatalog(cat);
|
||||
m_columnModel->setData(cat, cls);
|
||||
m_Class = cls;
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||
{
|
||||
auto&& indexes = m_tableView->selectionModel()->selectedIndexes();
|
||||
std::unordered_set<int> rijen;
|
||||
for (const auto &e : indexes)
|
||||
rijen.insert(m_sortFilterProxy->mapToSource(e).row());
|
||||
|
||||
const QString alterTable = "ALTER TABLE " % m_Class->fullyQualifiedQuotedObjectName();
|
||||
|
||||
QString completeSql;
|
||||
if (!rijen.empty()) {
|
||||
QString drops;
|
||||
QString addsql;
|
||||
auto iter = rijen.begin();
|
||||
if (iter != rijen.end())
|
||||
{
|
||||
auto && col = m_columnModel->column(*iter);
|
||||
drops = alterTable % "\n DROP COLUMN " % quoteIdent(col.name);
|
||||
addsql = alterTable % "\n ADD COLUMN " % col.columnDefinition(*m_catalog);
|
||||
for (++iter; iter != rijen.end(); ++iter)
|
||||
{
|
||||
auto && col = m_columnModel->column(*iter);
|
||||
drops += ",\n DROP COLUMN " % quoteIdent(col.name);
|
||||
addsql += ",\n ADD COLUMN " % col.columnDefinition(*m_catalog);
|
||||
}
|
||||
drops += ";";
|
||||
addsql += ";";
|
||||
m_definitionView->setPlainText(drops % "\n\n" % addsql);
|
||||
completeSql += drops % "\n\n" % addsql % "\n\n";
|
||||
}
|
||||
for (auto r : rijen)
|
||||
{
|
||||
auto && col = m_columnModel->column(r);
|
||||
auto cs = col.commentStatement(*m_catalog, m_Class.value());
|
||||
if (!cs.isEmpty())
|
||||
completeSql += cs % "\n";
|
||||
}
|
||||
|
||||
completeSql += "\n-- SQL to correct just the defaults\n";
|
||||
for (auto r : rijen)
|
||||
{
|
||||
auto && col = m_columnModel->column(r);
|
||||
completeSql += alterTable % " ALTER COLUMN " % quoteIdent(col.name);
|
||||
if (col.hasdef)
|
||||
completeSql += " SET DEFAULT " % col.defaultValue % ";\n";
|
||||
else
|
||||
completeSql += " DROP DEFAULT;\n";
|
||||
}
|
||||
completeSql += "\n-- SQL to correct NULLABLE\n";
|
||||
for (auto r : rijen)
|
||||
{
|
||||
auto && col = m_columnModel->column(r);
|
||||
completeSql += alterTable % " ALTER COLUMN " % quoteIdent(col.name);
|
||||
if (col.notnull)
|
||||
completeSql += " SET NOT NULL;\n";
|
||||
else
|
||||
completeSql += " DROP NOT NULL;\n";
|
||||
}
|
||||
}
|
||||
m_definitionView->setPlainText(completeSql);
|
||||
}
|
||||
42
pglab/catalog/widgets/ColumnPage.h
Normal file
42
pglab/catalog/widgets/ColumnPage.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef COLUMNPAGE_H
|
||||
#define COLUMNPAGE_H
|
||||
|
||||
#include "catalog/PgClass.h"
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
|
||||
class PgLabTableView;
|
||||
class SqlCodePreview;
|
||||
class PgDatabaseCatalog;
|
||||
class ColumnTableModel;
|
||||
class QSortFilterProxyModel;
|
||||
class QItemSelection;
|
||||
class QAbstractItemModel;
|
||||
|
||||
class ColumnPage : public QSplitter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ColumnPage(QWidget *parent = nullptr);
|
||||
|
||||
void setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &cls);
|
||||
//void setFilter(const std::optional<PgClass> &cls);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
PgLabTableView *m_tableView = nullptr;
|
||||
SqlCodePreview *m_definitionView = nullptr;
|
||||
ColumnTableModel *m_columnModel = nullptr;
|
||||
QSortFilterProxyModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::optional<PgClass> m_Class;
|
||||
|
||||
private slots:
|
||||
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
};
|
||||
|
||||
#endif // COLUMNPAGE_H
|
||||
55
pglab/catalog/widgets/DependantsPage.cpp
Normal file
55
pglab/catalog/widgets/DependantsPage.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "catalog/widgets/DependantsPage.h"
|
||||
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "catalog/PgClass.h"
|
||||
#include "catalog/models/DependantsTableModel.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include <QStringBuilder>
|
||||
#include <unordered_set>
|
||||
|
||||
DependantsPage::DependantsPage(QWidget *parent)
|
||||
: CatalogPageBase(parent)
|
||||
{
|
||||
m_model = new DependantsTableModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
|
||||
// connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
// this, &DependentsPage::tableView_selectionChanged);
|
||||
// connect(m_model, &DependentsTableModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
}
|
||||
|
||||
|
||||
void DependantsPage::catalogSet()
|
||||
{
|
||||
m_model->setCatalog(m_catalog);
|
||||
}
|
||||
|
||||
|
||||
void DependantsPage::setFilter(const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_model->loadForTable(cls ? cls->oid() : InvalidOid);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
|
||||
//void DependentsPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||
//{
|
||||
// auto rijen = selectedRows();
|
||||
|
||||
// QString drops;
|
||||
// QString creates;
|
||||
// for (auto rij : rijen) {
|
||||
// auto&& t = m_model->trigger(rij);
|
||||
// drops += t.dropSql() % "\n";
|
||||
// creates += t.createSql() % "\n";
|
||||
|
||||
// const PgProc *proc = m_catalog->procs()->getByKey(t.foid);
|
||||
// if (proc) {
|
||||
// creates += "\n" % proc->createSql() % "\n";
|
||||
// }
|
||||
// }
|
||||
// m_definitionView->setPlainText(drops % "\n" % creates);
|
||||
//}
|
||||
30
pglab/catalog/widgets/DependantsPage.h
Normal file
30
pglab/catalog/widgets/DependantsPage.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef DEPENDENTSPAGE_H
|
||||
#define DEPENDENTSPAGE_H
|
||||
|
||||
#include "catalog/widgets/CatalogPageBase.h"
|
||||
|
||||
class PgClass;
|
||||
class DependantsTableModel;
|
||||
class QItemSelection;
|
||||
|
||||
class DependantsPage : public CatalogPageBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DependantsPage(QWidget *parent = nullptr);
|
||||
|
||||
void setFilter(const std::optional<PgClass> &cls);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
void catalogSet() override;
|
||||
private:
|
||||
DependantsTableModel *m_model = nullptr;
|
||||
|
||||
private slots:
|
||||
// void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
};
|
||||
|
||||
|
||||
#endif // DEPENDENTSPAGE_H
|
||||
57
pglab/catalog/widgets/TriggerPage.cpp
Normal file
57
pglab/catalog/widgets/TriggerPage.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "TriggerPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "catalog/PgClass.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "catalog/models/TriggerTableModel.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "util/PgLabTableView.h"
|
||||
#include "catalog/PgProcContainer.h"
|
||||
#include <QHeaderView>
|
||||
#include <QStringBuilder>
|
||||
#include <unordered_set>
|
||||
|
||||
TriggerPage::TriggerPage(QWidget *parent)
|
||||
: CatalogPageBase(parent)
|
||||
{
|
||||
m_model = new TriggerTableModel(this);
|
||||
m_sortFilterProxy->setSourceModel(m_model);
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &TriggerPage::tableView_selectionChanged);
|
||||
connect(m_model, &TriggerTableModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||
}
|
||||
|
||||
|
||||
void TriggerPage::catalogSet()
|
||||
{
|
||||
m_model->setCatalog(m_catalog);
|
||||
}
|
||||
|
||||
|
||||
void TriggerPage::setFilter(const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
|
||||
void TriggerPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||
{
|
||||
auto rijen = selectedRows();
|
||||
|
||||
QString drops;
|
||||
QString creates;
|
||||
for (auto rij : rijen) {
|
||||
auto&& t = m_model->trigger(rij);
|
||||
drops += t.dropSql() % "\n";
|
||||
creates += t.createSql() % "\n";
|
||||
|
||||
const PgProc *proc = m_catalog->procs()->getByKey(t.foid);
|
||||
if (proc) {
|
||||
creates += "\n" % proc->createSql() % "\n";
|
||||
}
|
||||
}
|
||||
m_definitionView->setPlainText(drops % "\n" % creates);
|
||||
}
|
||||
30
pglab/catalog/widgets/TriggerPage.h
Normal file
30
pglab/catalog/widgets/TriggerPage.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef TRIGGERPAGE_H
|
||||
#define TRIGGERPAGE_H
|
||||
|
||||
#include "catalog/widgets/CatalogPageBase.h"
|
||||
|
||||
class PgClass;
|
||||
class TriggerTableModel;
|
||||
class QItemSelection;
|
||||
|
||||
class TriggerPage : public CatalogPageBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TriggerPage(QWidget *parent = nullptr);
|
||||
// TriggerPage(QWidget *parent = nullptr);
|
||||
|
||||
void setFilter(const std::optional<PgClass> &cls);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
void catalogSet() override;
|
||||
private:
|
||||
TriggerTableModel *m_model = nullptr;
|
||||
|
||||
private slots:
|
||||
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
};
|
||||
|
||||
#endif // TRIGGERPAGE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue