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

Inconsistent insertion in QSortFilterProxyModel

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.11.1
    • Core: Item Models
    • None
    • Windows

    Description

      I use QSortFilterProxyModel in QComboBox with insertPolicy = InsertAtBottom. I fill the model of 2 rows: the first one will be filtered and the second row is OK. So the combobox list of items contains one row.  After insertion a new item I get the empty first row (instead of the old item) and the new item in the second row (it's OK).

      The bug is in QSortFilterProxyModel::insertRows method, in lines:

      int source_row = (row >= m->source_rows.count()
          ? m->source_rows.count()
          : m->source_rows.at(row));
      

      must be:

      int source_row = (row >= m->source_rows.count()
          ? m->proxy_rows.count()
          : m->source_rows.at(row));
      

      That is because later in QSortFilterProxyModelPrivate::source_items_inserted method there is a line: 

      source_to_proxy.insert(start, delta_item_count, -1);
      

      Here start is source_row of previous code (that is m->source_rows.count()) and source_to_proxy is m->proxy_rows.

      So, in my example, in my source model, there will be inserted an empty item at index position 1 (instead of 2), and then there will be changed Qt::DisplayRole data at index position 2.
       

      Attachments

        For Gerrit Dashboard: QTBUG-69158
        # Subject Branch Project Status CR V

        Activity

          People

            dfaure_kdab David Faure
            olya_r olya_r
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes