[Qt-interest] [QModelIndex/QAbstractItemView] sorted/not sorted ?

Castagne Nicolas nicolascastagne at yahoo.fr
Thu Dec 3 17:53:02 CET 2009


Hello,

Anyhow, "sorted QModelIndex" does mean  much in itself for a QAbstractItemView, since "sorting" could be made by row by column, by respecting the tree, etc.

When I've needed sorted list of 'selected model index ', I've used two solutions so far :

1/ go through all the indexes, in the order I want, and for each test if it is selected. Quite problematic when having very large data set, though...

2/ instead of sorting the index list itself, retrieve the QItemSelectionModel::selection (), and work on sorting the QItemSelectionRange it contains.
This allows to speed up the sorting process.

As for the "order" used by Qt to maintain the "list" of selected indexes, I have never relied on it and dunno its logic.

Hope this helps,
Best
Nicolas

--- En date de : Jeu 3.12.09, BRM <bm_witness at yahoo.com> a écrit :

De: BRM <bm_witness at yahoo.com>
Objet: Re: [Qt-interest] [QModelIndex/QAbstractItemView] sorted/not sorted ?
À: St.Vogelsang at gmx.de, qt-interest at trolltech.com
Date: Jeudi 3 Décembre 2009, 15h19

----- Original Message ----

> From: "St..Vogelsang at gmx.de" <St.Vogelsang at gmx.de>
> According to the documentation:
> http://qt.nokia.com/doc/4.5/qabstractitemview.html#selectedIndexes
> QModelIndexList QAbstractItemView::selectedIndexes () const;
> provides a _not_ sorted list. 
> Since I really need a sorted one, I implemented a sort algorithm. 
> But my debug-code shows always a already sorted List.. So I'm interested in understanding when (maybe memory allocation) or on which other circumstances the list gets unsorted. 
> Or is it a documentation bug?

>From my (limited) experience with that part of the API - you can select items in a row or randomly.
Qt provides a list of all the selected items, typically from start to end as they are displayed without any sorting applied.
The list may also not be fully continuous - that is you might have indices 1, 3-5, and 7 selected.

So - to sum it - it'll be sorted by index, but not necessarily continuous; not by the data be displayed.
That's not to say you can't sort it; though when I did my work a while back with it it was kind of bumpy as there doesn't seem to be an easy way to move around entries.
(I resorted to remove from one index then adding it back at another index; and had to be very careful about the order I did things in in order to keep the original selection list valid.)

Ben

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest



      





More information about the Qt-interest-old mailing list