WIP: Added page showing list of functions.
Only list is shown, still working on details.
This commit is contained in:
parent
7db859737a
commit
840af1e0a9
19 changed files with 635 additions and 92 deletions
40
pglab/FunctionsPage.cpp
Normal file
40
pglab/FunctionsPage.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "FunctionsPage.h"
|
||||
#include "ResultTableModelUtil.h"
|
||||
#include "CustomFilterSortModel.h"
|
||||
#include "CustomDataRole.h"
|
||||
#include "PgLabItemDelegate.h"
|
||||
#include "ProcTableModel.h"
|
||||
#include <QTableView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
FunctionsPage::FunctionsPage(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
||||
m_functionTable = new QTableView(this);
|
||||
SetTableViewDefault(m_functionTable);
|
||||
|
||||
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);
|
||||
|
||||
auto item_delegate = new PgLabItemDelegate(this);
|
||||
m_functionTable->setItemDelegate(item_delegate);
|
||||
|
||||
auto mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(m_functionTable);
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void FunctionsPage::retranslateUi(bool all)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FunctionsPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
m_catalog = cat;
|
||||
m_model->setCatalog(cat);
|
||||
}
|
||||
32
pglab/FunctionsPage.h
Normal file
32
pglab/FunctionsPage.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef FUNCTIONSPAGE_H
|
||||
#define FUNCTIONSPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
|
||||
class QTableView;
|
||||
class PgDatabaseCatalog;
|
||||
class ProcTableModel;
|
||||
class CustomFilterSortModel;
|
||||
|
||||
class FunctionsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FunctionsPage(QWidget *parent = nullptr);
|
||||
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QTableView *m_functionTable = nullptr;
|
||||
ProcTableModel *m_model = nullptr;
|
||||
CustomFilterSortModel *m_sortFilterProxy = nullptr;
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
|
||||
void retranslateUi(bool all = true);
|
||||
|
||||
};
|
||||
|
||||
#endif // FUNCTIONSPAGE_H
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#include "MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "TablesPage.h"
|
||||
#include "FunctionsPage.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
#include <QFileDialog>
|
||||
|
|
@ -103,8 +104,10 @@ void MainWindow::catalogLoaded()
|
|||
auto tt = new TablesPage(this);
|
||||
tt->setCatalog(m_database->catalog());
|
||||
ui->tabWidget->addTab(tt, "Tables");
|
||||
ui->tabWidget->setCurrentWidget(tt);
|
||||
|
||||
auto functions_page = new FunctionsPage(this);
|
||||
functions_page->setCatalog(m_database->catalog());
|
||||
ui->tabWidget->addTab(functions_page, "Functions");
|
||||
|
||||
newSqlPage();
|
||||
} catch (std::runtime_error &ex) {
|
||||
|
|
|
|||
90
pglab/ProcTableModel.cpp
Normal file
90
pglab/ProcTableModel.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include "ProcTableModel.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include "PgProcContainer.h"
|
||||
#include "CustomDataRole.h"
|
||||
|
||||
ProcTableModel::ProcTableModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant ProcTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case NameCol: return tr("Name");
|
||||
case NamespaceCol: return tr("Schema");
|
||||
case OwnerCol: return tr("Owner");
|
||||
case LangCol: return tr("Language");
|
||||
case AclCol: return tr("ACL");
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ProcTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
m_catalog = cat;
|
||||
m_procs = cat->procs();
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ProcTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_procs ? static_cast<int>(m_procs->count()) : 0;
|
||||
}
|
||||
|
||||
int ProcTableModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return colCount;
|
||||
}
|
||||
|
||||
QVariant ProcTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
return getData(index);
|
||||
else if (role == CustomDataTypeRole)
|
||||
return getType(index.column());
|
||||
// else if (role == FirstHiddenValue) {
|
||||
// auto&& t = m_triggers->getByIdx(index.row());
|
||||
// return t.relid; //
|
||||
// }
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
PgProc ProcTableModel::proc(int row) const
|
||||
{
|
||||
return m_procs->getByIdx(row);
|
||||
}
|
||||
|
||||
Oid ProcTableModel::getType(int ) const
|
||||
{
|
||||
// switch (column) {
|
||||
// case NameCol: return tr("Name");
|
||||
// case NamespaceCol: return tr("Schema");
|
||||
// case OwnerCol: return tr("Owner");
|
||||
// case LangCol: return tr("Language");
|
||||
// return Pgsql::bool_oid;
|
||||
// }
|
||||
return Pgsql::varchar_oid;
|
||||
}
|
||||
|
||||
QVariant ProcTableModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
auto&& t = m_procs->getByIdx(index.row());
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.name;
|
||||
case NamespaceCol: return t.schemaOid();
|
||||
case OwnerCol: return t.owner;
|
||||
case LangCol: return t.lang;
|
||||
case AclCol: return t.acl;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
56
pglab/ProcTableModel.h
Normal file
56
pglab/ProcTableModel.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef PROCTABLEMODEL_H
|
||||
#define PROCTABLEMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include "PgClass.h"
|
||||
#include "PgProc.h"
|
||||
#include <memory>
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
class PgProcContainer;
|
||||
|
||||
/**
|
||||
* @brief The ProcTableModel class
|
||||
*
|
||||
* Hidden values:
|
||||
*
|
||||
*/
|
||||
class ProcTableModel: public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
//using QAbstractTableModel::QAbstractTableModel;
|
||||
|
||||
enum e_Columns : int {
|
||||
NameCol, //
|
||||
NamespaceCol, // Schema
|
||||
OwnerCol,
|
||||
LangCol,
|
||||
AclCol,
|
||||
|
||||
colCount
|
||||
};
|
||||
|
||||
ProcTableModel(QObject *parent = nullptr);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
PgProc proc(int row) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||
std::shared_ptr<const PgProcContainer> m_procs;
|
||||
|
||||
Oid getType(int column) const;
|
||||
QVariant getData(const QModelIndex &index) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // PROCTABLEMODEL_H
|
||||
|
|
@ -92,32 +92,19 @@ void TablesTableModel::doSort(int )
|
|||
|
||||
QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant v;
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case NameCol:
|
||||
v = tr("Name");
|
||||
break;
|
||||
case NamespaceCol:
|
||||
v = tr("Schema");
|
||||
break;
|
||||
case OwnerCol:
|
||||
v = tr("Owner");
|
||||
break;
|
||||
case TablespaceCol:
|
||||
v = tr("Tablespace");
|
||||
break;
|
||||
case OptionsCol:
|
||||
v = tr("Options");
|
||||
break;
|
||||
// case AclCol:
|
||||
// v = tr("ACL");
|
||||
// break;
|
||||
case NameCol: return tr("Name");
|
||||
case NamespaceCol: return tr("Schema");
|
||||
case OwnerCol: return tr("Owner");
|
||||
case TablespaceCol: return tr("Tablespace");
|
||||
case OptionsCol: return tr("Options");
|
||||
case AclCol: return tr("ACL");
|
||||
}
|
||||
}
|
||||
}
|
||||
return v;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// Basic functionality:
|
||||
|
|
@ -140,7 +127,7 @@ Oid TablesTableModel::getType(int column) const
|
|||
case NameCol:
|
||||
case NamespaceCol:
|
||||
case OptionsCol:
|
||||
// case AclCol:
|
||||
case AclCol:
|
||||
default:
|
||||
oid = Pgsql::varchar_oid;
|
||||
}
|
||||
|
|
@ -149,30 +136,17 @@ Oid TablesTableModel::getType(int column) const
|
|||
|
||||
QVariant TablesTableModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
QVariant v;
|
||||
const auto &t = m_tables[index.row()];
|
||||
switch (index.column()) {
|
||||
case NameCol:
|
||||
v = t.name; //formatTableName(t);
|
||||
break;
|
||||
case NamespaceCol:
|
||||
v = getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
||||
break;
|
||||
case OwnerCol:
|
||||
v = getRoleDisplayString(*m_catalog, t.owner);
|
||||
break;
|
||||
case TablespaceCol:
|
||||
v = getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||
break;
|
||||
case OptionsCol:
|
||||
//v = t.options;
|
||||
break;
|
||||
// case AclCol:
|
||||
// v = t.acl;
|
||||
// break;
|
||||
case NameCol: return t.name; //formatTableName(t);
|
||||
case NamespaceCol: return getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
||||
case OwnerCol: return getRoleDisplayString(*m_catalog, t.owner);
|
||||
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||
case OptionsCol: break;
|
||||
case AclCol: return t.acl;
|
||||
}
|
||||
|
||||
return v;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
PgClass TablesTableModel::getTable(int row) const
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public:
|
|||
OwnerCol,
|
||||
TablespaceCol,
|
||||
OptionsCol,
|
||||
//AclCol,
|
||||
AclCol,
|
||||
colCount };
|
||||
|
||||
TablesTableModel(QObject *parent);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ PropertyProxyModel.cpp \
|
|||
SqlCodePreview.cpp \
|
||||
CustomFilterSortModel.cpp \
|
||||
PropertiesPage.cpp \
|
||||
PasswordPromptDialog.cpp
|
||||
PasswordPromptDialog.cpp \
|
||||
ProcTableModel.cpp \
|
||||
FunctionsPage.cpp
|
||||
|
||||
HEADERS += \
|
||||
QueryResultModel.h \
|
||||
|
|
@ -132,7 +134,9 @@ CustomDataRole.h \
|
|||
SqlCodePreview.h \
|
||||
CustomFilterSortModel.h \
|
||||
PropertiesPage.h \
|
||||
PasswordPromptDialog.h
|
||||
PasswordPromptDialog.h \
|
||||
ProcTableModel.h \
|
||||
FunctionsPage.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
ConnectionManagerWindow.ui \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue