PDA

View Full Version : QAbstractTableModel and sort



foxyproxy
22nd March 2008, 17:14
Hello, I have created my own QAbstractTableModel that uses. Now I have added the possibility to sort columns by using QSortFilterProxyModel. The problem is the model uses QList for adding new rows and when I sort a column the index between the model and QList doesnt match :S

How can I fix it? Can some1 help me pls? :)

Thank you for your help and suggestions ;)

wysota
22nd March 2008, 18:41
See QAbstractProxyModel::mapToSource() and QAbstractProxyModel::mapFromSource().

foxyproxy
22nd March 2008, 18:45
Thank wysota for your answer :)

Then I should reimplement those 2 methods. But what should they do? Sorting QList?

wysota
22nd March 2008, 19:17
You shouldn't implement them. You should use them - they are already implemented in the proxy. The truth is you shouldn't need to use them but interface through the proxy instead of accessing the source model directly.

foxyproxy
23rd March 2008, 17:56
Sorry if I bug you but can you make an example to be more clear please? Thank you :)

wysota
23rd March 2008, 18:33
Example of what exactly?

foxyproxy
23rd March 2008, 20:28
How to use mapToSource :)

wysota
25th March 2008, 10:30
QModelIndex proxyIndex = ...
QModelIndex srcIndex = proxy->mapToSource(proxyIndex);

Is that what you wanted?