So you're saying that if you want to support both sorting -and- source/proxy mapping, you need two layers of proxy model? One to handle the mapping and another handle sorting?
In my case I have a model with many virtual columns, only a few of which need to be shown in any one table view. In each view, the order of the columns is different. In one view I'd like to support sorting.
I derived from QSortFilterProxyModel and reimplemented mapToSource / mapFromSource and filterAcceptsColumn. All worked fine until I turned on sorting and clicked a column header. As you state, it blew up because the internal pointer in the proxy was invalid.
OK, so I need a plain vanilla QSortFilterProxyModel with my filterAcceptsColumn method. The table uses this one. Then I need a QAbstractProxyModel that implements my mapping, and I set this as the source model for the table's proxy. Finally, I set my base model as the source model for the mapping proxy.
Everything should cascade up and down through the proxy layers between the base model and the view, right?
Then, what happens with the table's item selection model? Does it need to use the middle proxy instead of the base model as its source?
Wish this were better documented somewhere. The Qt docs and examples are just too basic.
Bookmarks