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

ObjectModel::move() does not mark the changes as moves

    XMLWordPrintable

    Details

    • Commits:
      95f6dcbae17b72c8dfebc9f97c77310151b63ceb

      Description

      A ListView does not retain its currentIndex when moving objects in an ObjectModel. This is because QQmlObjectModel::move() creates a QQmlChangeSet with moveId -1 and therefore QQmlChangeSet::isMove() returns false. QQuickItemView does not see these changes as moves, but as removals and insertions, so the current index does not follow as it should.

      Steps to reproduce:

      • double click any item in the list
      • the item moves to the next position in the list

      Expected result:

      • the current index follows

      Actual result:

      • the current index leaves behind
      import QtQuick 2.7
      import QtQuick.Window 2.2
      import QtQml.Models 2.2
      
      Window {
          id: window
          width: 360
          height: 360
          visible: true
      
          ListView {
              id: listview
              anchors.fill: parent
              model: ObjectModel {
                  id: objectmodel
                  MouseArea {
                      width: listview.width; height: 20
                      Rectangle { anchors.fill: parent; color: "lightcoral"; border.width: parent.ListView.isCurrentItem }
                      onClicked: listview.currentIndex = ObjectModel.index
                      onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3)
                  }
                  MouseArea {
                      width: listview.width; height: 20
                      Rectangle { anchors.fill: parent; color: "lightsteelblue"; border.width: parent.ListView.isCurrentItem }
                      onClicked: listview.currentIndex = ObjectModel.index
                      onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3)
                  }
                  MouseArea {
                      width: listview.width; height: 20
                      Rectangle { anchors.fill: parent; color: "lightgreen"; border.width: parent.ListView.isCurrentItem }
                      onClicked: listview.currentIndex = ObjectModel.index
                      onDoubleClicked: objectmodel.move(ObjectModel.index, (ObjectModel.index + 1) % 3)
                  }
              }
          }
      }
      

        Attachments

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

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jpnurmi J-P Nurmi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes