I insert on a QMap each first level node if is Expanded or not
CollState.insert(cid,isExpanded(node) ? 1 : 0 );

after user chance the page order criteria from a node i must reload the model and restore
all expanded item state..

this is run only on first level ..
How i can register the state from child ?

node.child show not valid ... but exist!

i can not use expandAll the are to many childs..

Qt Code:
  1. void PageList::savestate()
  2. {
  3. /* enum COLLAPSENR { COLLAPSEID = Qt::UserRole + 20 }; */
  4. CollState.clear(); /* QMap<int,int> CollState; clear old state */
  5. for (int r = 0; r < model->rowCount(); ++r) {
  6. for (int c = 0; c < model->columnCount(); ++c) {
  7. QModelIndex node = model->index(r,c);
  8. savestate(node);
  9. }
  10. }
  11. }
  12.  
  13. void PageList::savestate( const QModelIndex node )
  14. {
  15. if (!node.isValid()) {
  16. return;
  17. }
  18. const int cid = node.data(COLLAPSEID).toInt();
  19. if (CollState[cid]) { /* is register on qmap ? after clear */
  20. return;
  21. }
  22. CollState.insert(cid,isExpanded(node) ? 1 : 0 );
  23. savestate(node.child(node.row(),node.column()));
  24. }
  25.  
  26.  
  27. /* restore if expanded or not */
  28.  
  29. void PageList::staterestore( const QModelIndex node )
  30. {
  31. if (!node.isValid()) {
  32. return;
  33. }
  34. const int cid = node.data(COLLAPSEID).toInt();
  35. if (!CollState[cid]) {
  36. return;
  37. }
  38. if (CollState[cid] == 1) {
  39. setExpanded(node,true);
  40. }
  41. staterestore(node.child(node.row(),node.column()));
  42. }
To copy to clipboard, switch view to plain text mode