diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-10-13 02:36:30 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-10-13 02:36:30 (GMT) |
commit | 7a9dada31e570b2884c1c3c7a094ca9b1690c743 (patch) | |
tree | 5256ebe5de00ef0065f10cbfadd6d52e43f8ed5f /tests | |
parent | 5e31c0cae45bae6f66decfb37825ed5d445e49e4 (diff) | |
parent | d39b7ce65f051da342dcc931e303a73339288c5e (diff) | |
download | Qt-7a9dada31e570b2884c1c3c7a094ca9b1690c743.zip Qt-7a9dada31e570b2884c1c3c7a094ca9b1690c743.tar.gz Qt-7a9dada31e570b2884c1c3c7a094ca9b1690c743.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
5 files changed, 127 insertions, 4 deletions
diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 2a5fa1c..1875836 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -34,6 +34,8 @@ private: QmlView *createView(const QString &filename); template<typename T> T *findItem(QFxItem *parent, const QString &id, int index=-1); + template<typename T> + QList<T*> findItems(QFxItem *parent, const QString &objectName); }; class TestModel : public QListModelInterface @@ -336,7 +338,8 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + int itemCount = findItems<QFxItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem<QFxItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -357,7 +360,8 @@ void tst_QFxListView::removed() QCOMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems<QFxItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem<QFxItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -370,7 +374,8 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems<QFxItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem<QFxItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -398,7 +403,8 @@ void tst_QFxListView::removed() QTest::qWait(1000); // Confirm items positioned correctly - for (int i = 0; i < model.count() && i < viewport->childItems().count(); ++i) { + itemCount = findItems<QFxItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { QFxItem *item = findItem<QFxItem>(viewport, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QVERIFY(item); @@ -493,6 +499,26 @@ T *tst_QFxListView::findItem(QFxItem *parent, const QString &objectName, int ind return 0; } +template<typename T> +QList<T*> tst_QFxListView::findItems(QFxItem *parent, const QString &objectName) +{ + QList<T*> items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QFxItem *item = qobject_cast<QFxItem*>(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast<T*>(item)); + items += findItems<T>(item, objectName); + } + + return items; +} + + QTEST_MAIN(tst_QFxListView) #include "tst_listview.moc" diff --git a/tests/auto/declarative/states/data/ExtendedRectangle.qml b/tests/auto/declarative/states/data/ExtendedRectangle.qml new file mode 100644 index 0000000..8d64663 --- /dev/null +++ b/tests/auto/declarative/states/data/ExtendedRectangle.qml @@ -0,0 +1,19 @@ +import Qt 4.6 +Rectangle { + id: extendedRect + objectName: "extendedRect" + property color extendedColor: "orange" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: { + extendedRect.color = "green" + extendedColor = "green" + } + } + } +} diff --git a/tests/auto/declarative/states/data/signalOverride.qml b/tests/auto/declarative/states/data/signalOverride.qml new file mode 100644 index 0000000..5ba1566 --- /dev/null +++ b/tests/auto/declarative/states/data/signalOverride.qml @@ -0,0 +1,18 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + + onDidSomething: color = "blue" + + width: 100; height: 100 + color: "red" + states: State { + name: "green" + PropertyChanges { + target: rect + onDidSomething: color = "green" + } + } +} diff --git a/tests/auto/declarative/states/data/signalOverride2.qml b/tests/auto/declarative/states/data/signalOverride2.qml new file mode 100644 index 0000000..527e165 --- /dev/null +++ b/tests/auto/declarative/states/data/signalOverride2.qml @@ -0,0 +1,9 @@ +import Qt 4.6 +import Qt.test 1.0 + +MyRectangle { + id: rect + onDidSomething: color = "blue" + width: 100; height: 100 + ExtendedRectangle {} +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 3a61bd6..b2532a2 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -13,6 +13,7 @@ private slots: void basicChanges(); void basicExtension(); void basicBinding(); + void signalOverride(); }; void tst_states::basicChanges() @@ -262,6 +263,56 @@ void tst_states::basicBinding() } } +class MyRect : public QFxRect +{ + Q_OBJECT +public: + MyRect() {} + void doSomething() { emit didSomething(); } +Q_SIGNALS: + void didSomething(); +}; + +QML_DECLARE_TYPE(MyRect) +QML_DEFINE_TYPE(Qt.test, 1, 0, 0, MyRectangle,MyRect); + +void tst_states::signalOverride() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride.qml"); + MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("green")); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/signalOverride2.qml"); + MyRect *rect = qobject_cast<MyRect*>(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("white")); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + + QFxRect *innerRect = qobject_cast<QFxRect*>(rect->findChild<QFxRect*>("extendedRect")); + + innerRect->setState("green"); + rect->doSomething(); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(innerRect->color(),QColor("green")); + QCOMPARE(innerRect->property("extendedColor").value<QColor>(),QColor("green")); + } +} + QTEST_MAIN(tst_states) #include "tst_states.moc" |