Functions page now shows sql for selected function.
The actual SQL needs some further checking.
This commit is contained in:
parent
31a77a1742
commit
c0a11f9b3b
3 changed files with 76 additions and 10 deletions
|
|
@ -4,13 +4,33 @@
|
|||
#include "CustomDataRole.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "ProcTableModel.h"
|
||||
#include "SqlCodePreview.h"
|
||||
#include <QApplication>
|
||||
#include <QTableView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabWidget>
|
||||
|
||||
FunctionsPage::FunctionsPage(QWidget *parent) : QWidget(parent)
|
||||
FunctionsPage::FunctionsPage(QWidget *parent)
|
||||
: QSplitter(Qt::Horizontal, parent)
|
||||
{
|
||||
|
||||
// create widgets
|
||||
m_functionTable = new QTableView(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
|
||||
SetTableViewDefault(m_functionTable);
|
||||
|
||||
m_model = new ProcTableModel(this);
|
||||
|
|
@ -23,14 +43,21 @@ FunctionsPage::FunctionsPage(QWidget *parent) : QWidget(parent)
|
|||
auto item_delegate = new PgLabItemDelegate(this);
|
||||
m_functionTable->setItemDelegate(item_delegate);
|
||||
|
||||
auto mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(m_functionTable);
|
||||
setLayout(mainLayout);
|
||||
|
||||
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&FunctionsPage::functionTable_currentRowChanged);
|
||||
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void FunctionsPage::retranslateUi(bool all)
|
||||
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)
|
||||
|
|
@ -38,3 +65,34 @@ void FunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
|||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
}
|
||||
|
||||
void FunctionsPage::functionTable_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->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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
#ifndef FUNCTIONSPAGE_H
|
||||
#define FUNCTIONSPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSplitter>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
class QTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class ProcTableModel;
|
||||
class CustomFilterSortModel;
|
||||
class QTabWidget;
|
||||
class SqlCodePreview;
|
||||
class PgProc;
|
||||
|
||||
class FunctionsPage : public QWidget {
|
||||
class FunctionsPage : public QSplitter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FunctionsPage(QWidget *parent = nullptr);
|
||||
|
|
@ -19,14 +23,19 @@ signals:
|
|||
|
||||
public slots:
|
||||
|
||||
void functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
private:
|
||||
QTableView *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(bool all = true);
|
||||
void retranslateUi();
|
||||
|
||||
void selectedProcChanged(const std::optional<PgProc> &proc);
|
||||
void updateSqlTab(const std::optional<PgProc> &proc);
|
||||
};
|
||||
|
||||
#endif // FUNCTIONSPAGE_H
|
||||
|
|
|
|||
|
|
@ -170,7 +170,6 @@ void TablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex>
|
|||
void TablesPage::selectedTableChanged(const std::optional<PgClass> &table)
|
||||
{
|
||||
m_columnsPage->setData(m_catalog, table);
|
||||
//ui->columnsTable->resizeColumnsToContents();
|
||||
|
||||
m_constraintModel->setData(m_catalog, table);
|
||||
ui->constraintsTable->resizeColumnsToContents();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue