Server window database tab tweaks

- Encoding as string instead of id
- Tablespace name instead of id
- Database list sorting enabled
- Database size
This commit is contained in:
eelke 2021-03-10 20:49:03 +01:00
parent 11459e1e12
commit 2724586f4e
5 changed files with 28 additions and 9 deletions

View file

@ -52,6 +52,9 @@ QVariant DatabasesTableModel::headerData(int section, Qt::Orientation orientatio
case TablespaceCol:
v = tr("Tablespace");
break;
case SizeCol:
v = tr("Size");
break;
case AclCol:
v = tr("ACL");
break;
@ -89,7 +92,10 @@ Oid DatabasesTableModel::getType(int column) const
case ConnLimitCol:
oid = int4_oid;
break;
case AclCol:
case SizeCol:
oid = int8_oid;
break;
case AclCol:
case CollateCol:
case CTypeCol:
case EncodingCol:
@ -119,7 +125,7 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
break;
case EncodingCol:
// todo lookup encoding name
v = db.encoding;
v = db.encodingString;
break;
case CollateCol:
v = db.collate;
@ -138,8 +144,11 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
break;
case TablespaceCol:
// todo lookup tablespace name
v = db.tablespace;
v = getTablespaceDisplayString(*m_catalog, db.tablespace);
break;
case SizeCol:
v = db.sizeBytes;
break;
case AclCol:
v = db.aclString();
break;

View file

@ -17,7 +17,7 @@ class DatabasesTableModel : public BaseTableModel
public:
enum e_Columns : int { NameCol, DbaCol, EncodingCol, CollateCol,
CTypeCol, IsTemplateCol, AllowConnCol, ConnLimitCol,
TablespaceCol, AclCol, COL_COUNT };
TablespaceCol, SizeCol, AclCol, COL_COUNT };

View file

@ -4,6 +4,7 @@
#include "DatabasesTableModel.h"
#include "RolesTableModel.h"
#include "catalog/PgDatabaseCatalog.h"
#include <QSortFilterProxyModel>
#include <QDebug>
ServerWindow::ServerWindow(MasterController *master, QWidget *parent)
@ -14,7 +15,12 @@ ServerWindow::ServerWindow(MasterController *master, QWidget *parent)
ui->setupUi(this);
m_databasesModel = new DatabasesTableModel(this);
ui->databasesTableView->setModel(m_databasesModel);
auto databasesSortFilter = new QSortFilterProxyModel(this);
databasesSortFilter->setSourceModel(m_databasesModel);
ui->databasesTableView->setModel(databasesSortFilter);
ui->databasesTableView->setSortingEnabled(true);
m_rolesModel = new RolesTableModel(this);
ui->rolesTableView->setModel(m_rolesModel);

View file

@ -10,12 +10,14 @@ public:
Oid dba; // owner?
int encoding;
QString encodingString;
QString collate;
QString ctype;
bool isTemplate;
bool allowConn;
int connLimit;
Oid tablespace;
int64_t sizeBytes;
using PgServerObject::PgServerObject;

View file

@ -3,8 +3,10 @@
std::string PgDatabaseContainer::getLoadQuery() const
{
return "SELECT oid,datname,datdba,encoding,datcollate,datctype,datistemplate,datallowconn,"
"datconnlimit,dattablespace,datacl FROM pg_database";
return "SELECT oid,datname,datdba,encoding,pg_encoding_to_char(encoding),datcollate \n"
",datctype,datistemplate,datallowconn,"
"datconnlimit,dattablespace,pg_database_size(oid),datacl "
"FROM pg_database";
}
PgDatabase PgDatabaseContainer::loadElem(const Pgsql::Row &row)
@ -14,8 +16,8 @@ PgDatabase PgDatabaseContainer::loadElem(const Pgsql::Row &row)
Oid oid = col.nextValue();
QString name = col.nextValue();
PgDatabase v(m_catalog, oid, name);
col >> v.dba >> v.encoding >> v.collate >> v.ctype >> v.isTemplate
>> v.allowConn >> v.connLimit >> v.tablespace;
col >> v.dba >> v.encoding >> v.encodingString >> v.collate >> v.ctype >> v.isTemplate
>> v.allowConn >> v.connLimit >> v.tablespace >> v.sizeBytes;
AclList acl_list;
col >> acl_list;