From 686fca1c78e6d4d2ba597dd75d982c76647c7707 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 12 Jul 2010 16:21:34 +1000 Subject: 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 --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 7 +++++- src/declarative/graphicsitems/qdeclarativeitem_p.h | 4 +++- .../qdeclarativefocusscope/data/chain.qml | 28 ++++++++++++++++++++++ .../qdeclarativefocusscope/data/forcefocus.qml | 4 ++-- .../qdeclarativefocusscope/data/test.qml | 2 +- .../qdeclarativefocusscope/data/test5.qml | 2 +- .../tst_qdeclarativefocusscope.cpp | 23 ++++++++++++++---- .../qdeclarativeitem/tst_qdeclarativeitem.cpp | 7 ++---- 8 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativefocusscope/data/chain.qml 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(view->rootObject(), QLatin1String("item0")); + QDeclarativeFocusScope *item0 = findItem(view->rootObject(), QLatin1String("item0")); QDeclarativeRectangle *item1 = findItem(view->rootObject(), QLatin1String("item1")); QDeclarativeRectangle *item2 = findItem(view->rootObject(), QLatin1String("item2")); QDeclarativeRectangle *item3 = findItem(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(view->rootObject(), QLatin1String("item0")); + QDeclarativeFocusScope *item0 = findItem(view->rootObject(), QLatin1String("item0")); QDeclarativeTextEdit *item1 = findItem(view->rootObject(), QLatin1String("item1")); QDeclarativeRectangle *item2 = findItem(view->rootObject(), QLatin1String("item2")); QDeclarativeTextEdit *item3 = findItem(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(view->rootObject(), QLatin1String("item0")); + QDeclarativeFocusScope *item0 = findItem(view->rootObject(), QLatin1String("item0")); QDeclarativeRectangle *item1 = findItem(view->rootObject(), QLatin1String("item1")); QDeclarativeRectangle *item2 = findItem(view->rootObject(), QLatin1String("item2")); - QDeclarativeRectangle *item3 = findItem(view->rootObject(), QLatin1String("item3")); + QDeclarativeFocusScope *item3 = findItem(view->rootObject(), QLatin1String("item3")); QDeclarativeRectangle *item4 = findItem(view->rootObject(), QLatin1String("item4")); QDeclarativeRectangle *item5 = findItem(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 wantsFocusArguments = wantsFocusSpy.first(); - QVERIFY(wantsFocusArguments.count() == 1); - QCOMPARE(wantsFocusArguments.at(0).toBool(), true); + QCOMPARE(parentItem->wantsFocus(), false); + QCOMPARE(wantsFocusSpy.count(),0); delete canvas; } -- cgit v0.12 From bfa139ff61d1e5b495fe92be6073ccbdcdc91c77 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 12 Jul 2010 16:35:41 +1000 Subject: Private variable cleanup. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 22 +++++++++++----------- src/declarative/graphicsitems/qdeclarativeitem_p.h | 16 +++++++--------- src/imports/particles/qdeclarativeparticles.cpp | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 62a3215..7022fac 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -1609,7 +1609,7 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const bool QDeclarativeItem::isComponentComplete() const { Q_D(const QDeclarativeItem); - return d->_componentComplete; + return d->componentComplete; } void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty *prop, QObject *o) @@ -1750,7 +1750,7 @@ QRectF QDeclarativeItem::childrenRect() Q_D(QDeclarativeItem); if (!d->_contents) { d->_contents = new QDeclarativeContents(this); - if (d->_componentComplete) + if (d->componentComplete) d->_contents->complete(); } return d->_contents->rectF(); @@ -2154,19 +2154,19 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const qreal QDeclarativeItem::baselineOffset() const { Q_D(const QDeclarativeItem); - if (!d->_baselineOffset.isValid()) { + if (!d->baselineOffset.isValid()) { return 0.0; } else - return d->_baselineOffset; + return d->baselineOffset; } void QDeclarativeItem::setBaselineOffset(qreal offset) { Q_D(QDeclarativeItem); - if (offset == d->_baselineOffset) + if (offset == d->baselineOffset) return; - d->_baselineOffset = offset; + d->baselineOffset = offset; for(int ii = 0; ii < d->changeListeners.count(); ++ii) { const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); @@ -2295,7 +2295,7 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) bool QDeclarativeItem::keepMouseGrab() const { Q_D(const QDeclarativeItem); - return d->_keepMouse; + return d->keepMouse; } /*! @@ -2319,7 +2319,7 @@ bool QDeclarativeItem::keepMouseGrab() const void QDeclarativeItem::setKeepMouseGrab(bool keep) { Q_D(QDeclarativeItem); - d->_keepMouse = keep; + d->keepMouse = keep; } /*! @@ -2592,7 +2592,7 @@ QDeclarativeListProperty QDeclarativeItem::transform() void QDeclarativeItem::classBegin() { Q_D(QDeclarativeItem); - d->_componentComplete = false; + d->componentComplete = false; if (d->_stateGroup) d->_stateGroup->classBegin(); if (d->_anchors) @@ -2610,7 +2610,7 @@ void QDeclarativeItem::classBegin() void QDeclarativeItem::componentComplete() { Q_D(QDeclarativeItem); - d->_componentComplete = true; + d->componentComplete = true; if (d->_stateGroup) d->_stateGroup->componentComplete(); if (d->_anchors) { @@ -2628,7 +2628,7 @@ QDeclarativeStateGroup *QDeclarativeItemPrivate::_states() Q_Q(QDeclarativeItem); if (!_stateGroup) { _stateGroup = new QDeclarativeStateGroup; - if (!_componentComplete) + if (!componentComplete) _stateGroup->classBegin(); QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)), q, SIGNAL(stateChanged(QString))); diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index 84ae4ef..bc5d809 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -120,11 +120,11 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItemPrivate : public QGraphicsItemPrivate public: QDeclarativeItemPrivate() : _anchors(0), _contents(0), - _baselineOffset(0), + baselineOffset(0), _anchorLines(0), _stateGroup(0), origin(QDeclarativeItem::Center), widthValid(false), heightValid(false), - _componentComplete(true), _keepMouse(false), + componentComplete(true), keepMouse(false), smooth(false), transformOriginDirty(true), doneEventPreHandler(false), keyHandler(0), mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0) { @@ -144,12 +144,10 @@ public: QDeclarative_setParent_noEvent(q, parent); q->setParentItem(parent); } - _baselineOffset.invalidate(); + baselineOffset.invalidate(); mouseSetsFocus = false; } - QString _id; - // Private Properties qreal width() const; void setWidth(qreal); @@ -203,7 +201,7 @@ public: if (!_anchors) { Q_Q(QDeclarativeItem); _anchors = new QDeclarativeAnchors(q); - if (!_componentComplete) + if (!componentComplete) _anchors->classBegin(); } return _anchors; @@ -211,7 +209,7 @@ public: QDeclarativeAnchors *_anchors; QDeclarativeContents *_contents; - QDeclarativeNullableValue _baselineOffset; + QDeclarativeNullableValue baselineOffset; struct AnchorLines { AnchorLines(QGraphicsObject *); @@ -260,8 +258,8 @@ public: QDeclarativeItem::TransformOrigin origin:4; bool widthValid:1; bool heightValid:1; - bool _componentComplete:1; - bool _keepMouse:1; + bool componentComplete:1; + bool keepMouse:1; bool smooth:1; bool transformOriginDirty : 1; bool doneEventPreHandler : 1; diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp index a7c445d..e95dfc7 100644 --- a/src/imports/particles/qdeclarativeparticles.cpp +++ b/src/imports/particles/qdeclarativeparticles.cpp @@ -1232,7 +1232,7 @@ void QDeclarativeParticles::burst(int count, int emissionRate) void QDeclarativeParticlesPainter::updateSize() { - if (!d->_componentComplete) + if (!d->componentComplete) return; const int parentX = parentItem()->x(); -- cgit v0.12 From 5efd577b1aea64f422e08ca8d54e041fa4b20783 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 13 Jul 2010 09:45:30 +1000 Subject: Autotest for QTBUG-5491 (Animation in a Behavior doesn't update running) --- .../qdeclarativebehaviors/data/runningTrue.qml | 20 ++++++++++++++++++++ .../tst_qdeclarativebehaviors.cpp | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/runningTrue.qml diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/runningTrue.qml b/tests/auto/declarative/qdeclarativebehaviors/data/runningTrue.qml new file mode 100644 index 0000000..d439875 --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/runningTrue.qml @@ -0,0 +1,20 @@ +import Qt 4.7 + +Rectangle { + id: root + width:200; height:200 + + property real myValue: 0 + + Rectangle { + anchors.centerIn: parent + width: 100 + height: 100 + color: "green" + smooth: true + rotation: myValue + Behavior on rotation { + RotationAnimation { id: rotAnim; objectName: "rotAnim"; direction: RotationAnimation.Shortest } + } + } +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index 70739fb..5c2c145 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include #include #include @@ -78,6 +79,7 @@ private slots: void dontStart(); void startup(); void groupedPropertyCrash(); + void runningTrue(); }; void tst_qdeclarativebehaviors::simpleBehavior() @@ -366,6 +368,22 @@ void tst_qdeclarativebehaviors::groupedPropertyCrash() QVERIFY(rect); //don't crash } +//QTBUG-5491 +void tst_qdeclarativebehaviors::runningTrue() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrue.qml")); + QDeclarativeRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeAbstractAnimation *animation = rect->findChild("rotAnim"); + QVERIFY(animation); + + QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool))); + rect->setProperty("myValue", 180); + QTRY_VERIFY(runningSpy.count() > 0); +} + QTEST_MAIN(tst_qdeclarativebehaviors) #include "tst_qdeclarativebehaviors.moc" -- cgit v0.12