Picker: selectedIndex changes incorrectly when removing model entries

Bug #1344883 reported by Sam Bull
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-ui-toolkit (Ubuntu)
Triaged
High
Zsombor Egri

Bug Description

I've attached a minimal program to demonstrate the problem.

The Model contains 20 items, and the selectedIndex is at 18.
Clicking the button below will remove the item at index 10.
Expected behaviour:
  Picker keeps number 18 selected.
Actual behaviour:
  Picker jumps to number 9, the index before the one just deleted.

Observe that when changing the button code to remove index 3 instead of 10, the picker works correctly, and remains at item 18.

The behaviour only breaks on some index removals.

inserts appear to behave correctly.

Zsombor Egri (zsombi)
Changed in ubuntu-ui-toolkit:
assignee: nobody → Zsombor Egri (zsombi)
importance: Undecided → High
status: New → Triaged
Zoltan Balogh (bzoltan)
Changed in ubuntu-ui-toolkit (Ubuntu):
assignee: nobody → Zsombor Egri (zsombi)
importance: Undecided → High
status: New → Triaged
Zoltan Balogh (bzoltan)
no longer affects: ubuntu-ui-toolkit
Revision history for this message
Sam Bull (dreamsorcerer) wrote :

I've now switched to using PageHeadSections for this, and am experiencing much the same issue. If I insert something before the current index I need to add 1 to the selected index to compensate, and the reverse for removal.

summary: - Picker: selectedIndex changes incorrectly when removing model entries
+ PageHeadSections/Picker: selectedIndex changes incorrectly when
+ inserting/removing model entries
Revision history for this message
Zsombor Egri (zsombi) wrote : Re: PageHeadSections/Picker: selectedIndex changes incorrectly when inserting/removing model entries

Your sample code doesn't remove items from the model, but inserts.

The behaviour you experience is due to both components using ListView (PathView or GridView behaves the same). When you alter the model, the currentIndex won't necessarily point to the same item was pointing anymore. Removing an element from the ListView will cause currentIndex to change as well. This bug is more related to ListView than to Picker itself.

Try the same with a ListView, and I'm sure you'll experience the same.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

OK, the section headers are not the same issue as the picker component. I've attached a new example showing both.

With both components set to index 12:
  After removing item 8, the section header moves to item 13, but the picker jumps to item 7.
  After removing item 3, the section header moves to item 13, whereas the picker remains on item 12.

I can't test this with a ListView directly, as it does not have a selectedIndex.
So, the picker jumps down to the deleted item on some indices and remains pointing at the correct item on others.
I've registered a separate bug for the off by one behaviour of the section header (bug #1493040).

Revision history for this message
Zsombor Egri (zsombi) wrote :

ListView has currentIndex, which is the selected one. Picker.selectedIndex works with that property as well. Then Sections.selectedIndex is not interacting with any ListView or such, so that works a bit differently, it always moves to the last item in the model when changes afaik.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Tried it with ListView by printing numModel.get(listview.currentIndex).num.
This behaves correctly, and always stays on the 12, until that item is removed.

The issue described is present in ONLY the Picker component.

summary: - PageHeadSections/Picker: selectedIndex changes incorrectly when
- inserting/removing model entries
+ Picker: selectedIndex changes incorrectly when removing model entries
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.