Reorganization of pgLab project

This commit is contained in:
eelke 2022-04-09 07:10:29 +02:00
parent 7300865c77
commit c71fdc4af7
78 changed files with 204 additions and 148 deletions

View file

@ -1,46 +0,0 @@
#include "CatalogConstraintPage.h"
#include "ConstraintModel.h"
#include "CustomFilterSortModel.h"
#include "IconColumnDelegate.h"
#include "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);
}

View file

@ -1,29 +0,0 @@
#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

View file

@ -1,100 +0,0 @@
#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 <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 &current, 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);
}

View file

@ -1,43 +0,0 @@
#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 &current, 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

View file

@ -1,46 +0,0 @@
#include "CatalogIndexPage.h"
#include "CustomFilterSortModel.h"
#include "IndexModel.h"
#include "PgLabTableView.h"
#include "SqlCodePreview.h"
#include <QHeaderView>
#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));
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);
}

View file

@ -1,29 +0,0 @@
#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

View file

@ -1,32 +0,0 @@
#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()
{
}

View file

@ -1,36 +0,0 @@
#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

View file

@ -1,35 +0,0 @@
#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;
}

View file

@ -1,32 +0,0 @@
#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

View file

@ -1,83 +0,0 @@
#include "CatalogSequencesPage.h"
#include "ResultTableModelUtil.h"
#include "CustomFilterSortModel.h"
#include "CustomDataRole.h"
#include "PgLabItemDelegate.h"
#include "SequenceModel.h"
#include "SqlCodePreview.h"
#include "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 &current, 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);
}

View file

@ -1,40 +0,0 @@
#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 &current, 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

View file

@ -1,205 +0,0 @@
#include "CatalogTablesPage.h"
#include "ColumnPage.h"
#include "ColumnTableModel.h"
#include "ConstraintModel.h"
#include "DependantsPage.h"
#include "PgLabTableView.h"
#include "PropertiesPage.h"
#include "ResultTableModelUtil.h"
#include "SqlCodePreview.h"
#include "TablesTableModel.h"
#include "TriggerPage.h"
#include "SqlFormattingUtils.h"
#include "catalog/PgAttributeContainer.h"
#include "catalog/PgIndexContainer.h"
#include "catalog/PgTriggerContainer.h"
#include "widgets/CatalogConstraintPage.h"
#include "widgets/CatalogIndexPage.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 &current, 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);
}

View file

@ -1,66 +0,0 @@
#ifndef CATALOGTABLESPAGE_H
#define CATALOGTABLESPAGE_H
#include "NamespaceFilter.h"
#include "TablesTableModel.h"
#include "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 &current, const QModelIndex &previous);
void tableListTable_layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
void on_tableListTable_doubleClicked(const QModelIndex &index);
};
#endif // CATALOGTABLESPAGE_H

View file

@ -1,80 +0,0 @@
#include "CatalogTypesPage.h"
#include "ResultTableModelUtil.h"
#include "CustomFilterSortModel.h"
#include "CustomDataRole.h"
#include "PgLabItemDelegate.h"
#include "catalog/PgType.h"
#include "model/TypeSelectionItemModel.h"
#include "SqlCodePreview.h"
#include "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 &current, 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);
}

View file

@ -1,34 +0,0 @@
#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 &current, 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);
};

View file

@ -0,0 +1,14 @@
#include "SingleRecordWidget.h"
#include "ui_SingleRecordWidget.h"
SingleRecordWidget::SingleRecordWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SingleRecordWidget)
{
ui->setupUi(this);
}
SingleRecordWidget::~SingleRecordWidget()
{
delete ui;
}

View file

@ -0,0 +1,20 @@
#pragma once
#include <QWidget>
namespace Ui {
class SingleRecordWidget;
}
class SingleRecordWidget : public QWidget
{
Q_OBJECT
public:
explicit SingleRecordWidget(QWidget *parent = nullptr);
~SingleRecordWidget();
private:
Ui::SingleRecordWidget *ui;
};

View file

@ -0,0 +1,21 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>SingleRecordWidget</class>
<widget name="SingleRecordWidget" class="QWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>