Made a start with showing foreignkeys in column list.

Not finished, need to decide what to do with multiple and multi column fkeys.
This commit is contained in:
eelke 2017-12-25 10:31:58 +01:00
parent a76686acfd
commit 190a6c04dc
14 changed files with 97 additions and 94 deletions

View file

@ -3,6 +3,7 @@
#include "PgAttribute.h"
#include "PgAttributeContainer.h"
#include "PgClassContainer.h"
#include "PgConstraintContainer.h"
#include "PgType.h"
#include "PgTypeContainer.h"
#include "PgIndexContainer.h"
@ -69,6 +70,9 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
case DefaultCol:
c = tr("Default");
break;
case ForeignKeyCol:
c = tr("Refs");
break;
case CollationCol:
c = tr("Collation");
break;
@ -104,6 +108,9 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
case DefaultCol:
v = tr("Default value for the columns");
break;
case ForeignKeyCol:
v = tr("Foreign key constraint for this column");
break;
// case CollationCol:
// c = tr("Collation");
// break;
@ -178,6 +185,9 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const
case DefaultCol:
s = t.defaultValue;
break;
case ForeignKeyCol:
s = getFKey(t);
break;
case CollationCol:
s = ""; //t.collation;
break;
@ -188,6 +198,16 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const
return v;
}
QString ColumnTableModel::getFKey(const PgAttribute &column) const
{
QString result;
const PgConstraint *c = m_catalog->constraints()->getFKeyForTableColumn(column.relid, column.num);
if (c) {
result = c->name;
}
return result;
}
QVariant ColumnTableModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::ForegroundRole && index.column() == TypeCol) {