[SailfishDevel] Issue with ListView.currentIndex

François K. daitheflu at free.fr
Fri Feb 6 15:10:14 UTC 2015


Hi,

Me again !

Disclaimer : I'm pretty new in Sailfish development, and this mail is rather long, because I'm trying to be precise.

Allright, I'm stuck by a "weird" issue that involves a SilicaListView, sections, currentIndex and cover.

My SilicaListView is divided in 2 sections : items marked as "favorite" are on the top of the list, and the others ones come after.
I'm using ListView.section property with a SortFilterProxyModel to achieve this. And it works pretty nicely.

On the cover of my app, I'm trying to show only the Favorites. The behavior I want is the following :
  If I don't have favorites, a placeholder is shown.
  If I have one favorite, it's shown.
  If I have more than one favorite, the first one is shown, and a coverAction allows me to chose the 2nd one, then the 3rd one, etc... (cycle through favorites).

To achieve this, I've bound the values displayed on the cover to the SilicaListView.currentItem properties :
  When the SilicaListView.currentItem changes, the values on the cover are updated accordingly.
  To select the next favorite from the cover, I just have to increment the SilicaListView.currentIndex which makes the SilicaListView.currentItem change, and updates the cover.

Now the tricky part comes when I remove items from favorites : I have to keep the SilicaListView.currentIndex updated and coherent.
In most cases, it's pretty easy.

BUT, in one case, I get a problem :
When I try to remove the first favorite (row zero) AND when this is the item displayed on the cover (currentIndex = 0) AND there are others favorites, the currentIndex must be kept to zero.
And for some reason, Qt updates it to the new index of the item that is being removed. Note that the 3 conditions have to be true to see this happen. It seems to be the only case where Qt updates the currentIndex.

I can understand that Qt updates the currentIndex, but why only in this particular case ?
How can I fix this ?

Thanks a lot,

-- 
François


More information about the Devel mailing list