I have custom hierarchical model, inherited from QAbstractModelItem. Also, I implement MySortFilterProxyModel subclassed from QSortFilterProxyModel. MySortFilterProxyModel can remove and swap columns. If first column in MySortFilterProxyModel corresponds the first column in model everything works fine. But if it is swaped in proxy model there are some troubles with view: MySortFilterProxyModel::hasChildren works fine, so on the top level i have "+" near the elements that has children. But when i try expand it - no child items are displayed. Here are some MySortFilterProxyModel methods:
bool MySortFilterProxyModel::hasChildren(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return false;
QModelIndex source_parent = mapToSource(parent);
return sourceModel()->hasChildren( source_parent.sibling(source_parent.row(), 0) );
}
int MySortFilterProxyModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return 0;
QModelIndex source_parent = mapToSource(parent);
return sourceModel()->rowCount( source_parent.sibling(source_parent.row(), 0) );
}
During degugging i found out that MySortFilterProxyModel::rowCount returns correct data. But also i notice that MyModel::rowCount is called not through the MySortFilterProxyModel::rowCount, but from QSortFilterProxyModel::index(). Peharps it's the problem?
So the particular question is What is the right way to implement proxy model for swapping and switching off columns in hierarchical model?
Help me please to solve the problem. Thank you.