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

New SortRole needed for QFileSystemModel (and QSortFilterProxyModel)

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.8.4, 4.8.5, 4.8.6
    • None

    Description

      QFileSystemModel::data() method only allows to return data from its 4 columns by using either the Qt::EditRole or the Qt::DisplayRole. It calls several other private methods depending on the column queried. Column 0 is file name, 1 is size, 2 is type, 3 is modified date. These methods appropriately return the corresponding value converted into a human-friendly QString.

      On the other hand, by default QSortFilterProxyModel uses the Qt::DisplayRole to query the needed data from the model.

      When using a QSortFilterProxyModel over a QFileSystemModel, the Qt::DisplayRole is not the correct role to be used, since comparison over a human-friendly QString is prone to be totally incorrect (and in fact it is, most of the times). QFileSystemModel::data() needs to support some "SortRole" to return raw (original typed) data for each column, so the proper sorting can be applied at QSortFilterProxyModel::lessThan().

      Example:
      Current behavior: when using a QSortFilterProxyModel over a QFileSystemModel, sorting by the 4th column will sort the date strings, but earlier dates won't necessarily come before later dates.
      Desired behavior: earlier dates come always before later dates, independently of what is the string representation of dates chosen by the locale.

      Similarly, sizes are transformed into SI standard magnitudes, thus not allowing a proper ordering.

      Proposed solution is that QFileSystemModel::data() returns QString variants when the requested role is Display role (current behaviour), but returns raw (base type) values when role is SortRole (not implemented).

      This SortRole would be set through the QSortFilterProxyModel::setSortRole() method.

      Attachments

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

        Activity

          People

            dfaure_kdab David Faure
            oneorjuan Juan Navarro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes