diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-04-13 23:30:03 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2010-04-15 08:26:29 (GMT) |
commit | 1c9cde4d2b9cc588890be7445ab4248cbd8f58aa (patch) | |
tree | 7edb61225f8de415c306be041ab13157ff402611 /tests | |
parent | 4061d0ff3e8ed72ecb83ef1026492511a0afb9fa (diff) | |
download | Qt-1c9cde4d2b9cc588890be7445ab4248cbd8f58aa.zip Qt-1c9cde4d2b9cc588890be7445ab4248cbd8f58aa.tar.gz Qt-1c9cde4d2b9cc588890be7445ab4248cbd8f58aa.tar.bz2 |
Ensure view position is correct for highlight range modes that have a static highlight
Task-number: QTBUG-9791
(cherry picked from commit 9416f29a3ee7511c182eaa68f5523132ff64921d)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/data/strictlyenforcerange.qml | 29 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp | 39 |
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelistview/data/strictlyenforcerange.qml b/tests/auto/declarative/qdeclarativelistview/data/strictlyenforcerange.qml new file mode 100644 index 0000000..6fc41fa --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/strictlyenforcerange.qml @@ -0,0 +1,29 @@ +import Qt 4.7 + +ListView { + id: list + objectName: "list" + width: 320 + height: 480 + + function fillModel() { + list.model.append({"col": "red"}); + list.currentIndex = list.count-1 + list.model.append({"col": "blue"}); + list.currentIndex = list.count-1 + list.model.append({"col": "green"}); + list.currentIndex = list.count-1 + } + + model: ListModel { id: listModel } // empty model + delegate: Rectangle { id: wrapper; objectName: "wrapper"; color: col; width: 300; height: 400 } + orientation: "Horizontal" + snapMode: "SnapToItem" + cacheBuffer: 1000 + + preferredHighlightBegin: 10 + preferredHighlightEnd: 10 + + highlightRangeMode: "StrictlyEnforceRange" + focus: true +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 8d94804..5b81d75 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -88,6 +88,7 @@ private slots: void propertyChanges(); void componentChanges(); void modelChanges(); + void QTBUG_9791(); private: template <class T> void items(); @@ -1472,6 +1473,44 @@ void tst_QDeclarativeListView::modelChanges() delete canvas; } +void tst_QDeclarativeListView::QTBUG_9791() +{ + QDeclarativeView *canvas = createView(); + + QDeclarativeContext *ctxt = canvas->rootContext(); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/strictlyenforcerange.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(canvas->rootObject()); + QTRY_VERIFY(listview != 0); + + QDeclarativeItem *viewport = listview->viewport(); + QTRY_VERIFY(viewport != 0); + QTRY_VERIFY(listview->delegate() != 0); + QTRY_VERIFY(listview->model() != 0); + + QMetaObject::invokeMethod(listview, "fillModel"); + qApp->processEvents(); + + // Confirm items positioned correctly + int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + QVERIFY(itemCount == 3); + + for (int i = 0; i < itemCount; ++i) { + QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QTRY_VERIFY(item); + QTRY_COMPARE(item->x(), i*300.0); + } + + // check that view is positioned correctly + QTRY_COMPARE(listview->contentX(), 590.0); + + delete canvas; +} + + void tst_QDeclarativeListView::qListModelInterface_items() { items<TestModel>(); |