diff options
author | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2010-12-07 13:27:14 (GMT) |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2010-12-07 20:51:16 (GMT) |
commit | 783a278f243c6411f5f32d11f2165b9eed9b6f8c (patch) | |
tree | 7c250ad639d7c669cb5622e2187ac91999479917 /tests/auto/declarative | |
parent | 6af078b2a13f4855a35d48376e58154ee2d57ec1 (diff) | |
download | Qt-783a278f243c6411f5f32d11f2165b9eed9b6f8c.zip Qt-783a278f243c6411f5f32d11f2165b9eed9b6f8c.tar.gz Qt-783a278f243c6411f5f32d11f2165b9eed9b6f8c.tar.bz2 |
Don't emit activeFocusChanged() unless the active focus actually changed
We would previously call subFocusItemChanged(0) on the item as part of
clearing the subfocus, even if the item in question would recieve a new
subfocus item as part of setting the new subfocus.
This resulted in the declarative item emitting activeFocusChanged(false)
and then activeFocusChanged(true), which was affecting any animation or
state bound to the activeFocus property of the item.
We now stop clearing the subfocus when encountering an item that we know
will get subfocus during the set-subfocus pass. We then set subfocus all
the way to the root item, since the subfocus item itself might change.
The effect of this is that the declarative item will only get one call
to subFocusItemChanged(), passing the new subfocus item, instead of two.
This means the declarative item can keep track of wherther ot not it had
a subfocus item previously, and only emit activeFocusChanged() when the
active focus goes from true to false or false to true.
Task-number: QTBUG-15615
Reviewed-by: Yoann Lopes <yoann.lopes@nokia.com>
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativefocusscope/data/forceActiveFocus.qml | 26 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp | 109 |
2 files changed, 135 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/forceActiveFocus.qml b/tests/auto/declarative/qdeclarativefocusscope/data/forceActiveFocus.qml new file mode 100644 index 0000000..6c39d4a --- /dev/null +++ b/tests/auto/declarative/qdeclarativefocusscope/data/forceActiveFocus.qml @@ -0,0 +1,26 @@ +import QtQuick 1.0 + +Rectangle { + objectName: "root" + FocusScope { + objectName: "scope" + Item { + objectName: "item-a1" + FocusScope { + objectName: "scope-a" + Item { + objectName: "item-a2" + } + } + } + Item { + objectName: "item-b1" + FocusScope { + objectName: "scope-b" + Item { + objectName: "item-b2" + } + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp index 1645dac..6a3627b 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp +++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp @@ -71,6 +71,7 @@ private slots: void noParentFocus(); void signalEmission(); void qtBug13380(); + void forceActiveFocus(); }; /* @@ -432,6 +433,114 @@ void tst_qdeclarativefocusscope::qtBug13380() delete view; } +void tst_qdeclarativefocusscope::forceActiveFocus() +{ + QDeclarativeView *view = new QDeclarativeView; + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forceActiveFocus.qml")); + + QGraphicsObject *rootObject = view->rootObject(); + QVERIFY(rootObject); + + QDeclarativeItem *scope = findItem<QDeclarativeItem>(rootObject, QLatin1String("scope")); + QDeclarativeItem *itemA1 = findItem<QDeclarativeItem>(rootObject, QLatin1String("item-a1")); + QDeclarativeItem *scopeA = findItem<QDeclarativeItem>(rootObject, QLatin1String("scope-a")); + QDeclarativeItem *itemA2 = findItem<QDeclarativeItem>(rootObject, QLatin1String("item-a2")); + QDeclarativeItem *itemB1 = findItem<QDeclarativeItem>(rootObject, QLatin1String("item-b1")); + QDeclarativeItem *scopeB = findItem<QDeclarativeItem>(rootObject, QLatin1String("scope-b")); + QDeclarativeItem *itemB2 = findItem<QDeclarativeItem>(rootObject, QLatin1String("item-b2")); + + QVERIFY(scope); + QVERIFY(itemA1); + QVERIFY(scopeA); + QVERIFY(itemA2); + QVERIFY(itemB1); + QVERIFY(scopeB); + QVERIFY(itemB2); + + QSignalSpy rootSpy(rootObject, SIGNAL(activeFocusChanged(bool))); + QSignalSpy scopeSpy(scope, SIGNAL(activeFocusChanged(bool))); + QSignalSpy scopeASpy(scopeA, SIGNAL(activeFocusChanged(bool))); + QSignalSpy scopeBSpy(scopeB, SIGNAL(activeFocusChanged(bool))); + + // First, walk the focus from item-a1 down to item-a2 and back again + itemA1->forceActiveFocus(); + QVERIFY(itemA1->hasActiveFocus()); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + scopeA->forceActiveFocus(); + QVERIFY(!itemA1->hasActiveFocus()); + QVERIFY(scopeA->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 1); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + itemA2->forceActiveFocus(); + QVERIFY(!itemA1->hasActiveFocus()); + QVERIFY(itemA2->hasActiveFocus()); + QVERIFY(scopeA->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 1); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + scopeA->forceActiveFocus(); + QVERIFY(!itemA1->hasActiveFocus()); + QVERIFY(itemA2->hasActiveFocus()); + QVERIFY(scopeA->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 1); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + itemA1->forceActiveFocus(); + QVERIFY(itemA1->hasActiveFocus()); + QVERIFY(!scopeA->hasActiveFocus()); + QVERIFY(!itemA2->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 2); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + // Then jump back and forth between branch 'a' and 'b' + itemB1->forceActiveFocus(); + QVERIFY(itemB1->hasActiveFocus()); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + scopeA->forceActiveFocus(); + QVERIFY(!itemA1->hasActiveFocus()); + QVERIFY(!itemB1->hasActiveFocus()); + QVERIFY(scopeA->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 3); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + scopeB->forceActiveFocus(); + QVERIFY(!scopeA->hasActiveFocus()); + QVERIFY(!itemB1->hasActiveFocus()); + QVERIFY(scopeB->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 4); + QCOMPARE(scopeBSpy.count(), 1); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + itemA2->forceActiveFocus(); + QVERIFY(!scopeB->hasActiveFocus()); + QVERIFY(itemA2->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 5); + QCOMPARE(scopeBSpy.count(), 2); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + itemB2->forceActiveFocus(); + QVERIFY(!itemA2->hasActiveFocus()); + QVERIFY(itemB2->hasActiveFocus()); + QCOMPARE(scopeASpy.count(), 6); + QCOMPARE(scopeBSpy.count(), 3); + QCOMPARE(rootSpy.count(), 1); + QCOMPARE(scopeSpy.count(), 1); + + delete view; +} + QTEST_MAIN(tst_qdeclarativefocusscope) #include "tst_qdeclarativefocusscope.moc" |