VSRonin / QtModelUtilities

A set of utilities for the model/view framework of Qt
Apache License 2.0
24 stars 5 forks source link

Crash when multiple RootIndexProxyModels have sibling rootIndexes #53

Closed vserdyuk closed 8 months ago

vserdyuk commented 1 year ago

Suppose we have the following tree model:

root
    - A <- first RootIndexProxyModel's rootIndex
        - C
        - D  
        - empty <- when a new row gets inserted here
    - B <- second RootIndexProxyModel's rootIndex
        - E
        - empty
        - empty <- beginInsertRows gets called here

How to reproduce:

  1. Have one source tree model with two sibling subtrees (e.g. above is A subtree with two child rows and B subtree with one child row). One sibling has more rows than the other.
  2. Create two RootIndexProxyModels pointing to the same source model
  3. Set their rootIndexes to siblings in the source model
  4. Insert a new child row to the first sibling which has more rows (A)
  5. Assert gets failed, deubg build crashes.

The problem is that second sibling (B) erroneously calls beginInsertRows passing row more than its rowCount. I modified one test to reproduce the problem (test.patch).

I made a workaround that fixes rows/columns insertion/deletion and it works fine in my project (workaround.patch).

However, this workaround is not complete because I did not fix moving rows/columns and changing layout (I suppose, all signal handlers onXxx should be modified). I did not complete the fix as PR because I don't have full understanding of the code that processes moving rows/columns and changing layout (I haven't had the chance to use this in my project yet).