pgLab/pglab/IndexModel.cpp
eelke 97d4e2a1a4 Created IndexModel for displaying the indexes on a table. Constraints can now show the SQL to drop and create them.
The keyword list is now directly based of the official keyword list from postgresql.
2018-01-06 21:22:22 +01:00

85 lines
1.6 KiB
C++

#include "IndexModel.h"
#include "PgDatabaseCatalog.h"
#include "PgIndexContainer.h"
#include "Pgsql_oids.h"
#include "ScopeGuard.h"
void IndexModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const PgClass &table)
{
beginResetModel();
SCOPE_EXIT { endResetModel(); };
m_catalog = cat;
m_table = table;
m_indexes = cat->indexes()->getIndexesForTable(table.oid);
}
int IndexModel::rowCount(const QModelIndex &parent) const
{
return m_indexes.size();
}
int IndexModel::columnCount(const QModelIndex &parent) const
{
return colCount;
}
Oid IndexModel::getType(int column) const
{
return Pgsql::varchar_oid;
}
QVariant IndexModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant v;
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
QString c;
switch (section) {
case TypeCol:
c = tr("Type");
break;
case NameCol:
c = tr("Name");
break;
case ColumnsCol:
c = tr("On");
break;
case ConditionCol:
c = tr("Condition");
break;
// case DefinitionCol:
// c = tr("Definition");
// break;
}
v = c;
}
}
return v;
}
QVariant IndexModel::getData(const QModelIndex &index) const
{
QVariant v;
int rij = index.row();
const auto &dat = m_indexes[rij];
switch (index.column()) {
case TypeCol:
if (dat.isprimary) v = ":/icons/constraints/primarykey.png";
else if (dat.isunique) v = ":/icons/constraints/unique.png";
break;
case NameCol:
v = getIndexDisplayString(*m_catalog, dat.indexrelid);
break;
case ColumnsCol:
break;
case ConditionCol:
break;
}
return v;
}