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:
eelke 2019-02-09 09:49:27 +01:00
parent a704332342
commit 42432b06a9
31 changed files with 598 additions and 472 deletions

View file

@ -1,90 +0,0 @@
#include "FunctionsPage.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>
FunctionsPage::FunctionsPage(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,
&FunctionsPage::functionTable_currentRowChanged);
retranslateUi();
}
void FunctionsPage::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 FunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
{
m_catalog = cat;
m_model->setCatalog(cat);
}
void FunctionsPage::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 FunctionsPage::selectedProcChanged(const std::optional<PgProc> &proc)
{
updateSqlTab(proc);
}
void FunctionsPage::updateSqlTab(const std::optional<PgProc> &proc)
{
if (!proc.has_value()) {
m_definitionView->clear();
return;
}
QString create_sql = proc->createSql();
m_definitionView->setPlainText(create_sql);
}