PDA

View Full Version : Invalid QItemSelection from QItemSelectionModel



TheRonin
9th February 2010, 08:38
I have a custom table where items are placed; one per row with a number of columns dedicated to item properties. My table supports extended selection. The items in my table are sorted according to a convoluted scheme. The item order may be changed dramatically at any time (trust me, it's not as weird as it sounds) based on external events.

It is important for me to retain the selection such that items selected prior to resorting will still be selected afterwards, regardless of their new position in the table. Therefore my data model emits signals before and after a call to the sorting method. The table view saves and resets the item selection in response to the model's signals.

When an item in a selection is removed from the table, the remaining items should still be selected. Deletion is implemented as removal from the table model's data followed by a call to removeRow. If the item removed is the first in the table (row 0), the selected and deselected QItemSelections in my receiving class both contain several invalid selections {tons of (row,column)==(-1,-1) with isValid()==false}. This only happens when more than one item is selected and row 0 is removed.

Example: the items from row 0 and 1 are selected and row 0 is deleted.
selected: (-1,-1) (-1,-1) ... (-1,-1) // n-times where n == number of columns.
deselected: (-1,-1) (-1,-1) ... (-1,-1) /* same as selected */ (0,0) (0,1) (0,2) ... (0,n)

Why am i getting the invalid selection? If i change the selection manually after the programmatic reselection i don't get this problem. I could work around the fact that a selection is invalid but i would like to understand the root of the problem.

Thanks in advance!

TheRonin
9th February 2010, 16:31
Why am i getting the invalid selection?

Could the problem be caused by deleting the data from the model before doing removeRow?

I changed the item deletion implementation to do removeRow before removing the data and my program no longer crashes. However, I'm not sure if i've cured the disease or just made a symptom dissapear. Thoughts? Comments?