2019-02-09 09:49:27 +01:00
|
|
|
|
#include "CatalogFunctionsPage.h"
|
2018-11-25 09:06:01 +01:00
|
|
|
|
#include "ResultTableModelUtil.h"
|
|
|
|
|
|
#include "CustomFilterSortModel.h"
|
|
|
|
|
|
#include "CustomDataRole.h"
|
|
|
|
|
|
#include "PgLabItemDelegate.h"
|
|
|
|
|
|
#include "ProcTableModel.h"
|
2018-12-16 20:40:04 +01:00
|
|
|
|
#include "SqlCodePreview.h"
|
|
|
|
|
|
#include <QApplication>
|
2018-12-29 17:54:54 +01:00
|
|
|
|
#include "PgLabTableView.h"
|
2018-11-25 09:06:01 +01:00
|
|
|
|
#include <QVBoxLayout>
|
2018-12-16 20:40:04 +01:00
|
|
|
|
#include <QTabWidget>
|
2018-11-25 09:06:01 +01:00
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
CatalogFunctionsPage::CatalogFunctionsPage(QWidget *parent)
|
2018-12-16 20:40:04 +01:00
|
|
|
|
: QSplitter(Qt::Horizontal, parent)
|
2018-11-25 09:06:01 +01:00
|
|
|
|
{
|
2018-12-16 20:40:04 +01:00
|
|
|
|
// create widgets
|
2018-12-29 17:54:54 +01:00
|
|
|
|
m_functionTable = new PgLabTableView(this);
|
2018-12-16 20:40:04 +01:00
|
|
|
|
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
|
2018-11-25 09:06:01 +01:00
|
|
|
|
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);
|
|
|
|
|
|
|
2018-12-16 20:40:04 +01:00
|
|
|
|
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
2019-02-09 09:49:27 +01:00
|
|
|
|
&CatalogFunctionsPage::functionTable_currentRowChanged);
|
2018-12-16 20:40:04 +01:00
|
|
|
|
|
|
|
|
|
|
retranslateUi();
|
2018-11-25 09:06:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void CatalogFunctionsPage::retranslateUi()
|
2018-11-25 09:06:01 +01:00
|
|
|
|
{
|
2018-12-16 20:40:04 +01:00
|
|
|
|
auto set_tabtext = [this] (QWidget *widget, QString translation) {
|
|
|
|
|
|
m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation);
|
|
|
|
|
|
};
|
2018-11-25 09:06:01 +01:00
|
|
|
|
|
2018-12-16 20:40:04 +01:00
|
|
|
|
set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr));
|
2018-11-25 09:06:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void CatalogFunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
2018-11-25 09:06:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
m_catalog = cat;
|
|
|
|
|
|
m_model->setCatalog(cat);
|
2019-02-09 14:59:33 +01:00
|
|
|
|
m_functionTable->resizeColumnsToContents();
|
2018-11-25 09:06:01 +01:00
|
|
|
|
}
|
2018-12-16 20:40:04 +01:00
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
2018-12-16 20:40:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
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({});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void CatalogFunctionsPage::selectedProcChanged(const std::optional<PgProc> &proc)
|
2018-12-16 20:40:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
updateSqlTab(proc);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void CatalogFunctionsPage::updateSqlTab(const std::optional<PgProc> &proc)
|
2018-12-16 20:40:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (!proc.has_value()) {
|
|
|
|
|
|
m_definitionView->clear();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString create_sql = proc->createSql();
|
|
|
|
|
|
|
|
|
|
|
|
m_definitionView->setPlainText(create_sql);
|
|
|
|
|
|
}
|