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

QSortFilterProxyModel with sorting and initially suppressing filter (with testcase)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 4.8.4, 5.0.2
    • Widgets: Itemviews
    • None
    • 6894bc0f3f8a579529dc0a7ab869ce565abd06ad

    Description

      Please try the following code:

      #include <QStringListModel>
      #include <QSortFilterProxyModel>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
        QStringListModel slm;
        QSortFilterProxyModel sfm;
      
        sfm.setSourceModel(&slm);
      
        // make sure the filter does not match any entry
        sfm.setFilterRegExp(QRegExp("[0-9]+"));
      
        sfm.setDynamicSortFilter(true);
        sfm.sort(0);
        slm.setStringList(QStringList() << "z" << "x" << "a" << "b");
      
        // this will make all entries visible - but unsorted
        sfm.setFilterRegExp(QRegExp("[a-z]+"));
      
        for (int i = 0; i < sfm.rowCount(); ++i)
          qDebug() << sfm.index(i, 0).data();
      }
      

      Instead of a sorted output we get:

      QVariant(QString, "z") 
      QVariant(QString, "x") 
      QVariant(QString, "a") 
      QVariant(QString, "b") 
      

      The reason is that in QSortFilterProxyModelPrivate::filter_changed source_sort_column is still -1. The proxy model is still empty then so any call to QSortFilterProxyModelPrivate::update_source_sort_column() is useless, because mapping of index(row=0) to the source model obviously fails.

      I tried hard but couldn't find a proper way to fix it without possibly breaking all the more complex models (trees and tables).

      Attachments

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

        Activity

          People

            stephen.kelly Stephen Kelly (Unused account) (Inactive)
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes