diff --git a/pglab/DatabasesTableModel.cpp b/pglab/DatabasesTableModel.cpp index 65a9d6a..30bbe23 100644 --- a/pglab/DatabasesTableModel.cpp +++ b/pglab/DatabasesTableModel.cpp @@ -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; diff --git a/pglab/DatabasesTableModel.h b/pglab/DatabasesTableModel.h index a19c9e1..b953048 100644 --- a/pglab/DatabasesTableModel.h +++ b/pglab/DatabasesTableModel.h @@ -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 }; diff --git a/pglab/ServerWindow.cpp b/pglab/ServerWindow.cpp index 10eb0c6..aa4767f 100644 --- a/pglab/ServerWindow.cpp +++ b/pglab/ServerWindow.cpp @@ -4,6 +4,7 @@ #include "DatabasesTableModel.h" #include "RolesTableModel.h" #include "catalog/PgDatabaseCatalog.h" +#include #include 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); diff --git a/pglablib/catalog/PgDatabase.h b/pglablib/catalog/PgDatabase.h index 22fc9e0..81f4d24 100644 --- a/pglablib/catalog/PgDatabase.h +++ b/pglablib/catalog/PgDatabase.h @@ -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; diff --git a/pglablib/catalog/PgDatabaseContainer.cpp b/pglablib/catalog/PgDatabaseContainer.cpp index 2746c26..b577d45 100644 --- a/pglablib/catalog/PgDatabaseContainer.cpp +++ b/pglablib/catalog/PgDatabaseContainer.cpp @@ -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;