Hi,

I have a tree model:

A
|_AA
| |_id1 a b c d e f
| |_id2 e r t y i j
| |_id3 t f g h s w
| |_id4 l o m n h k
| |_id5 a b c d e f
| |_id6 a b c d e f
| |_id7 a b c d e f
| |_id8 a b c d e f

and I'd like to display it in the tree view as the following arrangement:

A
|_AA
| |_id1 id2 id3 id4
| |_id5 id6 id7 id8

Mapping algorithm would be:
if index has children then pass index otherwise map row to row/4, column to column%4 and don't display indices with column > 0.

I've reimplemented mapToSource, mapFromSource, filterAcceptsColumn:

Qt Code:
  1. bool MyProxyModel::filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const
  2. {
  3. return ( sourceParent.isValid() ||
  4. sourceParent.child(0,0).isValid() ||
  5. ( !sourceParent.child(0,0).isValid() && sourceColumn==0 )
  6. );
  7. }
  8.  
  9. QModelIndex MyProxyModel::mapFromSource( const QModelIndex & sourceIndex ) const
  10. {
  11. if(sourceIndex.isValid()) {
  12. if( sourceIndex.child(0,0).isValid() ) {
  13. return sourceIndex;
  14. } else {
  15. if( sourceIndex.column() == 0 ) {
  16. return createIndex(sourceIndex.row()/4, sourceIndex.row()%4);
  17. } else {
  18. return QModelIndex();
  19. }
  20. }
  21. } else {
  22. return QModelIndex();
  23. }
  24. }
  25.  
  26.  
  27. QModelIndex MyProxyModel::mapToSource ( const QModelIndex & proxyIndex ) const
  28. {
  29. if(proxyIndex.isValid()) {
  30. QStandardItem *item = (QStandardItem *) proxyIndex.internalPointer();
  31. if( item!=0 && item->hasChildren() ) {
  32. return proxyIndex;
  33. } else {
  34. return sourceModel()->index(
  35. proxyIndex.row()*4 + proxyIndex.column(),
  36. 0,
  37. proxyIndex.parent()
  38. );
  39. }
  40. } else {
  41. return QModelIndex();
  42. }
  43. }
To copy to clipboard, switch view to plain text mode 

I'm crashing while clicking on AA and trying to expand it.
( QTreeViewPrivate::layout(int i); line 3130 Q_Assert(i>-1) )

I'd appreciate ideas on how to approach this issue.

Cheers,
Wojtek