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

QSortFilterProxyModel can remain empty after clearing filter

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.6.0 RC
    • 5.4.1
    • Core: Object Model
    • None
    • db377a420207be84b314b836d2756c57a25d057f

    Description

      If you set a filter such that it filters out everything from the source model, sort the source model, then remove the filter, rowsInserted doesn't get emitted from the QSortProxyModel.

      It appears to be because the invalid index isn't kept up to date and filter_changed just returns early when you clear the filter.

      This trivial patch fixes the problem for me (will put in a review shortly):

      diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
      index b01c9db..4cd27c7 100644
      --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp
      +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
      @@ -1053,6 +1053,7 @@ void QSortFilterProxyModelPrivate::filter_changed(const QModelIndex &source_pare
           if (it == source_index_mapping.constEnd())
               return;
           Mapping *m = it.value();
      +
           QSet<int> rows_removed = handle_filter_changed(m->proxy_rows, m->source_rows, source_parent, Qt::Vertical);
           QSet<int> columns_removed = handle_filter_changed(m->proxy_columns, m->source_columns, source_parent, Qt::Horizontal);
      
      @@ -1339,6 +1340,9 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersisten
           update_persistent_indexes(saved_persistent_indexes);
           saved_persistent_indexes.clear();
      
      +    // We need the invalid index up to date for filtering
      +    create_mapping(QModelIndex());
      +
           if (dynamic_sortfilter && update_source_sort_column()) {
               //update_source_sort_column might have created wrong mapping so we have to clear it again
               qDeleteAll(source_index_mapping);
      

      Attachments

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

        Activity

          People

            daiweili Daiwei Li
            daiweili Daiwei Li
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes