From 3bb4880d63e0ebc972d500d3c7538127cd709a5d Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 26 Jun 2012 13:13:11 +1000 Subject: Fix section delegates not updating when changed. Delete all allocated section items before doing an update when the section delegate is changed. Task-number: QTBUG-24899 Change-Id: I09dc7a1c602a49ad7bb37512a7e5116392259457 Reviewed-by: Martin Jones --- .../qquicklistview/data/sectiondelegatechange.qml | 61 ++++++++++++++++++++++ .../quick/qquicklistview/tst_qquicklistview.cpp | 41 +++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/auto/quick/qquicklistview/data/sectiondelegatechange.qml (limited to 'tests') diff --git a/tests/auto/quick/qquicklistview/data/sectiondelegatechange.qml b/tests/auto/quick/qquicklistview/data/sectiondelegatechange.qml new file mode 100644 index 0000000000..eee15ed2e0 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/sectiondelegatechange.qml @@ -0,0 +1,61 @@ +import QtQuick 2.0 + +ListView { + width: 240 + height: 320 + + function switchDelegates() { + section.delegate = section.delegate === delegate1 + ? delegate2 + : delegate1 + } + + Component { + id: delegate1 + + Rectangle { + objectName: "section1" + color: "lightsteelblue" + border.width: 1; + width: 240 + height: 25 + + Text { + anchors.centerIn: parent + text: section + } + } + } + Component { + id: delegate2 + + Rectangle { + objectName: "section2" + color: "yellow" + border.width: 1; + width: 240 + height: 50 + + Text { + anchors.centerIn: parent + text: section + } + } + } + + section.property: "modelData" + section.delegate: delegate1 + + model: 20 + delegate: Rectangle { + objectName: "item" + border.width: 1 + width: 240 + height: 25 + + Text { + anchors.centerIn: parent + text: modelData + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c6a72306f9..848ffb10ff 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -146,6 +146,7 @@ private slots: void sectionsDragOutsideBounds(); void sectionsDelegate_headerVisibility(); void sectionPropertyChange(); + void sectionDelegateChange(); void cacheBuffer(); void positionViewAtIndex(); void resetModel(); @@ -2431,6 +2432,46 @@ void tst_QQuickListView::sectionPropertyChange() delete canvas; } +void tst_QQuickListView::sectionDelegateChange() +{ + QQuickView *canvas = createView(); + + canvas->setSource(testFileUrl("sectiondelegatechange.qml")); + canvas->show(); + qApp->processEvents(); + + QQuickListView *listview = qobject_cast(canvas->rootObject()); + QVERIFY(listview != 0); + + QQuickItem *contentItem = listview->contentItem(); + QVERIFY(contentItem != 0); + + QQUICK_VERIFY_POLISH(listview); + + QVERIFY(findItems(contentItem, "section1").count() > 0); + QCOMPARE(findItems(contentItem, "section2").count(), 0); + + for (int i = 0; i < 3; ++i) { + QQuickItem *item = findItem(contentItem, "item", i); + QTRY_VERIFY(item); + QTRY_COMPARE(item->y(), qreal(25. + i*50.)); + } + + QMetaObject::invokeMethod(canvas->rootObject(), "switchDelegates"); + QQUICK_VERIFY_POLISH(listview); + + QCOMPARE(findItems(contentItem, "section1").count(), 0); + QVERIFY(findItems(contentItem, "section2").count() > 0); + + for (int i = 0; i < 3; ++i) { + QQuickItem *item = findItem(contentItem, "item", i); + QVERIFY(item); + QTRY_COMPARE(item->y(), qreal(50. + i*75.)); + } + + delete canvas; +} + void tst_QQuickListView::currentIndex_delayedItemCreation() { QFETCH(bool, setCurrentToZero); -- cgit v1.2.3