PDA

View Full Version : multiple sort



baray98
23rd August 2009, 06:15
I have an QSqlQueryModel attached to QTableView and I would like to supprt multiple column sort meaning-- I would like to sort by column 1 then sort column 2 and so on

e.g.


unsorted table
3 | C
1 | B
1 | K
1 | A


sorted table

1 | A
1 | B
1 | C
3 | C

My table my contain millions of row

Now, how can implement this , should i go and write a custom filter derived from QSortFilterProxy or I would go and parsed the sql statement of my model and and order by accordingly, (the latter seems to be tough) or next to impossible since my user will input the sql statement....

I need your suggestion guys

baray98

caduel
23rd August 2009, 11:12
The sql-parsing approach is not that hard (at least for simple queries without union etc).

Apart from that, yes a custom QSortFilterProxyModel that uses several columns in QSortFilterProxyModel::lessThan() will work, too. (Just don't compare only the columns given in die indexes but the ones you are interested in)

HTH

baray98
23rd August 2009, 16:09
The sql approach i think would be faster than QSortFilterProxy approach , mind you I have millions of row to sort right?

I think in my sort I would try to sort them SQL style first then if I can't I will switch to QSortFilterProxyStyle

any more ideas...

baray98

wysota
25th August 2009, 08:43
If you don't care about losing the selection and scrollbars position in the view then using the sql approach should be simpler but if you do care then you should use the proxy approach.