2017-08-26 11:44:40 +02:00
|
|
|
#include "DatabasesTableModel.h"
|
|
|
|
|
#include "PgDatabaseCatalogue.h"
|
2017-02-12 14:03:42 +01:00
|
|
|
#include "PgDatabaseContainer.h"
|
2017-02-19 17:41:05 +01:00
|
|
|
#include "PgAuthIdContainer.h"
|
2017-02-12 14:03:42 +01:00
|
|
|
|
|
|
|
|
DatabasesTableModel::DatabasesTableModel(QObject *parent)
|
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-26 11:44:40 +02:00
|
|
|
void DatabasesTableModel::setDatabaseList(const PgDatabaseCatalogue* cat)
|
2017-02-13 19:51:19 +01:00
|
|
|
{
|
|
|
|
|
beginResetModel();
|
2017-02-19 17:41:05 +01:00
|
|
|
m_catalog = cat;
|
|
|
|
|
m_databases = cat->databases();
|
2017-02-13 19:51:19 +01:00
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 14:03:42 +01:00
|
|
|
QVariant DatabasesTableModel::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 DbaCol:
|
|
|
|
|
v = tr("Owner");
|
|
|
|
|
break;
|
|
|
|
|
case EncodingCol:
|
|
|
|
|
v = tr("Encoding");
|
|
|
|
|
break;
|
|
|
|
|
case CollateCol:
|
|
|
|
|
v = tr("Collation");
|
|
|
|
|
break;
|
|
|
|
|
case CTypeCol:
|
|
|
|
|
v = tr("CType");
|
|
|
|
|
break;
|
|
|
|
|
case IsTemplateCol:
|
|
|
|
|
v = tr("Is template");
|
|
|
|
|
break;
|
|
|
|
|
case AllowConnCol:
|
|
|
|
|
v = tr("Can connect");
|
|
|
|
|
break;
|
|
|
|
|
case ConnLimitCol:
|
|
|
|
|
v = tr("Conn. limit");
|
|
|
|
|
break;
|
|
|
|
|
case TablespaceCol:
|
|
|
|
|
v = tr("Tablespace");
|
|
|
|
|
break;
|
|
|
|
|
case AclCol:
|
|
|
|
|
v = tr("ACL");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DatabasesTableModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
if (m_databases) {
|
2017-02-13 19:51:19 +01:00
|
|
|
result = m_databases->count();
|
2017-02-12 14:03:42 +01:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DatabasesTableModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
int result = 10;
|
|
|
|
|
// if (parent.isValid())
|
|
|
|
|
// return 10;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant DatabasesTableModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant v;
|
|
|
|
|
//if (!index.isValid())
|
|
|
|
|
if (m_databases) {
|
|
|
|
|
const PgDatabase &db = m_databases->getByIdx(index.row());
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case NameCol:
|
|
|
|
|
v = db.name;
|
|
|
|
|
break;
|
|
|
|
|
case DbaCol:
|
|
|
|
|
// todo lookup role name
|
2017-02-19 17:41:05 +01:00
|
|
|
{
|
|
|
|
|
const auto& roles = m_catalog->authIds();
|
|
|
|
|
v = QString("%1 (%2)").arg(roles->getByOid(db.dba).name).arg(db.dba);
|
|
|
|
|
}
|
2017-02-12 14:03:42 +01:00
|
|
|
break;
|
|
|
|
|
case EncodingCol:
|
|
|
|
|
// todo lookup encoding name
|
|
|
|
|
v = db.encoding;
|
|
|
|
|
break;
|
|
|
|
|
case CollateCol:
|
|
|
|
|
v = db.collate;
|
|
|
|
|
break;
|
|
|
|
|
case CTypeCol:
|
|
|
|
|
v = db.ctype;
|
|
|
|
|
break;
|
|
|
|
|
case IsTemplateCol:
|
|
|
|
|
v = db.isTemplate;
|
|
|
|
|
break;
|
|
|
|
|
case AllowConnCol:
|
|
|
|
|
v = db.allowConn;
|
|
|
|
|
break;
|
|
|
|
|
case ConnLimitCol:
|
|
|
|
|
v = db.connLimit;
|
|
|
|
|
break;
|
|
|
|
|
case TablespaceCol:
|
|
|
|
|
// todo lookup tablespace name
|
|
|
|
|
v = db.tablespace;
|
|
|
|
|
break;
|
|
|
|
|
case AclCol:
|
|
|
|
|
v = db.acl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|