Added listing of triggers for selected table (not completely finished).
Used slightly different approach. This tab is fully build in source code using subclasses to adjust behaviour of widgets for reuse in the other tabs. Uses custom proxy model for filtering triggers for correct table and supporting out of the box sorting by QTableView. SqlCodePreview: QPlainTextEditor which sql highlighter and in readonly mode but allows copy.
This commit is contained in:
parent
446923ebaf
commit
2a75e86102
23 changed files with 697 additions and 67 deletions
100
pglab/TriggerTableModel.cpp
Normal file
100
pglab/TriggerTableModel.cpp
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include "TriggerTableModel.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include "PgTriggerContainer.h"
|
||||
#include "CustomDataRole.h"
|
||||
|
||||
TriggerTableModel::TriggerTableModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant TriggerTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case NameCol: return tr("Name");
|
||||
case EventsCol: return tr("Events");
|
||||
case WhenCol: return tr("When");
|
||||
case DeferrableCol: return tr("Df");
|
||||
case InitiallyCol: return tr("ID");
|
||||
case ForCol: return tr("For");
|
||||
case CondCol: return tr("Cond.");
|
||||
case ReferencingCol: return tr("Referencing");
|
||||
case ProcedureCol: return tr("Function");
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void TriggerTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
m_catalog = cat;
|
||||
m_triggers = cat->triggers();//->getTriggersForRelation(table);
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int TriggerTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_triggers ? static_cast<int>(m_triggers->count()) : 0;
|
||||
}
|
||||
|
||||
|
||||
int TriggerTableModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return colCount;
|
||||
}
|
||||
|
||||
|
||||
QVariant TriggerTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
return getData(index);
|
||||
else if (role == CustomDataTypeRole)
|
||||
return getType(index.column());
|
||||
else if (role == FirstHiddenValue) {
|
||||
auto&& t = m_triggers->getByIdx(index.row());
|
||||
return t.relid; //
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
PgTrigger TriggerTableModel::trigger(int row) const
|
||||
{
|
||||
return m_triggers->getByIdx(row);
|
||||
}
|
||||
|
||||
|
||||
Oid TriggerTableModel::getType(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case DeferrableCol:
|
||||
case InitiallyCol:
|
||||
return Pgsql::bool_oid;
|
||||
}
|
||||
return Pgsql::varchar_oid;
|
||||
}
|
||||
|
||||
|
||||
QVariant TriggerTableModel::getData(const QModelIndex &index) const
|
||||
{
|
||||
auto&& t = m_triggers->getByIdx(index.row());
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.name;
|
||||
case EventsCol: return t.eventAbbr();
|
||||
case WhenCol: return t.typeFireWhen();
|
||||
case DeferrableCol: return t.deferrable;
|
||||
case InitiallyCol: return t.initdeferred;
|
||||
case ForCol: return t.forEach();
|
||||
// case CondCol: return tr("Cond.");
|
||||
// case ReferencingCol: return tr("Referencing");
|
||||
// case ProcedureCol: return tr("Function");
|
||||
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue