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

Moving a mixture of visible and non-visible items produces incorrect result

    XMLWordPrintable

Details

    Description

      With the following code, press return to move the GridView content y to 120, then the space key to execute a move(1, 6, 3).

      Observe the result is as attached in actual.png, where the item order is:

      0 3 4
      5 6 7
      1 2 3
      8 9 10
      

      When instead it should be as attached in expected.png, i.e.

      0 4 5
      6 7 8
      1 2 3
      9 10 11
      

      This is because the GridView in QSGItemView::applyModelChanges() receives the following changes:

      • [Removal] index 1, count 2
      • [Insertion] index 6, count 2
      • [Insertion] index 8, count 1

      When in fact it should receive just

      • [Removal] index 1, count 3
      • [Insertion] index 6, count 3

      The move is executed correctly if the content y is not changed to 120 before executing the move. The problem seems to arise from moving a mixture of visible and non-visible items.

      import QtQuick 2.0
      
      Item {
          width: 500; height: 500
      
          GridView {
              id: view2
              cellWidth: 80; cellHeight: 60
              width: 240; height: 320
              x: 100
              y: 100
      
              model: ListModel {
                  id: model2
                  Component.onCompleted: {
                      for (var i=0; i<30; i++) {
                          append({'name': 'item ' + i, 'size': 20 })
                      }
                  }
              }
              delegate: Rectangle {
                  width: 80; height: 60; border.width: 1
                  Column {
                      Text { text: name + " : " + index + " : " }
                      Text { text: " " + parent.parent.x + ", " + parent.parent.y }
                  }
              }
      
              highlight: Rectangle { width: 100; height: 100; color: "red"; opacity: 0.5; z:2 }
      
              focus: true
              Keys.onReturnPressed: view2.contentY = 120
              Keys.onSpacePressed: model2.move(1, 6, 3)
          }
      
          Rectangle {
              anchors.fill: view2
              color: "lightsteelblue"
              opacity: 0.7
      
          }
      
          Text { anchors.right: parent.right; text: "content y:" + view2.contentY + ", count: " + model2.count }
      }
      

      Attachments

        1. actual.png
          actual.png
          53 kB
        2. expected.png
          expected.png
          53 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            denexter Andrew den Exter (closed Nokia identity) (Inactive)
            bealam Bea Lam (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes