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 "CustomDataRole.h"
|
||||||
#include "PgLabItemDelegate.h"
|
#include "PgLabItemDelegate.h"
|
||||||
#include "ProcTableModel.h"
|
#include "ProcTableModel.h"
|
||||||
|
#include "SqlCodePreview.h"
|
||||||
|
#include <QApplication>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QVBoxLayout>
|
#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_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);
|
SetTableViewDefault(m_functionTable);
|
||||||
|
|
||||||
m_model = new ProcTableModel(this);
|
m_model = new ProcTableModel(this);
|
||||||
|
|
@ -23,14 +43,21 @@ FunctionsPage::FunctionsPage(QWidget *parent) : QWidget(parent)
|
||||||
auto item_delegate = new PgLabItemDelegate(this);
|
auto item_delegate = new PgLabItemDelegate(this);
|
||||||
m_functionTable->setItemDelegate(item_delegate);
|
m_functionTable->setItemDelegate(item_delegate);
|
||||||
|
|
||||||
auto mainLayout = new QVBoxLayout;
|
|
||||||
mainLayout->addWidget(m_functionTable);
|
connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||||
setLayout(mainLayout);
|
&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)
|
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_catalog = cat;
|
||||||
m_model->setCatalog(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
|
#ifndef FUNCTIONSPAGE_H
|
||||||
#define FUNCTIONSPAGE_H
|
#define FUNCTIONSPAGE_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QSplitter>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class QTableView;
|
class QTableView;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
class ProcTableModel;
|
class ProcTableModel;
|
||||||
class CustomFilterSortModel;
|
class CustomFilterSortModel;
|
||||||
|
class QTabWidget;
|
||||||
|
class SqlCodePreview;
|
||||||
|
class PgProc;
|
||||||
|
|
||||||
class FunctionsPage : public QWidget {
|
class FunctionsPage : public QSplitter {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FunctionsPage(QWidget *parent = nullptr);
|
explicit FunctionsPage(QWidget *parent = nullptr);
|
||||||
|
|
@ -19,14 +23,19 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
void functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
private:
|
private:
|
||||||
QTableView *m_functionTable = nullptr;
|
QTableView *m_functionTable = nullptr;
|
||||||
|
QTabWidget *m_detailTabs = nullptr;
|
||||||
|
SqlCodePreview *m_definitionView = nullptr;
|
||||||
ProcTableModel *m_model = nullptr;
|
ProcTableModel *m_model = nullptr;
|
||||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
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
|
#endif // FUNCTIONSPAGE_H
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,6 @@ void TablesPage::tableListTable_layoutChanged(const QList<QPersistentModelIndex>
|
||||||
void TablesPage::selectedTableChanged(const std::optional<PgClass> &table)
|
void TablesPage::selectedTableChanged(const std::optional<PgClass> &table)
|
||||||
{
|
{
|
||||||
m_columnsPage->setData(m_catalog, table);
|
m_columnsPage->setData(m_catalog, table);
|
||||||
//ui->columnsTable->resizeColumnsToContents();
|
|
||||||
|
|
||||||
m_constraintModel->setData(m_catalog, table);
|
m_constraintModel->setData(m_catalog, table);
|
||||||
ui->constraintsTable->resizeColumnsToContents();
|
ui->constraintsTable->resizeColumnsToContents();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue