SortFilterModel cannot sort by a numeric role

Bug #1495482 reported by Olivier Tilloy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-ui-toolkit (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I’d like to replace a custom model in webbrowser-app with SortFilterModel (my model does both sorting and filtering), but at the moment I can’t because SortFilterModel does its sort on string comparisons, and the role I want to compare on is an integer.
10 > 2, but "2" > "10".
Ideally, SortFilterModel would detect the type of the role, and apply the appropriate comparison, instead of casting everything to a string.

Revision history for this message
Olivier Tilloy (osomon) wrote :

This is invalid. For future reference, the situation is slightly more complex. I’m trying to do something like that:

  SortFilterModel {
    sort.property: "blah"
    sort.order: Qt.DescendingOrder
    model: CustomSortFilterModel {
      sourceModel: CustomListModel {}
    }
  }

where CustomListModel is a custom QAbstractListModel and CustomSortFilterModel is a custom QSortFilterProxyModel that does sorting and filtering. When model gets set on the SortFilterModel, its sourceModel might not have been set yet, so querying the roleNames will return an empty QHash, and subsequent attempts to sort the model will fail because property "blah" couldn’t be matched to a role index.

Changed in ubuntu-ui-toolkit (Ubuntu):
status: New → Invalid
Revision history for this message
Olivier Tilloy (osomon) wrote :

And it appears that if I instantiate the models at the same level, without nesting them, this works:

  CustomListModel { id: customListModel }
  CustomSortFilterModel { id: customSortFilterModel }
  SortFilterModel {
    sort.property: "blah"
    sort.order: Qt.DescendingOrder
    model: customSortFilterModel
  }

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.