PDA

View Full Version : QSortFilterProxyModel mapping



Sparhawk
17th December 2011, 17:58
Hi All,

I have an issue, and maybe you can suggest me a workaround. I have implemented a QAbstractItemModel that can have a huge amount of rows (several thousands) that are fetching from database on demand. I subclass QSortFilterProxyModel, to give dynamic filters. All data is show on QTableView. I'm using Qt 4.7.3.

Suppose this sequence: I set the model for QTableView to be QSortFilterProxyModel. QTableView is then show to user. Internally, QTableView on paintEvent, has a call to QSortFilterProxyModel::index(row, column, parent) that, internally, has a call to d->create_mapping (Qt sources), that force QSortFilterProxyModel to fetch all rows calling to filterAcceptsRow.

It is supossed that QTableView only needs to call to QSortFilterProxyModel to get the visible rows using, rowCount from QSortFilterProxyModel, but "index" on QSortFilterProxyModel is fetching all rows... Is there any solution to that? Maybe am I using a wrong idea? The only solution I see is reimplement all QSortFilterProxyModel with my own mapping source-proxy.

Thanks a lot!!!

Sparhawk
17th December 2011, 21:00
Reply myself: The key is to have a very good accept row rule. In my case, I modified the QSortFilterProxyModel to count the row using an appropiate sql query. I put a fetched mark to the row that I read from database on source model. On filterAccepsRow all the rows that wasn't fetched, are accepted, and the filter is only applied to fetched row: because this row was requested by the widgets to be shown to user.

It is hard to explain, but you must be very careful with filter on a large amount of rows.