Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
4.5.3
-
None
-
aefd76b0052cd36ed7f890dd4b91f38873bec251
Description
The symptoms are as follows:
- select all rows in a view with a sort filter proxy
- change the number of elements to the model
- call QSortProxyFilterModel::invalidate()
The selected rows will be incorrect.
This is very easy to reproduce if you simply take a custom filter and replace the call to "invalidateFilter" with "invalidate". Filter out some rows, select all of the rows (I'm using QAbstractItemView::ExtendedSelection), then unfilter. The wrong rows will be selected.
What's happening is this. Inside of QItemSelectionModelPrivate::_q_layoutAboutToBeChanged(), there is this code:
// special case for when all indexes are selected
if (ranges.isEmpty() && currentSelection.count() == 1) {
QItemSelectionRange range = currentSelection.first();
QModelIndex parent = range.parent();
if (range.top() == 0
&& range.left() == 0
&& range.bottom() == model->rowCount(parent) - 1
&& range.right() == model->columnCount(parent) - 1)
}
So when everything is selected, then the selection is NOT split into individual persistent indexes. Since QSortProxyFilterModel::invalidate() works by simply remapping all of the persistent indexes, then this case will not work correctly. Instead, it will simply map the selection rectangle to the new indexes and select those, which may or not contain the original selection, and can easily select new rows.
I have simply removed the above code locally and everything works as expected.
Thanks.