summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-07-12 06:21:34 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-07-13 00:00:39 (GMT)
commit686fca1c78e6d4d2ba597dd75d982c76647c7707 (patch)
treefaa3b83407b4ec02efe1b57e5eec5efc0770e956
parent8979501336a441e585d38b711ee0fe4a284040f3 (diff)
downloadQt-686fca1c78e6d4d2ba597dd75d982c76647c7707.zip
Qt-686fca1c78e6d4d2ba597dd75d982c76647c7707.tar.gz
Qt-686fca1c78e6d4d2ba597dd75d982c76647c7707.tar.bz2
wantsFocus should be based on FocusScope chain, not parent chain.
Ancestors of the item with focus should only report wantsFocus as true when they are a FocusScope or a top-level item. Reviewed-by: Aaron Kennedy Reviewed-by: Yann Bodson
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp7
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h4
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/chain.qml28
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml4
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/test.qml2
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/data/test5.qml2
-rw-r--r--tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp23
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp7
8 files changed, 62 insertions, 15 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index f5ea537..62a3215 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2416,6 +2416,8 @@ QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const
void QDeclarativeItemPrivate::focusChanged(bool flag)
{
Q_Q(QDeclarativeItem);
+ if (!(flags & QGraphicsItem::ItemIsFocusScope) && parent)
+ emit q->wantsFocusChanged(flag); //see also QDeclarativeItemPrivate::subFocusItemChange()
emit q->focusChanged(flag);
}
@@ -3107,7 +3109,10 @@ void QDeclarativeItem::setSize(const QSizeF &size)
/*! \internal */
bool QDeclarativeItem::wantsFocus() const
{
- return focusItem() != 0;
+ Q_D(const QDeclarativeItem);
+ return focusItem() == this ||
+ (d->flags & QGraphicsItem::ItemIsFocusScope && focusItem() != 0) ||
+ (!parentItem() && focusItem() != 0);
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index fb416c2..84ae4ef 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -286,7 +286,9 @@ public:
// Reimplemented from QGraphicsItemPrivate
virtual void subFocusItemChange()
{
- emit q_func()->wantsFocusChanged(subFocusItem != 0);
+ if (flags & QGraphicsItem::ItemIsFocusScope || !parent)
+ emit q_func()->wantsFocusChanged(subFocusItem != 0);
+ //see also QDeclarativeItemPrivate::focusChanged
}
// Reimplemented from QGraphicsItemPrivate
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml b/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml
new file mode 100644
index 0000000..6c39f20
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/chain.qml
@@ -0,0 +1,28 @@
+import Qt 4.7
+
+Rectangle {
+ id: root
+ width:300; height:400
+
+ property bool focus1: root.wantsFocus
+ property bool focus2: item1.wantsFocus
+ property bool focus3: fs1.wantsFocus
+ property bool focus4: fs2.wantsFocus
+ property bool focus5: theItem.wantsFocus
+
+ Item {
+ id: item1
+ FocusScope {
+ id: fs1
+ focus: true
+ FocusScope {
+ id: fs2
+ focus: true
+ Item {
+ id: theItem
+ focus: true
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml
index 5904fd6..af9c420 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/forcefocus.qml
@@ -8,10 +8,10 @@ Rectangle {
FocusScope {
id: firstScope
+ objectName: "item0"
focus: true
Rectangle {
- objectName: "item0"
height: 120; width: 420
color: "transparent"
@@ -44,9 +44,9 @@ Rectangle {
FocusScope {
id: secondScope
+ objectName: "item3"
Rectangle {
- objectName: "item3"
y: 160; height: 120; width: 420
color: "transparent"
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml
index 6b09c29..aa43ba8 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/test.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/test.qml
@@ -9,12 +9,12 @@ Rectangle {
FocusScope {
id: myScope
+ objectName: "item0"
focus: true
Keys.onDigit9Pressed: console.log("Error - FocusScope")
Rectangle {
- objectName: "item0"
height: 120
width: 420
diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml
index d67ec57..cdb5164 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml
+++ b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml
@@ -9,12 +9,12 @@ Rectangle {
FocusScope {
id: myScope
+ objectName: "item0"
focus: true
Keys.onReturnPressed: console.log("Error - FocusScope")
Rectangle {
- objectName: "item0"
height: 120
width: 420
diff --git a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
index 7732e6d..2559087 100644
--- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
+++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
@@ -68,6 +68,7 @@ private slots:
void noFocus();
void textEdit();
void forceFocus();
+ void noParentFocus();
};
/*
@@ -97,7 +98,7 @@ void tst_qdeclarativefocusscope::basic()
QDeclarativeView *view = new QDeclarativeView;
view->setSource(QUrl::fromLocalFile(SRCDIR "/data/test.qml"));
- QDeclarativeRectangle *item0 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item0"));
+ QDeclarativeFocusScope *item0 = findItem<QDeclarativeFocusScope>(view->rootObject(), QLatin1String("item0"));
QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1"));
QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2"));
QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3"));
@@ -228,7 +229,7 @@ void tst_qdeclarativefocusscope::textEdit()
QDeclarativeView *view = new QDeclarativeView;
view->setSource(QUrl::fromLocalFile(SRCDIR "/data/test5.qml"));
- QDeclarativeRectangle *item0 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item0"));
+ QDeclarativeFocusScope *item0 = findItem<QDeclarativeFocusScope>(view->rootObject(), QLatin1String("item0"));
QDeclarativeTextEdit *item1 = findItem<QDeclarativeTextEdit>(view->rootObject(), QLatin1String("item1"));
QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2"));
QDeclarativeTextEdit *item3 = findItem<QDeclarativeTextEdit>(view->rootObject(), QLatin1String("item3"));
@@ -283,10 +284,10 @@ void tst_qdeclarativefocusscope::forceFocus()
QDeclarativeView *view = new QDeclarativeView;
view->setSource(QUrl::fromLocalFile(SRCDIR "/data/forcefocus.qml"));
- QDeclarativeRectangle *item0 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item0"));
+ QDeclarativeFocusScope *item0 = findItem<QDeclarativeFocusScope>(view->rootObject(), QLatin1String("item0"));
QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1"));
QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2"));
- QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3"));
+ QDeclarativeFocusScope *item3 = findItem<QDeclarativeFocusScope>(view->rootObject(), QLatin1String("item3"));
QDeclarativeRectangle *item4 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item4"));
QDeclarativeRectangle *item5 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item5"));
QVERIFY(item0 != 0);
@@ -333,6 +334,20 @@ void tst_qdeclarativefocusscope::forceFocus()
delete view;
}
+void tst_qdeclarativefocusscope::noParentFocus()
+{
+ QDeclarativeView *view = new QDeclarativeView;
+ view->setSource(QUrl::fromLocalFile(SRCDIR "/data/chain.qml"));
+ QVERIFY(view->rootObject());
+
+ QVERIFY(view->rootObject()->property("focus1") == true);
+ QVERIFY(view->rootObject()->property("focus2") == false);
+ QVERIFY(view->rootObject()->property("focus3") == true);
+ QVERIFY(view->rootObject()->property("focus4") == true);
+ QVERIFY(view->rootObject()->property("focus5") == true);
+
+ delete view;
+}
QTEST_MAIN(tst_qdeclarativefocusscope)
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index 4a57def..ffb2105 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -703,11 +703,8 @@ void tst_QDeclarativeItem::propertyChanges()
QCOMPARE(focusArguments.at(0).toBool(), true);
QCOMPARE(parentItem->hasFocus(), false);
- QCOMPARE(parentItem->wantsFocus(), true);
- QCOMPARE(wantsFocusSpy.count(),1);
- QList<QVariant> wantsFocusArguments = wantsFocusSpy.first();
- QVERIFY(wantsFocusArguments.count() == 1);
- QCOMPARE(wantsFocusArguments.at(0).toBool(), true);
+ QCOMPARE(parentItem->wantsFocus(), false);
+ QCOMPARE(wantsFocusSpy.count(),0);
delete canvas;
}