Added page with the types (no details yet)
This commit is contained in:
parent
bdef76ed8a
commit
4c175d8c2c
16 changed files with 418 additions and 11 deletions
78
pglab/widgets/CatalogTypesPage.cpp
Normal file
78
pglab/widgets/CatalogTypesPage.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#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>
|
||||
|
||||
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->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/widgets/CatalogTypesPage.h
Normal file
34
pglab/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);
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue