Updating of detail tabs besides list of tables works correctly again.
Had stopped working because the catalog now behaves a little different, returning nullptr instead of an invalid element.
This commit is contained in:
parent
fcb191f2cc
commit
52011a9842
12 changed files with 114 additions and 92 deletions
|
|
@ -11,35 +11,56 @@
|
|||
#include "SqlFormattingUtils.h"
|
||||
#include <QBrush>
|
||||
|
||||
void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const PgClass &table)
|
||||
namespace {
|
||||
|
||||
// Filter dropped and system columns but keep the oid column
|
||||
bool ColumnFilterWithOidsPred(PgAttribute &e)
|
||||
{
|
||||
return e.isdropped || (e.num <= 0 && e.name != "oid");
|
||||
}
|
||||
|
||||
// Filter dropped and system columns
|
||||
bool ColumnFilterWithoutOidsPred(PgAttribute &e)
|
||||
{
|
||||
return e.isdropped || e.num <= 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &table)
|
||||
{
|
||||
beginResetModel();
|
||||
SCOPE_EXIT { endResetModel(); };
|
||||
|
||||
m_table = table;
|
||||
m_catalog = cat;
|
||||
m_columns = cat->attributes()->getColumnsForRelation(table.oid);
|
||||
if (m_table) {
|
||||
m_columns = cat->attributes()->getColumnsForRelation(table->oid);
|
||||
// hide system and dropped columns
|
||||
auto column_filter_pred = table->hasoids ? ColumnFilterWithOidsPred : ColumnFilterWithoutOidsPred;
|
||||
auto si = std::remove_if(m_columns.begin(), m_columns.end(), column_filter_pred);
|
||||
// move columns to end and remove them
|
||||
m_columns.erase(si, m_columns.end());
|
||||
|
||||
// hide system columns
|
||||
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; });
|
||||
}
|
||||
else
|
||||
m_columns.clear();
|
||||
|
||||
// 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);
|
||||
std::sort(m_indexes.begin(), m_indexes.end(),
|
||||
if (m_table) {
|
||||
m_indexes = m_catalog->indexes()->getIndexesForTable(table->oid);
|
||||
std::sort(m_indexes.begin(), m_indexes.end(),
|
||||
[] (const auto &l, const auto &r) -> bool
|
||||
{
|
||||
return l.isprimary > r.isprimary
|
||||
|| (l.isprimary == r.isprimary && l.indexrelid < r.indexrelid);
|
||||
});
|
||||
}
|
||||
else
|
||||
m_indexes.clear();
|
||||
}
|
||||
|
||||
QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
|
@ -224,33 +245,37 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const
|
|||
if (role == Qt::ForegroundRole && index.column() == TypeCol) {
|
||||
QVariant v;
|
||||
const auto &t = m_columns[index.row()];
|
||||
auto c = m_catalog->types()->getByKey(t.typid);
|
||||
switch (c->category) {
|
||||
case TypCategory::Boolean:
|
||||
v = QBrush(Qt::darkGreen);
|
||||
break;
|
||||
case TypCategory::Numeric:
|
||||
v = QBrush(Qt::darkBlue);
|
||||
break;
|
||||
case TypCategory::DateTime:
|
||||
case TypCategory::Timespan:
|
||||
v = QBrush(Qt::darkMagenta);
|
||||
break;
|
||||
case TypCategory::String:
|
||||
v = QBrush(Qt::darkYellow);
|
||||
break;
|
||||
case TypCategory::Array:
|
||||
case TypCategory::Composite:
|
||||
case TypCategory::Enum:
|
||||
case TypCategory::Geometric:
|
||||
case TypCategory::NetworkAddress:
|
||||
case TypCategory::Pseudo:
|
||||
case TypCategory::Range:
|
||||
case TypCategory::UserDefined:
|
||||
case TypCategory::BitString:
|
||||
case TypCategory::Unknown:
|
||||
default:
|
||||
if (t.typid == InvalidOid)
|
||||
v = QBrush(Qt::black);
|
||||
else {
|
||||
auto c = m_catalog->types()->getByKey(t.typid);
|
||||
switch (c->category) {
|
||||
case TypCategory::Boolean:
|
||||
v = QBrush(Qt::darkGreen);
|
||||
break;
|
||||
case TypCategory::Numeric:
|
||||
v = QBrush(Qt::darkBlue);
|
||||
break;
|
||||
case TypCategory::DateTime:
|
||||
case TypCategory::Timespan:
|
||||
v = QBrush(Qt::darkMagenta);
|
||||
break;
|
||||
case TypCategory::String:
|
||||
v = QBrush(Qt::darkYellow);
|
||||
break;
|
||||
case TypCategory::Array:
|
||||
case TypCategory::Composite:
|
||||
case TypCategory::Enum:
|
||||
case TypCategory::Geometric:
|
||||
case TypCategory::NetworkAddress:
|
||||
case TypCategory::Pseudo:
|
||||
case TypCategory::Range:
|
||||
case TypCategory::UserDefined:
|
||||
case TypCategory::BitString:
|
||||
case TypCategory::Unknown:
|
||||
default:
|
||||
v = QBrush(Qt::black);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue