#include "IndexModel.h" #include "PgDatabaseCatalog.h" #include "PgIndexContainer.h" #include "Pgsql_oids.h" #include "ScopeGuard.h" void IndexModel::setData(std::shared_ptr 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; }