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

QStandardItem doesn't use natural sort

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 4.7.2
    • None

    Description

      QStandardItem's operator < sorts numerically for numeric types, but alphabetically (via QString::compare) for textual types. This means that numeric items will sort

      {1, 2, 10, 20}

      however textual items will sort

      {"1", "10", "2", "20"}

      .

      All modern GUIs use "natural sort" (http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html) for lists of text-containing-numbers, however QStandardItem's default behaviour makes QTreeView (and similar views) look incorrect.

      QStandardItem should use a natural sort when comparing textual items, and ideally QString would expose this as an improved compare() interface.

      This could be done by replacing Qt::CaseSensitivity with a more general bitfield which could support:

      • Case sensitivity
      • Natural sort order
      • Locale aware

      Combinations that didn't make sense could trip an assert in debug builds, however this would prevent the need to add a new 'naturalCompare' on top of 'compare' and 'localeAwareCompare'.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            refnum Dair Grant
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes