The oid column is now shown for tables that are "with oids".
This commit is contained in:
parent
172e2bcd1d
commit
7051ef2efc
5 changed files with 23 additions and 9 deletions
|
|
@ -8,24 +8,29 @@
|
||||||
#include "ScopeGuard.h"
|
#include "ScopeGuard.h"
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
|
||||||
void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, Oid table_oid)
|
void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const PgClass &table)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
SCOPE_EXIT { endResetModel(); };
|
SCOPE_EXIT { endResetModel(); };
|
||||||
|
|
||||||
|
m_table = table;
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
m_columns = cat->attributes()->getColumnsForRelation(table_oid);
|
m_columns = cat->attributes()->getColumnsForRelation(table.oid);
|
||||||
|
|
||||||
// hide system columns
|
// hide system columns
|
||||||
m_columns.erase(std::remove_if(m_columns.begin(), m_columns.end(),
|
auto si = table.hasoids
|
||||||
[](auto &e) { return e.num <= 0; } ),
|
? std::remove_if(m_columns.begin(), m_columns.end(),
|
||||||
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
|
// sort remaining columns by order in table
|
||||||
std::sort(m_columns.begin(), m_columns.end(),
|
std::sort(m_columns.begin(), m_columns.end(),
|
||||||
[] (auto &l, auto &r) -> bool { return l.num < r.num; });
|
[] (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(),
|
std::sort(m_indexes.begin(), m_indexes.end(),
|
||||||
[] (const auto &l, const auto &r) -> bool
|
[] (const auto &l, const auto &r) -> bool
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define COLUMNTABLEMODEL_H
|
#define COLUMNTABLEMODEL_H
|
||||||
|
|
||||||
#include "BaseTableModel.h"
|
#include "BaseTableModel.h"
|
||||||
|
#include "PgClass.h"
|
||||||
#include "PgIndex.h"
|
#include "PgIndex.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -22,7 +23,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
using BaseTableModel::BaseTableModel;
|
using BaseTableModel::BaseTableModel;
|
||||||
void setData(std::shared_ptr<const PgDatabaseCatalog> cat, Oid table_oid);
|
void setData(std::shared_ptr<const PgDatabaseCatalog> cat, const PgClass &table);
|
||||||
|
|
||||||
// Header:
|
// Header:
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
|
|
@ -39,6 +40,7 @@ protected:
|
||||||
using t_Columns = std::vector<PgAttribute>;
|
using t_Columns = std::vector<PgAttribute>;
|
||||||
|
|
||||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||||
|
PgClass m_table;
|
||||||
t_Columns m_columns;
|
t_Columns m_columns;
|
||||||
std::vector<PgIndex> m_indexes;
|
std::vector<PgIndex> m_indexes;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||||
void TablesPage::on_tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
void TablesPage::on_tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
if (current.row() != previous.row()) {
|
if (current.row() != previous.row()) {
|
||||||
Oid table_oid = m_tablesModel->getTableOid(current.row());
|
PgClass table = m_tablesModel->getTable(current.row());
|
||||||
m_columnsModel->setData(m_catalog, table_oid);
|
m_columnsModel->setData(m_catalog, table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,11 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PgClass TablesTableModel::getTable(int row) const
|
||||||
|
{
|
||||||
|
return m_tables[row];
|
||||||
|
}
|
||||||
|
|
||||||
Oid TablesTableModel::getTableOid(int row) const
|
Oid TablesTableModel::getTableOid(int row) const
|
||||||
{
|
{
|
||||||
return m_tables[row].oid;
|
return m_tables[row].oid;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define TABLESTABLEMODEL_H
|
#define TABLESTABLEMODEL_H
|
||||||
|
|
||||||
#include "BaseTableModel.h"
|
#include "BaseTableModel.h"
|
||||||
|
#include "PgClass.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ public:
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
PgClass getTable(int row) const;
|
||||||
Oid getTableOid(int row) const;
|
Oid getTableOid(int row) const;
|
||||||
protected:
|
protected:
|
||||||
virtual Oid getType(int column) const override;
|
virtual Oid getType(int column) const override;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue