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.
This commit is contained in:
parent
b436814eb5
commit
97d4e2a1a4
24 changed files with 754 additions and 228 deletions
85
pglab/IndexModel.cpp
Normal file
85
pglab/IndexModel.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue