3

I'm trying to use beginMoveRows / endMoveRows to make persistent indexes stick, but sometimes expanded state flags / persistent indexes are duplicated, where they should not be.

There is quite a lot of code, so I'll go through what I think I have told the machine to do:

There is a method, sortChildrenOf(item) which does all the magic.

  • Find children from item and call sortChildrenOf with each child as a parameter
  • save old order
  • quickSort children
  • find differences in old order and the new
  • for each difference:
  • beingMoveRows
  • apply change
  • endMoveRows

Everything works perfectly when there are 2 levels, but when I input a "long" tree of data, persistent indexes get corrupted.

The data in the tree is updated from network, but the actual update is done in the gui thread.

Is there some precise order I should do stuff in? Might I have forgotten to inherit some method that causes this?

I'v got these methods implemented: - data - flags - getItem - index - parent - setData

Edit: forgot to mention, i got emit layoutAboutToBeChanged and emit layoutChanged before and after the main sortChildrenOf call.

0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46
  • 1
    I could be way off, but are you emitting layoutChanged() signal after sorting? I usually just do layoutAboutToBeChanged() -> sort -> layoutChanged() and don't even need beginMoveRows() and endMoveRows(). – LLLL Jul 30 '13 at 11:17
  • Yes, i'm doing that. It didn't occur to me that it could work without the begin and endmove method calls. I'll try to remove them and see what happens. Did your sort work recursively on child data? – 0xbaadf00d Jul 30 '13 at 11:48
  • Removing beginMoveRows and endMoveRows removed persistent indices completely. What this causes is that the selection doesn't stick to the data, it sticks to the position. If user selects "Node 10" I want it to stick to "Node 10". – 0xbaadf00d Jul 30 '13 at 11:58

1 Answers1

2

I got it to work, but not with beginMoveRows and endMoveRows. I used the old system of emitting layoutAboutToChange getting the list of persistent indexes manipulating that and setting it back with changePersistentIndexList and finally emitting layout changed.

Since this was the fix, I'm lead to believe that there is some bug withtin beginMoveRows, endMoveRows and persistent indexes with tree type data.

Ask if you need a better example of the code.

0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46