Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-6197

CLONE -QItemSelectionModelPrivate::_q_layoutAboutToBeChanged() confuses QSortFilterProxyModel::invalidate()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • 4.6.1
    • 4.5.3
    • Widgets: Itemviews
    • 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)

      { tableSelected = true; tableParent = parent; tableColCount = model->columnCount(parent); tableRowCount = model->rowCount(parent); return; }

      }

      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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            pstark Paul Stark
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes