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

Wrong DelegateModelGroup emits changed signal during move

    XMLWordPrintable

Details

    • Linux/X11
    • 32de8dce311ddc562f88db47149c702fe9dcc950 (qt/qtdeclarative/5.12)

    Description

      If I move an Item of a DelegateModel within one of its groups (DelegateModelGroup), the `changed` signal is emitted for another group.

      Let's say I have a DelegateModel with it's standard `items` group and an additional `visible` group:

          DelegateModel {
              id: delegateModel
              model: fruitModel
              delegate: delegate
              filterOnGroup: "visible"
              groups: [
                  DelegateModelGroup {
                      id: visibleGroup
                      name: "visible"
                      includeByDefault: false
                  }
      
              ]
          }
      

      Let's say I added all items to the visible group and move them around within that group using visibleGroup.move. This always causes the items group to emit the changed signal, even though no member in the items group has been inserted or removed and the move of an item was performed for visibleGroup.

      Summarized:

      delegateModel.items.onChanged = function (){
          console.log("Changes in items");
      }
      // move item in visibleGroup
      visibleGroup.move(visibleGroup.count - 1, 0, 1); // causes: "Changes in items"
      

      If this was intended behaviour, the documentation of DelegateModel would lack clarity.

       

      The following example illustrates the problem in detail. Every 800ms, the visible items are moved around and the items group always receives a signal.

       

       

      import QtQuick.Window 2.2
      import QtQuick 2.6
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      import QtQml.Models 2.11
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Error 1")
          ListView {
              anchors.fill: parent
              model: delegateModel
          }    
          DelegateModel {
              id: delegateModel
              model: fruitModel
              delegate: delegate
              filterOnGroup: "visible"
              groups: [
                  DelegateModelGroup {
                      id: visibleGroup
                      name: "visible"
                      includeByDefault: false
                  }
              ]
              function parameterToString(parameter) {
                  var result = "";
                  for(var i=0; i<parameter.length; ++i) {
                      if(result.length>0) result = result + ", "
                      result = (result + "[" + parameter[i].index + ", "
                                + parameter[i].count + "]");
                  }
                  return "{" + result + "}";
              }
              items.onChanged: {
                  console.log("items.onChanged",
                              parameterToString(removed),
                              parameterToString(inserted));
              }
          }
          Component {
              id: delegate
              Rectangle {
                  anchors.left: parent.left
                  anchors.right: parent.right
                  height: 30
                  Text {
                      text: "Data: " + name + " costs " + cost
                  }
              }
          }
          ListModel {
              id: fruitModel
              ListElement {
                  name: "Apple"
                  cost: 2.45
              }
              ListElement {
                  name: "Orange"
                  cost: 3.25
              }
              ListElement {
                  name: "Banana"
                  cost: 1.95
              }
              ListElement {
                  name: "Ananas"
                  cost: 1.95
              }
              ListElement {
                  name: "Pear"
                  cost: 1.95
              }
              ListElement {
                  name: "Grapes"
                  cost: 1.95
              }
              ListElement {
                  name: "Lemon"
                  cost: 1.95
              }
              ListElement {
                  name: "Apricot"
                  cost: 1.95
              }
          }
          Timer {
              id: changeModelTimer
              property int count: 0
              interval: 800
              onTriggered: {
                  count++;
                  console.log("Iteration", count);
                  visibleGroup.move(visibleGroup.count - 1, 0, 1);
                  if(count>=100) {
                      Qt.quit()
                  }
              }
              repeat: true
          }
          Component.onCompleted: {
              delegateModel.items.setGroups(0, delegateModel.items.count, ["items"]);
              delegateModel.items.addGroups(0, delegateModel.items.count, ["visible"]);
              changeModelTimer.start();
          }
      }
      
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            robert_most Willy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes