Section comparison should be case insensitive.
authorMartin Jones <martin.jones@nokia.com>
Tue, 27 Mar 2012 23:17:02 +0000 (09:17 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 28 Mar 2012 01:10:14 +0000 (03:10 +0200)
Allows use of mixed case model data without having to add a
special role just for sectioning.

Change-Id: I0a747e51542b5bf0f9db8fc2732882928a6cc676
Reviewed-by: Bea Lam <bea.lam@nokia.com>

src/quick/items/qquicklistview.cpp
tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

index 6f33545..1cc2637 100644 (file)
@@ -577,7 +577,7 @@ void QQuickListViewPrivate::initializeViewItem(FxViewItem *item)
     itemPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry);
 
     if (sectionCriteria && sectionCriteria->delegate()) {
-        if (item->attached->m_prevSection != item->attached->m_section)
+        if (QString::compare(item->attached->m_prevSection, item->attached->m_section, Qt::CaseInsensitive))
             updateInlineSection(static_cast<FxListItemSG*>(item));
     }
 }
@@ -962,7 +962,7 @@ void QQuickListViewPrivate::updateInlineSection(FxListItemSG *listItem)
 {
     if (!sectionCriteria || !sectionCriteria->delegate())
         return;
-    if (listItem->attached->m_prevSection != listItem->attached->m_section
+    if (QString::compare(listItem->attached->m_prevSection, listItem->attached->m_section, Qt::CaseInsensitive)
             && (sectionCriteria->labelPositioning() & QQuickViewSection::InlineLabels
                 || (listItem->index == 0 && sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart))) {
         if (!listItem->section()) {
@@ -1022,7 +1022,7 @@ void QQuickListViewPrivate::updateStickySections()
     if (sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart && isValid() && visibleItems.count()) {
         if (!currentSectionItem) {
             currentSectionItem = getSectionItem(currentSection);
-        } else if (currentStickySection != currentSection) {
+        } else if (QString::compare(currentStickySection, currentSection, Qt::CaseInsensitive)) {
             QQmlContext *context = QQmlEngine::contextForObject(currentSectionItem)->parentContext();
             context->setContextProperty(QLatin1String("section"), currentSection);
         }
@@ -1055,7 +1055,7 @@ void QQuickListViewPrivate::updateStickySections()
     if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd && isValid() && visibleItems.count()) {
         if (!nextSectionItem) {
             nextSectionItem = getSectionItem(nextSection);
-        } else if (nextStickySection != nextSection) {
+        } else if (QString::compare(nextStickySection, nextSection, Qt::CaseInsensitive)) {
             QQmlContext *context = QQmlEngine::contextForObject(nextSectionItem)->parentContext();
             context->setContextProperty(QLatin1String("section"), nextSection);
         }
@@ -2040,6 +2040,9 @@ void QQuickListView::setOrientation(QQuickListView::Orientation orientation)
     sections, etc. for an address book)
     \endlist
 
+    A case insensitive comparison is used when determining section
+    boundaries.
+
     \c section.delegate holds the delegate component for each section.
 
     \c section.labelPositioning determines whether the current and/or
index 1218d3c..1ef895d 100644 (file)
@@ -2120,13 +2120,13 @@ void tst_QQuickListView::sectionsPositioning()
     QVERIFY(bottomItem);
     QCOMPARE(bottomItem->y(), 380.);
 
-    // Change current section
+    // Change current section, and verify case insensitive comparison
     listview->setContentY(10);
     model.modifyItem(0, "One", "aaa");
-    model.modifyItem(1, "Two", "aaa");
-    model.modifyItem(2, "Three", "aaa");
-    model.modifyItem(3, "Four", "aaa");
-    model.modifyItem(4, "Five", "aaa");
+    model.modifyItem(1, "Two", "AAA");
+    model.modifyItem(2, "Three", "aAa");
+    model.modifyItem(3, "Four", "aaA");
+    model.modifyItem(4, "Five", "Aaa");
     QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
 
     QTRY_COMPARE(listview->currentSection(), QString("aaa"));