From: Andrew den Exter Date: Mon, 25 Jun 2012 23:13:52 +0000 (+1000) Subject: Position section headers correctly when section property changes. X-Git-Tag: 071012131707~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4089c2bbc51717a642f17c76c17c9ca73e180f00;p=profile%2Fivi%2Fqtdeclarative.git Position section headers correctly when section property changes. 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 --- diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 018cb86..062cd58 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -1144,6 +1144,8 @@ void QQuickListViewPrivate::updateSections() lastVisibleSection = QString(); updateCurrentSection(); updateStickySections(); + forceLayout = true; + q->polish(); } void QQuickListViewPrivate::updateCurrentSection() diff --git a/tests/auto/quick/qquicklistview/data/sectionpropertychange.qml b/tests/auto/quick/qquicklistview/data/sectionpropertychange.qml index f4679b5..feb2240 100644 --- a/tests/auto/quick/qquicklistview/data/sectionpropertychange.qml +++ b/tests/auto/quick/qquicklistview/data/sectionpropertychange.qml @@ -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); diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index f051e5b..c6a7230 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -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(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(contentItem, "wrapper", i); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), qreal(25. + i*75.)); + } + delete canvas; }