From 5c238b1260f589a906aae3f20d9b412ed2f76a65 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Feb 2010 14:10:44 +1000 Subject: Fix test. --- .../tst_qmlgraphicsgridview.cpp | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index f389d2c..9d79407 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -73,6 +73,7 @@ private: T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); template QList findItems(QmlGraphicsItem *parent, const QString &objectName); + void dumpTree(QmlGraphicsItem *parent, int depth = 0); }; class TestModel : public QAbstractListModel @@ -923,17 +924,19 @@ T *tst_QmlGraphicsGridView::findItem(QmlGraphicsItem *parent, const QString &obj { const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); if(!item) continue; //qDebug() << "try" << item; if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { if (index != -1) { - QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); - if (e.value().toInt() == index) - return static_cast(item); + QmlContext *context = QmlEngine::contextForObject(item); + if (context) { + if (context->contextProperty("index").toInt() == index) { + return static_cast(item); + } + } } else { return static_cast(item); } @@ -967,6 +970,19 @@ QList tst_QmlGraphicsGridView::findItems(QmlGraphicsItem *parent, const QStr return items; } +void tst_QmlGraphicsGridView::dumpTree(QmlGraphicsItem *parent, int depth) +{ + static QString padding(" "); + for (int i = 0; i < parent->childItems().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->childItems().at(i)); + if(!item) + continue; + QmlContext *context = QmlEngine::contextForObject(item); + qDebug() << padding.left(depth*2) << item << (context ? context->contextProperty("index").toInt() : -1); + dumpTree(item, depth+1); + } +} + QTEST_MAIN(tst_QmlGraphicsGridView) -- cgit v0.12