Results 1 to 1 of 1

Thread: Incrementing and decrementing ListView

  1. #1
    Join Date
    Jun 2018
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Incrementing and decrementing ListView

    I have an element that is a delegate for a ListView and it is loading this or that component depending on certain properties of the model like so:

    Qt Code:
    1. Component.onCompleted:
    2. {
    3. ...
    4. else if(typeof(modelData.value) === "string" && modelData.optionsList.length === 0)
    5. {
    6. _firstLoader.sourceComponent = _textEntryComponent
    7. _valueContainerItem.objectName = "textbox"
    8. }
    9. else if(modelData.is_boolean)
    10. {
    11. _firstLoader.sourceComponent = _booleanComponent
    12. _valueContainerItem.objectName = "boolean switch"
    13. }
    14. ...
    15. }
    To copy to clipboard, switch view to plain text mode 

    The model is essentially just various properties defined in the back end. Here is the ListView (wizard):

    Qt Code:
    1. ListView
    2. {
    3. id: setupList
    4.  
    5. onCurrentIndexChanged: vehicleSetupTitle.text = model[setupList.currentIndex].label
    6. model: currentSelectedVehicle.propertiesForVehicle
    7. delegate: Item
    8. {
    9. id: buffer
    10.  
    11. HardwareSettingsDisplay
    12. {
    13. title: modelData.label
    14. onProgressWizard:
    15. {
    16. setupList.incrementCurrentIndex()
    17. currentSelectedImplement.setLastConfigurationResumeStep(setupList.currentIndex)
    18. }
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    Where ProgressWizard is a signal created in HardwareSettingsDisplay that fires whenever the user makes an acceptable selection for one of the different components:

    Qt Code:
    1. signal progressWizard
    To copy to clipboard, switch view to plain text mode 

    Alright, so I am having trouble with increment/decrement. So when I want to increment the wizard the user makes a selection and that selection fires the progressWizard() function which moves the wizard forward, in theory. However, I am getting odd behavior so I threw in some print statements:

    Qt Code:
    1. onModelChanged:
    2. {
    3. console.info("Model just changed.")
    4. console.info("Current index: ", setupList.currentIndex)
    5. console.info("Last configuration step: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    6. }
    7.  
    8. onCurrentIndexChanged:
    9. {
    10. console.info("Index just changed.")
    11. console.info("Current index: ", setupList.currentIndex)
    12. console.info("Last configuration step: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    13.  
    14. visible ? vehicleSetupTitle.text = model[setupList.currentIndex].label : ""
    15. }
    16.  
    17. onProgressWizard:
    18. {
    19. console.info("Progress wizard called. Current index value: ", setupList.currentIndex)
    20. console.info("Last configuration step: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    21. setupList.incrementCurrentIndex()
    22. console.info("Progress wizard called. Index was just incremented: ", setupList.currentIndex)
    23. console.info("Last configuration step: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    24. presentationManager.settingsPresenter.currentSelectedImplement.setLastConfigurationResumeStep(setupList.currentIndex)
    25. console.info("Last configuration step just set too current index: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    26. }
    To copy to clipboard, switch view to plain text mode 

    Here is the output:

    //First thing I do is create a new item. It seems to print everything twice
    qml: Index just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Index just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 0

    //Now I enter in a name. The wizard progresses and all seems well but the last configuration step isn't being set properly for some reason
    qml: Progress wizard called. Current index value: 0
    qml: Last configuration step: 0
    qml: Index just changed.
    qml: Current index: 1
    qml: Last configuration step: 0
    qml: Progress wizard called. Index was just incremented: 1
    qml: Last configuration step: 0
    qml: Last configuration step just set too current index: 0

    //Now I hit the boolean switch and the wizard goes backwards
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 0

    How is this possible it's not calling: setupList.decrementCurrentIndex() it's not even calling progressWizard() the only thing I can think is that changing the model is somehow reloading the entire Item or ListView. If that's the case then maybe I can do something like this:

    Qt Code:
    1. onModelChanged:
    2. {
    3. setupList.currentIndex = presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep
    4. setupList.positionViewAtIndex(setupList.currentIndex, ListView.Beginning)
    5. }
    To copy to clipboard, switch view to plain text mode 

    but until I can figure out why my setter isn't working... but that might not even be the case or the best solution here. So I wanted to post my problem here in the hopes that you guys could take a look and help me out if you can think of something I am not doing or am doing wrong please let me know.


    EDIT:

    I figured out why the last configuration step wasn't being set so I tried the onModelChanged idea:

    Qt Code:
    1. onModelChanged:
    2. {
    3. console.info("Model just changed.")
    4. console.info("Current index: ", setupList.currentIndex)
    5. console.info("Last configuration step: ", presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep)
    6.  
    7. setupList.currentIndex = presentationManager.settingsPresenter.currentSelectedVehicle.lastConfigurationStep
    8. setupList.positionViewAtIndex(setupList.currentIndex, ListView.Beginning)
    9. }
    To copy to clipboard, switch view to plain text mode 

    it worked... for the second component. However, the third component is now sending me back to the second component

    Output

    //First creation nothing changed
    qml: Index just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Index just changed.
    qml: Current index: 0
    qml: Last configuration step: 0
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 0

    //Text element component entry now reports everything correctly and all seems well. wizard progresses:
    qml: Progress wizard called. Current index value: 0
    qml: Last configuration step: 0
    qml: Index just changed.
    qml: Current index: 1
    qml: Last configuration step: 0
    qml: Progress wizard called. Index was just incremented: 1
    qml: Last configuration step: 0
    qml: Last configuration step just set too current index: 1

    //Second boolean component is no longer sending me backwards but the index is definitely being reset for some reason:
    qml: Index just changed.
    qml: Current index: 0 //index reset
    qml: Last configuration step: 1
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 1
    qml: Index just changed.
    qml: Current index: 1 //index set to last configuration onModelChanged
    qml: Last configuration step: 1

    //So I hit next and come to another component which is a List Selection component but it's sending me backwards
    qml: Index just changed.
    qml: Current index: 0 //Got reset to zero
    qml: Last configuration step: 1
    qml: Model just changed.
    qml: Current index: 0
    qml: Last configuration step: 1
    qml: Index just changed.
    qml: Current index: 1 //frustrating...
    qml: Last configuration step: 1
    Last edited by Vysero; 17th February 2020 at 23:23. Reason: updated contents

Similar Threads

  1. Listview inside Listview inside Treeview
    By Tomundo in forum Qt Programming
    Replies: 3
    Last Post: 11th April 2017, 01:47
  2. Replies: 2
    Last Post: 17th May 2016, 00:50
  3. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 11:18
  4. listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 23rd June 2013, 11:51
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 13:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.