diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-08-16 05:38:15 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-08-16 05:38:15 (GMT) |
commit | b83c295650b3f28bc9da542acf4652f4ce2d168b (patch) | |
tree | 794a392706234c3bcbfe66ce28bbc9806f2cfa9a | |
parent | 7fcc1daf1762d345ca39f9599a8de2567bb8e788 (diff) | |
download | Qt-b83c295650b3f28bc9da542acf4652f4ce2d168b.zip Qt-b83c295650b3f28bc9da542acf4652f4ce2d168b.tar.gz Qt-b83c295650b3f28bc9da542acf4652f4ce2d168b.tar.bz2 |
Handle QGraphicsWidgets in Flickable
Task-number: QTBUG-12830
Reviewed-by: Michael Brasser
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeflickable.cpp | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 19cabdd..9bcadd2 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1027,7 +1027,7 @@ void QDeclarativeFlickable::cancelFlick() void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) { - QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o); + QGraphicsObject *i = qobject_cast<QGraphicsObject *>(o); if (i) i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem); else diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index 678996b..e7ded8a 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -44,6 +44,7 @@ #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativeflickable_p.h> #include <private/qdeclarativevaluetype_p.h> +#include <QtGui/qgraphicswidget.h> #include <math.h> #ifdef Q_OS_SYMBIAN @@ -67,9 +68,13 @@ private slots: void flickDeceleration(); void pressDelay(); void flickableDirection(); + void qgraphicswidget(); private: QDeclarativeEngine engine; + + template<typename T> + T *findItem(QGraphicsObject *parent, const QString &objectName); }; tst_qdeclarativeflickable::tst_qdeclarativeflickable() @@ -261,6 +266,38 @@ void tst_qdeclarativeflickable::flickableDirection() QCOMPARE(spy.count(),3); } +void tst_qdeclarativeflickable::qgraphicswidget() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/flickableqgraphicswidget.qml")); + QDeclarativeFlickable *flickable = qobject_cast<QDeclarativeFlickable*>(c.create()); + + QVERIFY(flickable != 0); + QGraphicsWidget *widget = findItem<QGraphicsWidget>(flickable->contentItem(), "widget1"); + QVERIFY(widget); +} + +template<typename T> +T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->childItems().count() << "children"; + for (int i = 0; i < parent->childItems().count(); ++i) { + QGraphicsObject *item = qobject_cast<QGraphicsObject*>(parent->childItems().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + return static_cast<T*>(item); + } + item = findItem<T>(item, objectName); + if (item) + return static_cast<T*>(item); + } + + return 0; +} + QTEST_MAIN(tst_qdeclarativeflickable) #include "tst_qdeclarativeflickable.moc" |