diff options
author | Andreas Aardal Hanssen <andreas@hanssen.name> | 2012-03-07 20:26:17 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-13 20:07:27 +0100 |
commit | bb364c14157df635cf166b293f8cab6c22534aa1 (patch) | |
tree | e2dcbd8a53a0e2eb077b7e4af131e73dcbdaa113 /tests/auto/declarative | |
parent | c051ea15c75851132d08f22825d84d4ea3f49241 (diff) |
Fix QDeclarativeItem::hasActiveFocus().
This function returns true if the item (or, in case it's a focus
scope, one of its children,) has focus (i.e., will
receive key events now), or will receive focus once the scene is
activated. It also returns true if the item has not yet been added
to a scene, but has subFocus, implicating that someone has called
setFocus() on it prior to it being added to the scene; the latter
case seen most commonly in unit tests.
Task-number: QTBUG-24681
Change-Id: Ia1265158108d5d856b57e34a8efee2545cd0deeb
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp index 51e3463d..6359ca86 100644 --- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp +++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp @@ -90,6 +90,7 @@ private slots: void testQtQuick11Attributes_data(); void qtbug_16871(); void qtbug_21045(); + void hasActiveFocusAfterClear(); private: QDeclarativeEngine engine; }; @@ -1250,6 +1251,33 @@ void tst_QDeclarativeItem::qtbug_21045() QVERIFY(!i->hasActiveFocus()); } +void tst_QDeclarativeItem::hasActiveFocusAfterClear() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + view.show(); + + QDeclarativeEngine engine; + 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<QDeclarativeItem*>(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" |