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/qdeclarativegridview | |
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/qdeclarativegridview')
-rw-r--r-- | tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml | 39 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp | 43 |
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml b/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml new file mode 100644 index 0000000..d3cdcd8 --- /dev/null +++ b/tests/auto/declarative/qdeclarativegridview/data/displaygrid.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 80 + height: 60 + border.color: "blue" + Text { + text: index + } + Text { + y: 20 + id: displayText + objectName: "displayText" + text: display + } + color: GridView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ] + GridView { + id: grid + objectName: "grid" + width: 240 + height: 320 + cellWidth: 80 + cellHeight: 60 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 9c7468d..9c9d1d3 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -41,6 +41,7 @@ #include <qdeclarativeengine.h> #include <qdeclarativecomponent.h> +#include <QStringListModel> #include <QtTest/QtTest> #include <private/qlistmodelinterface_p.h> #include <qdeclarativeview.h> @@ -66,6 +67,7 @@ private slots: void defaultValues(); void properties(); void positionViewAtIndex(); + void resetModel(); void QTBUG_8456(); private: @@ -884,6 +886,47 @@ void tst_QDeclarativeGridView::positionViewAtIndex() delete canvas; } +void tst_QDeclarativeGridView::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/displaygrid.qml")); + qApp->processEvents(); + + QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); + QVERIFY(gridview != 0); + + QDeclarativeItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(gridview->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(gridview->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_QDeclarativeGridView::QTBUG_8456() { QDeclarativeView *canvas = createView(); |