Rework of catalog objects. Several of them are now inheriting from common

base classes that implement common functionality.
This commit is contained in:
eelke 2018-11-25 19:45:06 +01:00
parent 840af1e0a9
commit 73c4cf4790
45 changed files with 340 additions and 265 deletions

View file

@ -23,12 +23,12 @@ void TablesTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
// How many?
int n = 0;
for (const auto &e : *classes)
if (e.kind == RelKind::Table && !e.system_namespace) ++n;
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) ++n;
m_tables.clear();
m_tables.reserve(n); // reserve space
for (const auto &e : *classes) {
if (e.kind == RelKind::Table && !e.system_namespace) {
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) {
m_tables.push_back(e);
}
}
@ -48,14 +48,14 @@ namespace {
inline bool compareByName(PgClass l, PgClass r)
{
return l.name < r.name
|| (l.name == r.name && l.relnamespace_name < r.relnamespace_name);
return l.objectName() < r.objectName()
|| (l.objectName() == r.objectName() && l.nsName() < r.nsName());
}
inline bool compareBySchema(PgClass l, PgClass r)
{
return l.relnamespace_name < r.relnamespace_name
|| (l.relnamespace_name == r.relnamespace_name && l.name < r.name);
return l.nsName() < r.nsName()
|| (l.nsName() == r.nsName() && l.objectName() < r.objectName());
}
}
@ -138,9 +138,9 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
{
const auto &t = m_tables[index.row()];
switch (index.column()) {
case NameCol: return t.name; //formatTableName(t);
case NamespaceCol: return getNamespaceDisplayString(*m_catalog, t.relnamespace);
case OwnerCol: return getRoleDisplayString(*m_catalog, t.owner);
case NameCol: return t.objectName();
case NamespaceCol: return t.nsName(); //getNamespaceDisplayString(*m_catalog, t.relnamespace);
case OwnerCol: return t.ownerName();
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
case OptionsCol: break;
case AclCol: return t.acl;
@ -156,15 +156,15 @@ PgClass TablesTableModel::getTable(int row) const
Oid TablesTableModel::getTableOid(int row) const
{
return m_tables[row].oid;
return m_tables[row].oid();
}
QString TablesTableModel::formatTableName(const PgClass &cls) const
{
const char * format = "%2 (%1)";
QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
return QString(format).arg(ns_name).arg(cls.name);
}
//QString TablesTableModel::formatTableName(const PgClass &cls) const
//{
// const char * format = "%2 (%1)";
// QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
// return QString(format).arg(ns_name).arg(cls.objectName());
//}
QVariant TablesTableModel::data(const QModelIndex &index, int role) const
{