diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp index e6b2fdd..7299a43 100644 --- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp +++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp @@ -45,9 +45,15 @@ #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> +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + inline QUrl TEST_FILE(const QString &filename) { return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); @@ -70,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); }; @@ -307,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; } @@ -382,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; |