Restructuring catalog tabs
- Moved detail tabs of table to their own components - Table list has become seperate component on seperate tab - Table list does not use designer anymore - Moved sequences and functions tabs into the catalog inspector
This commit is contained in:
parent
a704332342
commit
42432b06a9
31 changed files with 598 additions and 472 deletions
42
pglab/widgets/CatalogConstraintPage.cpp
Normal file
42
pglab/widgets/CatalogConstraintPage.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "CatalogConstraintPage.h"
|
||||
#include "ConstraintModel.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "IconColumnDelegate.h"
|
||||
#include "PgLabTableView.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#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));
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &CatalogConstraintPage::tableView_selectionChanged);
|
||||
}
|
||||
|
||||
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/widgets/CatalogConstraintPage.h
Normal file
29
pglab/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
|
||||
90
pglab/widgets/CatalogFunctionsPage.cpp
Normal file
90
pglab/widgets/CatalogFunctionsPage.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include "CatalogFunctionsPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "ProcTableModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QApplication>
|
||||
#include "PgLabTableView.h"
|
||||
#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->setSortingEnabled(true);
|
||||
m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogFunctionsPage::functionTable_currentRowChanged);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
41
pglab/widgets/CatalogFunctionsPage.h
Normal file
41
pglab/widgets/CatalogFunctionsPage.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef FUNCTIONSPAGE_H
|
||||
#define FUNCTIONSPAGE_H
|
||||
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
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);
|
||||
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
|
||||
43
pglab/widgets/CatalogIndexPage.cpp
Normal file
43
pglab/widgets/CatalogIndexPage.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "CatalogIndexPage.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "IndexModel.h"
|
||||
#include "PgLabTableView.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QStringBuilder>
|
||||
#include "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));
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &CatalogIndexPage::tableView_selectionChanged);
|
||||
}
|
||||
|
||||
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/widgets/CatalogIndexPage.h
Normal file
29
pglab/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
|
||||
35
pglab/widgets/CatalogPageBase.cpp
Normal file
35
pglab/widgets/CatalogPageBase.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "CatalogPageBase.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "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/widgets/CatalogPageBase.h
Normal file
32
pglab/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
|
||||
77
pglab/widgets/CatalogSequencesPage.cpp
Normal file
77
pglab/widgets/CatalogSequencesPage.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include "CatalogSequencesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "SequenceModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "PgLabTableView.h"
|
||||
|
||||
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->setSortingEnabled(true);
|
||||
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
connect(m_sequenceTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogSequencesPage::sequenceTable_currentRowChanged);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CatalogSequencesPage::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 CatalogSequencesPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
38
pglab/widgets/CatalogSequencesPage.h
Normal file
38
pglab/widgets/CatalogSequencesPage.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef SEQUENCESPAGES_H
|
||||
#define SEQUENCESPAGES_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);
|
||||
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
|
||||
189
pglab/widgets/CatalogTablesPage.cpp
Normal file
189
pglab/widgets/CatalogTablesPage.cpp
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
#include "CatalogTablesPage.h"
|
||||
|
||||
#include "ColumnPage.h"
|
||||
#include "ColumnTableModel.h"
|
||||
#include "ConstraintModel.h"
|
||||
#include "PgLabTableView.h"
|
||||
#include "PropertiesPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include "TriggerPage.h"
|
||||
#include "catalog/PgIndexContainer.h"
|
||||
#include "catalog/PgTriggerContainer.h"
|
||||
#include "widgets/CatalogConstraintPage.h"
|
||||
#include "widgets/CatalogIndexPage.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStringBuilder>
|
||||
#include <QTableWidget>
|
||||
|
||||
CatalogTablesPage::CatalogTablesPage(QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
m_tableView = new PgLabTableView(this);
|
||||
m_detailsTabs = new QTabWidget(this);
|
||||
|
||||
// Populate splitter
|
||||
addWidget(m_tableView);
|
||||
addWidget(m_detailsTabs);
|
||||
|
||||
// Setup model(s)
|
||||
m_tablesModel = new TablesTableModel(this);
|
||||
m_tableView->setModel(m_tablesModel);
|
||||
|
||||
// - 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_tablesModel);
|
||||
m_detailsTabs->addTab(m_propertiesPage, "");
|
||||
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||
m_propertiesPage, &PropertiesPage::setActiveRow);
|
||||
|
||||
// - Trigger page
|
||||
m_triggerPage = new TriggerPage(this);
|
||||
m_detailsTabs->addTab(m_triggerPage, "");
|
||||
|
||||
// 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(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&CatalogTablesPage::tableListTable_currentRowChanged);
|
||||
|
||||
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
|
||||
this, &CatalogTablesPage::tableListTable_layoutChanged);
|
||||
}
|
||||
|
||||
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_tableSql, QApplication::translate("TablesPage", "SQL", nullptr));
|
||||
}
|
||||
|
||||
void CatalogTablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_tablesModel->setCatalog(cat);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
|
||||
m_constraintPage->setCatalog(cat);
|
||||
m_indexPage->setCatalog(cat);
|
||||
m_triggerPage->setCatalog(cat);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::setNamespaceFilter(TablesTableModel::NamespaceFilter filter)
|
||||
{
|
||||
m_tablesModel->setNamespaceFilter(filter);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
if (current.isValid()) {
|
||||
PgClass table = m_tablesModel->getTable(current.row());
|
||||
selectedTableChanged(table);
|
||||
}
|
||||
else
|
||||
selectedTableChanged({});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CatalogTablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex> &, QAbstractItemModel::LayoutChangeHint )
|
||||
{
|
||||
auto&& index = m_tableView->selectionModel()->currentIndex();
|
||||
if (index.isValid()) {
|
||||
PgClass table = m_tablesModel->getTable(index.row());
|
||||
selectedTableChanged(table);
|
||||
}
|
||||
else
|
||||
selectedTableChanged({});
|
||||
}
|
||||
|
||||
void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
PgClass table = m_tablesModel->getTable(index.row());
|
||||
if (table.oid() != InvalidOid) {
|
||||
// context()->moduleAction("pglab.crudpage", "open", {
|
||||
// { "oid", 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);
|
||||
|
||||
updateSqlTab(table);
|
||||
}
|
||||
|
||||
void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
||||
{
|
||||
if (!table.has_value()) {
|
||||
m_tableSql->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
QString drop_sql;
|
||||
QString create_sql;
|
||||
// create table
|
||||
create_sql += table->createSql();
|
||||
// - columns
|
||||
// - constraints
|
||||
// table details (inherits etc)
|
||||
|
||||
// Indexes
|
||||
drop_sql += "-- drop Indexes\n";
|
||||
create_sql += "-- create Indexes\n";
|
||||
auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
||||
for (auto && index : indexes) {
|
||||
drop_sql += index.dropSql() % "\n";
|
||||
create_sql += index.createSql() % "\n";
|
||||
}
|
||||
|
||||
// Triggers
|
||||
drop_sql += "-- drop Triggers\n";
|
||||
create_sql += "-- create Triggers\n";
|
||||
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
||||
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";
|
||||
//
|
||||
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||
}
|
||||
57
pglab/widgets/CatalogTablesPage.h
Normal file
57
pglab/widgets/CatalogTablesPage.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef CATALOGTABLESPAGE_H
|
||||
#define CATALOGTABLESPAGE_H
|
||||
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include "TablesTableModel.h"
|
||||
|
||||
class CatalogConstraintPage;
|
||||
class CatalogIndexPage;
|
||||
class ColumnPage;
|
||||
class ColumnTableModel;
|
||||
class ConstraintModel;
|
||||
class PgClass;
|
||||
class PgDatabaseCatalog;
|
||||
class PgLabTableView;
|
||||
class PropertiesPage;
|
||||
class QTabWidget;
|
||||
class SqlCodePreview;
|
||||
class TablesTableModel;
|
||||
class TriggerPage;
|
||||
|
||||
|
||||
class CatalogTablesPage: public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CatalogTablesPage(QWidget * parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
|
||||
void setNamespaceFilter(TablesTableModel::NamespaceFilter filter);
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
private:
|
||||
PgLabTableView *m_tableView = nullptr;
|
||||
TablesTableModel* m_tablesModel = nullptr;
|
||||
|
||||
// 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;
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue