Hello,

I'm trying to alter a QFileSystemModel by means of a subclassed QidentityProyModel. The alteration consists in removing all rows but one at a specific location in the proxy model, and I don't want any modifications in the source model.
I tried to reimplement the mapToSource and mapFromSource methods that way:
Qt Code:
  1. QModelIndex RootItemProxyModel::mapFromSource(const QModelIndex & sourceIdx) const
  2. {
  3. // If the proxy is not activated, use the base mapFromSource function.
  4. if (m_ActivatedProxy == false)
  5. return IdentityFileSystemProxyModel::mapFromSource(sourceIdx);
  6.  
  7. // Alter the mapping so the proxy model sees only m_rootSrcIdx's row as m_rootSrcParentIdx child.
  8. if (sourceIdx.parent().internalPointer() == m_rootSrcParentIdx.internalPointer())
  9. {
  10. if (sourceIdx.row() != 0)
  11. return QModelIndex();
  12. else
  13. return createIndex(0,
  14. sourceIdx.column(),
  15. sourceModel()->sibling(m_rootSrcIdx.row(),sourceIdx.column(),m_rootSrcIdx).internalPointer());
  16. }
  17. // In any other cases, use the base mapFromSource function.
  18. return IdentityFileSystemProxyModel::mapFromSource(sourceIdx);
  19. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QModelIndex RootItemProxyModel::mapToSource(const QModelIndex & proxyIndex) const
  2. {
  3. // If the proxy is not activated, use the base mapToSource function.
  4. if (m_ActivatedProxy == false)
  5. return IdentityFileSystemProxyModel::mapToSource(proxyIndex);
  6.  
  7. // Alter the mapping so the proxy model sees only m_rootSrcIdx's row as m_rootSrcParentIdx child.
  8. QModelIndex sourceIdx = IdentityFileSystemProxyModel::mapToSource(proxyIndex);
  9. if (sourceIdx.parent().internalPointer() == m_rootSrcParentIdx.internalPointer())
  10. {
  11. if (proxyIndex.row() != 0)
  12. return QModelIndex();
  13. else
  14. return sourceModel()->sibling(m_rootSrcIdx.row(),
  15. proxyIndex.column(),
  16. m_rootSrcIdx);
  17. }
  18. // In any other cases, use the base mapToSource function.
  19. return sourceIdx;
  20. }
To copy to clipboard, switch view to plain text mode 
The only examples I could find about mapToSource and mapFromSource reimplemented methods were for transpose proxy models in which each Modelindex in the Source model maps to a Modelindex in the Proxy model. In my case, the Proxy model has less Modelindexes than the SourceModel. I return QModelIndex() for any ModelIndex that maps to, or from, a ModelIndex that belong to the rows I want to remove.
I'm not sure that it is what I should return in that case. I'm not even sure that my overall strategy is correct.

If someone experienced can put me on the right track, that would be great.
Thanks.