Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54156

Invalid QQuickTreeModelAdaptor behavior.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.6.0
    • Quick: Controls 1
    • None
    • Shovelling Snow, Q1/2020 Finale

    Description

      Method QQuickTreeModelAdaptor::lastChildIndex (C:\Qt\Qt5.6.0\5.6\Src\qtquickcontrols\src\controls\Private\qquicktreemodeladaptor.cpp, 496) returns invalid child node inserion row index in case, where sbling model item is expanded, and has children (while (parent.isValid())... code branch). Method returns last visible child row index of PARENT item, instead of item, given in index parameter. This results in difference in model layout on side of QQuickTreeModelAdaptor::m_items and source QAbstractItemModel. Later notifications about source model structure and layout changes (rowInserted, rowsRemoved, layoutChanged) causes view model layout corruption, tree "falling apart" visually.

      Simplest way to reproduce. Source model sctructure:

      VirtualRoot
      ├ A
      │ └ B
      └ D

      Now, if this model is visible and expaned in QML TreeView, and node C is added in source model in a VirtualRoot after node A:

      VirtualRoot
      ├ A
      │ └ B
      ├ C
      └ D

      In GUI it will be placed after D instead:

      VirualRoot
      ├ A
      │ └ B
      ├ D
      └ C

      because QQuickTreeModelAdaptor::lastChildIndex will return row insert index 3 instead of 2. Now when tree is in this state, if user will rename node C, for example, to Z, and QAbstractItemModel::layoutChanged notification will fire, then visual appearance of a tree will remain the same, or glitch, but selection logic will break. I haven't debugged exact logic behind this, but it'd definitely caused by layout differences between source model and QQuickTreeModelAdaptor. Later notifications about node additions or removals will cause all sorts of incosistent tree behavior.

      Reproduction example. How to use:
      1. Start application and expand all nodes.

      2. Click "Add new" and notice new node "C" is placed at incorrect position.

      3. Click "Rename" and notice that node "D" is renamed to "Z", but tree is not sorted.

      4. Try to collapse "X" node and notice tree consistency corruption.

      5. Try to collapse and expand "Root" node and notice further tree consistency corruption.

      Notice, that when "A" node is collapsed, at the moment of "C" node addition, new node is placed at correct position.

      Attachments

        1. step1.png
          step1.png
          7 kB
        2. step2.png
          step2.png
          8 kB
        3. step3.png
          step3.png
          7 kB
        4. step4.png
          step4.png
          8 kB
        5. step5.png
          step5.png
          8 kB
        6. TreeViewBug.zip
          33 kB
        7. TreeViewBug2 (2).zip
          788 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              richard Richard Moe Gustavsen
              johnwhiter John Whiter
              Votes:
              6 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes