TractsListProxyModel
::TractsListProxyModel(QObject *parent
) m_state(0)
{
setDynamicSortFilter(true);
}
bool TractsListProxyModel::filterAcceptsRow(int sourceRow,
{
QModelIndex index
= sourceModel
()->index
(sourceRow,
0, sourceParent
);
Tract::Ptr tract = index.data(Qt::EditRole).value<Tract::Ptr>();
}
bool TractsListProxyModel::stateFilter(Tract::Ptr tract) const
{
return m_state == 0 ?
true
: tract->getState() == m_state;
}
void TractsListProxyModel::setStateFilter(terminal::TractState::Type state)
{
m_state = state;
invalidateFilter();
}
{
}
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
invalidateFilter();
}
TractsListProxyModel::TractsListProxyModel(QObject *parent)
: QSortFilterProxyModel(parent),
m_state(0)
{
setDynamicSortFilter(true);
}
bool TractsListProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
Tract::Ptr tract = index.data(Qt::EditRole).value<Tract::Ptr>();
return stateFilter(tract) && QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
bool TractsListProxyModel::stateFilter(Tract::Ptr tract) const
{
return m_state == 0 ?
true
: tract->getState() == m_state;
}
void TractsListProxyModel::setStateFilter(terminal::TractState::Type state)
{
m_state = state;
invalidateFilter();
}
void TractsListProxyModel::setSourceModel(QAbstractItemModel *model)
{
connect_assert(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(sourceModelDataChanged(QModelIndex, QModelIndex)));
QSortFilterProxyModel::setSourceModel(model);
}
void TractsListProxyModel::sourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_UNUSED(topLeft);
Q_UNUSED(bottomRight);
invalidateFilter();
}
To copy to clipboard, switch view to plain text mode
P.S. I’ve tried to connect
connect(sourceModel,
SIGNAL(rowsInserted
(QModelIndex,
int,
int)),
this, SLOT(invalidate()));
connect(sourceModel,
SIGNAL(rowsRemoved
(QModelIndex,
int,
int)),
this, SLOT(invalidate()));
connect(sourceModel,
SIGNAL(columnsInserted
(QModelIndex,
int,
int)),
this, SLOT(invalidate()));
connect(sourceModel,
SIGNAL(columnsRemoved
(QModelIndex,
int,
int)),
this, SLOT(invalidate()));
this, SLOT(invalidate()));
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(modelReset()),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(invalidate()));
connect(sourceModel, SIGNAL(modelReset()),
this, SLOT(invalidate()));
To copy to clipboard, switch view to plain text mode
But with no avail
Bookmarks