summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-06-17 03:51:26 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-06-17 03:51:26 (GMT)
commitb294bedf9d6fdabca9fd384f1b2d910c02ec1c50 (patch)
treed831ab657561f924b811086c4e97aa09651da929 /tests
parent5ae513c05a1b844745cc80834dac43f16bf62092 (diff)
downloadQt-b294bedf9d6fdabca9fd384f1b2d910c02ec1c50.zip
Qt-b294bedf9d6fdabca9fd384f1b2d910c02ec1c50.tar.gz
Qt-b294bedf9d6fdabca9fd384f1b2d910c02ec1c50.tar.bz2
Add test for model data changes.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/data/repeater2.qml5
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp44
2 files changed, 47 insertions, 2 deletions
diff --git a/tests/auto/declarative/qdeclarativerepeater/data/repeater2.qml b/tests/auto/declarative/qdeclarativerepeater/data/repeater2.qml
index c8b863c..7f2f85a 100644
--- a/tests/auto/declarative/qdeclarativerepeater/data/repeater2.qml
+++ b/tests/auto/declarative/qdeclarativerepeater/data/repeater2.qml
@@ -9,12 +9,13 @@ Rectangle {
Item {
objectName: "myDelegate"
height: 20
+ width: 240
Text {
- y: index*20
+ objectName: "myName"
text: name
}
Text {
- y: index*20
+ objectName: "myNumber"
x: 100
text: number
}
diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
index 3cc68f4..7299a43 100644
--- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
+++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
@@ -45,6 +45,7 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativeview.h>
#include <QtDeclarative/qdeclarativecontext.h>
+#include <QtDeclarative/qdeclarativeexpression.h>
#include <private/qdeclarativerepeater_p.h>
#include <private/qdeclarativetext_p.h>
@@ -75,6 +76,8 @@ private slots:
private:
QDeclarativeView *createView();
template<typename T>
+ T *findItem(QGraphicsObject *parent, const QString &objectName, int index);
+ template<typename T>
T *findItem(QGraphicsObject *parent, const QString &id);
};
@@ -312,6 +315,20 @@ void tst_QDeclarativeRepeater::dataModel()
testModel.removeItem(2);
QCOMPARE(container->childItems().count(), 4);
+ // Check that model changes are propagated
+ QDeclarativeText *text = findItem<QDeclarativeText>(canvas->rootObject(), "myName", 1);
+ QVERIFY(text);
+ QCOMPARE(text->text(), QString("two"));
+
+ testModel.modifyItem(1, "Item two", "_2");
+ text = findItem<QDeclarativeText>(canvas->rootObject(), "myName", 1);
+ QVERIFY(text);
+ QCOMPARE(text->text(), QString("Item two"));
+
+ text = findItem<QDeclarativeText>(canvas->rootObject(), "myNumber", 1);
+ QVERIFY(text);
+ QCOMPARE(text->text(), QString("_2"));
+
delete testObject;
delete canvas;
}
@@ -387,6 +404,33 @@ QDeclarativeView *tst_QDeclarativeRepeater::createView()
}
template<typename T>
+T *tst_QDeclarativeRepeater::findItem(QGraphicsObject *parent, const QString &objectName, int index)
+{
+ const QMetaObject &mo = T::staticMetaObject;
+ //qDebug() << parent->childItems().count() << "children";
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(parent->childItems().at(i));
+ if(!item)
+ continue;
+ //qDebug() << "try" << item;
+ if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
+ if (index != -1) {
+ QDeclarativeExpression e(qmlContext(item), item, "index");
+ if (e.evaluate().toInt() == index)
+ return static_cast<T*>(item);
+ } else {
+ return static_cast<T*>(item);
+ }
+ }
+ item = findItem<T>(item, objectName, index);
+ if (item)
+ return static_cast<T*>(item);
+ }
+
+ return 0;
+}
+
+template<typename T>
T *tst_QDeclarativeRepeater::findItem(QGraphicsObject *parent, const QString &objectName)
{
const QMetaObject &mo = T::staticMetaObject;