Position section headers correctly when section property changes.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Mon, 25 Jun 2012 23:13:52 +0000 (09:13 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jun 2012 06:08:32 +0000 (08:08 +0200)
Schedule a new layout after the section property is changed to correct
item positions if section headers are added or removed.

Task-number: QTBUG-24900

Change-Id: I7e46ec6dc00e5a810029396a4c5ca4e87ee1d94d
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquicklistview.cpp
tests/auto/quick/qquicklistview/data/sectionpropertychange.qml
tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

index 018cb86..062cd58 100644 (file)
@@ -1144,6 +1144,8 @@ void QQuickListViewPrivate::updateSections()
     lastVisibleSection = QString();
     updateCurrentSection();
     updateStickySections();
+    forceLayout = true;
+    q->polish();
 }
 
 void QQuickListViewPrivate::updateCurrentSection()
index f4679b5..feb2240 100644 (file)
@@ -23,12 +23,20 @@ Rectangle {
     }
 
     function switchGroups() {
+        myListView.model.move(0,1,1)
         if ("title" === myListView.groupBy)
             myListView.groupBy = "genre"
         else
             myListView.groupBy = "title"
     }
 
+    function switchGrouped() {
+        if ("pageCount" === myListView.groupBy)
+            myListView.groupBy = "genre"
+        else
+            myListView.groupBy = "pageCount"
+    }
+
     Component.onCompleted: {
         myListView.model = generateModel(myListView)
     }
@@ -56,11 +64,6 @@ Rectangle {
             Text { text: parent.y; anchors.right: parent.right }
         }
 
-        onGroupByChanged: {
-            model.move(0,1,1)
-            section.property = groupBy
-        }
-
         section {
             criteria: ViewSection.FullString
             delegate: Rectangle { width: 320; height: 25; color: "lightblue"
@@ -68,15 +71,15 @@ Rectangle {
                 Text {text: section }
                 Text { text: parent.y; anchors.right: parent.right }
             }
-            property: "title"
+            property: myListView.groupBy
         }
     }
 
     function generateModel(theParent)
     {
         var books = [
-                    { "author": "Billy Bob", "genre": "Anarchism", "title": "Frogs and Love" },
-                    { "author": "Lefty Smith", "genre": "Horror", "title": "Chainsaws for Noobs" }
+                { "author": "Billy Bob", "genre": "Anarchism", "title": "Frogs and Love", "pageCount": 80 },
+                { "author": "Lefty Smith", "genre": "Horror", "title": "Chainsaws for Noobs", "pageCount": 80 }
                 ];
 
         var model = Qt.createQmlObject("import QtQuick 2.0; ListModel {}", theParent);
index f051e5b..c6a7230 100644 (file)
@@ -2408,6 +2408,26 @@ void tst_QQuickListView::sectionPropertyChange()
         QTRY_COMPARE(item->y(), qreal(25. + i*75.));
     }
 
+    QMetaObject::invokeMethod(canvas->rootObject(), "switchGrouped");
+    QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+    // Confirm items positioned correctly
+    for (int i = 0; i < 2; ++i) {
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        QTRY_VERIFY(item);
+        QTRY_COMPARE(item->y(), qreal(25. + i*50.));
+    }
+
+    QMetaObject::invokeMethod(canvas->rootObject(), "switchGrouped");
+    QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+    // Confirm items positioned correctly
+    for (int i = 0; i < 2; ++i) {
+        QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+        QTRY_VERIFY(item);
+        QTRY_COMPARE(item->y(), qreal(25. + i*75.));
+    }
+
     delete canvas;
 }