From c520a69f06317fb90d37324bf284ef9614cb5dbf Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 25 Feb 2013 17:01:16 +1000 Subject: Improve emission of FocusScope focusChanged signals. Emit activeFocusChanged up the focus tree when an item receives a focus event, rather than when the focusItem changes which happens before internal state is sufficiently updated for hasFocus and hasActiveFocus to return the correct values from within a changed signal handler. There are some limitions to this. First the signals are not emitted reliably when the scene is not active which makes sense for activeFocus but not for focus. The second is in some instances the focus and activeFocus can update unnecessarily while the focus chain sorts itself out. QDeclarativeItem tests by Andreas Aardal Hanssen Task-number: QTBUG-28288 Task-number: QTBUG-25644 Change-Id: Ib3d17c42754c15a08b34c3388f50b45cc1d2a831 Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Alan Alpert --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 24 +- src/declarative/graphicsitems/qdeclarativeitem_p.h | 23 +- .../qdeclarativefocusscope/data/notifications.qml | 81 ++++++ .../tst_qdeclarativefocusscope.cpp | 293 ++++++++++++++++++++- .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 179 ++++++++++++- 5 files changed, 569 insertions(+), 31 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 99b3857d..c3bb5d9f 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2744,9 +2744,27 @@ QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const void QDeclarativeItemPrivate::focusChanged(bool flag) { Q_Q(QDeclarativeItem); - if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent) - emit q->activeFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange() - emit q->focusChanged(flag); + + if (hadActiveFocus != flag) { + hadActiveFocus = flag; + emit q->activeFocusChanged(flag); + } + + QDeclarativeItem *focusItem = q; + for (QDeclarativeItem *p = q->parentItem(); p; p = p->parentItem()) { + if (p->flags() & QGraphicsItem::ItemIsFocusScope) { + if (!flag && QGraphicsItemPrivate::get(p)->focusScopeItem != focusItem) + break; + if (p->d_func()->hadActiveFocus != flag) { + p->d_func()->hadActiveFocus = flag; + emit p->activeFocusChanged(flag); + } + focusItem = p; + } + } + + // For all but the top most focus scope/item this will be called for us by QGraphicsItem. + focusItem->d_func()->focusScopeItemChange(flag); } QDeclarativeListProperty QDeclarativeItemPrivate::resources() diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 8ef91887..20262307 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -128,8 +128,8 @@ public: componentComplete(true), keepMouse(false), smooth(false), transformOriginDirty(true), doneEventPreHandler(false), inheritedLayoutMirror(false), effectiveLayoutMirror(false), isMirrorImplicit(true), - inheritMirrorFromParent(false), inheritMirrorFromItem(false), keyHandler(0), - mWidth(0), mHeight(0), mImplicitWidth(0), mImplicitHeight(0), attachedLayoutDirection(0), hadSubFocusItem(false) + inheritMirrorFromParent(false), inheritMirrorFromItem(false), hadFocus(false), hadActiveFocus(false), keyHandler(0), + mWidth(0), mHeight(0), mImplicitWidth(0), mImplicitHeight(0), attachedLayoutDirection(0) { QGraphicsItemPrivate::acceptedMouseButtons = 0; isDeclarativeItem = 1; @@ -289,6 +289,8 @@ public: bool isMirrorImplicit:1; bool inheritMirrorFromParent:1; bool inheritMirrorFromItem:1; + bool hadFocus:1; + bool hadActiveFocus:1; QDeclarativeItemKeyFilter *keyHandler; @@ -299,7 +301,6 @@ public: QDeclarativeLayoutMirroringAttached* attachedLayoutDirection; - bool hadSubFocusItem; QPointF computeTransformOrigin() const; @@ -311,23 +312,15 @@ public: q->geometryChanged(QRectF(this->pos.x(), this->pos.y(), mWidth, mHeight), oldGeometry); } - // Reimplemented from QGraphicsItemPrivate - virtual void subFocusItemChange() - { - bool hasSubFocusItem = subFocusItem != 0; - if (((flags & QGraphicsItem::ItemIsFocusScope) || !parent) && hasSubFocusItem != hadSubFocusItem) - emit q_func()->activeFocusChanged(hasSubFocusItem); - //see also QDeclarativeItemPrivate::focusChanged - hadSubFocusItem = hasSubFocusItem; - } - // Reimplemented from QGraphicsItemPrivate virtual void focusScopeItemChange(bool isSubFocusItem) { - emit q_func()->focusChanged(isSubFocusItem); + if (hadFocus != isSubFocusItem) { + hadFocus = isSubFocusItem; + emit q_func()->focusChanged(isSubFocusItem); + } } - // Reimplemented from QGraphicsItemPrivate virtual void siblingOrderChange() { diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml new file mode 100644 index 00000000..8345972a --- /dev/null +++ b/tests/auto/declarative/qdeclarativefocusscope/data/notifications.qml @@ -0,0 +1,81 @@ +import QtQuick 1.1 + +Item { + objectName: "rootItem" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item1" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + + Item { + objectName: "item2" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item3" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + } + + FocusScope { + objectName: "scope1" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item4" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + + FocusScope { + objectName: "scope2" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + + Item { + objectName: "item5" + + property bool handlerFocus + property bool handlerActiveFocus + + onFocusChanged: handlerFocus = focus + onActiveFocusChanged: handlerActiveFocus = activeFocus + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index 64c8d210..f7099ba2 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -68,6 +68,10 @@ private slots: void signalEmission(); void qtBug13380(); void forceActiveFocus(); + void notifications(); + void notifications_data(); + void notificationsInScope(); + void notificationsInScope_data(); }; /* @@ -396,8 +400,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus() { QDeclarativeView *view = new QDeclarativeView; view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forceActiveFocus.qml")); + view->show(); + view->activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(view)); - QGraphicsObject *rootObject = view->rootObject(); + QDeclarativeItem *rootObject = qobject_cast(view->rootObject()); QVERIFY(rootObject); QDeclarativeItem *scope = findItem(rootObject, QLatin1String("scope")); @@ -416,6 +423,11 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(scopeB); QVERIFY(itemB2); + QCOMPARE(rootObject->hasActiveFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(scopeA->hasActiveFocus(), false); + QCOMPARE(scopeB->hasActiveFocus(), false); + QSignalSpy rootSpy(rootObject, SIGNAL(activeFocusChanged(bool))); QSignalSpy scopeSpy(scope, SIGNAL(activeFocusChanged(bool))); QSignalSpy scopeASpy(scopeA, SIGNAL(activeFocusChanged(bool))); @@ -424,22 +436,34 @@ void tst_qdeclarativefocusscope::forceActiveFocus() // First, walk the focus from item-a1 down to item-a2 and back again itemA1->forceActiveFocus(); QVERIFY(itemA1->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA2->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); + if (scopeASpy.count() == 3) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeASpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeASpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeASpy.first().first().toBool(), true); + } QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); + if (scopeSpy.count() == 3) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeSpy.first().first().toBool(), true); + } QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); @@ -447,7 +471,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA1->forceActiveFocus(); @@ -455,13 +479,13 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(!scopeA->hasActiveFocus()); QVERIFY(!itemA2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 2); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); // Then jump back and forth between branch 'a' and 'b' itemB1->forceActiveFocus(); QVERIFY(itemB1->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeA->forceActiveFocus(); @@ -469,7 +493,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(!itemB1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 3); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); scopeB->forceActiveFocus(); @@ -478,7 +502,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(scopeB->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 4); QCOMPARE(scopeBSpy.count(), 1); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemA2->forceActiveFocus(); @@ -486,7 +510,7 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemA2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 5); QCOMPARE(scopeBSpy.count(), 2); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); itemB2->forceActiveFocus(); @@ -494,12 +518,259 @@ void tst_qdeclarativefocusscope::forceActiveFocus() QVERIFY(itemB2->hasActiveFocus()); QCOMPARE(scopeASpy.count(), 6); QCOMPARE(scopeBSpy.count(), 3); - QCOMPARE(rootSpy.count(), 1); + QCOMPARE(rootSpy.count(), 0); QCOMPARE(scopeSpy.count(), 1); delete view; } + +void tst_qdeclarativefocusscope::notifications_data() +{ + QTest::addColumn("objectName"); + + QTest::newRow("rootItem") << ""; + QTest::newRow("item1") << "item1"; + QTest::newRow("item3") << "item3"; + QTest::newRow("focusScope") << "scope1"; +} + +void tst_qdeclarativefocusscope::notifications() +{ + QFETCH(QString, objectName); + QDeclarativeView canvas; + canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml")); + canvas.show(); + canvas.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&canvas)); + + QGraphicsScene *scene = canvas.scene(); + + QDeclarativeItem *item = qobject_cast(canvas.rootObject()); + QVERIFY(item); + + item = objectName.isEmpty() ? item : item->findChild(objectName); + QVERIFY(item); + + QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool))); + QSignalSpy activeFocusSpy(item, SIGNAL(activeFocusChanged(bool))); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + + item->setFocus(true); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), true); + + item->setFocus(false); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + + item->QGraphicsItem::setFocus(); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), true); + + item->clearFocus(); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + + scene->setFocusItem(item); + + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), true); + + scene->setFocusItem(0); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(focusSpy.count(), 1); + QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); +} + +void tst_qdeclarativefocusscope::notificationsInScope_data() +{ + QTest::addColumn("itemName"); + QTest::addColumn("scopeName"); + + QTest::newRow("item4") << "item4" << "scope1"; + QTest::newRow("item5") << "item5" << "scope2"; +} + +void tst_qdeclarativefocusscope::notificationsInScope() +{ + QFETCH(QString, itemName); + QFETCH(QString, scopeName); + QDeclarativeView canvas; + canvas.setSource(QUrl::fromLocalFile(SRCDIR "/data/notifications.qml")); + canvas.show(); + canvas.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&canvas)); + + QVERIFY(canvas.rootObject()); + + QDeclarativeItem *scope = canvas.rootObject()->findChild(scopeName); + QVERIFY(scope); + + QDeclarativeItem *item = scope->findChild(itemName); + QVERIFY(item); + + QSignalSpy itemFocusSpy(item, SIGNAL(focusChanged(bool))); + QSignalSpy itemActiveFocusSpy(item, SIGNAL(activeFocusChanged(bool))); + + QSignalSpy scopeFocusSpy(scope, SIGNAL(focusChanged(bool))); + QSignalSpy scopeActiveFocusSpy(scope, SIGNAL(activeFocusChanged(bool))); + + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + QCOMPARE(scope->property("handlerFocus").value(), false); + QCOMPARE(scope->property("handlerActiveFocus").value(), false); + + item->setFocus(true); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(itemActiveFocusSpy.count(), 0); + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + QCOMPARE(scope->property("handlerFocus").value(), false); + QCOMPARE(scope->property("handlerActiveFocus").value(), false); + + item->setFocus(false); + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(itemActiveFocusSpy.count(), 0); + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + QCOMPARE(scope->property("handlerFocus").value(), false); + QCOMPARE(scope->property("handlerActiveFocus").value(), false); + + item->forceActiveFocus(); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), true); + QCOMPARE(scope->property("handlerFocus").value(), true); + QCOMPARE(scope->property("handlerActiveFocus").value(), true); + + scope->setFocus(false); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), false); + QCOMPARE(scope->hasActiveFocus(), false); + QCOMPARE(itemFocusSpy.count(), 0); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + QCOMPARE(scope->property("handlerFocus").value(), false); + QCOMPARE(scope->property("handlerActiveFocus").value(), false); + + scope->setFocus(true); + QCOMPARE(item->hasFocus(), true); + QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 0); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeFocusSpy.count(), 1); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(scopeActiveFocusSpy.count(), 1); + QCOMPARE(scopeActiveFocusSpy.takeFirst().first().toBool(), true); + QCOMPARE(item->property("handlerFocus").value(), true); + QCOMPARE(item->property("handlerActiveFocus").value(), true); + QCOMPARE(scope->property("handlerFocus").value(), true); + QCOMPARE(scope->property("handlerActiveFocus").value(), true); + + item->setFocus(false); + QCOMPARE(item->hasFocus(), false); + QCOMPARE(item->hasActiveFocus(), false); + QCOMPARE(scope->hasFocus(), true); + QCOMPARE(scope->hasActiveFocus(), true); + QCOMPARE(itemFocusSpy.count(), 1); + QCOMPARE(itemFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(itemActiveFocusSpy.count(), 1); + QCOMPARE(itemActiveFocusSpy.takeFirst().first().toBool(), false); + if (scopeFocusSpy.count() == 2) { + qWarning() << "ignoring spurious changed signals"; + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), false); + QCOMPARE(scopeFocusSpy.takeFirst().first().toBool(), true); + } + QCOMPARE(scopeFocusSpy.count(), 0); + QCOMPARE(scopeActiveFocusSpy.count(), 0); + QCOMPARE(item->property("handlerFocus").value(), false); + QCOMPARE(item->property("handlerActiveFocus").value(), false); + QCOMPARE(scope->property("handlerFocus").value(), true); + QCOMPARE(scope->property("handlerActiveFocus").value(), true); +} + QTEST_MAIN(tst_qdeclarativefocusscope) #include "tst_qdeclarativefocusscope.moc" diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 0f61bb7e..0251d74d 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -86,6 +86,11 @@ private slots: void qtbug_16871(); void qtbug_21045(); void hasActiveFocusAfterClear(); + void setAndClearFocusOfItem(); + void setAndClearFocusScopeFocus(); + void setFocusThenSetFocusItem0(); + void setFocusFocusItem0ThenHasActiveFocus(); + private: QDeclarativeEngine engine; }; @@ -1043,6 +1048,7 @@ void tst_QDeclarativeItem::propertyChanges() QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); QCOMPARE(item->hasActiveFocus(), true); + QCOMPARE(item->hasFocus(), true); QCOMPARE(focusSpy.count(),1); QList focusArguments = focusSpy.first(); QVERIFY(focusArguments.count() == 1); @@ -1249,8 +1255,9 @@ void tst_QDeclarativeItem::qtbug_21045() void tst_QDeclarativeItem::hasActiveFocusAfterClear() { QGraphicsScene scene; - QGraphicsView view(&scene); - view.show(); + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); QDeclarativeEngine engine; QDeclarativeComponent qmlComponent(&engine); @@ -1273,6 +1280,174 @@ void tst_QDeclarativeItem::hasActiveFocusAfterClear() QVERIFY(!createdItem->hasActiveFocus()); } +void tst_QDeclarativeItem::setAndClearFocusOfItem() +{ + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "Item { id: root; " + "signal focusChangedTo(bool value);" + "signal activeFocusChangedTo(bool value);" + "onFocusChanged: root.focusChangedTo(focus);" + "onActiveFocusChanged: root.activeFocusChangedTo(activeFocus);" + "}", QUrl("test")); + + QGraphicsItem *createdItem = qobject_cast(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + scene.addItem(createdItem); + + QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool))); + QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool))); + + QVERIFY(!createdItem->hasFocus()); + createdItem->toGraphicsObject()->setFocus(); + QCOMPARE(focusChangedSpy.count(), 1); + QCOMPARE(activeFocusChangedSpy.count(), 1); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true); + + createdItem->toGraphicsObject()->clearFocus(); + QCOMPARE(focusChangedSpy.count(), 1); + QCOMPARE(activeFocusChangedSpy.count(), 1); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false); +} + +void tst_QDeclarativeItem::setAndClearFocusScopeFocus() +{ + //graphicsview init + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + //declarative init + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + + qmlComponent.setData( + "\nimport QtQuick 1.1" + "\nFocusScope {" + "\n id: root" + "\n signal listActiveFocusChangedTo(bool value)" + "\n signal topRectActiveFocusChangedTo(bool value)" + "\n Rectangle {" + "\n id: topRect" + "\n focus: true" + "\n onActiveFocusChanged: root.topRectActiveFocusChangedTo(topRect.activeFocus)" + "\n }" + "\n FocusScope {" + "\n objectName: \"focusScope\"" + "\n onActiveFocusChanged: root.listActiveFocusChangedTo(activeFocus)" + "\n }" + "\n Rectangle { objectName: \"bottom\" }" + "}", QUrl("")); + + QGraphicsItem *createdItem = qobject_cast(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + scene.addItem(createdItem); + + QDeclarativeItem *focusScope = createdItem->toGraphicsObject()->findChild("focusScope"); + QDeclarativeItem *bottomRect = createdItem->toGraphicsObject()->findChild("bottom"); + + QSignalSpy focusScopeSpy(createdItem->toGraphicsObject(), SIGNAL(listActiveFocusChangedTo(bool))); + QSignalSpy topRectFocusSpy(createdItem->toGraphicsObject(), SIGNAL(topRectActiveFocusChangedTo(bool))); + + //#1: root gets activefocus, and in turn the top rectangle + createdItem->setFocus(); + + //#2 + focusScope->setFocus(true); + + //#3 + bottomRect->setFocus(true); + + QCOMPARE(topRectFocusSpy.count(), 2); + QCOMPARE(focusScopeSpy.count(), 2); + + QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), true); //from #1 + QCOMPARE(topRectFocusSpy.takeFirst().first().toBool(), false); //from #2 + + QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), true); //from #2 + QCOMPARE(focusScopeSpy.takeFirst().first().toBool(), false); //from #3 +} + +void tst_QDeclarativeItem::setFocusThenSetFocusItem0() +{ + //graphicsview init + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + //declarative init + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "Item {" + "signal focusChangedTo(bool value);" + "signal activeFocusChangedTo(bool value);" + "onFocusChanged: focusChangedTo(focus);" + "onActiveFocusChanged: activeFocusChangedTo(activeFocus);" + "}", QUrl("")); + + QGraphicsItem *createdItem = qobject_cast(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem); + + scene.addItem(createdItem); + + QSignalSpy focusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(focusChangedTo(bool))); + QSignalSpy activeFocusChangedSpy(createdItem->toGraphicsObject(), SIGNAL(activeFocusChangedTo(bool))); + + createdItem->toGraphicsObject()->setFocus(); + QVERIFY(!focusChangedSpy.isEmpty()); + QVERIFY(!activeFocusChangedSpy.isEmpty()); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), true); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), true); + + scene.setFocusItem(0); + QVERIFY(!focusChangedSpy.isEmpty()); + QVERIFY(!activeFocusChangedSpy.isEmpty()); + QCOMPARE(focusChangedSpy.takeFirst().first().toBool(), false); + QCOMPARE(activeFocusChangedSpy.takeFirst().first().toBool(), false); + QVERIFY(activeFocusChangedSpy.isEmpty()); +} + +void tst_QDeclarativeItem::setFocusFocusItem0ThenHasActiveFocus() +{ + QGraphicsScene scene; + scene.setFocus(); + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + QDeclarativeEngine engine(&scene); + QDeclarativeComponent qmlComponent(&engine); + qmlComponent.setData( + "import QtQuick 1.1;" + "TextInput {" + "width: 100; height: 100;" + "Rectangle { anchors.fill: parent; color: \"yellow\"; z: parent.z - 1 }" + "}", QUrl("")); + QDeclarativeItem *createdItem = qobject_cast(qmlComponent.create(engine.rootContext())); + QVERIFY(createdItem != 0); + + scene.addItem(createdItem); + + createdItem->QGraphicsItem::setFocus(); + QCoreApplication::processEvents(); + scene.setFocusItem(0); + QCoreApplication::processEvents(); + + QVERIFY(!createdItem->hasActiveFocus()); +} + QTEST_MAIN(tst_QDeclarativeItem) #include "tst_qdeclarativeitem.moc" -- cgit v1.2.3 From 86ea7dad2fba0b7262e7f2c665a99324f9bc2f9f Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 7 Mar 2013 14:59:13 +0100 Subject: Fix warnings about unused variables in tests (CLANG). Change-Id: I29d4a41d2b6c4ac5c7b27930257c3853500325a1 Reviewed-by: Frederik Gladhorn --- .../tst_qdeclarativedebugjs.cpp | 4 --- .../tst_qdeclarativedebugobservermode.cpp | 4 --- .../qdeclarativeengine/tst_qdeclarativeengine.cpp | 7 ++++- .../tst_qdeclarativepathview.cpp | 36 ++++++++++------------ 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index 903b3739..995c375a 100644 --- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -133,10 +133,6 @@ private: class tst_QDeclarativeDebugJS : public QDeclarativeDataTest { Q_OBJECT -private: - QDeclarativeDebugConnection *m_conn; - QDeclarativeEngine *m_engine; - QJSDebugClient *m_client; private slots: void initTestCase(); diff --git a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp index 83c2f21a..d97ae70d 100644 --- a/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp +++ b/tests/auto/declarative/qdeclarativedebugobservermode/tst_qdeclarativedebugobservermode.cpp @@ -117,10 +117,6 @@ private: class tst_QDeclarativeDebugObserverMode : public QDeclarativeDataTest { Q_OBJECT -private: - QDeclarativeDebugConnection *m_conn; - QDeclarativeEngine *m_engine; - QDeclarativeObserverModeClient *m_client; private slots: void initTestCase(); diff --git a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp index 7795e026..f67cecdc 100644 --- a/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp +++ b/tests/auto/declarative/qdeclarativeengine/tst_qdeclarativeengine.cpp @@ -334,6 +334,8 @@ public: setFinished(true); } virtual qint64 readData(char* buffer, qint64 number) { + Q_UNUSED(buffer) + Q_UNUSED(number) return 0; } virtual void abort() { } @@ -348,6 +350,9 @@ public: } QNetworkReply *createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0) { + Q_UNUSED(op) + Q_UNUSED(req) + Q_UNUSED(outgoingData) return new MyReply; } }; @@ -356,7 +361,7 @@ class MyFactory : public QDeclarativeNetworkAccessManagerFactory { public: QNetworkAccessManager *create(QObject *parent) { - return new MyManager; + return new MyManager(parent); } }; diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index cd8c5aed..8815dbfb 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -615,45 +615,44 @@ void tst_QDeclarativePathView::moveModel_data() QTest::addColumn("from"); QTest::addColumn("to"); QTest::addColumn("count"); - QTest::addColumn("offset"); QTest::addColumn("currentIndex"); // We have 8 items, with currentIndex == 4 QTest::newRow("move after current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 1 << 4; QTest::newRow("move before current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 3 << 1 << 4; QTest::newRow("move before current to after") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 5. << 3; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 6 << 1 << 3; QTest::newRow("move multiple after current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 5 << 6 << 2 << 4; QTest::newRow("move multiple before current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4. << 4; + << int(QDeclarativePathView::StrictlyEnforceRange) << 0 << 1 << 2 << 4; QTest::newRow("move before current to end") - << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 5. << 3; + << int(QDeclarativePathView::StrictlyEnforceRange) << 2 << 7 << 1 << 3; QTest::newRow("move last to beginning") - << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 3. << 5; + << int(QDeclarativePathView::StrictlyEnforceRange) << 7 << 0 << 1 << 5; QTest::newRow("move current") - << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 2. << 6; + << int(QDeclarativePathView::StrictlyEnforceRange) << 4 << 6 << 1 << 6; QTest::newRow("no range - move after current") - << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 1 << 4; QTest::newRow("no range - move before current") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 3 << 1 << 4; QTest::newRow("no range - move before current to after") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 5. << 3; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 6 << 1 << 3; QTest::newRow("no range - move multiple after current") - << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 5 << 6 << 2 << 4; QTest::newRow("no range - move multiple before current") - << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4. << 4; + << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 2 << 4; QTest::newRow("no range - move before current to end") - << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 5. << 3; + << int(QDeclarativePathView::NoHighlightRange) << 2 << 7 << 1 << 3; QTest::newRow("no range - move last to beginning") - << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 3. << 5; + << int(QDeclarativePathView::NoHighlightRange) << 7 << 0 << 1 << 5; QTest::newRow("no range - move current") - << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 4. << 6; + << int(QDeclarativePathView::NoHighlightRange) << 4 << 6 << 1 << 6; QTest::newRow("no range - move multiple incl. current") - << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 4. << 5; + << int(QDeclarativePathView::NoHighlightRange) << 0 << 1 << 5 << 5; } void tst_QDeclarativePathView::moveModel() @@ -662,7 +661,6 @@ void tst_QDeclarativePathView::moveModel() QFETCH(int, from); QFETCH(int, to); QFETCH(int, count); - QFETCH(qreal, offset); QFETCH(int, currentIndex); QDeclarativeView *window = createView(); -- cgit v1.2.3 From f23ec41d573563e8f2361221bc7bbb5d4d635677 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 7 Mar 2013 15:01:09 +0100 Subject: Fix warning about adding int to a QString (CLANG). Change-Id: If83018b1bd6dcaf7f8104fa9c4c3f4359062623e Reviewed-by: Frederik Gladhorn --- .../qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 1b2fdc4e..6e7c7f6b 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -520,7 +520,7 @@ void tst_qdeclarativevisualdatamodel::qaimRowsMoved() SingleRoleModel model; model.list.clear(); for (int i=0; i<30; i++) - model.list << ("item " + i); + model.list << (QStringLiteral("item ") + QString::number(i)); engine.rootContext()->setContextProperty("myModel", &model); QDeclarativeVisualDataModel *obj = qobject_cast(c.create()); -- cgit v1.2.3 From 8c683045f8933a8574a39e8222d29cb5bc5b243a Mon Sep 17 00:00:00 2001 From: Thomas Kristensen Date: Mon, 11 Mar 2013 12:24:40 +0100 Subject: Makes QSmoothedAnimation respect zero duration. In automated GUI test scenarios it often desired not to wait for animations before verifying a result, so setting the duration to zero should accomplish this, before this patch; if duration was set to zero QSmoothedAnimation would treat it as if duration was not set, and used velocity to calculate animation speed. Change-Id: Ie6520d6c595bd014f3cab69bbb527e773f3850da Reviewed-by: Andreas Aardal Hanssen --- .../util/qdeclarativesmoothedanimation.cpp | 4 ++-- .../data/smoothedanimationZeroDuration.qml | 12 ++++++++++++ .../tst_qdeclarativesmoothedanimation.cpp | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp index 1e68a7a1..240bc5d6 100644 --- a/src/declarative/util/qdeclarativesmoothedanimation.cpp +++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp @@ -100,10 +100,10 @@ bool QSmoothedAnimation::recalc() s = (invert? qreal(-1.0): qreal(1.0)) * s; - if (userDuration > 0 && velocity > 0) { + if (userDuration >= 0 && velocity > 0) { tf = s / velocity; if (tf > (userDuration / qreal(1000.))) tf = (userDuration / qreal(1000.)); - } else if (userDuration > 0) { + } else if (userDuration >= 0) { tf = userDuration / qreal(1000.); } else if (velocity > 0) { tf = s / velocity; diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml new file mode 100644 index 00000000..cba1ffe5 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesmoothedanimation/data/smoothedanimationZeroDuration.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Rectangle { + width: 300; height: 300; + Rectangle { + objectName: "theRect" + color: "red" + width: 60; height: 60; + x: 100; y: 100; + SmoothedAnimation on x { objectName: "easeX"; to: 200; duration: 0 } + } +} diff --git a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp index 452168a6..1d511779 100644 --- a/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp +++ b/tests/auto/declarative/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp @@ -58,6 +58,7 @@ private slots: void simpleAnimation(); void valueSource(); void behavior(); + void zeroDuration(); private: QDeclarativeEngine engine; @@ -201,6 +202,26 @@ void tst_qdeclarativesmoothedanimation::behavior() QTRY_COMPARE(theRect->y(), qreal(200)); } +void tst_qdeclarativesmoothedanimation::zeroDuration() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/smoothedanimationZeroDuration.qml")); + + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *theRect = rect->findChild("theRect"); + QVERIFY(theRect); + + QDeclarativeSmoothedAnimation *easeX = rect->findChild("easeX"); + QVERIFY(easeX); + QVERIFY(easeX->isRunning()); + + QTRY_VERIFY(!easeX->isRunning()); + QTRY_COMPARE(theRect->x(), qreal(200)); +} + QTEST_MAIN(tst_qdeclarativesmoothedanimation) #include "tst_qdeclarativesmoothedanimation.moc" -- cgit v1.2.3