Hello,

I'm trying to create a proxy for the simpletreemodel from the examples. But I have a problem translating the parent relation. The first level beneath the root works fine but my proxy doesn't get the right parents for the subitems.
Qt Code:
  1. QModelIndex CUserProxyNoMeta::index(int r, int c, const QModelIndex& parent) const
  2. {
  3. if (!hasIndex(r, c))
  4. return QModelIndex();
  5. return createIndex(r, c);
  6. }
  7.  
  8. QModelIndex CUserProxyNoMeta::mapFromSource(const QModelIndex& sourceIndex) const
  9. {
  10. if (!sourceIndex.isValid()){
  11. return QModelIndex();
  12. }
  13.  
  14. return index(sourceIndex.row(), sourceIndex.column());
  15. }
  16.  
  17. QModelIndex CUserProxyNoMeta::mapToSource(const QModelIndex& proxyIndex) const
  18. {
  19. if (!proxyIndex.isValid()){
  20. return QModelIndex();
  21. }
  22. return sourceModel()->index(proxyIndex.row(), proxyIndex.column());
  23. }
  24.  
  25. QVariant CUserProxyNoMeta::data(const QModelIndex& ind, int role) const
  26. {
  27. return sourceModel()->data(mapToSource(ind), role);
  28. }
  29.  
  30. QModelIndex CUserProxyNoMeta::parent(const QModelIndex& index) const
  31. {
  32. if (!index.isValid()){
  33. return QModelIndex();
  34. }
  35. return mapFromSource(sourceModel()->parent(mapToSource(index)));
  36. }
  37.  
  38. int CUserProxyNoMeta::rowCount(const QModelIndex& ind) const{
  39. return sourceModel()->rowCount(mapToSource(ind));
  40. }
  41.  
  42. int CUserProxyNoMeta::columnCount(const QModelIndex& ind) const
  43. {
  44. return sourceModel()->columnCount(mapToSource(ind));
  45. }
To copy to clipboard, switch view to plain text mode 

How can I get the right parent relations for the proxy?

Thanks,
Patrik