aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@jollamobile.com>2015-06-24 15:56:09 +1000
committerMartin Jones <martin.jones@qinetic.com.au>2015-06-25 23:22:37 +0000
commit30a65658c84e9e631b55f03303e19148b391b08b (patch)
tree7de7f6f95135ba1d82388cb3ec8f3f9cc4272083 /tests/auto/quick
parent12c7d018eccb979273fe447c9a0f17b1988ccbf4 (diff)
Correctly initialize ListView section attached properties.
During item insertion, indexes of items in the visibleItems list were not adjusted before new items were created. Section initialization was broken during insertion because section calculation relies on the indexes of the items in the visibleItems list. The incorrect section properties caused spurious section header creation, and layout issues. Apply the index offset before creating the new items. This mirrors what GridView already does. Change-Id: I549a81825cf0e979bc5830840bf6cb75c7a82cac Task-number: QTBUG-43873 Reviewed-by: Bea Lam <bea.lam@jollamobile.com>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquicklistview/data/listview-sections_delegate.qml3
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp62
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/data/listview-sections_delegate.qml b/tests/auto/quick/qquicklistview/data/listview-sections_delegate.qml
index 7245025bac..11da286f4d 100644
--- a/tests/auto/quick/qquicklistview/data/listview-sections_delegate.qml
+++ b/tests/auto/quick/qquicklistview/data/listview-sections_delegate.qml
@@ -12,6 +12,9 @@ Rectangle {
Item {
id: wrapper
objectName: "wrapper"
+ property string section: ListView.section
+ property string nextSection: ListView.nextSection
+ property string prevSection: ListView.previousSection
height: 20;
width: 240
Rectangle {
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 3e19b005b7..c93aac456d 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -133,6 +133,7 @@ private slots:
void sectionsDelegate_headerVisibility();
void sectionPropertyChange();
void sectionDelegateChange();
+ void sectionsItemInsertion();
void cacheBuffer();
void positionViewAtBeginningEnd();
void positionViewAtIndex();
@@ -2540,6 +2541,67 @@ void tst_QQuickListView::sectionDelegateChange()
delete window;
}
+// QTBUG-43873
+void tst_QQuickListView::sectionsItemInsertion()
+{
+ QQuickView *window = createView();
+
+ QaimModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i/5));
+
+ QQmlContext *ctxt = window->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ window->setSource(testFileUrl("listview-sections_delegate.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+ QQuickItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+ for (int i = 0; i < 3; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "sect_" + QString::number(i));
+ QVERIFY(item);
+ QTRY_COMPARE(item->y(), qreal(i*20*6));
+ }
+
+ QQuickItem *topItem = findVisibleChild(contentItem, "sect_0"); // section header
+ QVERIFY(topItem);
+ QCOMPARE(topItem->y(), 0.);
+
+ // Insert a full screen of items at the beginning.
+ for (int i = 0; i < 10; i++)
+ model.insertItem(i, "Item" + QString::number(i), QLatin1String("A"));
+
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+ int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
+ QVERIFY(itemCount > 10);
+
+ // Verify that the new items are postioned correctly, and have the correct attached section properties
+ for (int i = 0; i < 10 && i < itemCount; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY(item);
+ QTRY_COMPARE(item->y(), 20+i*20.0);
+ QCOMPARE(item->property("section").toString(), QLatin1String("A"));
+ QCOMPARE(item->property("nextSection").toString(), i < 9 ? QLatin1String("A") : QLatin1String("0"));
+ QCOMPARE(item->property("prevSection").toString(), i > 0 ? QLatin1String("A") : QLatin1String(""));
+ }
+ // Verify that the exiting items are postioned correctly, and have the correct attached section properties
+ for (int i = 10; i < 15 && i < itemCount; ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY(item);
+ QTRY_COMPARE(item->y(), 40+i*20.0);
+ QCOMPARE(item->property("section").toString(), QLatin1String("0"));
+ QCOMPARE(item->property("nextSection").toString(), i < 14 ? QLatin1String("0") : QLatin1String("1"));
+ QCOMPARE(item->property("prevSection").toString(), i > 10 ? QLatin1String("0") : QLatin1String("A"));
+ }
+}
+
void tst_QQuickListView::currentIndex_delayedItemCreation()
{
QFETCH(bool, setCurrentToZero);