I have a little problem with ListModel and ListView, in particular concerning the move function of ListModel. I will show you code snippets from the DynamicList example included in the SDK with some modifications just to debug it: Code:
Item {
property alias nameText: nameTextBox.text
id: delegateItem
width: listView.width; height: 55
clip: true
Row {
anchors.verticalCenter: parent.verticalCenter
spacing: 10
Column {
Image {
source: "content/pics/arrow-up.png"
MouseArea {
anchors.fill: parent;
onClicked: {
var voice
var nameInModel
var nameInView
voice = listView.contentItem.children[1]
nameInModel = fruitModel.get(1).name
nameInView = voice.nameText
console.log("name before move in model at 1: "+nameInModel)
console.log("name before move in list at 1: "+nameInView)
fruitModel.move(index, index-1, 1)
voice = listView.contentItem.children[1]
nameInView = voice.nameText
nameInModel = fruitModel.get(1).name
console.log("name after move in model at 1: "+nameInModel)
console.log("name after move in list at 1: "+nameInView)
}
}
}
....
因此,在点击“相传/宇宙/甚长......png”图像时,模型中的一个项目被一个位置移,现在,例如有四个项目,以便“Apple”-“Banana”-“Cumqat”-“Durian”,这是结局的结果。 如果我点击“巴纳纳”的“上号”,将该项目移至第一个位置:
name before move in model at 1: Banana name before move in list at 1: Apple name after move in model at 1: Apple name after move in list at 1: Apple
This is what happens if I click on Apple (that now is in the 2nd place) to moving it to the 1st position:
name before move in model at 1: Apple name before move in list at 1: Apple name after move in model at 1: Banana name after move in list at 1: Apple
So, first of all it is evident that the first index of ListModel is 0 while the first index of ListView is 1, then it is evident that items in the model have been moved but items in the list have not. Now, this is my problem: Imagine that "name" is the text of a TextEdit, so the the ListView delegate includes a TextEdit and it can be edited by the user. If I want to take that text I know that I can do this: Code:
for (var i = 0; i <= myListView.count; i++){
myItem= myListView.contentItem.children[i]
myName = myListView.name
But here is the problem, in my ListView there is also the possibility to move the items by using the move function of ListModel but if I move items and I use the previous cycle to take the "name" nothing seems to change (exactly as in the DynamicList example). On the other hand, if I take the "name" by using:
myName= myListModel.get(i).name
那么,在我修改文本Edit案文时,似乎没有任何变化,我试图采用“名称”,
So, what I have to do to obtain a ListView with TextEdit and with the possibility to move itemsof which I can record any changment?
I hope I have been clear, Thank you very much, Giammarco