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

@ -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 &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);
}