From 8ad965ff19490d8c38ff4562f61fa0ca5b33e3e4 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 4 Nov 2009 14:06:07 +0100 Subject: Fix to the unregistration of the animation to the global timer The unregistration has to happen befaire calling virtual methods to support changing the state in those functions. Reviewed-by: ogoffart --- src/corelib/animation/qabstractanimation.cpp | 30 ++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 948a084..6ab5bde 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -347,29 +347,26 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) state = newState; QWeakPointer guard(q); - q->updateState(oldState, newState); - if (!guard) - return; + //unregistration of the animation must always happen before calls to + //virtual function (updateState) to ensure a correct state of the timer + if (oldState == QAbstractAnimation::Running) { + if (newState == QAbstractAnimation::Paused && hasRegisteredTimer) + QUnifiedTimer::instance()->ensureTimerUpdate(); + //the animation, is not running any more + QUnifiedTimer::instance()->unregisterAnimation(q); + } - //this is to be safe if updateState changes the state - if (state == oldState) + q->updateState(oldState, newState); + if (!guard || newState != state) //this is to be safe if updateState changes the state return; // Notify state change emit q->stateChanged(oldState, newState); - if (!guard) + if (!guard || newState != state) //this is to be safe if updateState changes the state return; switch (state) { case QAbstractAnimation::Paused: - if (hasRegisteredTimer) - // currentTime needs to be updated if pauseTimer is active - QUnifiedTimer::instance()->ensureTimerUpdate(); - if (!guard) - return; - //here we're sure that we were in running state before and that the - //animation is currently registered - QUnifiedTimer::instance()->unregisterAnimation(q); break; case QAbstractAnimation::Running: { @@ -389,15 +386,10 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) case QAbstractAnimation::Stopped: // Leave running state. int dura = q->duration(); - if (!guard) - return; if (deleteWhenStopped) q->deleteLater(); - if (oldState == QAbstractAnimation::Running) - QUnifiedTimer::instance()->unregisterAnimation(q); - if (dura == -1 || loopCount < 0 || (oldDirection == QAbstractAnimation::Forward && (oldCurrentTime * (oldCurrentLoop + 1)) == (dura * loopCount)) || (oldDirection == QAbstractAnimation::Backward && oldCurrentTime == 0)) { -- cgit v0.12 From 41c740c0e3fe0edb08dea9cfabfb91c26baecee5 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 5 Nov 2009 13:48:28 +0100 Subject: Another fix for the registration of the animations --- src/corelib/animation/qabstractanimation.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 6ab5bde..94e88aa 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -347,13 +347,16 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) state = newState; QWeakPointer guard(q); - //unregistration of the animation must always happen before calls to + //(un)registration of the animation must always happen before calls to //virtual function (updateState) to ensure a correct state of the timer + bool isTopLevel = !group || group->state() == QAbstractAnimation::Stopped; if (oldState == QAbstractAnimation::Running) { if (newState == QAbstractAnimation::Paused && hasRegisteredTimer) QUnifiedTimer::instance()->ensureTimerUpdate(); //the animation, is not running any more QUnifiedTimer::instance()->unregisterAnimation(q); + } else { + QUnifiedTimer::instance()->registerAnimation(q, isTopLevel); } q->updateState(oldState, newState); @@ -370,8 +373,6 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState) break; case QAbstractAnimation::Running: { - bool isTopLevel = !group || group->state() == QAbstractAnimation::Stopped; - QUnifiedTimer::instance()->registerAnimation(q, isTopLevel); // this ensures that the value is updated now that the animation is running if (oldState == QAbstractAnimation::Stopped) { -- cgit v0.12 From 2ba1454ff6e3468f8871d2de3afbef8f80b3da07 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 6 Nov 2009 09:14:04 +1000 Subject: Fix bad merge. --- src/corelib/animation/qabstractanimation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 94e88aa..5110ce8 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -262,11 +262,11 @@ void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation, bool isTopL void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) { + unregisterRunningAnimation(animation); + if (!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer) return; - unregisterRunningAnimation(animation); - int idx = animations.indexOf(animation); if (idx != -1) { animations.removeAt(idx); -- cgit v0.12 From 135f09e3599accca53ae825f6c36a17bf1c0f295 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 6 Nov 2009 10:27:58 +1000 Subject: Impove triggerOnStart docs. --- src/declarative/util/qmltimer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 0aa0747..8ee9059 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -176,6 +176,11 @@ void QmlTimer::setRepeating(bool repeating) /*! \qmlproperty bool Timer::triggeredOnStart + When the Timer is started the first trigger is normally after the specified + interval has elapsed. It is sometimes desireable to trigger immediately + when the timer is started, for example to establish an initial + state. + If \a triggeredOnStart is true, the timer will be triggered immediately when started, and subsequently at the specified interval. Note that for a Timer with \e repeat set to false, this will result in the timer being -- cgit v0.12 From cf6bc08676638b01c0f8a40e001b8fb303aaa5f5 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 6 Nov 2009 11:05:50 +1000 Subject: Update semantics of targets/properties and target/property. This is in preparation for renaming targets -> matchTargets and properties to matchProperties. --- demos/declarative/flickr/flickr-desktop.qml | 2 +- demos/declarative/flickr/mobile/GridDelegate.qml | 2 +- demos/declarative/webbrowser/webbrowser.qml | 2 +- src/declarative/util/qmlanimation.cpp | 141 ++++++++++++--------- .../declarative/animations/data/badproperty1.qml | 2 +- .../auto/declarative/animations/tst_animations.cpp | 5 +- 6 files changed, 86 insertions(+), 68 deletions(-) diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml index 337f77c..6dd12eb 100644 --- a/demos/declarative/flickr/flickr-desktop.qml +++ b/demos/declarative/flickr/flickr-desktop.qml @@ -92,7 +92,7 @@ Item { SequentialAnimation { ParentAction { } NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { target: wrapper; properties: "z" } + PropertyAction { targets: wrapper; properties: "z" } } } ] diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 9b9fb24..6c12896 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -62,7 +62,7 @@ SequentialAnimation { ParentAction { } NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { target: wrapper; properties: "z" } + PropertyAction { targets: wrapper; properties: "z" } } } ] diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index cfc2aa7..6cce4c3 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -149,7 +149,7 @@ Item { transitions: [ Transition { NumberAnimation { - target: header + targets: header properties: "progressOff" easing: "easeInOutQuad" duration: 300 diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index bd4c6f7..20e13af 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1014,19 +1014,26 @@ void QmlPropertyAction::transition(QmlStateActions &actions, QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); for (int ii = 0; ii < props.count(); ++ii) props[ii] = props.at(ii).trimmed(); - if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) - props.append(d->propertyName); - - bool targetNeedsReset = false; - if (d->userProperty.isValid() && props.isEmpty() && !target()) { - props.append(d->userProperty.value.name()); - d->target = d->userProperty.value.object(); - targetNeedsReset = true; - } + + bool hasSelectors = !props.isEmpty() || !d->targets.isEmpty() || !d->exclude.isEmpty(); + bool hasTarget = !d->propertyName.isEmpty() || d->target; + + if (hasSelectors && hasTarget) { + qmlInfo(tr("targets/properties/exclude and target/property are mutually exclusive."), this); + return; + } QmlSetPropertyAnimationAction *data = new QmlSetPropertyAnimationAction; - QSet objs; + if (hasTarget && d->value.isValid()) { + Action myAction; + myAction.property = d->createProperty(target(), d->propertyName); + if (myAction.property.isValid()) { + myAction.toValue = d->value; + data->actions << myAction; + } + } + for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -1038,9 +1045,7 @@ void QmlPropertyAction::transition(QmlStateActions &actions, if ((d->targets.isEmpty() || d->targets.contains(obj) || (!same && d->targets.contains(sObj))) && (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) && - (props.contains(propertyName) || (!same && props.contains(sPropertyName))) && - (!target() || target() == obj || (!same && target() == sObj))) { - objs.insert(obj); + (props.contains(propertyName) || (!same && props.contains(sPropertyName)))) { Action myAction = action; if (d->value.isValid()) @@ -1049,18 +1054,20 @@ void QmlPropertyAction::transition(QmlStateActions &actions, modified << action.property; data->actions << myAction; action.fromValue = myAction.toValue; - } - } + } else if (d->userProperty.isValid() && + !hasSelectors && !hasTarget) { + if ((d->userProperty.value.object() == obj || (!same && d->userProperty.value.object() == sObj)) && + (d->userProperty.value.name() == propertyName || (!same && d->userProperty.value.name() == sPropertyName))) { + //### same as above. merge + Action myAction = action; - if (d->value.isValid() && target() && !objs.contains(target())) { - QObject *obj = target(); - for (int jj = 0; jj < props.count(); ++jj) { - Action myAction; - myAction.property = d->createProperty(obj, props.at(jj)); - if (!myAction.property.isValid()) - continue; - myAction.toValue = d->value; - data->actions << myAction; + if (d->value.isValid()) + myAction.toValue = d->value; + + modified << action.property; + data->actions << myAction; + action.fromValue = myAction.toValue; + } } } @@ -1069,8 +1076,6 @@ void QmlPropertyAction::transition(QmlStateActions &actions, } else { delete data; } - if (targetNeedsReset) - d->target = 0; } QML_DEFINE_TYPE(Qt,4,6,PropertyAction,QmlPropertyAction) @@ -1933,24 +1938,37 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); for (int ii = 0; ii < props.count(); ++ii) props[ii] = props.at(ii).trimmed(); - if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) - props.append(d->propertyName); - bool useType = (props.isEmpty() && d->defaultToInterpolatorType) ? true : false; + bool hasSelectors = !props.isEmpty() || !d->targets.isEmpty() || !d->exclude.isEmpty(); + bool hasTarget = !d->propertyName.isEmpty() || d->target; - bool targetNeedsReset = false; - if (d->userProperty.isValid() && props.isEmpty() && !target()) { - props.append(d->userProperty.value.name()); - d->target = d->userProperty.value.object(); - targetNeedsReset = true; + if (hasSelectors && hasTarget) { + qmlInfo(tr("targets/properties/exclude and target/property are mutually exclusive."), this); + return; } + bool useType = (props.isEmpty() && d->propertyName.isEmpty() && d->defaultToInterpolatorType) ? true : false; + PropertyUpdater *data = new PropertyUpdater; data->interpolatorType = d->interpolatorType; data->interpolator = d->interpolator; data->reverse = direction == Backward ? true : false; - QSet objs; + //an explicit animation has been specified + if (hasTarget && d->toIsDefined) { + Action myAction; + myAction.property = d->createProperty(target(), d->propertyName); + if (myAction.property.isValid()) { + if (d->fromIsDefined) { + d->convertVariant(d->from, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); + myAction.fromValue = d->from; + } + d->convertVariant(d->to, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); + myAction.toValue = d->to; + data->actions << myAction; + } + } + for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; @@ -1963,16 +1981,13 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, if ((d->targets.isEmpty() || d->targets.contains(obj) || (!same && d->targets.contains(sObj))) && (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) && (props.contains(propertyName) || (!same && props.contains(sPropertyName)) - || (useType && action.property.propertyType() == d->interpolatorType)) && - (!target() || target() == obj || (!same && target() == sObj))) { - objs.insert(obj); + || (useType && action.property.propertyType() == d->interpolatorType))) { Action myAction = action; - if (d->fromIsDefined) { + if (d->fromIsDefined) myAction.fromValue = d->from; - } else { + else myAction.fromValue = QVariant(); - } if (d->toIsDefined) myAction.toValue = d->to; @@ -1983,25 +1998,29 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, data->actions << myAction; action.fromValue = myAction.toValue; - } - } - - if (d->toIsDefined && target() && !objs.contains(target())) { - QObject *obj = target(); - for (int jj = 0; jj < props.count(); ++jj) { - Action myAction; - myAction.property = d->createProperty(obj, props.at(jj)); - if (!myAction.property.isValid()) - continue; - - if (d->fromIsDefined) { - d->convertVariant(d->from, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); - myAction.fromValue = d->from; - } - d->convertVariant(d->to, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); - myAction.toValue = d->to; - data->actions << myAction; - } + } else if (d->userProperty.isValid() && + !hasSelectors && !hasTarget) { + if ((d->userProperty.value.object() == obj || (!same && d->userProperty.value.object() == sObj)) && + (d->userProperty.value.name() == propertyName || (!same && d->userProperty.value.name() == sPropertyName))) { + //### same as above. merge + Action myAction = action; + + if (d->fromIsDefined) + myAction.fromValue = d->from; + else + myAction.fromValue = QVariant(); + if (d->toIsDefined) + myAction.toValue = d->to; + + d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); + d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()); + + modified << action.property; + + data->actions << myAction; + action.fromValue = myAction.toValue; + } + } } if (data->actions.count()) { @@ -2009,8 +2028,6 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, } else { delete data; } - if (targetNeedsReset) - d->target = 0; } QML_DEFINE_TYPE(Qt,4,6,PropertyAnimation,QmlPropertyAnimation) diff --git a/tests/auto/declarative/animations/data/badproperty1.qml b/tests/auto/declarative/animations/data/badproperty1.qml index 78da34a..df1a98d 100644 --- a/tests/auto/declarative/animations/data/badproperty1.qml +++ b/tests/auto/declarative/animations/data/badproperty1.qml @@ -19,6 +19,6 @@ Rectangle { PropertyChanges { target: MyRect; border.color: "blue" } } transitions: Transition { - ColorAnimation { target: MyRect; to: "red"; properties: "pen.colr"; duration: 1000 } + ColorAnimation { target: MyRect; to: "red"; property: "pen.colr"; duration: 1000 } } } diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index ca383bb..418a3dc 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -198,11 +198,12 @@ void tst_animations::badProperties() { QmlEngine engine; QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badproperty1.qml")); + QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); QmlGraphicsRectangle *rect = qobject_cast(c.create()); QVERIFY(rect); - QTest::ignoreMessage(QtWarningMsg, "QML QmlColorAnimation (file://" SRCDIR "/data/badproperty1.qml:22:9) Cannot animate non-existant property \"pen.colr\""); - rect->setState("state1"); + //### should we warn here are well? + //rect->setState("state1"); } } -- cgit v0.12 From aff81e3fb3253d99cb42f68d08b2979d946153f4 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 6 Nov 2009 12:01:41 +1000 Subject: Rename targets -> matchTargets and properties -> matchProperties. --- demos/declarative/calculator/calculator.qml | 4 +- demos/declarative/flickr/common/ImageDetails.qml | 2 +- demos/declarative/flickr/common/MediaLineEdit.qml | 2 +- demos/declarative/flickr/common/ScrollBar.qml | 2 +- demos/declarative/flickr/common/Star.qml | 2 +- demos/declarative/flickr/flickr-desktop.qml | 8 +- demos/declarative/flickr/flickr-mobile.qml | 4 +- demos/declarative/flickr/mobile/GridDelegate.qml | 6 +- demos/declarative/flickr/mobile/ImageDetails.qml | 2 +- demos/declarative/flickr/mobile/TitleBar.qml | 2 +- demos/declarative/minehunt/minehunt.qml | 2 +- demos/declarative/twitter/content/HomeTitleBar.qml | 2 +- .../declarative/twitter/content/MultiTitleBar.qml | 2 +- demos/declarative/twitter/content/TitleBar.qml | 2 +- demos/declarative/twitter/twitter.qml | 2 +- .../declarative/webbrowser/fieldtext/FieldText.qml | 2 +- demos/declarative/webbrowser/webbrowser.qml | 8 +- doc/src/declarative/animation.qdoc | 12 +- .../snippets/declarative/listview/highlight.qml | 2 +- examples/declarative/anchors/anchor-changes.qml | 2 +- examples/declarative/animations/easing.qml | 4 +- examples/declarative/behaviours/test.qml | 8 +- examples/declarative/layouts/Button.qml | 2 +- examples/declarative/layouts/positioners.qml | 26 ++-- examples/declarative/listview/dynamic.qml | 2 +- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/listview/recipes.qml | 2 +- examples/declarative/loader/Browser.qml | 10 +- examples/declarative/parallax/qml/ParallaxView.qml | 2 +- examples/declarative/scrollbar/ScrollBar.qml | 2 +- examples/declarative/scrollbar/display.qml | 2 +- examples/declarative/searchbox/SearchBox.qml | 4 +- examples/declarative/slideswitch/Switch.qml | 2 +- examples/declarative/snow/ImageBatch.qml | 12 +- examples/declarative/states/transitions.qml | 8 +- .../declarative/tutorials/helloworld/tutorial3.qml | 2 +- .../samegame/samegame4/content/BoomBlock.qml | 2 +- examples/declarative/velocity/Day.qml | 2 +- examples/declarative/webview/autosize.qml | 2 +- examples/declarative/webview/content/FieldText.qml | 2 +- examples/declarative/xmldata/yahoonews.qml | 4 +- src/declarative/QmlChanges.txt | 2 + src/declarative/util/qmlanimation.cpp | 168 ++++++++++++++------- src/declarative/util/qmlanimation_p.h | 8 +- .../auto/declarative/animations/data/badtype4.qml | 4 +- .../declarative/animations/data/dotproperty.qml | 4 +- .../declarative/animations/data/mixedtype1.qml | 2 +- .../declarative/animations/data/mixedtype2.qml | 2 +- .../declarative/behaviors/data/nonSelecting.qml | 2 +- .../declarative/behaviors/data/nonSelecting2.qml | 26 ++++ tests/auto/declarative/behaviors/tst_behaviors.cpp | 27 +++- .../declarative/layouts/data/grid-animated.qml | 6 +- .../layouts/data/horizontal-animated.qml | 6 +- .../declarative/layouts/data/vertical-animated.qml | 6 +- .../visual/bindinganimation/bindinganimation.qml | 2 +- tests/auto/declarative/visual/easing/easing.qml | 2 +- 56 files changed, 273 insertions(+), 166 deletions(-) create mode 100644 tests/auto/declarative/behaviors/data/nonSelecting2.qml diff --git a/demos/declarative/calculator/calculator.qml b/demos/declarative/calculator/calculator.qml index 54af7ad..d9b73ed 100644 --- a/demos/declarative/calculator/calculator.qml +++ b/demos/declarative/calculator/calculator.qml @@ -118,7 +118,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { properties: "x,y,width"; easing: "easeOutBounce"; duration: 500 } - NumberAnimation { properties: "opacity"; easing: "easeInOutQuad"; duration: 500 } + NumberAnimation { matchProperties: "x,y,width"; easing: "easeOutBounce"; duration: 500 } + NumberAnimation { matchProperties: "opacity"; easing: "easeInOutQuad"; duration: 500 } } } diff --git a/demos/declarative/flickr/common/ImageDetails.qml b/demos/declarative/flickr/common/ImageDetails.qml index 19cad06..95c32e8 100644 --- a/demos/declarative/flickr/common/ImageDetails.qml +++ b/demos/declarative/flickr/common/ImageDetails.qml @@ -149,7 +149,7 @@ Flipable { property: "smooth" value: false } - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } + NumberAnimation { easing: "easeInOutQuad"; matchProperties: "angle"; duration: 500 } PropertyAction { target: bigImage property: "smooth" diff --git a/demos/declarative/flickr/common/MediaLineEdit.qml b/demos/declarative/flickr/common/MediaLineEdit.qml index b24b296..abc8034 100644 --- a/demos/declarative/flickr/common/MediaLineEdit.qml +++ b/demos/declarative/flickr/common/MediaLineEdit.qml @@ -42,7 +42,7 @@ Item { ] transitions: [ Transition { - NumberAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x,width"; duration: 500; easing: "easeInOutQuad" } } ] diff --git a/demos/declarative/flickr/common/ScrollBar.qml b/demos/declarative/flickr/common/ScrollBar.qml index feebcb0..2c1ec8a 100644 --- a/demos/declarative/flickr/common/ScrollBar.qml +++ b/demos/declarative/flickr/common/ScrollBar.qml @@ -32,7 +32,7 @@ Item { to: "*" NumberAnimation { target: container - properties: "opacity" + matchProperties: "opacity" duration: 400 } } diff --git a/demos/declarative/flickr/common/Star.qml b/demos/declarative/flickr/common/Star.qml index 173021b..c5abcca 100644 --- a/demos/declarative/flickr/common/Star.qml +++ b/demos/declarative/flickr/common/Star.qml @@ -37,7 +37,7 @@ Item { transitions: [ Transition { NumberAnimation { - properties: "opacity,scale,x,y" + matchProperties: "opacity,scale,x,y" easing: "easeOutBounce" } } diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml index 6dd12eb..9c85237 100644 --- a/demos/declarative/flickr/flickr-desktop.qml +++ b/demos/declarative/flickr/flickr-desktop.qml @@ -84,15 +84,15 @@ Item { from: "*"; to: "Details" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } } }, Transition { from: "Details"; to: "*" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { targets: wrapper; properties: "z" } + NumberAnimation { matchProperties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + PropertyAction { matchTargets: wrapper; matchProperties: "z" } } } ] @@ -178,7 +178,7 @@ Item { transitions: [ Transition { from: "*"; to: "*" - NumberAnimation { properties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" } + NumberAnimation { matchProperties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" } } ] } diff --git a/demos/declarative/flickr/flickr-mobile.qml b/demos/declarative/flickr/flickr-mobile.qml index 0a89c4f..583f992 100644 --- a/demos/declarative/flickr/flickr-mobile.qml +++ b/demos/declarative/flickr/flickr-mobile.qml @@ -38,7 +38,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x"; duration: 500; easing: "easeInOutQuad" } } } @@ -76,7 +76,7 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x"; duration: 500; easing: "easeInOutQuad" } } } } diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml index 6c12896..3a42507 100644 --- a/demos/declarative/flickr/mobile/GridDelegate.qml +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -55,14 +55,14 @@ Transition { from: "Show"; to: "Details" ParentAction { } - NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x,y"; duration: 500; easing: "easeInOutQuad" } }, Transition { from: "Details"; to: "Show" SequentialAnimation { ParentAction { } - NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { targets: wrapper; properties: "z" } + NumberAnimation { matchProperties: "x,y"; duration: 500; easing: "easeInOutQuad" } + PropertyAction { matchTargets: wrapper; matchProperties: "z" } } } ] diff --git a/demos/declarative/flickr/mobile/ImageDetails.qml b/demos/declarative/flickr/mobile/ImageDetails.qml index 1963bf5..9116428 100644 --- a/demos/declarative/flickr/mobile/ImageDetails.qml +++ b/demos/declarative/flickr/mobile/ImageDetails.qml @@ -117,7 +117,7 @@ Flipable { transitions: Transition { SequentialAnimation { PropertyAction { target: bigImage; property: "smooth"; value: false } - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } + NumberAnimation { easing: "easeInOutQuad"; matchProperties: "angle"; duration: 500 } PropertyAction { target: bigImage; property: "smooth"; value: !flickable.moving } } } diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index 07b9762..0341585 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -71,6 +71,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x"; easing: "easeInOutQuad" } } } diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index e71ce90..596e82d 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -93,7 +93,7 @@ Item { } NumberAnimation { easing: "easeInOutQuad" - properties: "angle" + matchProperties: "angle" } ScriptAction{ script: if(modelData.hasMine && modelData.flipped){expl.explode = true;} diff --git a/demos/declarative/twitter/content/HomeTitleBar.qml b/demos/declarative/twitter/content/HomeTitleBar.qml index f0d6d75..b4f24ea 100644 --- a/demos/declarative/twitter/content/HomeTitleBar.qml +++ b/demos/declarative/twitter/content/HomeTitleBar.qml @@ -114,7 +114,7 @@ Item { transitions: [ Transition { from: "*"; to: "*" - NumberAnimation { properties: "x,y,width,height"; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x,y,width,height"; easing: "easeInOutQuad" } } ] } diff --git a/demos/declarative/twitter/content/MultiTitleBar.qml b/demos/declarative/twitter/content/MultiTitleBar.qml index ef7de65..ef8a450 100644 --- a/demos/declarative/twitter/content/MultiTitleBar.qml +++ b/demos/declarative/twitter/content/MultiTitleBar.qml @@ -18,7 +18,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } } + Transition { NumberAnimation { matchProperties: "x,y"; duration: 500; easing: "easeInOutQuad" } } ] } diff --git a/demos/declarative/twitter/content/TitleBar.qml b/demos/declarative/twitter/content/TitleBar.qml index 07b9762..0341585 100644 --- a/demos/declarative/twitter/content/TitleBar.qml +++ b/demos/declarative/twitter/content/TitleBar.qml @@ -71,6 +71,6 @@ Item { } transitions: Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "x"; easing: "easeInOutQuad" } } } diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index 6cc67a1..db1ae39 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -87,7 +87,7 @@ Item { } ] transitions: [ - Transition { NumberAnimation { properties: "x,y"; duration: 500; easing: "easeInOutQuad" } } + Transition { NumberAnimation { matchProperties: "x,y"; duration: 500; easing: "easeInOutQuad" } } ] } } diff --git a/demos/declarative/webbrowser/fieldtext/FieldText.qml b/demos/declarative/webbrowser/fieldtext/FieldText.qml index b1c1938..6b1d271 100644 --- a/demos/declarative/webbrowser/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/fieldtext/FieldText.qml @@ -149,7 +149,7 @@ Item { to: "*" reversible: true NumberAnimation { - properties: "opacity,leftMargin,rightMargin" + matchProperties: "opacity,leftMargin,rightMargin" duration: 200 } ColorAnimation { diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index 6cce4c3..6be3e09 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -149,8 +149,8 @@ Item { transitions: [ Transition { NumberAnimation { - targets: header - properties: "progressOff" + matchTargets: header + matchProperties: "progressOff" easing: "easeInOutQuad" duration: 300 } @@ -341,7 +341,7 @@ Item { transitions: [ Transition { NumberAnimation { - properties: "opacity" + matchProperties: "opacity" easing: "easeInOutQuad" duration: 300 } @@ -397,7 +397,7 @@ Item { transitions: [ Transition { NumberAnimation { - properties: "opacity" + matchProperties: "opacity" easing: "easeInOutQuad" duration: 320 } diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index ef18de3..ba45d81 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -113,7 +113,7 @@ For example, a transition could describe how an item moves from its initial posi transitions: [ Transition { NumberAnimation { - properties: "x,y" + matchProperties: "x,y" easing: "easeOutBounce" duration: 200 } @@ -123,7 +123,7 @@ transitions: [ As you can see from the above example, transitions make use of the same basic animation classes introduced above. However, you generally use a different set of properties when working with transitions. In the example, -no target or property has been specified. Instead, we have specified properties, which acts as a selector to +no target or property has been specified. Instead, we have specified matchProperties, which acts as a selector to determine which property changes to animate; in this case, we will animate any x,y properties that have changed on any objects. @@ -156,13 +156,13 @@ Transition { NumberAnimation { duration: 1000 easing: "easeOutBounce" - target: box1 - properties: "x,y" + matchTargets: box1 + matchProperties: "x,y" } NumberAnimation { duration: 1000 - target: box2 - properties: "x,y" + matchTargets: box2 + matchProperties: "x,y" } } } diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index 7970ede..b016f9a 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -30,7 +30,7 @@ Rectangle { } ] transitions: [ - Transition { NumberAnimation { properties: "x"; duration: 200 } } + Transition { NumberAnimation { matchProperties: "x"; duration: 200 } } ] } } diff --git a/examples/declarative/anchors/anchor-changes.qml b/examples/declarative/anchors/anchor-changes.qml index f6fd35d..2ebe1c0 100644 --- a/examples/declarative/anchors/anchor-changes.qml +++ b/examples/declarative/anchors/anchor-changes.qml @@ -41,6 +41,6 @@ Item { } transitions : Transition { - NumberAnimation { properties: "y,height" } + NumberAnimation { matchProperties: "y,height" } } } diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml index 59e9b17..a9ba05f 100644 --- a/examples/declarative/animations/easing.qml +++ b/examples/declarative/animations/easing.qml @@ -80,8 +80,8 @@ Rectangle { transitions: Transition { ParallelAnimation { - NumberAnimation { properties: "x"; easing: type; duration: 1000 } - ColorAnimation { properties: "color"; easing: type; duration: 1000 } + NumberAnimation { matchProperties: "x"; easing: type; duration: 1000 } + ColorAnimation { matchProperties: "color"; easing: type; duration: 1000 } } } } diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml index 946559b..4a44fd7 100644 --- a/examples/declarative/behaviours/test.qml +++ b/examples/declarative/behaviours/test.qml @@ -61,7 +61,7 @@ Rectangle { SequentialAnimation { NumberAnimation { target: bluerect - properties: "y" + property: "y" from: 0 to: 10 easing: "easeOutBounce(amplitude:30)" @@ -69,7 +69,7 @@ Rectangle { } NumberAnimation { target: bluerect - properties: "y" + property: "y" from: 10 to: 0 easing: "easeOutBounce(amplitude:30)" @@ -83,14 +83,14 @@ Rectangle { SequentialAnimation { NumberAnimation { target: bluerect - properties: "opacity" + property: "opacity" to: 0 duration: 150 } PropertyAction {} NumberAnimation { target: bluerect - properties: "opacity" + property: "opacity" to: 1 duration: 150 } diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml index 44d0c7b..215b536 100644 --- a/examples/declarative/layouts/Button.qml +++ b/examples/declarative/layouts/Button.qml @@ -17,6 +17,6 @@ Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.wid transitions: Transition{ - NumberAnimation { properties:"x,left"; easing:"easeInOutQuad"; duration:200 } + NumberAnimation { matchProperties:"x,left"; easing:"easeInOutQuad"; duration:200 } } } diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index 90efde2..129effe 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -11,17 +11,17 @@ Rectangle { y: 0 move: Transition { NumberAnimation { - properties: "y"; easing: "easeOutBounce" + matchProperties: "y"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - properties: "y"; from: 500; duration:500; easing: "easeOutQuad" + matchProperties: "y"; from: 500; duration:500; easing: "easeOutQuad" } } remove: Transition { NumberAnimation { - properties:"y"; to: 500; duration:500; easing: "easeInQuad" + matchProperties:"y"; to: 500; duration:500; easing: "easeInQuad" } } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } @@ -36,23 +36,23 @@ Rectangle { y: 300 move: Transition { NumberAnimation { - properties: "x"; easing: "easeOutBounce" + matchProperties: "x"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - properties: "x"; from: 500; duration:500; easing: "easeOutQuad" + matchProperties: "x"; from: 500; duration:500; easing: "easeOutQuad" } NumberAnimation { - properties: "opacity"; from: 0; duration: 500; + matchProperties: "opacity"; from: 0; duration: 500; } } remove: Transition { NumberAnimation { - properties: "x"; to: 500; duration:500; easing: "easeInQuad" + matchProperties: "x"; to: 500; duration:500; easing: "easeInQuad" } NumberAnimation { - properties: "opacity"; from: 1; duration: 500 + matchProperties: "opacity"; from: 1; duration: 500 } } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } @@ -103,25 +103,25 @@ Rectangle { remove: Transition { NumberAnimation { - properties: "opacity"; from: 1; to: 0; duration: 500 + matchProperties: "opacity"; from: 1; to: 0; duration: 500 } NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + matchProperties: "x,y"; easing: "easeOutBounce" } } move: Transition { NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + matchProperties: "x,y"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - properties: "opacity"; from: 0; to: 1; duration: 500 + matchProperties: "opacity"; from: 0; to: 1; duration: 500 } NumberAnimation { - properties: "x,y"; easing: "easeOutBounce" + matchProperties: "x,y"; easing: "easeOutBounce" } } diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 2607527..101b708 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -122,7 +122,7 @@ Rectangle { PropertyChanges { target: verticalScrollBar; opacity: 1 } } ] - transitions: [ Transition { NumberAnimation { properties: "opacity"; duration: 400 } } ] + transitions: [ Transition { NumberAnimation { matchProperties: "opacity"; duration: 400 } } ] } Row { diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index be1f62d..9665499 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -31,7 +31,7 @@ Rectangle { transitions: [ Transition { NumberAnimation { - properties: "x"; duration: 200 + matchProperties: "x"; duration: 200 } } ] diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml index 3410f56..c133351 100644 --- a/examples/declarative/listview/recipes.qml +++ b/examples/declarative/listview/recipes.qml @@ -124,7 +124,7 @@ Rectangle { ParallelAnimation { ColorAnimation { property: "color"; duration: 500 } NumberAnimation { - duration: 300; properties: "detailsOpacity,x,viewportY,height,width" + duration: 300; matchProperties: "detailsOpacity,x,viewportY,height,width" } } } diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 9139346..f3a1182 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -132,12 +132,12 @@ Rectangle { Transition { to: "current" SequentialAnimation { - NumberAnimation { properties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } } }, Transition { - NumberAnimation { properties: "x"; duration: 250 } - NumberAnimation { properties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } } ] } @@ -171,11 +171,11 @@ Rectangle { Transition { to: "current" SequentialAnimation { - NumberAnimation { properties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } } }, Transition { - NumberAnimation { properties: "x"; duration: 250 } + NumberAnimation { matchProperties: "x"; duration: 250 } } ] } diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index ac84b47..98dd246 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -80,7 +80,7 @@ Item { } transitions: Transition { NumberAnimation { - properties: "scale,y" + matchProperties: "scale,y" } } } diff --git a/examples/declarative/scrollbar/ScrollBar.qml b/examples/declarative/scrollbar/ScrollBar.qml index 802b537..f68775c 100644 --- a/examples/declarative/scrollbar/ScrollBar.qml +++ b/examples/declarative/scrollbar/ScrollBar.qml @@ -2,7 +2,7 @@ import Qt 4.6 Item { id: scrollBar - // The properties that define the scrollbar's state. + // The matchProperties that define the scrollbar's state. // position and pageSize are in the range 0.0 - 1.0. They are relative to the // height of the page, i.e. a pageSize of 0.5 means that you can see 50% // of the height of the view. diff --git a/examples/declarative/scrollbar/display.qml b/examples/declarative/scrollbar/display.qml index 536a8b7..0b9f95a 100644 --- a/examples/declarative/scrollbar/display.qml +++ b/examples/declarative/scrollbar/display.qml @@ -27,7 +27,7 @@ Rectangle { from: "*" to: "*" NumberAnimation { - properties: "opacity" + matchProperties: "opacity" duration: 400 } } diff --git a/examples/declarative/searchbox/SearchBox.qml b/examples/declarative/searchbox/SearchBox.qml index 7077a11..42b5d67 100644 --- a/examples/declarative/searchbox/SearchBox.qml +++ b/examples/declarative/searchbox/SearchBox.qml @@ -50,11 +50,11 @@ FocusScope { transitions: [ Transition { from: ""; to: "hasText" - NumberAnimation { exclude: typeSomething; properties: "opacity" } + NumberAnimation { exclude: typeSomething; matchProperties: "opacity" } }, Transition { from: "hasText"; to: "" - NumberAnimation { properties: "opacity" } + NumberAnimation { matchProperties: "opacity" } } ] } diff --git a/examples/declarative/slideswitch/Switch.qml b/examples/declarative/slideswitch/Switch.qml index 1620805..4e13976 100644 --- a/examples/declarative/slideswitch/Switch.qml +++ b/examples/declarative/slideswitch/Switch.qml @@ -52,7 +52,7 @@ Item { ] transitions: [ Transition { - NumberAnimation { properties: "x"; easing: "easeInOutQuad"; duration: 200 } + NumberAnimation { matchProperties: "x"; easing: "easeInOutQuad"; duration: 200 } } ] } diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml index 95b9b97..1d738b2 100644 --- a/examples/declarative/snow/ImageBatch.qml +++ b/examples/declarative/snow/ImageBatch.qml @@ -23,7 +23,7 @@ GridView { transitions: Transition { SequentialAnimation { PauseAnimation { duration: 150 } - PropertyAction { properties: "z" } + PropertyAction { matchProperties: "z" } } } model: XmlListModel { @@ -42,7 +42,7 @@ GridView { width: grid.imageWidth; height: grid.imageHeight; Image { id: flickrImage; source: url; fillMode: Image.PreserveAspectFit; smooth: true; anchors.fill: parent; - opacity: (status == Image.Ready)?1:0; opacity: Behavior { NumberAnimation { properties: "opacity" } } } + opacity: (status == Image.Ready)?1:0; opacity: Behavior { NumberAnimation { } } } Loading { anchors.centerIn: parent; visible: flickrImage.status!=1 } states: State { @@ -55,15 +55,15 @@ GridView { to: "selected" SequentialAnimation { PauseAnimation { duration: 150 } - PropertyAction { properties: "z" } - NumberAnimation { properties: "scale"; duration: 150; } + PropertyAction { matchProperties: "z" } + NumberAnimation { matchProperties: "scale"; duration: 150; } } }, Transition { from: "selected" SequentialAnimation { - NumberAnimation { properties: "scale"; duration: 150 } - PropertyAction { properties: "z" } + NumberAnimation { matchProperties: "scale"; duration: 150 } + PropertyAction { matchProperties: "z" } } } ] diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index ba97d9be..925d90e 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -48,23 +48,23 @@ Rectangle { } ] - // transitions define how the properties change. + // transitions define how the matchProperties change. transitions: [ // When transitioning to 'Position1' move x,y over a duration of 1 second, // with easeOutBounce easing function. Transition { from: "*"; to: "Position1" - NumberAnimation { properties: "x,y"; easing: "easeOutBounce"; duration: 1000 } + NumberAnimation { matchProperties: "x,y"; easing: "easeOutBounce"; duration: 1000 } }, // When transitioning to 'Position2' move x,y over a duration of 2 seconds, // with easeInOutQuad easing function. Transition { from: "*"; to: "Position2" - NumberAnimation { properties: "x,y"; easing: "easeInOutQuad"; duration: 2000 } + NumberAnimation { matchProperties: "x,y"; easing: "easeInOutQuad"; duration: 2000 } }, // For any other state changes move x,y linearly over duration of 200ms. Transition { - NumberAnimation { properties: "x,y"; duration: 200 } + NumberAnimation { matchProperties: "x,y"; duration: 200 } } ] } diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 534d663..52c3fe8 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -28,7 +28,7 @@ Rectangle { transitions: Transition { from: ""; to: "down"; reversible: true ParallelAnimation { - NumberAnimation { properties: "y,rotation"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { matchProperties: "y,rotation"; duration: 500; easing: "easeInOutQuad" } ColorAnimation { property: "color"; duration: 500 } } } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index 4c2ba43..2eb2ceb 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -24,7 +24,7 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } + opacity: Behavior { NumberAnimation { matchProperties:"opacity"; duration: 200 } } anchors.fill: parent } //![2] diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 030fa13..3a7ffa9 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -71,7 +71,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { properties: "rotation,scale"; duration: 200 } + NumberAnimation { matchProperties: "rotation,scale"; duration: 200 } } } } diff --git a/examples/declarative/webview/autosize.qml b/examples/declarative/webview/autosize.qml index 74c6844..1614906 100644 --- a/examples/declarative/webview/autosize.qml +++ b/examples/declarative/webview/autosize.qml @@ -1,7 +1,7 @@ import Qt 4.6 // The WebView size is determined by the width, height, -// preferredWidth, and preferredHeight properties. +// preferredWidth, and preferredHeight matchProperties. Rectangle { id: rect color: "white" diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml index b1c1938..6b1d271 100644 --- a/examples/declarative/webview/content/FieldText.qml +++ b/examples/declarative/webview/content/FieldText.qml @@ -149,7 +149,7 @@ Item { to: "*" reversible: true NumberAnimation { - properties: "opacity,leftMargin,rightMargin" + matchProperties: "opacity,leftMargin,rightMargin" duration: 200 } ColorAnimation { diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 7d8b8a2..4add361 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -61,8 +61,8 @@ Rectangle { transitions: Transition { from: "*"; to: "Details"; reversible: true SequentialAnimation { - NumberAnimation { duration: 200; properties: "height"; easing: "easeOutQuad" } - NumberAnimation { duration: 200; properties: "opacity" } + NumberAnimation { duration: 200; matchProperties: "height"; easing: "easeOutQuad" } + NumberAnimation { duration: 200; matchProperties: "opacity" } } } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index c85ef77..97cefd5 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -70,6 +70,8 @@ ListView: wrap -> keyNavigationWraps ListView: autoHighlight -> highlightFollowsCurrentItem GridView: wrap -> keyNavigationWraps GridView: autoHighlight -> highlightFollowsCurrentItem +Animation: targets -> matchTargets +Animation: properties -> matchProperties Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 20e13af..7c5bc50 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -422,21 +422,6 @@ void QmlAbstractAnimation::setGroup(QmlAnimationGroup *g) setParent(g); } -/*! - \qmlproperty Object PropertyAction::target - This property holds an explicit target object to animate. - - The exact effect of the \c target property depends on how the animation - is being used. Refer to the \l animation documentation for details. -*/ - -/*! - \qmlproperty Object PropertyAnimation::target - This property holds an explicit target object to animate. - - The exact effect of the \c target property depends on how the animation - is being used. Refer to the \l animation documentation for details. -*/ QObject *QmlAbstractAnimation::target() const { Q_D(const QmlAbstractAnimation); @@ -459,21 +444,6 @@ void QmlAbstractAnimation::setTarget(QObject *o) emit targetChanged(d->target, d->propertyName); } -/*! - \qmlproperty string PropertyAction::property - This property holds an explicit property to animated. - - The exact effect of the \c property property depends on how the animation - is being used. Refer to the \l animation documentation for details. -*/ - -/*! - \qmlproperty string PropertyAnimation::property - This property holds an explicit property to animated. - - The exact effect of the \c property property depends on how the animation - is being used. Refer to the \l animation documentation for details. -*/ QString QmlAbstractAnimation::property() const { Q_D(const QmlAbstractAnimation); @@ -880,7 +850,7 @@ QML_DEFINE_TYPE(Qt,4,6,ScriptAction,QmlScriptAction) Set \c thewebview.url to the value set for the destination state: \code - PropertyAction { target: thewebview; property: "url" } + PropertyAction { matchTargets: thewebview; matchProperties: "url" } \endcode The PropertyAction is immediate - @@ -909,8 +879,33 @@ void QmlPropertyActionPrivate::init() } /*! - \qmlproperty string PropertyAction::properties - This property holds the properties to be immediately set, comma-separated. + \qmlproperty Object PropertyAction::target + This property holds an explicit target object to animate. + + The exact effect of the \c target property depends on how the animation + is being used. Refer to the \l animation documentation for details. +*/ + +/*! + \qmlproperty string PropertyAction::property + This property holds an explicit property to animated. + + The exact effect of the \c property property depends on how the animation + is being used. Refer to the \l animation documentation for details. +*/ + +/*! + \qmlproperty string PropertyAction::matchProperties + This property holds a comma-separated list of property names this action + will match against. These names are used in conjunction with matchTargets + to create a list of properties that the action will set, assuming those + properties have changed. + + This property is typically used for an action appearing as part of a Transition. + + By default, no property names will be matched. + + \sa matchTargets PropertyAnimation::matchProperties */ QString QmlPropertyAction::properties() const { @@ -928,9 +923,16 @@ void QmlPropertyAction::setProperties(const QString &p) } /*! - \qmlproperty list PropertyAction::targets - This property holds the items selected to be affected by this animation (all if not set). - \sa exclude + \qmlproperty list PropertyAction::matchTargets + This property holds a list of objects this action will match against. + These objects are used in conjunction with matchProperties to create a list of properties + that the action will set, assuming those properties have changed. + + This property is typically used for an action appearing as part of a Transition. + + By default, all changing targets will be matched. + + \sa exclude matchProperties PropertyAnimation::matchTargets */ QList *QmlPropertyAction::targets() { @@ -939,9 +941,9 @@ QList *QmlPropertyAction::targets() } /*! - \qmlproperty list PropertyAction::exclude - This property holds the items not to be affected by this animation. - \sa targets + \qmlproperty list PropertyAction::exclude + This property holds the objects not to be affected by this animation. + \sa matchTargets */ QList *QmlPropertyAction::exclude() { @@ -1019,7 +1021,7 @@ void QmlPropertyAction::transition(QmlStateActions &actions, bool hasTarget = !d->propertyName.isEmpty() || d->target; if (hasSelectors && hasTarget) { - qmlInfo(tr("targets/properties/exclude and target/property are mutually exclusive."), this); + qmlInfo(tr("matchTargets/matchProperties/exclude and target/property are mutually exclusive."), this); return; } @@ -1227,7 +1229,7 @@ QML_DEFINE_TYPE(Qt,4,6,ParentAction,QmlParentAction) Animate a set of properties over 200ms, from their values in the start state to their values in the end state of the transition: \code - NumberAnimation { properties: "x,y,scale"; duration: 200 } + NumberAnimation { matchProperties: "x,y,scale"; duration: 200 } \endcode */ @@ -1790,11 +1792,47 @@ void QmlPropertyAnimation::setEasing(const QString &e) } /*! - \qmlproperty string PropertyAnimation::properties - This property holds the properties this animation should be applied to. + \qmlproperty Object PropertyAnimation::target + This property holds an explicit target object to animate. + + The exact effect of the \c target property depends on how the animation + is being used. Refer to the \l animation documentation for details. +*/ + +/*! + \qmlproperty string PropertyAnimation::property + This property holds an explicit property to animated. + + The exact effect of the \c property property depends on how the animation + is being used. Refer to the \l animation documentation for details. +*/ + +/*! + \qmlproperty string PropertyAnimation::matchProperties + This property holds a comma-separated list of property names this animation + will match against. These names are used in conjunction with matchTargets + to create a list of properties that the animation will animate, assuming those + properties have changed. + + In the following example, the change in 'x' will be animated by the transition, while + the change in 'y' will not. + \qml + State { + PropertyChanges { + target: myItem + x: 15; y: 15 + } + } + Transition { + PropertyAnimation { + matchProperties: "x" + } + } + \endqml + + This property is typically used for an animation appearing as part of a Transition. - This is a comma-separated list of properties that should use - this animation when they change. + By default, no property names will be matched. */ QString QmlPropertyAnimation::properties() const { @@ -1813,9 +1851,37 @@ void QmlPropertyAnimation::setProperties(const QString &prop) } /*! - \qmlproperty list PropertyAnimation::targets - This property holds the items selected to be affected by this animation (all if not set). - \sa exclude + \qmlproperty list PropertyAnimation::matchTargets + This property holds a list of objects this animation will match against. + These objects are used in conjunction with matchProperties to create a list of properties + that the animation will animate, assuming those properties have changed. + + In the following example, the changes to \c myItem will be animated by the transition, while + the changes to \c myOtherItem will not. + \qml + State { + PropertyChanges { + target: myItem + x: 15; y: 15 + } + PropertyChanges { + target: myOtherItem + x: 30; y: 30 + } + } + Transition { + PropertyAnimation { + matchTargets: myItem + matchProperties: "x,y" + } + } + \endqml + + This property is typically used for an animation appearing as part of a Transition. + + By default, all changing targets will be matched. + + \sa exclude matchProperties */ QList *QmlPropertyAnimation::targets() { @@ -1824,9 +1890,9 @@ QList *QmlPropertyAnimation::targets() } /*! - \qmlproperty list PropertyAnimation::exclude + \qmlproperty list PropertyAnimation::exclude This property holds the items not to be affected by this animation. - \sa targets + \sa matchTargets */ QList *QmlPropertyAnimation::exclude() { @@ -1943,7 +2009,7 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, bool hasTarget = !d->propertyName.isEmpty() || d->target; if (hasSelectors && hasTarget) { - qmlInfo(tr("targets/properties/exclude and target/property are mutually exclusive."), this); + qmlInfo(tr("matchTargets/matchProperties/exclude and target/property are mutually exclusive."), this); return; } diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 214bab9..3a9839e 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -191,8 +191,8 @@ class QmlPropertyAction : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) - Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) + Q_PROPERTY(QString matchProperties READ properties WRITE setProperties NOTIFY propertiesChanged) + Q_PROPERTY(QList* matchTargets READ targets) Q_PROPERTY(QList* exclude READ exclude) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) @@ -260,8 +260,8 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) - Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* targets READ targets) + Q_PROPERTY(QString matchProperties READ properties WRITE setProperties NOTIFY propertiesChanged) + Q_PROPERTY(QList* matchTargets READ targets) Q_PROPERTY(QList* exclude READ exclude) public: diff --git a/tests/auto/declarative/animations/data/badtype4.qml b/tests/auto/declarative/animations/data/badtype4.qml index 0c0a636..5db6c17 100644 --- a/tests/auto/declarative/animations/data/badtype4.qml +++ b/tests/auto/declarative/animations/data/badtype4.qml @@ -20,7 +20,7 @@ Rectangle { } transitions: Transition { //comment out each in turn to make sure each only animates the relevant property - ColorAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color - NumberAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color + ColorAnimation { matchProperties: "x,color"; duration: 1000 } //x is real, color is color + NumberAnimation { matchProperties: "x,color"; duration: 1000 } //x is real, color is color } } diff --git a/tests/auto/declarative/animations/data/dotproperty.qml b/tests/auto/declarative/animations/data/dotproperty.qml index ee076c2..3ddb002 100644 --- a/tests/auto/declarative/animations/data/dotproperty.qml +++ b/tests/auto/declarative/animations/data/dotproperty.qml @@ -16,9 +16,9 @@ Rectangle { } states: State { name: "state1" - PropertyChanges { target: MyRect; pen.color: "blue" } + PropertyChanges { target: MyRect; border.color: "blue" } } transitions: Transition { - ColorAnimation { properties: "pen.color"; duration: 1000 } + ColorAnimation { matchProperties: "border.color"; duration: 1000 } } } diff --git a/tests/auto/declarative/animations/data/mixedtype1.qml b/tests/auto/declarative/animations/data/mixedtype1.qml index ed50582..5ecf14f 100644 --- a/tests/auto/declarative/animations/data/mixedtype1.qml +++ b/tests/auto/declarative/animations/data/mixedtype1.qml @@ -19,6 +19,6 @@ Rectangle { PropertyChanges { target: MyRect; x: 200; border.width: 10 } } transitions: Transition { - PropertyAnimation { properties: "x,border.width"; duration: 1000 } //x is real, border.width is int + PropertyAnimation { matchProperties: "x,border.width"; duration: 1000 } //x is real, border.width is int } } diff --git a/tests/auto/declarative/animations/data/mixedtype2.qml b/tests/auto/declarative/animations/data/mixedtype2.qml index 4854c2e..645f1d0 100644 --- a/tests/auto/declarative/animations/data/mixedtype2.qml +++ b/tests/auto/declarative/animations/data/mixedtype2.qml @@ -19,6 +19,6 @@ Rectangle { PropertyChanges { target: MyRect; x: 200; color: "blue" } } transitions: Transition { - PropertyAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color + PropertyAnimation { matchProperties: "x,color"; duration: 1000 } //x is real, color is color } } diff --git a/tests/auto/declarative/behaviors/data/nonSelecting.qml b/tests/auto/declarative/behaviors/data/nonSelecting.qml index ae9a9f5..ba36d93 100644 --- a/tests/auto/declarative/behaviors/data/nonSelecting.qml +++ b/tests/auto/declarative/behaviors/data/nonSelecting.qml @@ -8,7 +8,7 @@ Rectangle { width: 100; height: 100; color: "green" x: Behavior { objectName: "MyBehavior"; - NumberAnimation { target: rect; property: "y"; duration: 200; } + NumberAnimation { target: rect; property: "x"; duration: 200; } } } MouseRegion { diff --git a/tests/auto/declarative/behaviors/data/nonSelecting2.qml b/tests/auto/declarative/behaviors/data/nonSelecting2.qml new file mode 100644 index 0000000..e9849eb --- /dev/null +++ b/tests/auto/declarative/behaviors/data/nonSelecting2.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { matchTargets: rect; matchProperties: "y"; duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index da910d9..6343968 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -208,14 +208,27 @@ void tst_behaviors::emptyBehavior() void tst_behaviors::nonSelectingBehavior() { - QmlEngine engine; - QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); - QmlGraphicsRectangle *rect = qobject_cast(c.create()); - QVERIFY(rect); + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); - rect->setState("moved"); - qreal x = qobject_cast(rect->findChild("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //should change immediately + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/nonSelecting2.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + qreal x = qobject_cast(rect->findChild("MyRect"))->x(); + QCOMPARE(x, qreal(200)); //should change immediately + } } void tst_behaviors::reassignedAnimation() diff --git a/tests/auto/declarative/layouts/data/grid-animated.qml b/tests/auto/declarative/layouts/data/grid-animated.qml index 9edccaf..6b128ce 100644 --- a/tests/auto/declarative/layouts/data/grid-animated.qml +++ b/tests/auto/declarative/layouts/data/grid-animated.qml @@ -7,17 +7,17 @@ Item { columns: 3 add: Transition { NumberAnimation { - properties: "x,y"; from: -100 + matchProperties: "x,y"; from: -100 } } remove: Transition { NumberAnimation { - properties: "x,y"; to: -100 + matchProperties: "x,y"; to: -100 } } move: Transition { NumberAnimation { - properties: "x,y"; + matchProperties: "x,y"; } } Rectangle { diff --git a/tests/auto/declarative/layouts/data/horizontal-animated.qml b/tests/auto/declarative/layouts/data/horizontal-animated.qml index f757d18..c29d6df 100644 --- a/tests/auto/declarative/layouts/data/horizontal-animated.qml +++ b/tests/auto/declarative/layouts/data/horizontal-animated.qml @@ -6,17 +6,17 @@ Item { Row { add: Transition { NumberAnimation { - properties: "x"; from: -100 + matchProperties: "x"; from: -100 } } remove: Transition { NumberAnimation { - properties: "x"; to: -100 + matchProperties: "x"; to: -100 } } move: Transition { NumberAnimation { - properties: "x"; + matchProperties: "x"; } } Rectangle { diff --git a/tests/auto/declarative/layouts/data/vertical-animated.qml b/tests/auto/declarative/layouts/data/vertical-animated.qml index f52a78a..fcbc5f7 100644 --- a/tests/auto/declarative/layouts/data/vertical-animated.qml +++ b/tests/auto/declarative/layouts/data/vertical-animated.qml @@ -6,17 +6,17 @@ Item { Column { add: Transition { NumberAnimation { - properties: "y"; from: -100 + matchProperties: "y"; from: -100 } } remove: Transition { NumberAnimation { - properties: "y"; to: -100 + matchProperties: "y"; to: -100 } } move: Transition { NumberAnimation { - properties: "y"; + matchProperties: "y"; } } Rectangle { diff --git a/tests/auto/declarative/visual/bindinganimation/bindinganimation.qml b/tests/auto/declarative/visual/bindinganimation/bindinganimation.qml index 90ef1e5..efbb1b4 100644 --- a/tests/auto/declarative/visual/bindinganimation/bindinganimation.qml +++ b/tests/auto/declarative/visual/bindinganimation/bindinganimation.qml @@ -28,7 +28,7 @@ Rectangle { transitions: [ Transition { NumberAnimation { - properties: "x" + matchProperties: "x" } } ] diff --git a/tests/auto/declarative/visual/easing/easing.qml b/tests/auto/declarative/visual/easing/easing.qml index f81400b..1e8e907 100644 --- a/tests/auto/declarative/visual/easing/easing.qml +++ b/tests/auto/declarative/visual/easing/easing.qml @@ -176,7 +176,7 @@ Rectangle { to: "to" reversible: true NumberAnimation { - properties: "x" + matchProperties: "x" easing: type duration: 1000 } -- cgit v0.12 From 9cd41cbd61afd2459c0c3f053aa45a02954ef77c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 6 Nov 2009 13:13:29 +1000 Subject: Test Keys and KeyNavigation attached props. Fix Keys onPressed --- doc/src/declarative/focus.qdoc | 2 + src/declarative/graphicsitems/qmlgraphicsitem.cpp | 74 ++++++- tests/auto/declarative/declarative.pro | 1 + .../auto/declarative/qmlgraphicsitem/data/keys.qml | 15 ++ .../qmlgraphicsitem/qmlgraphicsitem.pro | 7 + .../qmlgraphicsitem/tst_qmlgraphicsitem.cpp | 237 +++++++++++++++++++++ 6 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlgraphicsitem/data/keys.qml create mode 100644 tests/auto/declarative/qmlgraphicsitem/qmlgraphicsitem.pro create mode 100644 tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index ec6a02f..6eca667 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -75,6 +75,8 @@ Item { \endlist +See also the \l {Keys}{Keys attached property} and {KeyNavigation}{KeyNavigation attached property}. + \section1 Querying the Active Focus Item Whether or not an \l Item has \e {active focus} can be queried through the diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 77e6db8..a46c2be 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -389,6 +389,76 @@ void QmlGraphicsItemKeyFilter::componentComplete() if (m_next) m_next->componentComplete(); } + +/*! + \qmlclass KeyNavigation + \brief The KeyNavigation attached property supports key navigation by arrow keys. + + It is common in key-based UIs to use arrow keys to navigate + between focussed items. The KeyNavigation property provides a + convenient way of specifying which item will gain focus + when an arrow key is pressed. The following example provides + key navigation for a 2x2 grid of items. + + \code + Grid { + columns: 2 + width: 100; height: 100 + Rectangle { + id: item1 + focus: true + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item2 + KeyNavigation.down: item3 + } + Rectangle { + id: item2 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item1 + KeyNavigation.down: item4 + } + Rectangle { + id: item3 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item4 + KeyNavigation.up: item1 + } + Rectangle { + id: item4 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item3 + KeyNavigation.up: item2 + } + } + \endcode + + KeyNavigation receives key events after the item it is attached to. + If the item accepts an arrow key event, the KeyNavigation + attached property will not receive an event for that key. + + If an item has been set for a direction and the KeyNavigation + attached property receives the corresponding + key press and release events, the events will be accepted by + KeyNaviagtion and will not propagate any further. + + \sa {Keys}{Keys attached property} +*/ + +/*! + \qmlproperty Item KeyNavigation::left + \qmlproperty Item KeyNavigation::right + \qmlproperty Item KeyNavigation::up + \qmlproperty Item KeyNavigation::down + + These properties hold the item to assign focus to + when Key_Left, Key_Right, Key_Up or Key_Down are + pressed. +*/ + class QmlGraphicsKeyNavigationAttachedPrivate : public QObjectPrivate { public: @@ -606,7 +676,7 @@ void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. - \sa KeyEvent + \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property} */ /*! @@ -1119,7 +1189,7 @@ void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event) // If we specifically handle a key then default to accepted ke.setAccepted(true); int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal); - metaObject()->method(idx).invoke(this, Q_ARG(QmlGraphicsKeysAttached, &ke)); + metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QmlGraphicsKeyEvent*, &ke)); } } if (!ke.isAccepted()) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 02d5a55..472fd93 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -20,6 +20,7 @@ SUBDIRS += \ qmldom \ # Cover qmlecmascript \ # Cover qmlfontloader \ # Cover + qmlgraphicsitem \ # Cover qmlgraphicsborderimage \ # Cover qmlgraphicsparticles \ # Cover qmlgraphicstext \ # Cover diff --git a/tests/auto/declarative/qmlgraphicsitem/data/keys.qml b/tests/auto/declarative/qmlgraphicsitem/data/keys.qml new file mode 100644 index 0000000..7c16559 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsitem/data/keys.qml @@ -0,0 +1,15 @@ +import Qt 4.6 + +Item { + focus: true + Keys.onPressed: keysTestObject.keyPress(event.key, event.text, event.modifiers) + Keys.onReleased: { keysTestObject.keyRelease(event.key, event.text, event.modifiers); event.accepted = true; } + Keys.onReturnPressed: keysTestObject.keyPress(event.key, "Return", event.modifiers) + Keys.forwardTo: [ item2 ] + + Item { + id: item2 + Keys.onPressed: keysTestObject.forwardedKey(event.key) + Keys.onReleased: keysTestObject.forwardedKey(event.key) + } +} diff --git a/tests/auto/declarative/qmlgraphicsitem/qmlgraphicsitem.pro b/tests/auto/declarative/qmlgraphicsitem/qmlgraphicsitem.pro new file mode 100644 index 0000000..ddabf9a --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsitem/qmlgraphicsitem.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsitem.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp new file mode 100644 index 0000000..b3b5374 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include + +class tst_QmlGraphicsItem : public QObject + +{ + Q_OBJECT +public: + tst_QmlGraphicsItem(); + +private slots: + void keys(); + void keyNavigation(); + +private: + template + T *findItem(QmlGraphicsItem *parent, const QString &objectName); +}; + +class KeysTestObject : public QObject +{ + Q_OBJECT +public: + KeysTestObject() : mKey(0), mModifiers(0), mForwardedKey(0) {} + + void reset() { + mKey = 0; + mText = QString(); + mModifiers = 0; + mForwardedKey = 0; + } + +public slots: + void keyPress(int key, QString text, int modifiers) { + mKey = key; + mText = text; + mModifiers = modifiers; + } + void keyRelease(int key, QString text, int modifiers) { + mKey = key; + mText = text; + mModifiers = modifiers; + } + void forwardedKey(int key) { + mForwardedKey = key; + } + +public: + int mKey; + QString mText; + int mModifiers; + int mForwardedKey; + +private: +}; + + +tst_QmlGraphicsItem::tst_QmlGraphicsItem() +{ +} + +void tst_QmlGraphicsItem::keys() +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + canvas->setUrl(QUrl("file://" SRCDIR "/data/keys.qml")); + + KeysTestObject *testObject = new KeysTestObject; + canvas->rootContext()->setContextProperty("keysTestObject", testObject); + + canvas->execute(); + canvas->show(); + qApp->processEvents(); + + QEvent wa(QEvent::WindowActivate); + QApplication::sendEvent(canvas, &wa); + QFocusEvent fe(QEvent::FocusIn); + QApplication::sendEvent(canvas, &fe); + + QKeyEvent key(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1); + QApplication::sendEvent(canvas, &key); + QCOMPARE(testObject->mKey, int(Qt::Key_A)); + QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); + QCOMPARE(testObject->mText, QLatin1String("A")); + QVERIFY(testObject->mModifiers == Qt::NoModifier); + QVERIFY(!key.isAccepted()); + + testObject->reset(); + + key = QKeyEvent(QEvent::KeyRelease, Qt::Key_A, Qt::ShiftModifier, "A", false, 1); + QApplication::sendEvent(canvas, &key); + QCOMPARE(testObject->mKey, int(Qt::Key_A)); + QCOMPARE(testObject->mForwardedKey, int(Qt::Key_A)); + QCOMPARE(testObject->mText, QLatin1String("A")); + QVERIFY(testObject->mModifiers == Qt::ShiftModifier); + QVERIFY(key.isAccepted()); + + testObject->reset(); + + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QCOMPARE(testObject->mKey, int(Qt::Key_Return)); + QCOMPARE(testObject->mForwardedKey, int(Qt::Key_Return)); + QCOMPARE(testObject->mText, QLatin1String("Return")); + QVERIFY(testObject->mModifiers == Qt::NoModifier); + QVERIFY(key.isAccepted()); + + delete canvas; + delete testObject; +} + +void tst_QmlGraphicsItem::keyNavigation() +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + canvas->setUrl(QUrl("file://" SRCDIR "/data/keynavigation.qml")); + canvas->execute(); + canvas->show(); + qApp->processEvents(); + + QEvent wa(QEvent::WindowActivate); + QApplication::sendEvent(canvas, &wa); + QFocusEvent fe(QEvent::FocusIn); + QApplication::sendEvent(canvas, &fe); + + QmlGraphicsItem *item = findItem(canvas->root(), "item1"); + QVERIFY(item); + QVERIFY(item->hasFocus()); + + // right + QKeyEvent key(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->root(), "item2"); + QVERIFY(item); + QVERIFY(item->hasFocus()); + + // down + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->root(), "item4"); + QVERIFY(item); + QVERIFY(item->hasFocus()); + + // left + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->root(), "item3"); + QVERIFY(item); + QVERIFY(item->hasFocus()); + + // up + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + + item = findItem(canvas->root(), "item1"); + QVERIFY(item); + QVERIFY(item->hasFocus()); +} + +template +T *tst_QmlGraphicsItem::findItem(QmlGraphicsItem *parent, const QString &objectName) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + return static_cast(item); + item = findItem(item, objectName); + if (item) + return static_cast(item); + } + + return 0; +} + + + +QTEST_MAIN(tst_QmlGraphicsItem) + +#include "tst_qmlgraphicsitem.moc" -- cgit v0.12 From 9c984b6b421e7cc6c091623f63ed84ce700f1ee1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 6 Nov 2009 13:28:34 +1000 Subject: Add autotest for target/property matchTargets/matchProperties semantics. --- .../declarative/animations/data/properties.qml | 14 +++ .../declarative/animations/data/properties2.qml | 14 +++ .../declarative/animations/data/properties3.qml | 14 +++ .../declarative/animations/data/properties4.qml | 14 +++ .../declarative/animations/data/properties5.qml | 14 +++ .../animations/data/propertiesTransition.qml | 29 +++++ .../animations/data/propertiesTransition2.qml | 29 +++++ .../animations/data/propertiesTransition3.qml | 29 +++++ .../animations/data/propertiesTransition4.qml | 29 +++++ .../animations/data/propertiesTransition5.qml | 29 +++++ .../animations/data/propertiesTransition6.qml | 29 +++++ .../auto/declarative/animations/tst_animations.cpp | 139 +++++++++++++++++++++ 12 files changed, 383 insertions(+) create mode 100644 tests/auto/declarative/animations/data/properties.qml create mode 100644 tests/auto/declarative/animations/data/properties2.qml create mode 100644 tests/auto/declarative/animations/data/properties3.qml create mode 100644 tests/auto/declarative/animations/data/properties4.qml create mode 100644 tests/auto/declarative/animations/data/properties5.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition2.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition3.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition4.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition5.qml create mode 100644 tests/auto/declarative/animations/data/propertiesTransition6.qml diff --git a/tests/auto/declarative/animations/data/properties.qml b/tests/auto/declarative/animations/data/properties.qml new file mode 100644 index 0000000..a8023b4 --- /dev/null +++ b/tests/auto/declarative/animations/data/properties.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumberAnimation { to: 200; running: true; } + } +} diff --git a/tests/auto/declarative/animations/data/properties2.qml b/tests/auto/declarative/animations/data/properties2.qml new file mode 100644 index 0000000..aab7661 --- /dev/null +++ b/tests/auto/declarative/animations/data/properties2.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumberAnimation { matchTargets: theRect; matchProperties: "x"; to: 200; running: true } + } +} diff --git a/tests/auto/declarative/animations/data/properties3.qml b/tests/auto/declarative/animations/data/properties3.qml new file mode 100644 index 0000000..fd21a85 --- /dev/null +++ b/tests/auto/declarative/animations/data/properties3.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumberAnimation { target: theRect; property: "x"; to: 300; running: true } + } +} diff --git a/tests/auto/declarative/animations/data/properties4.qml b/tests/auto/declarative/animations/data/properties4.qml new file mode 100644 index 0000000..e23651c --- /dev/null +++ b/tests/auto/declarative/animations/data/properties4.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumberAnimation { target: theRect; property: "y"; to: 200; running: true } + } +} diff --git a/tests/auto/declarative/animations/data/properties5.qml b/tests/auto/declarative/animations/data/properties5.qml new file mode 100644 index 0000000..25c9866 --- /dev/null +++ b/tests/auto/declarative/animations/data/properties5.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumberAnimation { matchTargets: theRect; matchProperties: "y"; to: 200; running: true } + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition.qml b/tests/auto/declarative/animations/data/propertiesTransition.qml new file mode 100644 index 0000000..75603b9 --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { matchTargets: theRect; matchProperties: "x" } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition2.qml b/tests/auto/declarative/animations/data/propertiesTransition2.qml new file mode 100644 index 0000000..ae59157 --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition2.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { target: theRect; property: "y"; to: 200 } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition3.qml b/tests/auto/declarative/animations/data/propertiesTransition3.qml new file mode 100644 index 0000000..eedba7b --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition3.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { matchTargets: theRect; matchProperties: "y" } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition4.qml b/tests/auto/declarative/animations/data/propertiesTransition4.qml new file mode 100644 index 0000000..301f796 --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition4.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { target: theRect; matchProperties: "x" } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition5.qml b/tests/auto/declarative/animations/data/propertiesTransition5.qml new file mode 100644 index 0000000..565c519 --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition5.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { matchTargets: theRect; property: "x" } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/data/propertiesTransition6.qml b/tests/auto/declarative/animations/data/propertiesTransition6.qml new file mode 100644 index 0000000..b541dab --- /dev/null +++ b/tests/auto/declarative/animations/data/propertiesTransition6.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Rectangle { + width: 400 + height: 400 + Rectangle { + id: theRect + objectName: "TheRect" + color: "red" + width: 50; height: 50 + x: 100; y: 100 + } + + states: State { + name: "moved" + PropertyChanges { + target: theRect + x: 200 + } + } + transitions: Transition { + NumberAnimation { matchTargets: theItem; matchProperties: "x" } + } + + MouseRegion { + anchors.fill: parent + onClicked: parent.state = "moved" + } +} diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp index 418a3dc..a4402cb 100644 --- a/tests/auto/declarative/animations/tst_animations.cpp +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -59,6 +59,8 @@ private slots: void badTypes(); void badProperties(); void mixedTypes(); + void properties(); + void propertiesTransition(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -245,6 +247,143 @@ void tst_animations::mixedTypes() } } +void tst_animations::properties() +{ + const int waitDuration = 300; + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/properties.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->x(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/properties2.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->x(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/properties3.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->x(),qreal(300)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/properties4.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->y(),qreal(200)); + QTIMED_COMPARE(myRect->x(),qreal(100)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/properties5.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->x(),qreal(100)); + QTIMED_COMPARE(myRect->y(),qreal(100)); + } +} + +void tst_animations::propertiesTransition() +{ + const int waitDuration = 300; + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/propertiesTransition.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + rect->setState("moved"); + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->x(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/propertiesTransition2.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + rect->setState("moved"); + QCOMPARE(myRect->x(),qreal(200)); + QCOMPARE(myRect->y(),qreal(100)); + QTest::qWait(waitDuration); + QTIMED_COMPARE(myRect->y(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/propertiesTransition3.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (file:///home/brasser/depot/kinetic-declarativeui/qt/tests/auto/declarative/animations/data/propertiesTransition4.qml:22:9) targets/properties/exclude and target/property are mutually exclusive."); + rect->setState("moved"); + QCOMPARE(myRect->x(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/propertiesTransition4.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + QTest::ignoreMessage(QtWarningMsg, "QML QmlNumberAnimation (file:///home/brasser/depot/kinetic-declarativeui/qt/tests/auto/declarative/animations/data/propertiesTransition5.qml:22:9) targets/properties/exclude and target/property are mutually exclusive."); + rect->setState("moved"); + QCOMPARE(myRect->x(),qreal(200)); + } + + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/propertiesTransition5.qml")); + QmlGraphicsRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + //### should output warning at some point -- theItem doesn't exist + QmlGraphicsRectangle *myRect = rect->findChild("TheRect"); + QVERIFY(myRect); + rect->setState("moved"); + QCOMPARE(myRect->x(),qreal(200)); + } +} + QTEST_MAIN(tst_animations) #include "tst_animations.moc" -- cgit v0.12 From 61d479a412e43255bf0681bec1cfb599cb7be886 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 6 Nov 2009 13:29:03 +1000 Subject: More Timer testing --- tests/auto/declarative/qmltimer/tst_qmltimer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp index 9c5dc30..cf54647 100644 --- a/tests/auto/declarative/qmltimer/tst_qmltimer.cpp +++ b/tests/auto/declarative/qmltimer/tst_qmltimer.cpp @@ -91,6 +91,9 @@ void tst_qmltimer::notRepeating() QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; running: true }"), QUrl("file://")); QmlTimer *timer = qobject_cast(component.create()); QVERIFY(timer != 0); + QVERIFY(timer->isRunning()); + QVERIFY(!timer->isRepeating()); + QCOMPARE(timer->interval(), 100); TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); @@ -107,6 +110,7 @@ void tst_qmltimer::notRepeatingStart() QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100 }"), QUrl("file://")); QmlTimer *timer = qobject_cast(component.create()); QVERIFY(timer != 0); + QVERIFY(!timer->isRunning()); TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); @@ -138,6 +142,11 @@ void tst_qmltimer::repeat() QTest::qWait(TIMEOUT_TIMEOUT); QVERIFY(helper.count > oldCount); + + oldCount = helper.count; + timer->stop(); + QTest::qWait(TIMEOUT_TIMEOUT); + QVERIFY(helper.count == oldCount); } void tst_qmltimer::triggeredOnStart() @@ -146,6 +155,7 @@ void tst_qmltimer::triggeredOnStart() QmlComponent component(&engine, QByteArray("import Qt 4.6\nTimer { interval: 100; running: true; triggeredOnStart: true }"), QUrl("file://")); QmlTimer *timer = qobject_cast(component.create()); QVERIFY(timer != 0); + QVERIFY(timer->triggeredOnStart()); TimerHelper helper; connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout())); -- cgit v0.12 From b2f9f3f2157629eae2544cf6fa2215b26e4e5a84 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 6 Nov 2009 13:49:08 +1000 Subject: Test more anchors. --- tests/auto/declarative/anchors/data/anchors.qml | 27 +++++++++++++++++++++++++ tests/auto/declarative/anchors/tst_anchors.cpp | 16 +++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tests/auto/declarative/anchors/data/anchors.qml b/tests/auto/declarative/anchors/data/anchors.qml index 377dd2d..765e5b6 100644 --- a/tests/auto/declarative/anchors/data/anchors.qml +++ b/tests/auto/declarative/anchors/data/anchors.qml @@ -114,4 +114,31 @@ Rectangle { y: 70; width: 10; height: 10 anchors.horizontalCenter: parent.left } + Rectangle { + id: Rect22; objectName: "Rect22" + width: 10; height: 10 + anchors.centerIn: MasterRect + } + Rectangle { + id: Rect23; objectName: "Rect23" + anchors.left: MasterRect.left + anchors.leftMargin: 5 + anchors.right: MasterRect.right + anchors.rightMargin: 5 + anchors.top: MasterRect.top + anchors.topMargin: 5 + anchors.bottom: MasterRect.bottom + anchors.bottomMargin: 5 + } + Text { + id: text1; objectName: "text1" + y: 200; + text: "Hello" + } + Text { + id: text2; objectName: "text2" + anchors.baseline: text1.baseline + anchors.left: text1.right + text: "World" + } } diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 8abf04f..c3a857c 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -131,6 +132,21 @@ void tst_anchors::basicAnchors() QCOMPARE(findItem(view->root(), QLatin1String("Rect20"))->x(), 235.0); QCOMPARE(findItem(view->root(), QLatin1String("Rect21"))->x(), -5.0); + //centerIn + QCOMPARE(findItem(view->root(), QLatin1String("Rect22"))->x(), 69.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect22"))->y(), 5.0); + + //margins + QCOMPARE(findItem(view->root(), QLatin1String("Rect23"))->x(), 31.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect23"))->y(), 5.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect23"))->width(), 86.0); + QCOMPARE(findItem(view->root(), QLatin1String("Rect23"))->height(), 10.0); + + //baseline + QmlGraphicsText *text1 = findItem(view->root(), QLatin1String("text1")); + QmlGraphicsText *text2 = findItem(view->root(), QLatin1String("text2")); + QCOMPARE(text1->y(), text2->y()); + delete view; } -- cgit v0.12 From 74d768ec05d5acfa8ef5b65535c908f2935f2783 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 6 Nov 2009 14:04:45 +1000 Subject: move ListView state to correct directory --- tests/auto/declarative/declarative.pro | 2 +- .../listview/data/listview-enforcerange.qml | 55 -- .../listview/data/listview-sections.qml | 59 -- tests/auto/declarative/listview/data/listview.qml | 46 -- tests/auto/declarative/listview/listview.pro | 8 - tests/auto/declarative/listview/tst_listview.cpp | 853 --------------------- .../data/listview-enforcerange.qml | 55 ++ .../qmlgraphicslistview/data/listview-sections.qml | 59 ++ .../qmlgraphicslistview/data/listview.qml | 46 ++ .../qmlgraphicslistview/qmlgraphicslistview.pro | 8 + .../tst_qmlgraphicslistview.cpp | 853 +++++++++++++++++++++ 11 files changed, 1022 insertions(+), 1022 deletions(-) delete mode 100644 tests/auto/declarative/listview/data/listview-enforcerange.qml delete mode 100644 tests/auto/declarative/listview/data/listview-sections.qml delete mode 100644 tests/auto/declarative/listview/data/listview.qml delete mode 100644 tests/auto/declarative/listview/listview.pro delete mode 100644 tests/auto/declarative/listview/tst_listview.cpp create mode 100644 tests/auto/declarative/qmlgraphicslistview/data/listview-enforcerange.qml create mode 100644 tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml create mode 100644 tests/auto/declarative/qmlgraphicslistview/data/listview.qml create mode 100644 tests/auto/declarative/qmlgraphicslistview/qmlgraphicslistview.pro create mode 100644 tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 82b135f..64672f6 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -7,7 +7,7 @@ SUBDIRS += \ datetimeformatter \ # Cover examples \ layouts \ # Cover - listview \ # Cover + qmlgraphicslistview \ # Cover qmlgraphicsgridview \ # Cover numberformatter \ # Cover pathview \ # Cover diff --git a/tests/auto/declarative/listview/data/listview-enforcerange.qml b/tests/auto/declarative/listview/data/listview-enforcerange.qml deleted file mode 100644 index 46fddae..0000000 --- a/tests/auto/declarative/listview/data/listview-enforcerange.qml +++ /dev/null @@ -1,55 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 240 - height: 320 - color: "#ffffff" - Component { - id: myDelegate - Item { - id: wrapper - objectName: "wrapper" - height: 20 - width: 240 - Text { - text: index - } - Text { - x: 30 - id: textName - objectName: "textName" - text: name - } - Text { - x: 120 - id: textNumber - objectName: "textNumber" - text: number - } - Text { - x: 200 - text: wrapper.y - } - } - } - - Component { - id: myHighlight - Rectangle { - color: "lightsteelblue" - } - } - - ListView { - id: list - objectName: "list" - width: 240 - height: 320 - model: testModel - delegate: myDelegate - highlight: myHighlight - preferredHighlightBegin: 100 - preferredHighlightEnd: 100 - highlightRangeMode: "StrictlyEnforceRange" - } -} diff --git a/tests/auto/declarative/listview/data/listview-sections.qml b/tests/auto/declarative/listview/data/listview-sections.qml deleted file mode 100644 index 56700be..0000000 --- a/tests/auto/declarative/listview/data/listview-sections.qml +++ /dev/null @@ -1,59 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 240 - height: 320 - color: "#ffffff" - resources: [ - Component { - id: myDelegate - Item { - id: wrapper - objectName: "wrapper" - height: ListView.prevSection != ListView.section ? 40 : 20; - width: 240 - Rectangle { - y: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 - height: 20 - width: parent.width - color: wrapper.ListView.isCurrentItem ? "lightsteelblue" : "white" - Text { - text: index - } - Text { - x: 30 - id: textName - objectName: "textName" - text: name - } - Text { - x: 120 - id: textNumber - objectName: "textNumber" - text: number - } - Text { - x: 200 - text: wrapper.y - } - } - Rectangle { - color: "#99bb99" - height: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 - width: parent.width - visible: wrapper.ListView.prevSection != wrapper.ListView.section ? true : false - Text { text: wrapper.ListView.section } - } - } - } - ] - ListView { - id: list - objectName: "list" - width: 240 - height: 320 - model: testModel - delegate: myDelegate - sectionExpression: "Math.floor(index/5)" - } -} diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml deleted file mode 100644 index b7b838b..0000000 --- a/tests/auto/declarative/listview/data/listview.qml +++ /dev/null @@ -1,46 +0,0 @@ -import Qt 4.6 - -Rectangle { - width: 240 - height: 320 - color: "#ffffff" - resources: [ - Component { - id: myDelegate - Rectangle { - id: wrapper - objectName: "wrapper" - height: 20 - width: 240 - Text { - text: index - } - Text { - x: 30 - id: textName - objectName: "textName" - text: name - } - Text { - x: 120 - id: textNumber - objectName: "textNumber" - text: number - } - Text { - x: 200 - text: wrapper.y - } - color: ListView.isCurrentItem ? "lightsteelblue" : "white" - } - } - ] - ListView { - id: list - objectName: "list" - width: 240 - height: 320 - model: testModel - delegate: myDelegate - } -} diff --git a/tests/auto/declarative/listview/listview.pro b/tests/auto/declarative/listview/listview.pro deleted file mode 100644 index 23b0706..0000000 --- a/tests/auto/declarative/listview/listview.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_listview.cpp - -# Define SRCDIR equal to test's source directory -DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp deleted file mode 100644 index 5575ace..0000000 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ /dev/null @@ -1,853 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include - -class tst_QmlGraphicsListView : public QObject -{ - Q_OBJECT -public: - tst_QmlGraphicsListView(); - -private slots: - // Test both QListModelInterface and QAbstractItemModel model types - void qListModelInterface_items(); - void qAbstractItemModel_items(); - - void qListModelInterface_changed(); - void qAbstractItemModel_changed(); - - void qListModelInterface_inserted(); - void qAbstractItemModel_inserted(); - - void qListModelInterface_removed(); - void qAbstractItemModel_removed(); - - void qListModelInterface_moved(); - void qAbstractItemModel_moved(); - - void enforceRange(); - void spacing(); - void sections(); - -private: - template void items(); - template void changed(); - template void inserted(); - template void removed(); - template void moved(); - QmlView *createView(const QString &filename); - template - T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); - template - QList findItems(QmlGraphicsItem *parent, const QString &objectName); -}; - -class TestModel : public QListModelInterface -{ - Q_OBJECT -public: - TestModel(QObject *parent = 0) : QListModelInterface(parent) {} - ~TestModel() {} - - enum Roles { Name, Number }; - - QString name(int index) const { return list.at(index).first; } - QString number(int index) const { return list.at(index).second; } - - int count() const { return list.count(); } - - QList roles() const { return QList() << Name << Number; } - QString toString(int role) const { - switch(role) { - case Name: - return "name"; - case Number: - return "number"; - default: - return ""; - } - } - - QHash data(int index, const QList &roles) const { - QHash returnHash; - - for (int i = 0; i < roles.size(); ++i) { - int role = roles.at(i); - QVariant info; - switch(role) { - case Name: - info = list.at(index).first; - break; - case Number: - info = list.at(index).second; - break; - default: - break; - } - returnHash.insert(role, info); - } - return returnHash; - } - - void addItem(const QString &name, const QString &number) { - list.append(QPair(name, number)); - emit itemsInserted(list.count()-1, 1); - } - - void insertItem(int index, const QString &name, const QString &number) { - list.insert(index, QPair(name, number)); - emit itemsInserted(index, 1); - } - - void removeItem(int index) { - list.removeAt(index); - emit itemsRemoved(index, 1); - } - - void moveItem(int from, int to) { - list.move(from, to); - emit itemsMoved(from, to, 1); - } - - void modifyItem(int index, const QString &name, const QString &number) { - list[index] = QPair(name, number); - emit itemsChanged(index, 1, roles()); - } - -private: - QList > list; -}; - - -class TestModel2 : public QAbstractListModel -{ -public: - enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; - - TestModel2(QObject *parent=0) : QAbstractListModel(parent) { - QHash roles; - roles[Name] = "name"; - roles[Number] = "number"; - setRoleNames(roles); - } - - int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } - QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { - QVariant rv; - if (role == Name) - rv = list.at(index.row()).first; - else if (role == Number) - rv = list.at(index.row()).second; - - return rv; - } - - int count() const { return rowCount(); } - QString name(int index) const { return list.at(index).first; } - QString number(int index) const { return list.at(index).second; } - - void addItem(const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), list.count(), list.count()); - list.append(QPair(name, number)); - emit endInsertRows(); - } - - void insertItem(int index, const QString &name, const QString &number) { - emit beginInsertRows(QModelIndex(), index, index); - list.insert(index, QPair(name, number)); - emit endInsertRows(); - } - - void removeItem(int index) { - emit beginRemoveRows(QModelIndex(), index, index); - list.removeAt(index); - emit endRemoveRows(); - } - - void moveItem(int from, int to) { - emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); - list.move(from, to); - emit endMoveRows(); - } - - void modifyItem(int idx, const QString &name, const QString &number) { - list[idx] = QPair(name, number); - emit dataChanged(index(idx,0), index(idx,0)); - } - -private: - QList > list; -}; - -tst_QmlGraphicsListView::tst_QmlGraphicsListView() -{ -} - -template -void tst_QmlGraphicsListView::items() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - T model; - model.addItem("Fred", "12345"); - model.addItem("John", "2345"); - model.addItem("Bob", "54321"); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - QCOMPARE(listview->count(), model.count()); - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - - for (int i = 0; i < model.count(); ++i) { - QmlGraphicsText *name = findItem(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); - QmlGraphicsText *number = findItem(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); - } - - listview->incrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 1); - listview->decrementCurrentIndex(); - QCOMPARE(listview->currentIndex(), 0); - - // set an empty model and confirm that items are destroyed - T model2; - ctxt->setContextProperty("testModel", &model2); - - int itemCount = findItems(viewport, "wrapper").count(); - QVERIFY(itemCount == 0); - - delete canvas; -} - -template -void tst_QmlGraphicsListView::changed() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - T model; - model.addItem("Fred", "12345"); - model.addItem("John", "2345"); - model.addItem("Bob", "54321"); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsFlickable *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - model.modifyItem(1, "Will", "9876"); - QmlGraphicsText *name = findItem(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); - QmlGraphicsText *number = findItem(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); - - delete canvas; -} - -template -void tst_QmlGraphicsListView::inserted() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - T model; - model.addItem("Fred", "12345"); - model.addItem("John", "2345"); - model.addItem("Bob", "54321"); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - model.insertItem(1, "Will", "9876"); - - // let transitions settle. - QTest::qWait(1000); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - - QmlGraphicsText *name = findItem(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); - QmlGraphicsText *number = findItem(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); - - // Confirm items positioned correctly - for (int i = 0; i < model.count(); ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - QVERIFY(item->y() == i*20); - } - - model.insertItem(0, "Foo", "1111"); // zero index, and current item - - // let transitions settle. - QTest::qWait(1000); - - QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - - name = findItem(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); - - QCOMPARE(listview->currentIndex(), 1); - - // Confirm items positioned correctly - for (int i = 0; i < model.count(); ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - QVERIFY(item->y() == i*20); - } - - for (int i = model.count(); i < 30; ++i) - model.insertItem(i, "Hello", QString::number(i)); - QTest::qWait(1000); - - listview->setViewportY(80); - QTest::qWait(1000); - - // Insert item outside visible area - model.insertItem(1, "Hello", "1324"); - QTest::qWait(1000); - - QVERIFY(listview->viewportY() == 80); - - // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count() - 1; - for (int i = 5; i < 5+itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - QVERIFY(item->y() == i*20 - 20); - } - - delete canvas; -} - -template -void tst_QmlGraphicsListView::removed() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - T model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - model.removeItem(1); - - // let transitions settle. - QTest::qWait(1000); - - QmlGraphicsText *name = findItem(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); - QmlGraphicsText *number = findItem(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); - - // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20); - } - - // Remove first item (which is the current item); - model.removeItem(0); // post: top item starts at 20 - - // let transitions settle. - QTest::qWait(1000); - - name = findItem(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); - number = findItem(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); - - // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),i*20.0 + 20.0); - } - - // Remove items not visible - model.removeItem(18); - // let transitions settle. - QTest::qWait(1000); - - // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),i*20.0+20.0); - } - - // Remove items before visible - listview->setViewportY(80); - listview->setCurrentIndex(10); - - model.removeItem(1); // post: top item will be at 40 - // let transitions settle. - QTest::qWait(1000); - - // Confirm items positioned correctly - for (int i = 2; i < 18; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),40+i*20.0); - } - - listview->setViewportY(40); // That's the top now - // let transitions settle. - QTest::qWait(1000); - - // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QCOMPARE(item->y(),40+i*20.0); - } - - delete canvas; -} - -template -void tst_QmlGraphicsListView::moved() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - T model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - model.moveItem(1, 4); - - // let transitions settle. - QTest::qWait(1000); - - QmlGraphicsText *name = findItem(viewport, "textName", 1); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(1)); - QmlGraphicsText *number = findItem(viewport, "textNumber", 1); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(1)); - - name = findItem(viewport, "textName", 4); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(4)); - number = findItem(viewport, "textNumber", 4); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(4)); - - // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20); - } - - listview->setViewportY(80); - - // move outside visible area - model.moveItem(1, 18); - - // let transitions settle. - QTest::qWait(1000); - - // Confirm items positioned correctly and indexes correct - for (int i = 3; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20 + 20); - name = findItem(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); - } - - // move from outside visible into visible - model.moveItem(20, 4); - - // let transitions settle. - QTest::qWait(1000); - - // Confirm items positioned correctly and indexes correct - for (int i = 3; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20 + 20); - name = findItem(viewport, "textName", i); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(i)); - number = findItem(viewport, "textNumber", i); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(i)); - } - - delete canvas; -} - -void tst_QmlGraphicsListView::enforceRange() -{ - QmlView *canvas = createView(SRCDIR "/data/listview-enforcerange.qml"); - - TestModel model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - // view should be positioned at the top of the range. - QmlGraphicsItem *item = findItem(viewport, "wrapper", 0); - QVERIFY(item); - QCOMPARE(listview->viewportY(), -100.0); - - QmlGraphicsText *name = findItem(viewport, "textName", 0); - QVERIFY(name != 0); - QCOMPARE(name->text(), model.name(0)); - QmlGraphicsText *number = findItem(viewport, "textNumber", 0); - QVERIFY(number != 0); - QCOMPARE(number->text(), model.number(0)); - - // Check currentIndex is updated when viewport moves - listview->setViewportY(20); - QTest::qWait(1000); - - QCOMPARE(listview->currentIndex(), 6); - - delete canvas; -} - -void tst_QmlGraphicsListView::spacing() -{ - QmlView *canvas = createView(SRCDIR "/data/listview.qml"); - - TestModel model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20); - } - - listview->setSpacing(10); - QVERIFY(listview->spacing() == 10); - - // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*30); - } - - listview->setSpacing(0); - - // Confirm items positioned correctly - itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - if (!item) qWarning() << "Item" << i << "not found"; - QVERIFY(item); - QVERIFY(item->y() == i*20); - } - - delete canvas; -} - -void tst_QmlGraphicsListView::sections() -{ - QmlView *canvas = createView(SRCDIR "/data/listview-sections.qml"); - - TestModel model; - for (int i = 0; i < 30; i++) - model.addItem("Item" + QString::number(i), ""); - - QmlContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("testModel", &model); - - canvas->execute(); - qApp->processEvents(); - - QmlGraphicsListView *listview = findItem(canvas->root(), "list"); - QVERIFY(listview != 0); - - QmlGraphicsItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); - - // Confirm items positioned correctly - int itemCount = findItems(viewport, "wrapper").count(); - for (int i = 0; i < model.count() && i < itemCount; ++i) { - QmlGraphicsItem *item = findItem(viewport, "wrapper", i); - QVERIFY(item); - QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); - } - - QVERIFY(listview->currentSection() == "0"); - - listview->setViewportY(140); - QVERIFY(listview->currentSection() == "1"); - - delete canvas; -} - -void tst_QmlGraphicsListView::qListModelInterface_items() -{ - items(); -} - -void tst_QmlGraphicsListView::qAbstractItemModel_items() -{ - items(); -} - -void tst_QmlGraphicsListView::qListModelInterface_changed() -{ - changed(); -} - -void tst_QmlGraphicsListView::qAbstractItemModel_changed() -{ - changed(); -} - -void tst_QmlGraphicsListView::qListModelInterface_inserted() -{ - inserted(); -} - -void tst_QmlGraphicsListView::qAbstractItemModel_inserted() -{ - inserted(); -} - -void tst_QmlGraphicsListView::qListModelInterface_removed() -{ - removed(); -} - -void tst_QmlGraphicsListView::qAbstractItemModel_removed() -{ - removed(); -} - -void tst_QmlGraphicsListView::qListModelInterface_moved() -{ - moved(); -} - -void tst_QmlGraphicsListView::qAbstractItemModel_moved() -{ - moved(); -} - - -QmlView *tst_QmlGraphicsListView::createView(const QString &filename) -{ - QmlView *canvas = new QmlView(0); - canvas->setFixedSize(240,320); - - QFile file(filename); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, filename); - - return canvas; -} - -/* - Find an item with the specified objectName. If index is supplied then the - item must also evaluate the {index} expression equal to index -*/ -template -T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); - if(!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QmlExpression e(qmlContext(item), "index", item); - e.setTrackChange(false); - if (e.value().toInt() == index) - return static_cast(item); - } else { - return static_cast(item); - } - } - item = findItem(item, objectName, index); - if (item) - return static_cast(item); - } - - return 0; -} - -template -QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QString &objectName) -{ - QList items; - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->QGraphicsObject::children().count() << "children"; - for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { - QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); - if(!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) - items.append(static_cast(item)); - items += findItems(item, objectName); - } - - return items; -} - - -QTEST_MAIN(tst_QmlGraphicsListView) - -#include "tst_listview.moc" diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview-enforcerange.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview-enforcerange.qml new file mode 100644 index 0000000..46fddae --- /dev/null +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview-enforcerange.qml @@ -0,0 +1,55 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + Component { + id: myDelegate + Item { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + } + } + + Component { + id: myHighlight + Rectangle { + color: "lightsteelblue" + } + } + + ListView { + id: list + objectName: "list" + width: 240 + height: 320 + model: testModel + delegate: myDelegate + highlight: myHighlight + preferredHighlightBegin: 100 + preferredHighlightEnd: 100 + highlightRangeMode: "StrictlyEnforceRange" + } +} diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml new file mode 100644 index 0000000..56700be --- /dev/null +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview-sections.qml @@ -0,0 +1,59 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Item { + id: wrapper + objectName: "wrapper" + height: ListView.prevSection != ListView.section ? 40 : 20; + width: 240 + Rectangle { + y: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + height: 20 + width: parent.width + color: wrapper.ListView.isCurrentItem ? "lightsteelblue" : "white" + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + } + Rectangle { + color: "#99bb99" + height: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + width: parent.width + visible: wrapper.ListView.prevSection != wrapper.ListView.section ? true : false + Text { text: wrapper.ListView.section } + } + } + } + ] + ListView { + id: list + objectName: "list" + width: 240 + height: 320 + model: testModel + delegate: myDelegate + sectionExpression: "Math.floor(index/5)" + } +} diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml new file mode 100644 index 0000000..b7b838b --- /dev/null +++ b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml @@ -0,0 +1,46 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + text: index + } + Text { + x: 30 + id: textName + objectName: "textName" + text: name + } + Text { + x: 120 + id: textNumber + objectName: "textNumber" + text: number + } + Text { + x: 200 + text: wrapper.y + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ] + ListView { + id: list + objectName: "list" + width: 240 + height: 320 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qmlgraphicslistview/qmlgraphicslistview.pro b/tests/auto/declarative/qmlgraphicslistview/qmlgraphicslistview.pro new file mode 100644 index 0000000..f00de39 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicslistview/qmlgraphicslistview.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicslistview.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp new file mode 100644 index 0000000..5575ace --- /dev/null +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -0,0 +1,853 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +class tst_QmlGraphicsListView : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsListView(); + +private slots: + // Test both QListModelInterface and QAbstractItemModel model types + void qListModelInterface_items(); + void qAbstractItemModel_items(); + + void qListModelInterface_changed(); + void qAbstractItemModel_changed(); + + void qListModelInterface_inserted(); + void qAbstractItemModel_inserted(); + + void qListModelInterface_removed(); + void qAbstractItemModel_removed(); + + void qListModelInterface_moved(); + void qAbstractItemModel_moved(); + + void enforceRange(); + void spacing(); + void sections(); + +private: + template void items(); + template void changed(); + template void inserted(); + template void removed(); + template void moved(); + QmlView *createView(const QString &filename); + template + T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); + template + QList findItems(QmlGraphicsItem *parent, const QString &objectName); +}; + +class TestModel : public QListModelInterface +{ + Q_OBJECT +public: + TestModel(QObject *parent = 0) : QListModelInterface(parent) {} + ~TestModel() {} + + enum Roles { Name, Number }; + + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + int count() const { return list.count(); } + + QList roles() const { return QList() << Name << Number; } + QString toString(int role) const { + switch(role) { + case Name: + return "name"; + case Number: + return "number"; + default: + return ""; + } + } + + QHash data(int index, const QList &roles) const { + QHash returnHash; + + for (int i = 0; i < roles.size(); ++i) { + int role = roles.at(i); + QVariant info; + switch(role) { + case Name: + info = list.at(index).first; + break; + case Number: + info = list.at(index).second; + break; + default: + break; + } + returnHash.insert(role, info); + } + return returnHash; + } + + void addItem(const QString &name, const QString &number) { + list.append(QPair(name, number)); + emit itemsInserted(list.count()-1, 1); + } + + void insertItem(int index, const QString &name, const QString &number) { + list.insert(index, QPair(name, number)); + emit itemsInserted(index, 1); + } + + void removeItem(int index) { + list.removeAt(index); + emit itemsRemoved(index, 1); + } + + void moveItem(int from, int to) { + list.move(from, to); + emit itemsMoved(from, to, 1); + } + + void modifyItem(int index, const QString &name, const QString &number) { + list[index] = QPair(name, number); + emit itemsChanged(index, 1, roles()); + } + +private: + QList > list; +}; + + +class TestModel2 : public QAbstractListModel +{ +public: + enum Roles { Name = Qt::UserRole+1, Number = Qt::UserRole+2 }; + + TestModel2(QObject *parent=0) : QAbstractListModel(parent) { + QHash roles; + roles[Name] = "name"; + roles[Number] = "number"; + setRoleNames(roles); + } + + int rowCount(const QModelIndex &parent=QModelIndex()) const { return list.count(); } + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const { + QVariant rv; + if (role == Name) + rv = list.at(index.row()).first; + else if (role == Number) + rv = list.at(index.row()).second; + + return rv; + } + + int count() const { return rowCount(); } + QString name(int index) const { return list.at(index).first; } + QString number(int index) const { return list.at(index).second; } + + void addItem(const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), list.count(), list.count()); + list.append(QPair(name, number)); + emit endInsertRows(); + } + + void insertItem(int index, const QString &name, const QString &number) { + emit beginInsertRows(QModelIndex(), index, index); + list.insert(index, QPair(name, number)); + emit endInsertRows(); + } + + void removeItem(int index) { + emit beginRemoveRows(QModelIndex(), index, index); + list.removeAt(index); + emit endRemoveRows(); + } + + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + + void modifyItem(int idx, const QString &name, const QString &number) { + list[idx] = QPair(name, number); + emit dataChanged(index(idx,0), index(idx,0)); + } + +private: + QList > list; +}; + +tst_QmlGraphicsListView::tst_QmlGraphicsListView() +{ +} + +template +void tst_QmlGraphicsListView::items() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + QCOMPARE(listview->count(), model.count()); + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsText *name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + QmlGraphicsText *number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + listview->incrementCurrentIndex(); + QCOMPARE(listview->currentIndex(), 1); + listview->decrementCurrentIndex(); + QCOMPARE(listview->currentIndex(), 0); + + // set an empty model and confirm that items are destroyed + T model2; + ctxt->setContextProperty("testModel", &model2); + + int itemCount = findItems(viewport, "wrapper").count(); + QVERIFY(itemCount == 0); + + delete canvas; +} + +template +void tst_QmlGraphicsListView::changed() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsFlickable *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.modifyItem(1, "Will", "9876"); + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + delete canvas; +} + +template +void tst_QmlGraphicsListView::inserted() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + model.addItem("Fred", "12345"); + model.addItem("John", "2345"); + model.addItem("Bob", "54321"); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.insertItem(1, "Will", "9876"); + + // let transitions settle. + QTest::qWait(1000); + + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + // Confirm items positioned correctly + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->y() == i*20); + } + + model.insertItem(0, "Foo", "1111"); // zero index, and current item + + // let transitions settle. + QTest::qWait(1000); + + QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + + name = findItem(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + number = findItem(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + QCOMPARE(listview->currentIndex(), 1); + + // Confirm items positioned correctly + for (int i = 0; i < model.count(); ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->y() == i*20); + } + + for (int i = model.count(); i < 30; ++i) + model.insertItem(i, "Hello", QString::number(i)); + QTest::qWait(1000); + + listview->setViewportY(80); + QTest::qWait(1000); + + // Insert item outside visible area + model.insertItem(1, "Hello", "1324"); + QTest::qWait(1000); + + QVERIFY(listview->viewportY() == 80); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count() - 1; + for (int i = 5; i < 5+itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->y() == i*20 - 20); + } + + delete canvas; +} + +template +void tst_QmlGraphicsListView::removed() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.removeItem(1); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + // Remove first item (which is the current item); + model.removeItem(0); // post: top item starts at 20 + + // let transitions settle. + QTest::qWait(1000); + + name = findItem(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + number = findItem(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->y(),i*20.0 + 20.0); + } + + // Remove items not visible + model.removeItem(18); + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->y(),i*20.0+20.0); + } + + // Remove items before visible + listview->setViewportY(80); + listview->setCurrentIndex(10); + + model.removeItem(1); // post: top item will be at 40 + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly + for (int i = 2; i < 18; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->y(),40+i*20.0); + } + + listview->setViewportY(40); // That's the top now + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QCOMPARE(item->y(),40+i*20.0); + } + + delete canvas; +} + +template +void tst_QmlGraphicsListView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 4); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem(viewport, "textName", 4); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(4)); + number = findItem(viewport, "textNumber", 4); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(4)); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setViewportY(80); + + // move outside visible area + model.moveItem(1, 18); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(20, 4); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + +void tst_QmlGraphicsListView::enforceRange() +{ + QmlView *canvas = createView(SRCDIR "/data/listview-enforcerange.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // view should be positioned at the top of the range. + QmlGraphicsItem *item = findItem(viewport, "wrapper", 0); + QVERIFY(item); + QCOMPARE(listview->viewportY(), -100.0); + + QmlGraphicsText *name = findItem(viewport, "textName", 0); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(0)); + QmlGraphicsText *number = findItem(viewport, "textNumber", 0); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(0)); + + // Check currentIndex is updated when viewport moves + listview->setViewportY(20); + QTest::qWait(1000); + + QCOMPARE(listview->currentIndex(), 6); + + delete canvas; +} + +void tst_QmlGraphicsListView::spacing() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setSpacing(10); + QVERIFY(listview->spacing() == 10); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*30); + } + + listview->setSpacing(0); + + // Confirm items positioned correctly + itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + delete canvas; +} + +void tst_QmlGraphicsListView::sections() +{ + QmlView *canvas = createView(SRCDIR "/data/listview-sections.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item); + QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); + } + + QVERIFY(listview->currentSection() == "0"); + + listview->setViewportY(140); + QVERIFY(listview->currentSection() == "1"); + + delete canvas; +} + +void tst_QmlGraphicsListView::qListModelInterface_items() +{ + items(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_items() +{ + items(); +} + +void tst_QmlGraphicsListView::qListModelInterface_changed() +{ + changed(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_changed() +{ + changed(); +} + +void tst_QmlGraphicsListView::qListModelInterface_inserted() +{ + inserted(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_inserted() +{ + inserted(); +} + +void tst_QmlGraphicsListView::qListModelInterface_removed() +{ + removed(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_removed() +{ + removed(); +} + +void tst_QmlGraphicsListView::qListModelInterface_moved() +{ + moved(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_moved() +{ + moved(); +} + + +QmlView *tst_QmlGraphicsListView::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + return canvas; +} + +/* + Find an item with the specified objectName. If index is supplied then the + item must also evaluate the {index} expression equal to index +*/ +template +T *tst_QmlGraphicsListView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index) +{ + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { + if (index != -1) { + QmlExpression e(qmlContext(item), "index", item); + e.setTrackChange(false); + if (e.value().toInt() == index) + return static_cast(item); + } else { + return static_cast(item); + } + } + item = findItem(item, objectName, index); + if (item) + return static_cast(item); + } + + return 0; +} + +template +QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QString &objectName) +{ + QList items; + const QMetaObject &mo = T::staticMetaObject; + //qDebug() << parent->QGraphicsObject::children().count() << "children"; + for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { + QmlGraphicsItem *item = qobject_cast(parent->QGraphicsObject::children().at(i)); + if(!item) + continue; + //qDebug() << "try" << item; + if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) + items.append(static_cast(item)); + items += findItems(item, objectName); + } + + return items; +} + + +QTEST_MAIN(tst_QmlGraphicsListView) + +#include "tst_listview.moc" -- cgit v0.12 From 47f50491cafe76216f209d25d4a96643a05c1253 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 6 Nov 2009 14:09:22 +1000 Subject: More language tests --- src/declarative/qml/qmlcompiler.cpp | 13 +++++--- .../qmllanguage/data/assignBasicTypes.qml | 1 + .../qmllanguage/data/attachedProperties.qml | 3 ++ .../qmllanguage/data/fakeDotProperty.errors.txt | 2 +- .../data/invalidAttachedProperty.1.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.1.qml | 7 +++++ .../data/invalidAttachedProperty.10.errors.txt | 1 + .../data/invalidAttachedProperty.10.qml | 6 ++++ .../data/invalidAttachedProperty.11.errors.txt | 1 + .../data/invalidAttachedProperty.11.qml | 7 +++++ .../data/invalidAttachedProperty.2.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.2.qml | 6 ++++ .../data/invalidAttachedProperty.3.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.3.qml | 8 +++++ .../data/invalidAttachedProperty.4.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.4.qml | 7 +++++ .../data/invalidAttachedProperty.5.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.5.qml | 7 +++++ .../data/invalidAttachedProperty.6.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.6.qml | 7 +++++ .../data/invalidAttachedProperty.7.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.7.qml | 6 ++++ .../data/invalidAttachedProperty.8.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.8.qml | 6 ++++ .../data/invalidAttachedProperty.9.errors.txt | 1 + .../qmllanguage/data/invalidAttachedProperty.9.qml | 7 +++++ .../data/invalidGroupedProperty.1.errors.txt | 2 +- .../data/invalidGroupedProperty.2.errors.txt | 2 +- .../data/invalidGroupedProperty.3.errors.txt | 1 + .../qmllanguage/data/invalidGroupedProperty.3.qml | 5 +++ .../data/invalidGroupedProperty.4.errors.txt | 1 + .../qmllanguage/data/invalidGroupedProperty.4.qml | 5 +++ .../data/invalidGroupedProperty.5.errors.txt | 1 + .../qmllanguage/data/invalidGroupedProperty.5.qml | 5 +++ .../data/invalidGroupedProperty.6.errors.txt | 1 + .../qmllanguage/data/invalidGroupedProperty.6.qml | 6 ++++ .../data/invalidGroupedProperty.7.errors.txt | 1 + .../qmllanguage/data/invalidGroupedProperty.7.qml | 5 +++ .../data/missingValueTypeProperty.errors.txt | 1 + .../qmllanguage/data/missingValueTypeProperty.qml | 5 +++ .../data/objectValueTypeProperty.errors.txt | 1 + .../qmllanguage/data/objectValueTypeProperty.qml | 6 ++++ .../qmllanguage/data/wrongType.15.errors.txt | 1 + .../declarative/qmllanguage/data/wrongType.15.qml | 4 +++ tests/auto/declarative/qmllanguage/testtypes.h | 19 +++++++++++- .../declarative/qmllanguage/tst_qmllanguage.cpp | 36 +++++++++++++++++++++- 46 files changed, 202 insertions(+), 10 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.qml create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.qml create mode 100644 tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.qml create mode 100644 tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.qml create mode 100644 tests/auto/declarative/qmllanguage/data/wrongType.15.errors.txt create mode 100644 tests/auto/declarative/qmllanguage/data/wrongType.15.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 240f16c..8e92eb4 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1714,7 +1714,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value, obj, ctxt.incr())); obj->addValueTypeProperty(prop); } else { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property access")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access")); } } else { @@ -1722,7 +1722,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop, prop->value->metatype = QmlEnginePrivate::get(engine)->metaObjectForType(prop->type); if (!prop->value->metatype) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot nest non-QObject property \"%1\"").arg(QString::fromUtf8(prop->name))); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access")); obj->addGroupedProperty(prop); @@ -1749,8 +1749,11 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, prop->index = idx; prop->type = p.userType(); - if (prop->value || prop->values.count() != 1) - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use")); + if (prop->value) + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Property assignment expected")); + + if (prop->values.count() != 1) + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Single property assignment expected")); Value *value = prop->values.at(0); @@ -1758,7 +1761,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type, bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1; if (!isPropertyValue && !isPropertyInterceptor) { - COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use")); + COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Unexpected object assignment")); } else { COMPILE_CHECK(buildObject(value->object, ctxt)); diff --git a/tests/auto/declarative/qmllanguage/data/assignBasicTypes.qml b/tests/auto/declarative/qmllanguage/data/assignBasicTypes.qml index 50723a3..c86c96b 100644 --- a/tests/auto/declarative/qmllanguage/data/assignBasicTypes.qml +++ b/tests/auto/declarative/qmllanguage/data/assignBasicTypes.qml @@ -23,6 +23,7 @@ MyTypeObject { boolProperty: true variantProperty: "Hello World!" vectorProperty: "10,1,2.2" + urlProperty: "main.qml" objectProperty: MyTypeObject { intProperty: 8 } } diff --git a/tests/auto/declarative/qmllanguage/data/attachedProperties.qml b/tests/auto/declarative/qmllanguage/data/attachedProperties.qml index 8343754..fec96cc 100644 --- a/tests/auto/declarative/qmllanguage/data/attachedProperties.qml +++ b/tests/auto/declarative/qmllanguage/data/attachedProperties.qml @@ -1,5 +1,8 @@ import Test 1.0 +import Test 1.0 as Namespace import Qt 4.6 + Object { MyQmlObject.value: 10 + Namespace.MyQmlObject.value2: 13 } diff --git a/tests/auto/declarative/qmllanguage/data/fakeDotProperty.errors.txt b/tests/auto/declarative/qmllanguage/data/fakeDotProperty.errors.txt index e56ad3a..3074823 100644 --- a/tests/auto/declarative/qmllanguage/data/fakeDotProperty.errors.txt +++ b/tests/auto/declarative/qmllanguage/data/fakeDotProperty.errors.txt @@ -1 +1 @@ -3:5:Invalid property access +3:5:Invalid grouped property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.errors.txt new file mode 100644 index 0000000..68fe671 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.errors.txt @@ -0,0 +1 @@ +5:17:Cannot assign to non-existant property "foo" diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.qml new file mode 100644 index 0000000..e99c635 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.1.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 + +Object { + MyQmlObject.foo: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.errors.txt new file mode 100644 index 0000000..7f630f4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.errors.txt @@ -0,0 +1 @@ +5:15:Non-existant attached object diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.qml new file mode 100644 index 0000000..8f987ce --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.10.qml @@ -0,0 +1,6 @@ +import Test 1.0 as Namespace +import Qt 4.6 + +Object { + Namespace.MadeUpClass.foo: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.errors.txt new file mode 100644 index 0000000..fee5050 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.errors.txt @@ -0,0 +1 @@ +5:15:Not an attached property name diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.qml new file mode 100644 index 0000000..18770fc --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.11.qml @@ -0,0 +1,7 @@ +import Test 1.0 as Namespace +import Qt 4.6 + +Object { + Namespace.madeUpClass.foo: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.errors.txt new file mode 100644 index 0000000..9f06e07 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.errors.txt @@ -0,0 +1 @@ +5:27:Cannot assign to non-existant property "foo" diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.qml new file mode 100644 index 0000000..3c9ae5b --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.2.qml @@ -0,0 +1,6 @@ +import Test 1.0 as Namespace +import Qt 4.6 + +Object { + Namespace.MyQmlObject.foo: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.errors.txt new file mode 100644 index 0000000..05161c4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.errors.txt @@ -0,0 +1 @@ +5:5:Invalid attached object assignment diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.qml new file mode 100644 index 0000000..e9405a4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.3.qml @@ -0,0 +1,8 @@ +import Test 1.0 +import Qt 4.6 + +Object { + MyQmlObject: 10 +} + + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.errors.txt new file mode 100644 index 0000000..a208bcf --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.errors.txt @@ -0,0 +1 @@ +5:15:Invalid attached object assignment diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.qml new file mode 100644 index 0000000..6fbf718 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.4.qml @@ -0,0 +1,7 @@ +import Test 1.0 as Namespace +import Qt 4.6 + +Object { + Namespace.MyQmlObject: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.errors.txt new file mode 100644 index 0000000..05161c4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.errors.txt @@ -0,0 +1 @@ +5:5:Invalid attached object assignment diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.qml new file mode 100644 index 0000000..1827a16 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.5.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 + +Object { + MyQmlObject: Object {} +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.errors.txt new file mode 100644 index 0000000..e232b23 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.errors.txt @@ -0,0 +1 @@ +5:5:Non-existant attached object diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.qml new file mode 100644 index 0000000..5c7f0ec --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.6.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 + +Object { + Test.MyQmlObject: Object {} +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.errors.txt new file mode 100644 index 0000000..e232b23 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.errors.txt @@ -0,0 +1 @@ +5:5:Non-existant attached object diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.qml new file mode 100644 index 0000000..841cc08 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.7.qml @@ -0,0 +1,6 @@ +import Test 1.0 +import Qt 4.6 + +Object { + MyTypeObject.foo: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.errors.txt new file mode 100644 index 0000000..7f630f4 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.errors.txt @@ -0,0 +1 @@ +5:15:Non-existant attached object diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.qml new file mode 100644 index 0000000..f1b4b96 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.8.qml @@ -0,0 +1,6 @@ +import Test 1.0 as Namespace +import Qt 4.6 + +Object { + Namespace.MyTypeObject.foo: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.errors.txt new file mode 100644 index 0000000..e232b23 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.errors.txt @@ -0,0 +1 @@ +5:5:Non-existant attached object diff --git a/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.qml b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.qml new file mode 100644 index 0000000..99c4a5c --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidAttachedProperty.9.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import Qt 4.6 + +Object { + MadeUpClass.foo: 10 +} + diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt index 7c00ce4..810fd31 100644 --- a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.1.errors.txt @@ -1 +1 @@ -5:5:Invalid property access +5:5:Invalid grouped property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt index 7c00ce4..810fd31 100644 --- a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.2.errors.txt @@ -1 +1 @@ -5:5:Invalid property access +5:5:Invalid grouped property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.errors.txt new file mode 100644 index 0000000..f6d6f29 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.errors.txt @@ -0,0 +1 @@ +4:5:Invalid grouped property access diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.qml new file mode 100644 index 0000000..0bbfc4f --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.3.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyQmlObject { + customType.x: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.errors.txt new file mode 100644 index 0000000..19934fa --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.errors.txt @@ -0,0 +1 @@ +4:5:Cannot assign to non-existant property "foo" diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.qml new file mode 100644 index 0000000..134fef9 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.4.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyQmlObject { + foo.x: 10 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.errors.txt new file mode 100644 index 0000000..2c8a970 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.errors.txt @@ -0,0 +1 @@ +4:18:Property assignment expected diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.qml new file mode 100644 index 0000000..55cefe6 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.5.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + rectProperty.x.foo: 100 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.errors.txt new file mode 100644 index 0000000..8331725 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.errors.txt @@ -0,0 +1 @@ +5:18:Single property assignment expected diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.qml new file mode 100644 index 0000000..9ec33ab --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.6.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + rectProperty.x: 100 + rectProperty.x: 101 +} diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.errors.txt b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.errors.txt new file mode 100644 index 0000000..4a7e383 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.errors.txt @@ -0,0 +1 @@ +4:-1:Cannot set properties on nullGrouped as it is null diff --git a/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.qml b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.qml new file mode 100644 index 0000000..b77fb90 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/invalidGroupedProperty.7.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + nullGrouped.script: print(1921) +} diff --git a/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.errors.txt b/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.errors.txt new file mode 100644 index 0000000..dfaa218 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.errors.txt @@ -0,0 +1 @@ +4:18:Cannot assign to non-existant property "foo" diff --git a/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.qml b/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.qml new file mode 100644 index 0000000..9a0fa6a --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/missingValueTypeProperty.qml @@ -0,0 +1,5 @@ +import Test 1.0 + +MyTypeObject { + rectProperty.foo: 9 +} diff --git a/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.errors.txt b/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.errors.txt new file mode 100644 index 0000000..db7d9c0 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.errors.txt @@ -0,0 +1 @@ +4:18:Unexpected object assignment diff --git a/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.qml b/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.qml new file mode 100644 index 0000000..9924773 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/objectValueTypeProperty.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + rectProperty.x: MyTypeObject {} +} + diff --git a/tests/auto/declarative/qmllanguage/data/wrongType.15.errors.txt b/tests/auto/declarative/qmllanguage/data/wrongType.15.errors.txt new file mode 100644 index 0000000..44768e3 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/wrongType.15.errors.txt @@ -0,0 +1 @@ +3:18:Invalid property assignment: url expected diff --git a/tests/auto/declarative/qmllanguage/data/wrongType.15.qml b/tests/auto/declarative/qmllanguage/data/wrongType.15.qml new file mode 100644 index 0000000..633a5ba --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/wrongType.15.qml @@ -0,0 +1,4 @@ +import Test 1.0 +MyTypeObject { + urlProperty: 12 +} diff --git a/tests/auto/declarative/qmllanguage/testtypes.h b/tests/auto/declarative/qmllanguage/testtypes.h index e654faa..b251f87 100644 --- a/tests/auto/declarative/qmllanguage/testtypes.h +++ b/tests/auto/declarative/qmllanguage/testtypes.h @@ -80,14 +80,19 @@ class MyAttachedObject : public QObject { Q_OBJECT Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int value2 READ value2 WRITE setValue2) public: - MyAttachedObject(QObject *parent) : QObject(parent), m_value(0) {} + MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0) {} int value() const { return m_value; } void setValue(int v) { m_value = v; } + int value2() const { return m_value2; } + void setValue2(int v) { m_value2 = v; } + private: int m_value; + int m_value2; }; class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus @@ -201,9 +206,11 @@ class MyTypeObject : public QObject Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty); + Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty); Q_PROPERTY(QmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty); Q_PROPERTY(MyGroupedObject *grouped READ grouped CONSTANT); + Q_PROPERTY(MyGroupedObject *nullGrouped READ nullGrouped CONSTANT); public: MyTypeObject() @@ -413,6 +420,14 @@ public: vectorPropertyValue = v; } + QUrl urlPropertyValue; + QUrl urlProperty() const { + return urlPropertyValue; + } + void setUrlProperty(const QUrl &v) { + urlPropertyValue = v; + } + QmlScriptString scriptPropertyValue; QmlScriptString scriptProperty() const { return scriptPropertyValue; @@ -424,6 +439,8 @@ public: MyGroupedObject groupedValue; MyGroupedObject *grouped() { return &groupedValue; } + MyGroupedObject *nullGrouped() { return 0; } + void doAction() { emit action(); } signals: void action(); diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index c646583..c23bb2d 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -141,6 +141,7 @@ private: QFile file(QLatin1String("data/") + QLatin1String(errorfile)); \ QVERIFY(file.open(QIODevice::ReadOnly)); \ QByteArray data = file.readAll(); \ + file.close(); \ QList expected = data.split('\n'); \ expected.removeAll(QByteArray("")); \ QList errors = component.errors(); \ @@ -154,7 +155,16 @@ private: } \ if (qgetenv("DEBUG") != "" && expected != actual) \ qWarning() << "Expected:" << expected << "Actual:" << actual; \ - QCOMPARE(expected, actual); \ + if (qgetenv("QMLLANGUAGE_UPDATEERRORS") != "" && expected != actual) {\ + QFile file(QLatin1String("data/") + QLatin1String(errorfile)); \ + QVERIFY(file.open(QIODevice::WriteOnly)); \ + for (int ii = 0; ii < actual.count(); ++ii) { \ + file.write(actual.at(ii)); file.write("\n"); \ + } \ + file.close(); \ + } else { \ + QCOMPARE(expected, actual); \ + } \ } inline QUrl TEST_FILE(const QString &filename) @@ -214,6 +224,7 @@ void tst_qmllanguage::errors_data() QTest::newRow("wrongType (color for size)") << "wrongType.12.qml" << "wrongType.12.errors.txt" << false; QTest::newRow("wrongType (number string for int)") << "wrongType.13.qml" << "wrongType.13.errors.txt" << false; QTest::newRow("wrongType (int for string)") << "wrongType.14.qml" << "wrongType.14.errors.txt" << false; + QTest::newRow("wrongType (int for url)") << "wrongType.15.qml" << "wrongType.15.errors.txt" << false; QTest::newRow("readOnly.1") << "readOnly.1.qml" << "readOnly.1.errors.txt" << false; QTest::newRow("readOnly.2") << "readOnly.2.qml" << "readOnly.2.errors.txt" << false; @@ -240,8 +251,14 @@ void tst_qmllanguage::errors_data() QTest::newRow("missingSignal") << "missingSignal.qml" << "missingSignal.errors.txt" << false; QTest::newRow("finalOverride") << "finalOverride.qml" << "finalOverride.errors.txt" << false; QTest::newRow("customParserIdNotAllowed") << "customParserIdNotAllowed.qml" << "customParserIdNotAllowed.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.1") << "invalidGroupedProperty.1.qml" << "invalidGroupedProperty.1.errors.txt" << false; QTest::newRow("invalidGroupedProperty.2") << "invalidGroupedProperty.2.qml" << "invalidGroupedProperty.2.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.3") << "invalidGroupedProperty.3.qml" << "invalidGroupedProperty.3.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.4") << "invalidGroupedProperty.4.qml" << "invalidGroupedProperty.4.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.5") << "invalidGroupedProperty.5.qml" << "invalidGroupedProperty.5.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.6") << "invalidGroupedProperty.6.qml" << "invalidGroupedProperty.6.errors.txt" << false; + QTest::newRow("invalidGroupedProperty.7") << "invalidGroupedProperty.7.qml" << "invalidGroupedProperty.7.errors.txt" << true; QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false; QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false; @@ -278,13 +295,28 @@ void tst_qmllanguage::errors_data() QTest::newRow("Component.5") << "component.5.qml" << "component.5.errors.txt" << false; QTest::newRow("Component.6") << "component.6.qml" << "component.6.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.1") << "invalidAttachedProperty.1.qml" << "invalidAttachedProperty.1.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.2") << "invalidAttachedProperty.2.qml" << "invalidAttachedProperty.2.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.3") << "invalidAttachedProperty.3.qml" << "invalidAttachedProperty.3.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.4") << "invalidAttachedProperty.4.qml" << "invalidAttachedProperty.4.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.5") << "invalidAttachedProperty.5.qml" << "invalidAttachedProperty.5.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.6") << "invalidAttachedProperty.6.qml" << "invalidAttachedProperty.6.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.7") << "invalidAttachedProperty.7.qml" << "invalidAttachedProperty.7.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.8") << "invalidAttachedProperty.8.qml" << "invalidAttachedProperty.8.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.9") << "invalidAttachedProperty.9.qml" << "invalidAttachedProperty.9.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.10") << "invalidAttachedProperty.10.qml" << "invalidAttachedProperty.10.errors.txt" << false; + QTest::newRow("invalidAttachedProperty.11") << "invalidAttachedProperty.11.qml" << "invalidAttachedProperty.11.errors.txt" << false; + QTest::newRow("nestedErrors") << "nestedErrors.qml" << "nestedErrors.errors.txt" << false; QTest::newRow("defaultGrouped") << "defaultGrouped.qml" << "defaultGrouped.errors.txt" << false; QTest::newRow("emptySignal") << "emptySignal.qml" << "emptySignal.errors.txt" << false; QTest::newRow("doubleSignal") << "doubleSignal.qml" << "doubleSignal.errors.txt" << false; QTest::newRow("invalidRoot") << "invalidRoot.qml" << "invalidRoot.errors.txt" << false; + QTest::newRow("missingValueTypeProperty") << "missingValueTypeProperty.qml" << "missingValueTypeProperty.errors.txt" << false; + QTest::newRow("objectValueTypeProperty") << "objectValueTypeProperty.qml" << "objectValueTypeProperty.errors.txt" << false; } + void tst_qmllanguage::errors() { QFETCH(QString, file); @@ -420,6 +452,7 @@ void tst_qmllanguage::assignBasicTypes() QCOMPARE(object->boolProperty(), true); QCOMPARE(object->variantProperty(), QVariant("Hello World!")); QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2)); + QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml"))); QVERIFY(object->objectProperty() != 0); MyTypeObject *child = qobject_cast(object->objectProperty()); QVERIFY(child != 0); @@ -611,6 +644,7 @@ void tst_qmllanguage::attachedProperties() QObject *attached = qmlAttachedPropertiesObject(object); QVERIFY(attached != 0); QCOMPARE(attached->property("value"), QVariant(10)); + QCOMPARE(attached->property("value2"), QVariant(13)); } // Tests non-static object properties -- cgit v0.12 From d13d9d070e63cb9321bbdbc0eacf965f1ed070bb Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 6 Nov 2009 14:13:11 +1000 Subject: A missing fixup after rename --- tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index 5575ace..9f904b8 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -850,4 +850,4 @@ QList tst_QmlGraphicsListView::findItems(QmlGraphicsItem *parent, const QStr QTEST_MAIN(tst_QmlGraphicsListView) -#include "tst_listview.moc" +#include "tst_qmlgraphicslistview.moc" -- cgit v0.12