×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    ListModel and ListView index

    Hallo there,
    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)
    
                                }
                            }
                        }
    ....
    So, when the image "content/pics/arrow-up.png" is clicked, one item in the model is moved up by one position, now, in the example there are four items in order: "Apple"-"Banana"-"Cumqat"-"Durian" and this is the result of consol.log if I click "up" on the "Banana" moving that item to the first position:

    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
    then, nothing seems to change when I modify the text in the TextEdit and I try to take the "name",

    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 have I have been clear, Thank you very much,
    Giammarco
    Last edited by GiammarcoF; 2012-05-02 at 19:24.

  2. #2
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    Re: ListModel and ListView index

    I see two possibilities
    1. Reloading the listView after operation
    2. Creating a property and binding function with the propertyChanged slot

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    5

    Re: ListModel and ListView index

    uhm ok, can you explain it a little bit better? If I reload the listView then all the changes in the textEdit will be lost, am I wrong? I should update the database with those data before calling the "move" function.

    For the second suggestion, how can I set this property? "property alias myProperty =" what ?

    Thank you for your answer!

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    Re: ListModel and ListView index

    Maybe you could put the textEdit data into the listModel also, and them reload?
    To say the truth, I couldn't catch the root of actual problem. But I could give you a little suggestion.
    There's a toDo manager app in qml examples of nokia developer, that app supports arranging, and saving positions of list items. Maybe you should take a look in there?

Similar Threads

  1. listview scrolling current index
    By AdnanShoukat in forum [Archived] Qt Quick
    Replies: 4
    Last Post: 2012-04-09, 06:34
  2. QML ListView positionViewAtIndex always moving to index 1
    By birch01 in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2012-03-23, 12:32
  3. GridView within a ListView using a Nested ListModel
    By Interactive-lem1313 in forum [Archived] Qt Quick
    Replies: 0
    Last Post: 2011-12-19, 10:41
  4. How should we create a Array of ListModel ?
    By biren in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-11-22, 09:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×