VisualDataModel : 'model' property modification problem
-
Hello everyone. I'm facing a problem with a VisualDataModel element.
I want to modify the 'model' property of a VisualDataModel but the views using this visual data model are acting weirdly after the change.
Is it a bug or is there a means to fix that behavior ?
Thanks in advance for your answers.Here is a piece of code inspired by an example from Qt highlighting this problem (tested with Qt 4.8.0 and 4.8.4):
@import QtQuick 1.1
Rectangle {
id: root
color: "white"
width: 400
height: 150
property bool mySwitch: trueListModel { id: myModel property string name: "model1" ListElement { display: "One" } ListElement { display: "Two" } ListElement { display: "Three" } ListElement { display: "Four" } } ListModel { id: myModel2 property string name: "model2" ListElement { display: "Orange" } ListElement { display: "Apple" } ListElement { display: "Pear" } ListElement { display: "Banana" } } //![0] VisualDataModel { id: visualModel delegate: delegate model: root.mySwitch ? myModel : myModel2 } ListView { width: 200; height:100 model: visualModel.parts.list } GridView { x: 200; width: 200; height:100 cellHeight: 50 model: visualModel.parts.grid } //![0] Rectangle { color: "red" anchors.left: parent.left anchors.bottom: parent.bottom anchors.right: parent.right height: 50 Text { anchors.centerIn: parent text: "Click Me !" } MouseArea { anchors.fill: parent onClicked: { root.mySwitch = !root.mySwitch; console.log(visualModel.model.name) } } } Component { id: delegate Package { Text { id: listDelegate; width: 200; height: 25; text: 'Empty'; Package.name: 'list' } Text { id: gridDelegate; width: 100; height: 50; text: 'Empty'; Package.name: 'grid' } Rectangle { id: wrapper width: 200; height: 25 color: 'lightsteelblue' Text { text: display; anchors.centerIn: parent } MouseArea { anchors.fill: parent onClicked: { if (wrapper.state == 'inList') wrapper.state = 'inGrid'; else wrapper.state = 'inList'; } } state: 'inList' states: [ State { name: 'inList' ParentChange { target: wrapper; parent: listDelegate } }, State { name: 'inGrid' ParentChange { target: wrapper; parent: gridDelegate x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height } } ] transitions: [ Transition { ParentAnimation { NumberAnimation { properties: 'x,y,width,height'; duration: 300 } } } ] } } }
}@