PDA

View Full Version : Subclassing QSortFilterProxyModel with lazy population of items



sokopok
4th August 2009, 13:16
I'm creating a sortable/filterable tree model displaying DBus services/nodes.
My code is based on the code used in qdbusviewer, and everything worked fine, until I started implementing lazy population of items (using hasChildren, canFetchMore and fetchMore).
My base model (DBusModel) works like a charm, but the accompanying proxy model (DBusSortFilterModel) started behaving very strange.
Sorting seems to work fine, Filtering seems to work fine, but when I expand any item, the whole view gets messed up (items just disappear!!).
See attached screenshots...

At the moment my implementation does something like this:


bool DBusSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
// ...
}
bool DBusSortFilterProxyModel::hasChildren(const QModelIndex& parent) const
{
return sourceModel()->hasChildren(mapToSource(parent));
}
bool DBusSortFilterProxyModel::canFetchMore(const QModelIndex& parent) const
{
return sourceModel()->canFetchMore(mapToSource(parent));
}
void DBusSortFilterProxyModel::fetchMore(const QModelIndex& parent)
{
return sourceModel()->fetchMore(mapToSource(parent));
}


Probably I'm just overlooking something, or didn't implement some required functionality for this to work. But what?
Anybody has some experience with this?

wysota
9th August 2009, 19:51
Why are you reimplementing the sort filter proxy model? Why isn't implementing lazy population in the source model enough?