From 7051ef2efc175e2173f40eb1542c006e3a9e1048 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 17 Dec 2017 19:54:23 +0100 Subject: [PATCH] The oid column is now shown for tables that are "with oids". --- pglab/ColumnTableModel.cpp | 17 +++++++++++------ pglab/ColumnTableModel.h | 4 +++- pglab/TablesPage.cpp | 4 ++-- pglab/TablesTableModel.cpp | 5 +++++ pglab/TablesTableModel.h | 2 ++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pglab/ColumnTableModel.cpp b/pglab/ColumnTableModel.cpp index 6a193f4..db15c6c 100644 --- a/pglab/ColumnTableModel.cpp +++ b/pglab/ColumnTableModel.cpp @@ -8,24 +8,29 @@ #include "ScopeGuard.h" #include -void ColumnTableModel::setData(std::shared_ptr cat, Oid table_oid) +void ColumnTableModel::setData(std::shared_ptr cat, const PgClass &table) { beginResetModel(); SCOPE_EXIT { endResetModel(); }; + m_table = table; m_catalog = cat; - m_columns = cat->attributes()->getColumnsForRelation(table_oid); + m_columns = cat->attributes()->getColumnsForRelation(table.oid); // hide system columns - m_columns.erase(std::remove_if(m_columns.begin(), m_columns.end(), - [](auto &e) { return e.num <= 0; } ), - m_columns.end()); + auto si = table.hasoids + ? std::remove_if(m_columns.begin(), m_columns.end(), + [](PgAttribute &e) { return e.num <= 0 && e.name != "oid"; }) + : std::remove_if(m_columns.begin(), m_columns.end(), + [](PgAttribute &e) { return e.num <= 0; }); + // move columns to end and remove them + m_columns.erase(si, m_columns.end()); // sort remaining columns by order in table std::sort(m_columns.begin(), m_columns.end(), [] (auto &l, auto &r) -> bool { return l.num < r.num; }); - m_indexes = m_catalog->indexes()->getIndexesForTable(table_oid); + m_indexes = m_catalog->indexes()->getIndexesForTable(table.oid); std::sort(m_indexes.begin(), m_indexes.end(), [] (const auto &l, const auto &r) -> bool { diff --git a/pglab/ColumnTableModel.h b/pglab/ColumnTableModel.h index 0771a2d..cae0786 100644 --- a/pglab/ColumnTableModel.h +++ b/pglab/ColumnTableModel.h @@ -2,6 +2,7 @@ #define COLUMNTABLEMODEL_H #include "BaseTableModel.h" +#include "PgClass.h" #include "PgIndex.h" #include #include @@ -22,7 +23,7 @@ public: using BaseTableModel::BaseTableModel; - void setData(std::shared_ptr cat, Oid table_oid); + void setData(std::shared_ptr cat, const PgClass &table); // Header: QVariant headerData(int section, Qt::Orientation orientation, int role) const override; @@ -39,6 +40,7 @@ protected: using t_Columns = std::vector; std::shared_ptr m_catalog; + PgClass m_table; t_Columns m_columns; std::vector m_indexes; diff --git a/pglab/TablesPage.cpp b/pglab/TablesPage.cpp index b796971..2773ab3 100644 --- a/pglab/TablesPage.cpp +++ b/pglab/TablesPage.cpp @@ -39,7 +39,7 @@ void TablesPage::setCatalog(std::shared_ptr cat) void TablesPage::on_tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) { if (current.row() != previous.row()) { - Oid table_oid = m_tablesModel->getTableOid(current.row()); - m_columnsModel->setData(m_catalog, table_oid); + PgClass table = m_tablesModel->getTable(current.row()); + m_columnsModel->setData(m_catalog, table); } } diff --git a/pglab/TablesTableModel.cpp b/pglab/TablesTableModel.cpp index 03d52fe..5499f35 100644 --- a/pglab/TablesTableModel.cpp +++ b/pglab/TablesTableModel.cpp @@ -123,6 +123,11 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const return v; } +PgClass TablesTableModel::getTable(int row) const +{ + return m_tables[row]; +} + Oid TablesTableModel::getTableOid(int row) const { return m_tables[row].oid; diff --git a/pglab/TablesTableModel.h b/pglab/TablesTableModel.h index 2ac42c0..78ddda6 100644 --- a/pglab/TablesTableModel.h +++ b/pglab/TablesTableModel.h @@ -2,6 +2,7 @@ #define TABLESTABLEMODEL_H #include "BaseTableModel.h" +#include "PgClass.h" #include #include @@ -32,6 +33,7 @@ public: int columnCount(const QModelIndex &parent) const override; virtual QVariant data(const QModelIndex &index, int role) const override; + PgClass getTable(int row) const; Oid getTableOid(int row) const; protected: virtual Oid getType(int column) const override;