andreas buykx
andreas buykx

Reputation: 12950

most effective row removal strategy for QStandardItemModel

I have a QStandardItemModel with several 100,000 records of data, and a QSortFilterProxyModel on top of it for filtering and sorting capabilities. I want to remove a substantial number of records, say 100,000, based on the value of one of the columns.

The current implementation iterates over the source model, tests for the value in the appropriate column, and calls removeRow. This turns out to be an extremely slow approach, I don't know why (I've already turned off the signalling of the source model and the sortfilterproxymodel).

What is a more efficient approach?

Can the QSortFilterProxyModel help, e.g. by creating a selection of records to be deleted, and using removeRows?

Thanks, Andreas

Upvotes: 2

Views: 1630

Answers (2)

alexkr
alexkr

Reputation: 4670

The more effecient approach would be implementing your own model with QAbstractItemModel interface instead of using QStandardItemModel. Then you can build custom indexes which will help you increase performance while deleting items.

Upvotes: 1

swongu
swongu

Reputation: 2299

QAbstractItemModel::removeRows() is a candidate, provided that the rows are contiguous. If the model is sorted by the column you are using to do the removal test, then you should be able to use this.

Upvotes: 1

Related Questions