95 lines
2.2 KiB
C++
95 lines
2.2 KiB
C++
#include "ProcTableModel.h"
|
|
#include "catalog/PgDatabaseCatalog.h"
|
|
#include "catalog/PgProcContainer.h"
|
|
#include "catalog/PgLanguageContainer.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.objectName();
|
|
case NamespaceCol: return t.nsName();
|
|
case OwnerCol: return t.ownerName();
|
|
case LangCol: {
|
|
auto lan = m_catalog->languages()->getByKey(t.lang);
|
|
if (lan) return lan->objectName();
|
|
return t.lang;
|
|
}
|
|
case AclCol: return t.aclString();
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
|