PDA

View Full Version : QSortFilterProxyModel



evgenM
13th March 2007, 16:27
ProxyModel::ProxyModel( ItemModel* s )
: QSortFilterProxyModel(s), mSource( s ), mFilterOn(false)
{
setSourceModel( mSource );
}
//
ItemModel* ProxyModel::source() const
{
return mSource;
}
//
bool ProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent) const
{
if (!mFilterOn)
return true;

QModelIndex index;
index = sourceModel()->index(sourceRow, 0, sourceParent);
return index.data(Item::FilterRole).toBool();
}
//
void ProxyModel::setFilter(int on)
{
if (!on)
mFilterOn = false;
else
mFilterOn = true;

if (mFilterOn)
{
setSortRole(Item::SortRole);
sort(0);
filterChanged ();
}
else
{
clear();
//reset();
}
}


now problem:
when i appling filter (setFilter(true)) my source model get filter and sorting - it's ok
when i remove filter (setFilter(false)) my source model loose filter but not sorting

how to remove sorting from proxy model?

jpn
18th March 2007, 12:53
Try:


...
else
{
clear();
sort(-1); // <---
//reset();
}