diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-02-25 00:21:52 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-02-25 00:21:52 (GMT) |
commit | 950f3849e3bd2edd6bcc2784dbeadcb604c38e2d (patch) | |
tree | a8a55a3f9f4ddef85bab6d789a3ffb9e7e560a64 /tests/auto/declarative/qdeclarativelistview | |
parent | f39bb2af2d81640d30222cd5abc31b076105dd8b (diff) | |
download | Qt-950f3849e3bd2edd6bcc2784dbeadcb604c38e2d.zip Qt-950f3849e3bd2edd6bcc2784dbeadcb604c38e2d.tar.gz Qt-950f3849e3bd2edd6bcc2784dbeadcb604c38e2d.tar.bz2 |
React to QAbstractItemModel::modelReset() signal.
Task-number: QTBUG-8494
Diffstat (limited to 'tests/auto/declarative/qdeclarativelistview')
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/data/displaylist.qml | 43 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp | 43 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml new file mode 100644 index 0000000..7b124a5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelistview/data/displaylist.qml @@ -0,0 +1,43 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + objectName: "displayText" + text: display + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + }, + Component { + id: myHighlight + Rectangle { color: "green" } + } + ] + ListView { + id: list + objectName: "list" + focus: true + width: 240 + height: 320 + model: testModel + delegate: myDelegate + highlight: myHighlight + highlightMoveSpeed: 1000 + highlightResizeSpeed: 1000 + } +} diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index daa40d1..9100522 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include <QtTest/QtTest> +#include <QStringListModel> #include <private/qlistmodelinterface_p.h> #include <qdeclarativeview.h> #include <private/qdeclarativelistview_p.h> @@ -80,6 +81,7 @@ private slots: void sections(); void cacheBuffer(); void positionViewAtIndex(); + void resetModel(); private: template <class T> void items(); @@ -1232,6 +1234,47 @@ void tst_QDeclarativeListView::positionViewAtIndex() delete canvas; } +void tst_QDeclarativeListView::resetModel() +{ + QDeclarativeView *canvas = createView(); + + QStringList strings; + strings << "one" << "two" << "three"; + QStringListModel model(strings); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/displaylist.qml")); + qApp->processEvents(); + + QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); + QVERIFY(listview != 0); + + QDeclarativeItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(listview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } + + strings.clear(); + strings << "four" << "five" << "six" << "seven"; + model.setStringList(strings); + + QCOMPARE(listview->count(), model.rowCount()); + + for (int i = 0; i < model.rowCount(); ++i) { + QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QVERIFY(display != 0); + QCOMPARE(display->text(), strings.at(i)); + } +} + void tst_QDeclarativeListView::qListModelInterface_items() { items<TestModel>(); |