diff options
Diffstat (limited to 'src/declarative/util')
31 files changed, 395 insertions, 1392 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 181ef0a..8c8dd95 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -52,6 +52,7 @@ #include <qdeclarativestringconverters_p.h> #include <qdeclarativeglobal_p.h> #include <qdeclarativemetatype_p.h> +#include <qdeclarativevaluetype_p.h> #include <qdeclarativeproperty_p.h> #include <qvariant.h> @@ -71,7 +72,7 @@ QT_BEGIN_NAMESPACE /*! \qmlclass Animation QDeclarativeAbstractAnimation - \since 4.7 + \since 4.7 \brief The Animation element is the base of all QML animations. The Animation element cannot be used directly in a QML file. It exists @@ -110,7 +111,7 @@ QDeclarativeAbstractAnimation::QDeclarativeAbstractAnimation(QDeclarativeAbstrac \code Rectangle { width: 100; height: 100 - x: NumberAnimation { + NumberAnimation on x { running: myMouse.pressed from: 0; to: 100 } @@ -310,7 +311,7 @@ void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f) \code Rectangle { - rotation: NumberAnimation { running: true; repeat: true; from: 0 to: 360 } + NumberAnimation on rotation { running: true; repeat: true; from: 0 to: 360 } } \endcode */ @@ -412,7 +413,7 @@ void QDeclarativeAbstractAnimation::resume() no further influence on property values. In this example animation \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode was stopped at time 250ms, the \c x property will have a value of 50. @@ -450,7 +451,7 @@ void QDeclarativeAbstractAnimation::restart() its end. In the following example, \code Rectangle { - x: NumberAnimation { from: 0; to: 100; duration: 500 } + NumberAnimation on x { from: 0; to: 100; duration: 500 } } \endcode calling \c stop() at time 250ms will result in the \c x property having @@ -515,7 +516,7 @@ void QDeclarativeAbstractAnimation::timelineComplete() /*! \qmlclass PauseAnimation QDeclarativePauseAnimation - \since 4.7 + \since 4.7 \inherits Animation \brief The PauseAnimation element provides a pause for an animation. @@ -552,7 +553,7 @@ void QDeclarativePauseAnimationPrivate::init() { Q_Q(QDeclarativePauseAnimation); pa = new QPauseAnimation; - QDeclarativeGraphics_setParent_noEvent(pa, q); + QDeclarative_setParent_noEvent(pa, q); } /*! @@ -589,7 +590,7 @@ QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation() /*! \qmlclass ColorAnimation QDeclarativeColorAnimation - \since 4.7 + \since 4.7 \inherits PropertyAnimation \brief The ColorAnimation element allows you to animate color changes. @@ -653,7 +654,7 @@ void QDeclarativeColorAnimation::setTo(const QColor &t) /*! \qmlclass ScriptAction QDeclarativeScriptAction - \since 4.7 + \since 4.7 \inherits Animation \brief The ScriptAction element allows scripts to be run during an animation. @@ -677,7 +678,7 @@ void QDeclarativeScriptActionPrivate::init() { Q_Q(QDeclarativeScriptAction); rsa = new QActionAnimation(&proxy); - QDeclarativeGraphics_setParent_noEvent(rsa, q); + QDeclarative_setParent_noEvent(rsa, q); } /*! @@ -759,7 +760,7 @@ QAbstractAnimation *QDeclarativeScriptAction::qtAnimation() /*! \qmlclass PropertyAction QDeclarativePropertyAction - \since 4.7 + \since 4.7 \inherits Animation \brief The PropertyAction element allows immediate property changes during animation. @@ -795,7 +796,7 @@ void QDeclarativePropertyActionPrivate::init() { Q_Q(QDeclarativePropertyAction); spa = new QActionAnimation; - QDeclarativeGraphics_setParent_noEvent(spa, q); + QDeclarative_setParent_noEvent(spa, q); } /*! @@ -1008,7 +1009,7 @@ void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions, /*! \qmlclass ParentAction QDeclarativeParentAction - \since 4.7 + \since 4.7 \inherits Animation \brief The ParentAction element allows parent changes during animation. @@ -1056,7 +1057,7 @@ void QDeclarativeParentActionPrivate::init() { Q_Q(QDeclarativeParentAction); cpa = new QActionAnimation; - QDeclarativeGraphics_setParent_noEvent(cpa, q); + QDeclarative_setParent_noEvent(cpa, q); } /*! @@ -1212,7 +1213,7 @@ void QDeclarativeParentAction::transition(QDeclarativeStateActions &actions, /*! \qmlclass NumberAnimation QDeclarativeNumberAnimation - \since 4.7 + \since 4.7 \inherits PropertyAnimation \brief The NumberAnimation element allows you to animate changes in properties of type qreal. @@ -1276,7 +1277,7 @@ void QDeclarativeNumberAnimation::setTo(qreal t) /*! \qmlclass Vector3dAnimation QDeclarativeVector3dAnimation - \since 4.7 + \since 4.7 \inherits PropertyAnimation \brief The Vector3dAnimation element allows you to animate changes in properties of type QVector3d. */ @@ -1292,7 +1293,7 @@ QDeclarativeVector3dAnimation::QDeclarativeVector3dAnimation(QObject *parent) Q_D(QDeclarativePropertyAnimation); d->interpolatorType = QMetaType::QVector3D; d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); - d->defaultToInterpolatorType = true; + d->defaultToInterpolatorType = true; } QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation() @@ -1335,28 +1336,31 @@ void QDeclarativeVector3dAnimation::setTo(QVector3D t) /*! \qmlclass RotationAnimation QDeclarativeRotationAnimation + \since 4.7 \inherits PropertyAnimation \brief The RotationAnimation element allows you to animate rotations. RotationAnimation is a specialized PropertyAnimation that gives control - over the direction of rotation. + over the direction of rotation. By default, it will rotate + via the shortest path; for example, a rotation from 20 to 340 degrees will + rotation 40 degrees counterclockwise. - The RotationAnimation in the following example ensures that we always take - the shortest rotation path when switching between our states. + When used in a transition RotationAnimation will rotate all + properties named "rotation" or "angle". You can override this by providing + your own properties via \c properties or \c property. + + In the following example we use RotationAnimation to animate the rotation + between states via the shortest path. \qml states: { State { name: "180"; PropertyChanges { target: myItem; rotation: 180 } } - State { name: "-180"; PropertyChanges { target: myItem; rotation: -180 } } - State { name: "180"; PropertyChanges { target: myItem; rotation: 270 } } + State { name: "90"; PropertyChanges { target: myItem; rotation: 90 } } + State { name: "-90"; PropertyChanges { target: myItem; rotation: -90 } } } transition: Transition { - RotationAnimation { direction: RotationAnimation.Shortest } + RotationAnimation { } } \endqml - - By default, when used in a transition RotationAnimation will rotate all - properties named "rotation" or "angle". You can override this by providing - your own properties via \c properties or \c property. */ /*! @@ -1549,7 +1553,7 @@ QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeAnimationGro /*! \qmlclass SequentialAnimation QDeclarativeSequentialAnimation - \since 4.7 + \since 4.7 \inherits Animation \brief The SequentialAnimation element allows you to run animations sequentially. @@ -1572,7 +1576,8 @@ QDeclarativeSequentialAnimation::QDeclarativeSequentialAnimation(QObject *parent QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QSequentialAnimationGroup(this); + d->ag = new QSequentialAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeSequentialAnimation::~QDeclarativeSequentialAnimation() @@ -1610,7 +1615,7 @@ void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actio /*! \qmlclass ParallelAnimation QDeclarativeParallelAnimation - \since 4.7 + \since 4.7 \inherits Animation \brief The ParallelAnimation element allows you to run animations in parallel. @@ -1637,7 +1642,8 @@ QDeclarativeParallelAnimation::QDeclarativeParallelAnimation(QObject *parent) : QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QParallelAnimationGroup(this); + d->ag = new QParallelAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeParallelAnimation::~QDeclarativeParallelAnimation() @@ -1707,19 +1713,20 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int break; } default: - if ((uint)type >= QVariant::UserType) { + if (QDeclarativeValueTypeFactory::isValueType((uint)type)) { + variant.convert((QVariant::Type)type); + } else { QDeclarativeMetaType::StringConverter converter = QDeclarativeMetaType::customStringConverter(type); if (converter) variant = converter(variant.toString()); - } else - variant.convert((QVariant::Type)type); + } break; } } /*! \qmlclass PropertyAnimation QDeclarativePropertyAnimation - \since 4.7 + \since 4.7 \inherits Animation \brief The PropertyAnimation element allows you to animate property changes. @@ -1731,14 +1738,14 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Animate any objects that have changed their x or y properties in the target state using an InOutQuad easing curve: \qml - Transition { PropertyAnimation { properties: "x,y"; easing: "InOutQuad" } } + Transition { PropertyAnimation { properties: "x,y"; easing.type: "InOutQuad" } } \endqml \o In a Behavior Animate all changes to a rectangle's x property. \qml Rectangle { - x: Behavior { PropertyAnimation {} } + Behavior on x { PropertyAnimation {} } } \endqml \o As a property value source @@ -1746,7 +1753,7 @@ void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int Repeatedly animate the rectangle's x property. \qml Rectangle { - x: SequentialAnimation { + SequentialAnimation on x { repeat: true PropertyAnimation { to: 50 } PropertyAnimation { to: 0 } @@ -1796,8 +1803,8 @@ QDeclarativePropertyAnimation::~QDeclarativePropertyAnimation() void QDeclarativePropertyAnimationPrivate::init() { Q_Q(QDeclarativePropertyAnimation); - va = new QDeclarativeTimeLineValueAnimator; - QDeclarativeGraphics_setParent_noEvent(va, q); + va = new QDeclarativeBulkValueAnimator; + QDeclarative_setParent_noEvent(va, q); } /*! @@ -1872,7 +1879,13 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) \qmlproperty QEasingCurve PropertyAnimation::easing \brief the easing curve used for the transition. - Available values are: + For the easing you can specify the following parameters: type, amplitude, period and overshoot. + + \qml + PropertyAnimation { properties: "y"; easing.type: "InOutElastc"; easing.amplitude: 2.0; easing.period: 1.5 } + \endqml + + Available types are: \table \row @@ -2043,6 +2056,15 @@ void QDeclarativePropertyAnimation::setTo(const QVariant &t) \o \inlineimage qeasingcurve-outinbounce.png \endtable + easing.amplitude is not applicable for all curve types. It is only applicable for bounce and elastic curves (curves of type + QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, QEasingCurve::OutInBounce, QEasingCurve::InElastic, + QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic). + + easing.overshoot is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InBack, QEasingCurve::OutBack, + QEasingCurve::InOutBack or QEasingCurve::OutInBack. + + easing.period is not applicable for all curve types. It is only applicable if type is: QEasingCurve::InElastic, QEasingCurve::OutElastic, + QEasingCurve::InOutElastic or QEasingCurve::OutInElastic. */ QEasingCurve QDeclarativePropertyAnimation::easing() const { @@ -2137,8 +2159,8 @@ void QDeclarativePropertyAnimation::setProperties(const QString &prop) id: theRect width: 100; height: 100 color: Qt.rgba(0,0,1) - x: NumberAnimation { to: 500; repeat: true } //animate theRect's x property - y: Behavior { NumberAnimation {} } //animate theRect's y property + NumberAnimation on x { to: 500; repeat: true } //animate theRect's x property + Behavior on y { NumberAnimation {} } //animate theRect's y property } \endqml \row @@ -2212,7 +2234,7 @@ QAbstractAnimation *QDeclarativePropertyAnimation::qtAnimation() return d->va; } -struct PropertyUpdater : public QDeclarativeTimeLineValue +struct PropertyUpdater : public QDeclarativeBulkValueUpdater { QDeclarativeStateActions actions; int interpolatorType; //for Number/ColorAnimation @@ -2222,7 +2244,7 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue bool fromSourced; bool fromDefined; bool *wasDeleted; - PropertyUpdater() : wasDeleted(0) {} + PropertyUpdater() : prevInterpolatorType(0), wasDeleted(0) {} ~PropertyUpdater() { if (wasDeleted) *wasDeleted = true; } void setValue(qreal v) { @@ -2230,7 +2252,6 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue wasDeleted = &deleted; if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1 v = 1 - v; - QDeclarativeTimeLineValue::setValue(v); for (int ii = 0; ii < actions.count(); ++ii) { QDeclarativeAction &action = actions[ii]; @@ -2370,12 +2391,58 @@ void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions } } +/*! + \qmlclass ParentAnimation QDeclarativeParentAnimation + \since 4.7 + \inherits Animation + \brief The ParentAnimation element allows you to animate parent changes. + + ParentAnimation is used in conjunction with NumberAnimation to smoothly + animate changing an item's parent. In the following example, + ParentAnimation wraps a NumberAnimation which animates from the + current position in the old parent to the new position in the new + parent. + + \qml + ... + State { + //reparent myItem to newParent. myItem's final location + //should be 10,10 in newParent. + ParentChange { + target: myItem + parent: newParent + x: 10; y: 10 + } + } + ... + Transition { + //smoothly reparent myItem and move into new position + ParentAnimation { + target: theItem + NumberAnimation { properties: "x,y" } + } + } + \endqml + + ParentAnimation can wrap any number of animations -- those animations will + be run in parallel (like those in a ParallelAnimation group). + + In some cases, such as reparenting between items with clipping, it's useful + to animate the parent change \i via another item with no clipping. + + When used in a transition, ParentAnimation will by default animate + all ParentChanges. +*/ +/*! + \internal + \class QDeclarativeParentAnimation +*/ QDeclarativeParentAnimation::QDeclarativeParentAnimation(QObject *parent) : QDeclarativeAnimationGroup(*(new QDeclarativeParentAnimationPrivate), parent) { Q_D(QDeclarativeParentAnimation); d->topLevelGroup = new QSequentialAnimationGroup; - QDeclarativeGraphics_setParent_noEvent(d->topLevelGroup, this); + QDeclarative_setParent_noEvent(d->topLevelGroup, this); d->startAction = new QActionAnimation; d->topLevelGroup->addAnimation(d->startAction); @@ -2391,6 +2458,13 @@ QDeclarativeParentAnimation::~QDeclarativeParentAnimation() { } +/*! + \qmlproperty item ParentAnimation::target + The item to reparent. + + When used in a transition, if no target is specified all + ParentChanges will be animated by the ParentAnimation. +*/ QDeclarativeItem *QDeclarativeParentAnimation::target() const { Q_D(const QDeclarativeParentAnimation); @@ -2403,6 +2477,12 @@ void QDeclarativeParentAnimation::setTarget(QDeclarativeItem *target) d->target = target; } +/*! + \qmlproperty item ParentAnimation::newParent + The new parent to animate to. + + If not set, then the parent defined in the end state of the transition. +*/ QDeclarativeItem *QDeclarativeParentAnimation::newParent() const { Q_D(const QDeclarativeParentAnimation); @@ -2415,6 +2495,19 @@ void QDeclarativeParentAnimation::setNewParent(QDeclarativeItem *newParent) d->newParent = newParent; } +/*! + \qmlproperty item ParentAnimation::via + The item to reparent via. This provides a way to do an unclipped animation + when both the old parent and new parent are clipped + + \qml + ParentAnimation { + target: myItem + via: topLevelItem + ... + } + \endqml +*/ QDeclarativeItem *QDeclarativeParentAnimation::via() const { Q_D(const QDeclarativeParentAnimation); @@ -2461,12 +2554,13 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, struct QDeclarativeParentActionData : public QAbstractAnimationAction { - QDeclarativeParentActionData(): pc(0) {} - ~QDeclarativeParentActionData() { delete pc; } + QDeclarativeParentActionData() {} + ~QDeclarativeParentActionData() { qDeleteAll(pc); } QDeclarativeStateActions actions; + //### reverse should probably apply on a per-action basis bool reverse; - QDeclarativeParentChange *pc; + QList<QDeclarativeParentChange *> pc; virtual void doAction() { for (int ii = 0; ii < actions.count(); ++ii) { @@ -2481,6 +2575,33 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, QDeclarativeParentActionData *data = new QDeclarativeParentActionData; QDeclarativeParentActionData *viaData = new QDeclarativeParentActionData; + + bool hasExplicit = false; + if (d->target && d->newParent) { + data->reverse = false; + QDeclarativeAction myAction; + QDeclarativeParentChange *pc = new QDeclarativeParentChange; + pc->setObject(d->target); + pc->setParent(d->newParent); + myAction.event = pc; + data->pc << pc; + data->actions << myAction; + hasExplicit = true; + if (d->via) { + viaData->reverse = false; + QDeclarativeAction myVAction; + QDeclarativeParentChange *vpc = new QDeclarativeParentChange; + vpc->setObject(d->target); + vpc->setParent(d->via); + myVAction.event = vpc; + viaData->pc << vpc; + viaData->actions << myVAction; + } + //### once actions have concept of modified, + // loop to match appropriate ParentChanges and mark as modified + } + + if (!hasExplicit) for (int i = 0; i < actions.size(); ++i) { QDeclarativeAction &action = actions[i]; if (action.event && action.event->typeName() == QLatin1String("ParentChange") @@ -2489,8 +2610,21 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, QDeclarativeParentChange *pc = static_cast<QDeclarativeParentChange*>(action.event); QDeclarativeAction myAction = action; data->reverse = action.reverseEvent; - action.actionDone = true; - data->actions << myAction; + + //### this logic differs from PropertyAnimation + // (probably a result of modified vs. done) + if (d->newParent) { + QDeclarativeParentChange *epc = new QDeclarativeParentChange; + epc->setObject(static_cast<QDeclarativeParentChange*>(action.event)->object()); + epc->setParent(d->newParent); + myAction.event = epc; + data->pc << epc; + data->actions << myAction; + pc = epc; + } else { + action.actionDone = true; + data->actions << myAction; + } if (d->via) { viaData->reverse = false; @@ -2499,7 +2633,7 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions, vpc->setObject(pc->object()); vpc->setParent(d->via); myAction.event = vpc; - viaData->pc = vpc; + viaData->pc << vpc; viaData->actions << myAction; QDeclarativeAction dummyAction; QDeclarativeAction &xAction = pc->xIsSet() ? actions[++i] : dummyAction; diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 0f23f5c..af48309 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -457,7 +457,7 @@ class QDeclarativeParentAnimation : public QDeclarativeAnimationGroup Q_DECLARE_PRIVATE(QDeclarativeParentAnimation) Q_PROPERTY(QDeclarativeItem *target READ target WRITE setTarget) - //Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent) + Q_PROPERTY(QDeclarativeItem *newParent READ newParent WRITE setNewParent) Q_PROPERTY(QDeclarativeItem *via READ via WRITE setVia) public: diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index e582066..ae82a90 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -149,14 +149,21 @@ private: bool running; }; -//animates QDeclarativeTimeLineValue (assumes start and end values will be reals or compatible) -class QDeclarativeTimeLineValueAnimator : public QVariantAnimation +class QDeclarativeBulkValueUpdater +{ +public: + virtual ~QDeclarativeBulkValueUpdater() {} + virtual void setValue(qreal value) = 0; +}; + +//animates QDeclarativeBulkValueUpdater (assumes start and end values will be reals or compatible) +class QDeclarativeBulkValueAnimator : public QVariantAnimation { Q_OBJECT public: - QDeclarativeTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} - ~QDeclarativeTimeLineValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } - void setAnimValue(QDeclarativeTimeLineValue *value, DeletionPolicy p) + QDeclarativeBulkValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} + ~QDeclarativeBulkValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } + void setAnimValue(QDeclarativeBulkValueUpdater *value, DeletionPolicy p) { if (state() == Running) stop(); @@ -193,7 +200,7 @@ protected: } private: - QDeclarativeTimeLineValue *animValue; + QDeclarativeBulkValueUpdater *animValue; bool *fromSourced; DeletionPolicy policy; }; @@ -352,7 +359,7 @@ public: int interpolatorType; QVariantAnimation::Interpolator interpolator; - QDeclarativeTimeLineValueAnimator *va; + QDeclarativeBulkValueAnimator *va; static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); static void convertVariant(QVariant &variant, int type); diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index e0189dc..d90ca33 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -70,17 +70,18 @@ public: /*! \qmlclass Behavior QDeclarativeBehavior + \since 4.7 \brief The Behavior element allows you to specify a default animation for a property change. Behaviors provide one way to specify \l{qdeclarativeanimation.html}{animations} in QML. - In the example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: + In the example below, the rectangle will use a bounce easing curve over 200 millisecond for any changes to its y property: \code Rectangle { width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: Behavior { + y: 200 // initial value + Behavior on y { NumberAnimation { easing: "easeOutBounce(amplitude:100)" duration: 200 @@ -156,6 +157,7 @@ void QDeclarativeBehavior::setEnabled(bool enabled) void QDeclarativeBehavior::write(const QVariant &value) { Q_D(QDeclarativeBehavior); + qmlExecuteDeferred(this); if (!d->animation || !d->enabled) { QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); return; diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h index a633b55..ff58210 100644 --- a/src/declarative/util/qdeclarativebehavior_p.h +++ b/src/declarative/util/qdeclarativebehavior_p.h @@ -65,6 +65,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeBehavior : public QObject, public QDeclar Q_CLASSINFO("DefaultProperty", "animation") Q_PROPERTY(QDeclarativeAbstractAnimation *animation READ animation WRITE setAnimation) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_CLASSINFO("DeferredPropertyNames", "animation") public: QDeclarativeBehavior(QObject *parent=0); diff --git a/src/declarative/util/qdeclarativebind.cpp b/src/declarative/util/qdeclarativebind.cpp index e95a03e..26baa38 100644 --- a/src/declarative/util/qdeclarativebind.cpp +++ b/src/declarative/util/qdeclarativebind.cpp @@ -72,7 +72,7 @@ public: /*! \qmlclass Binding QDeclarativeBind - \since 4.7 + \since 4.7 \brief The Binding element allows arbitrary property bindings to be created. Sometimes it is necessary to bind to a property of an object that wasn't @@ -114,6 +114,19 @@ QDeclarativeBind::~QDeclarativeBind() { } +/*! + \qmlproperty bool Binding::when + + This property holds when the binding is active. + This should be set to an expression that evaluates to true when you want the binding to be active. + + \code + Binding { + target: contactName; property: 'text' + value: name; when: list.ListView.isCurrentItem + } + \endcode +*/ bool QDeclarativeBind::when() const { Q_D(const QDeclarativeBind); diff --git a/src/declarative/util/qdeclarativedatetimeformatter.cpp b/src/declarative/util/qdeclarativedatetimeformatter.cpp deleted file mode 100644 index 4087091..0000000 --- a/src/declarative/util/qdeclarativedatetimeformatter.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 "qdeclarativedatetimeformatter_p.h" - -#include <QtCore/qlocale.h> - -#include <private/qobject_p.h> - -QT_BEGIN_NAMESPACE - -//TODO: may need optimisation as the QDateTime member may not be needed? -// be able to set a locale? - -class QDeclarativeDateTimeFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeDateTimeFormatter) -public: - QDeclarativeDateTimeFormatterPrivate() : locale(QLocale::system()), longStyle(false), componentComplete(true) {} - - void updateText(); - - QDateTime dateTime; - QDate date; - QTime time; - QLocale locale; - QString dateTimeText; - QString dateText; - QString timeText; - QString dateTimeFormat; //set for convienience? - QString dateFormat; - QString timeFormat; - bool longStyle; - bool componentComplete; -}; - -/*! - \qmlclass DateTimeFormatter QDeclarativeDateTimeFormatter - \since 4.7 - \brief The DateTimeFormatter allows you to control the format of a date string. - - \code - DateTimeFormatter { id: formatter; date: System.date } - Text { text: formatter.dateText } - \endcode - - By default, the text properties (dateText, timeText, and dateTimeText) will return the - date and time using the current system locale's format. -*/ - -/*! - \internal - \class QDeclarativeDateTimeFormatter - \ingroup group_utility - \brief The QDeclarativeDateTimeFormatter class allows you to format a date string. -*/ - -QDeclarativeDateTimeFormatter::QDeclarativeDateTimeFormatter(QObject *parent) -: QObject(*(new QDeclarativeDateTimeFormatterPrivate), parent) -{ -} - -QDeclarativeDateTimeFormatter::~QDeclarativeDateTimeFormatter() -{ -} - -/*! - \qmlproperty string DateTimeFormatter::dateText - \qmlproperty string DateTimeFormatter::timeText - \qmlproperty string DateTimeFormatter::dateTimeText - - Formatted text representations of the \c date, \c time, - and \c {date and time}, respectively. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - \code - // specify source date (assuming today is February 19, 2009) - DateTimeFormatter { id: formatter; dateTime: Today.date } - - // display the full date and time - Text { text: formatter.dateText } - \endcode - - Would be equivalent to the following for a US English locale: - - \code - // display the date - Text { text: "2/19/09" } - \endcode -*/ -QString QDeclarativeDateTimeFormatter::dateTimeText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTimeText; -} - -QString QDeclarativeDateTimeFormatter::dateText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateText; -} - -QString QDeclarativeDateTimeFormatter::timeText() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->timeText; -} - -/*! - \qmlproperty date DateTimeFormatter::date - \qmlproperty time DateTimeFormatter::time - \qmlproperty datetime DateTimeFormatter::dateTime - - The source date and time to be used by the formatter. - - \code - // setting the date and time - DateTimeFormatter { date: System.date; time: System.time } - \endcode - - For convienience it is possible to set the datetime property to set both the date and the time. - \code - // setting the datetime - DateTimeFormatter { dateTime: System.dateTime } - \endcode - - There can only be one instance of date and time per formatter; if date, time, and dateTime are all - set the actual date and time used is not guaranteed. - - \note If no date is set, dateTimeText will be just the date; - If no time is set, the dateTimeText will be just the time. - -*/ -QDate QDeclarativeDateTimeFormatter::date() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->date; -} - -QTime QDeclarativeDateTimeFormatter::time() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->time; -} - -QDateTime QDeclarativeDateTimeFormatter::dateTime() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTime; -} - -/*! - \qmlproperty string DateTimeFormatter::dateFormat - \qmlproperty string DateTimeFormatter::timeFormat - \qmlproperty string DateTimeFormatter::dateTimeFormat - - Specifies a custom format which the DateTime Formatter can use. - - If there is no explictly specified format the DateTimeFormatter - will use the system locale's default 'short' setting. - - The text's format may be modified by setting: - \list - \i \c dateFormat - \i \c timeFormat - \i \c dateTimeFormat - \endlist - - If only the format for date is defined, the time and dateTime formats will be defined - as the system locale default and likewise for the others. - - Syntax for the format is based on the QDateTime::toString() formatting options. - - \code - // Format the date such that the dateText is: '1997-12-12' - DateTimeFormatter { id: formatter; dateTime: Today.dateTime; formatDate: "yyyy-MM-d" } - \endcode - - Assigning an empty string to a particular format will reset it. -*/ -QString QDeclarativeDateTimeFormatter::dateTimeFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateTimeFormat; -} - -QString QDeclarativeDateTimeFormatter::dateFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->dateFormat; -} - -QString QDeclarativeDateTimeFormatter::timeFormat() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->timeFormat; -} - -/*! - \qmlproperty bool DateTimeFormatter::longStyle - - This property causes the formatter to use the system locale's long format rather than short format - by default. - - This setting is off by default. -*/ -bool QDeclarativeDateTimeFormatter::longStyle() const -{ - Q_D(const QDeclarativeDateTimeFormatter); - return d->longStyle; -} - -void QDeclarativeDateTimeFormatter::setDateTime(const QDateTime &dateTime) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime == dateTime) - return; - d->dateTime = dateTime; - d->date = d->dateTime.date(); - d->time = d->dateTime.time(); - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setTime(const QTime &time) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime.time() == time) - return; - d->time = time; - d->dateTime.setTime(time); - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setDate(const QDate &date) -{ - Q_D(QDeclarativeDateTimeFormatter); - if (d->dateTime.date() == date) - return; - d->date = date; - bool clearTime = d->dateTime.time().isValid() ? false : true; //because setting date generates default time - d->dateTime.setDate(date); - if (clearTime) - d->dateTime.setTime(QTime()); - d->updateText(); -} - -//DateTime formatting may be a combination of date and time? -void QDeclarativeDateTimeFormatter::setDateTimeFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->dateTimeFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setDateFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->dateFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setTimeFormat(const QString &format) -{ - Q_D(QDeclarativeDateTimeFormatter); - //no format checking - d->timeFormat = format; - d->updateText(); -} - -void QDeclarativeDateTimeFormatter::setLongStyle(bool longStyle) -{ - Q_D(QDeclarativeDateTimeFormatter); - d->longStyle = longStyle; - d->updateText(); -} - -void QDeclarativeDateTimeFormatterPrivate::updateText() -{ - Q_Q(QDeclarativeDateTimeFormatter); - if (!componentComplete) - return; - - QString str; - QString str1; - QString str2; - - Qt::DateFormat defaultFormat = longStyle ? Qt::SystemLocaleLongDate : Qt::SystemLocaleShortDate; - - if (dateFormat.isEmpty()) - str1 = date.toString(defaultFormat); - else - str1 = date.toString(dateFormat); - - if (timeFormat.isEmpty()) - str2 = time.toString(defaultFormat); - else - str2 = time.toString(timeFormat); - - if (dateTimeFormat.isEmpty()) - str = dateTime.toString(defaultFormat); - //else if (!formatTime.isEmpty() && !formatDate.isEmpty()) - // str = str1 + QLatin1Char(' ') + str2; - else - str = dateTime.toString(dateTimeFormat); - - if (dateTimeText == str && dateText == str1 && timeText == str2) - return; - - dateTimeText = str; - dateText = str1; - timeText = str2; - - emit q->textChanged(); -} - -void QDeclarativeDateTimeFormatter::classBegin() -{ - Q_D(QDeclarativeDateTimeFormatter); - d->componentComplete = false; -} - -void QDeclarativeDateTimeFormatter::componentComplete() -{ - Q_D(QDeclarativeDateTimeFormatter); - d->componentComplete = true; - d->updateText(); -} - - - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativedatetimeformatter_p.h b/src/declarative/util/qdeclarativedatetimeformatter_p.h deleted file mode 100644 index da900be..0000000 --- a/src/declarative/util/qdeclarativedatetimeformatter_p.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEDATETIMEFORMATTER_H -#define QDECLARATIVEDATETIMEFORMATTER_H - -#include <qdeclarative.h> - -#include <QtCore/qdatetime.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeDateTimeFormatterPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeDateTimeFormatter : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QString dateText READ dateText NOTIFY textChanged) - Q_PROPERTY(QString timeText READ timeText NOTIFY textChanged) - Q_PROPERTY(QString dateTimeText READ dateTimeText NOTIFY textChanged) - Q_PROPERTY(QDate date READ date WRITE setDate) - Q_PROPERTY(QTime time READ time WRITE setTime) - Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime) - Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) - Q_PROPERTY(QString timeFormat READ timeFormat WRITE setTimeFormat) - Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) - Q_PROPERTY(bool longStyle READ longStyle WRITE setLongStyle) -public: - QDeclarativeDateTimeFormatter(QObject *parent=0); - ~QDeclarativeDateTimeFormatter(); - - QString dateTimeText() const; - QString dateText() const; - QString timeText() const; - - QDate date() const; - void setDate(const QDate &); - - QTime time() const; - void setTime(const QTime &); - - QDateTime dateTime() const; - void setDateTime(const QDateTime &); - - QString dateTimeFormat() const; - void setDateTimeFormat(const QString &); - - QString dateFormat() const; - void setDateFormat(const QString &); - - QString timeFormat() const; - void setTimeFormat(const QString &); - - bool longStyle() const; - void setLongStyle(bool); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QDeclarativeDateTimeFormatter) - Q_DECLARE_PRIVATE(QDeclarativeDateTimeFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeDateTimeFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qdeclarativeeasefollow.cpp b/src/declarative/util/qdeclarativeeasefollow.cpp index 232dc90..ee181dd 100644 --- a/src/declarative/util/qdeclarativeeasefollow.cpp +++ b/src/declarative/util/qdeclarativeeasefollow.cpp @@ -59,10 +59,10 @@ class QDeclarativeEaseFollowPrivate : public QObjectPrivate public: QDeclarativeEaseFollowPrivate() : source(0), velocity(200), duration(-1), maximumEasingTime(-1), - reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), + reversingMode(QDeclarativeEaseFollow::Eased), initialVelocity(0), initialValue(0), invert(false), enabled(true), trackVelocity(0), clockOffset(0), lastTick(0), clock(this) - {} + {} qreal source; qreal velocity; @@ -173,7 +173,7 @@ bool QDeclarativeEaseFollowPrivate::recalc() } /* - qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" + qWarning() << "a:" << a << "tf:" << tf << "tp:" << tp << "vp:" << vp << "sp:" << sp << "vi:" << vi << "invert:" << invert; */ return true; @@ -251,21 +251,22 @@ void QDeclarativeEaseFollowPrivate::tick(int t) /*! \qmlclass EaseFollow QDeclarativeEaseFollow + \since 4.7 \brief The EaseFollow element allows a property to smoothly track a value. - The EaseFollow smoothly animates a property's value to a set target value + The EaseFollow smoothly animates a property's value to a set target value using an ease in/out quad easing curve. If the target value changes while - the animation is in progress, the easing curves used to animate to the old + the animation is in progress, the easing curves used to animate to the old and the new target values are spliced together to avoid any obvious visual glitches. The property animation is configured by setting the velocity at which the - animation should occur, or the duration that the animation should take. + animation should occur, or the duration that the animation should take. If both a velocity and a duration are specified, the one that results in the quickest animation is chosen for each change in the target value. For example, animating from 0 to 800 will take 4 seconds if a velocity - of 200 is set, will take 8 seconds with a duration of 8000 set, and will + of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 4 seconds with both a velocity of 200 and a duration of 8000 set. Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, will take 8 seconds with a duration of 8000 set, and will take 8 seconds @@ -282,8 +283,8 @@ Rectangle { color: "green" width: 60; height: 60; x: -5; y: -5; - x: EaseFollow { source: rect1.x - 5; velocity: 200 } - y: EaseFollow { source: rect1.y - 5; velocity: 200 } + EaseFollow on x { source: rect1.x - 5; velocity: 200 } + EaseFollow on y { source: rect1.y - 5; velocity: 200 } } Rectangle { @@ -337,8 +338,8 @@ qreal QDeclarativeEaseFollow::sourceValue() const Sets how the EaseFollow behaves if an animation direction is reversed. If reversing mode is \c Eased, the animation will smoothly decelerate, and - then reverse direction. If the reversing mode is \c Immediate, the - animation will immediately begin accelerating in the reverse direction, + then reverse direction. If the reversing mode is \c Immediate, the + animation will immediately begin accelerating in the reverse direction, begining with a velocity of 0. If the reversing mode is \c Sync, the property is immediately set to the target value. */ @@ -372,7 +373,7 @@ void QDeclarativeEaseFollowPrivate::restart() return; } - bool hasReversed = trackVelocity != 0. && + bool hasReversed = trackVelocity != 0. && ((trackVelocity > 0) == ((initialValue - source) > 0)); if (hasReversed) { @@ -439,7 +440,7 @@ void QDeclarativeEaseFollow::setDuration(qreal v) d->duration = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit durationChanged(); @@ -469,7 +470,7 @@ void QDeclarativeEaseFollow::setVelocity(qreal v) d->velocity = v; d->trackVelocity = 0; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit velocityChanged(); @@ -510,8 +511,8 @@ void QDeclarativeEaseFollow::setTarget(const QDeclarativeProperty &t) \qmlproperty qreal EaseFollow::maximumEasingTime This property specifies the maximum time an "eases" during the follow should take. -Setting this property causes the velocity to "level out" after at a time. Setting -a negative value reverts to the normal mode of easing over the entire animation +Setting this property causes the velocity to "level out" after at a time. Setting +a negative value reverts to the normal mode of easing over the entire animation duration. The default value is -1. @@ -527,7 +528,7 @@ void QDeclarativeEaseFollow::setMaximumEasingTime(qreal v) Q_D(QDeclarativeEaseFollow); d->maximumEasingTime = v; - if (d->clock.state() == QAbstractAnimation::Running) + if (d->clock.state() == QAbstractAnimation::Running) d->restart(); emit maximumEasingTimeChanged(); diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index ac30384..8f5f537 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -75,6 +75,7 @@ public: /*! \qmlclass FontLoader QDeclarativeFontLoader + \since 4.7 \ingroup group_utility \brief This item allows using fonts by name or url. @@ -188,6 +189,16 @@ void QDeclarativeFontLoader::setName(const QString &name) \o Loading - the font is currently being loaded \o Error - an error occurred while loading the font \endlist + + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the font loader internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = FontLoader.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. FontLoader{id: loader; onStatusChanged: if(loader.status == FontLoader.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=FontLoader.Ready){'Not Loaded';}else{'Loaded';}} + \endlist */ QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const { diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index e78e0e1..e3f26d7 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -70,6 +70,7 @@ static void dump(ModelNode *node, int ind); /*! \qmlclass ListModel QDeclarativeListModel + \since 4.7 \brief The ListModel element defines a free-form list data source. The ListModel is a simple hierarchy of elements containing data roles. The contents can @@ -936,6 +937,7 @@ bool QDeclarativeListModelParser::definesEmptyList(const QString &s) /*! \qmlclass ListElement + \since 4.7 \brief The ListElement element defines a data item in a ListModel. \sa ListModel diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h index 251a31f..8eb6583 100644 --- a/src/declarative/util/qdeclarativelistmodel_p.h +++ b/src/declarative/util/qdeclarativelistmodel_p.h @@ -50,7 +50,7 @@ #include <QtCore/QHash> #include <QtCore/QList> #include <QtCore/QVariant> -#include "../3rdparty/qlistmodelinterface_p.h" +#include <private/qlistmodelinterface_p.h> #include <QtScript/qscriptvalue.h> QT_BEGIN_HEADER diff --git a/src/declarative/util/qdeclarativenumberformatter.cpp b/src/declarative/util/qdeclarativenumberformatter.cpp deleted file mode 100644 index 5d81958..0000000 --- a/src/declarative/util/qdeclarativenumberformatter.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 "qdeclarativenumberformatter_p.h" - -#include <private/qobject_p.h> - -QT_BEGIN_NAMESPACE - -//TODO: set locale -// docs -// this is a wrapper around qnumberformat (test integration) -// if number or format haven't been explictly set, text should be an empty string - -class QDeclarativeNumberFormatterPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeNumberFormatter) -public: - QDeclarativeNumberFormatterPrivate() : locale(QLocale::system()), number(0), componentComplete(true) {} - - void updateText(); - - QLocale locale; - QString format; - QNumberFormat numberFormat; - QString text; - qreal number; - bool componentComplete; -}; -/*! - \qmlclass NumberFormatter - \since 4.7 - \brief The NumberFormatter allows you to control the format of a number string. - - The format property documentation has more details on how the format can be manipulated. - - In the following example, the text element will display the text "1,234.57". - \code - NumberFormatter { id: formatter; number: 1234.5678; format: "##,##0.##" } - Text { text: formatter.text } - \endcode - - */ -/*! - \internal - \class QDeclarativeNumberFormatter - \ingroup group_utility - \brief The QDeclarativeNumberFormatter class allows you to format a number to a particular string format/locale specific number format. -*/ - -QDeclarativeNumberFormatter::QDeclarativeNumberFormatter(QObject *parent) -: QObject(*(new QDeclarativeNumberFormatterPrivate), parent) -{ -} - -QDeclarativeNumberFormatter::~QDeclarativeNumberFormatter() -{ -} - -/*! - \qmlproperty string NumberFormatter::text - - The number in the specified format. - - If no format is specified the text will be empty. -*/ - -QString QDeclarativeNumberFormatter::text() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->text; -} - -/*! - \qmlproperty real NumberFormatter::number - - A single point precision number. (Doubles are not yet supported) - -*/ -qreal QDeclarativeNumberFormatter::number() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->number; -} - -/*! - \qmlproperty string NumberFormatter::format - - The particular format the number will adhere to during the conversion to text. - - The format syntax follows a style similar to the Unicode Standard (UTS35). - - The table below shows the characters, patterns that can be used in the format. - - \table - \header - \o Character - \o Meaning - \row - \o # - \o Any digit(s), zero shows as absent (for leading/trailing zeroes). - \row - \o 0 - \o Implicit digit. Zero will show in the case that the input number is too small. - \row - \o . - \o Decimal separator. Output decimal seperator will be dependant on system locale. - \row - \o , - \o Grouping separator. The number of digits (either #, or 0) between the grouping separator and the decimal (or the rightmost digit) will determine the groupingSize). - \row - \o other - \o Any other character will be taken as a string literal and placed directly into the output string. - \endtable - - Invalid formats will not guarantee a meaningful text output. - - \note Input numbers that are too long for the given format will be rounded dependent on precison based on the position of the decimal point. - - The following table illustrates the output text created by applying some examples of numeric formats to the formatter. - - \table - \header - \o Format - \o Number - \o Output - \row - \o ### - \o 123456 - \o 123456 - \row - \o 000 - \o 123456 - \o 123456 - \row - \o ###### - \o 1234 - \o 1234 - \row - \o 000000 - \o 1234 - \o 001234 - \row - \o ##,##0.## - \o 1234.456 - \o 1,234.46 (for US locale) - \codeline 1 234,46 (for FR locale) - \row - \o 000000,000.# - \o 123456 - \o 000,123,456 (for US locale) - \codeline 000 123 456 (for FR locale) - \row - \o 0.0### - \o 0.999997 - \o 1.0 - \row - \o (000) 000 - 000 - \o 12345678 - \o (012) 345 - 678 - \row - \o #A - \o 12 - \o 12A - \endtable - -*/ -QString QDeclarativeNumberFormatter::format() const -{ - Q_D(const QDeclarativeNumberFormatter); - return d->format; -} - -void QDeclarativeNumberFormatter::setNumber(const qreal &number) -{ - Q_D(QDeclarativeNumberFormatter); - if (d->number == number) - return; - d->number = number; - d->updateText(); -} - -void QDeclarativeNumberFormatter::setFormat(const QString &format) -{ - Q_D(QDeclarativeNumberFormatter); - //no format checking - if (format.isEmpty()) - d->format = QString::null; - else - d->format = format; - d->updateText(); -} - -void QDeclarativeNumberFormatterPrivate::updateText() -{ - Q_Q(QDeclarativeNumberFormatter); - if (!componentComplete) - return; - - QNumberFormat tempFormat; - tempFormat.setFormat(format); - tempFormat.setNumber(number); - - text = tempFormat.text(); - - emit q->textChanged(); -} - -void QDeclarativeNumberFormatter::classBegin() -{ - Q_D(QDeclarativeNumberFormatter); - d->componentComplete = false; -} - -void QDeclarativeNumberFormatter::componentComplete() -{ - Q_D(QDeclarativeNumberFormatter); - d->componentComplete = true; - d->updateText(); -} - - -QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativenumberformatter_p.h b/src/declarative/util/qdeclarativenumberformatter_p.h deleted file mode 100644 index 3b8c7e1..0000000 --- a/src/declarative/util/qdeclarativenumberformatter_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVENUMBERFORMATTER_H -#define QDECLARATIVENUMBERFORMATTER_H - -#include "qnumberformat_p.h" - -#include <qdeclarative.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeNumberFormatterPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeNumberFormatter : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QString text READ text NOTIFY textChanged) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(qreal number READ number WRITE setNumber) -public: - QDeclarativeNumberFormatter(QObject *parent=0); - ~QDeclarativeNumberFormatter(); - - QString text() const; - - qreal number() const; - void setNumber(const qreal &); - - QString format() const; - void setFormat(const QString &); - - virtual void classBegin(); - virtual void componentComplete(); - -Q_SIGNALS: - void textChanged(); - -private: - Q_DISABLE_COPY(QDeclarativeNumberFormatter) - Q_DECLARE_PRIVATE(QDeclarativeNumberFormatter) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeNumberFormatter) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/qdeclarativepackage.cpp b/src/declarative/util/qdeclarativepackage.cpp index 34ae466..d144777 100644 --- a/src/declarative/util/qdeclarativepackage.cpp +++ b/src/declarative/util/qdeclarativepackage.cpp @@ -42,7 +42,7 @@ #include "qdeclarativepackage_p.h" #include <private/qobject_p.h> -#include "private/qdeclarativeguard_p.h" +#include <private/qdeclarativeguard_p.h> QT_BEGIN_NAMESPACE diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringfollow.cpp index 012e6a0..1d69dd3 100644 --- a/src/declarative/util/qdeclarativespringfollow.cpp +++ b/src/declarative/util/qdeclarativespringfollow.cpp @@ -213,6 +213,7 @@ void QDeclarativeSpringFollowPrivate::stop() /*! \qmlclass SpringFollow QDeclarativeSpringFollow + \since 4.7 \brief The SpringFollow element allows a property to track a value. In example below, \e rect2 will follow \e rect1 moving with a velocity of up to 200: @@ -221,8 +222,8 @@ void QDeclarativeSpringFollowPrivate::stop() id: rect1 width: 20; height: 20 color: "#00ff00" - y: 200 //initial value - y: SequentialAnimation { + y: 200 // initial value + SequentialAnimation on y { running: true repeat: true NumberAnimation { @@ -238,7 +239,7 @@ void QDeclarativeSpringFollowPrivate::stop() x: rect1.width width: 20; height: 20 color: "#ff0000" - y: SpringFollow { source: rect1.y; velocity: 200 } + SpringFollow on y { source: rect1.y; velocity: 200 } } \endcode diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp index 1a7c256..083e87d 100644 --- a/src/declarative/util/qdeclarativestategroup.cpp +++ b/src/declarative/util/qdeclarativestategroup.cpp @@ -84,6 +84,7 @@ public: /*! \qmlclass StateGroup QDeclarativeStateGroup + \since 4.7 \brief The StateGroup element provides state support for non-Item elements. Item (and all dervied elements) provides built in support for states and transitions @@ -406,7 +407,7 @@ void QDeclarativeStateGroupPrivate::setCurrentStateInternal(const QString &state } if (oldState == 0 || newState == 0) { - if (!nullState) { nullState = new QDeclarativeState; QDeclarativeGraphics_setParent_noEvent(nullState, q); } + if (!nullState) { nullState = new QDeclarativeState; QDeclarative_setParent_noEvent(nullState, q); } if (!oldState) oldState = nullState; if (!newState) newState = nullState; } diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index cea9ad7..cd06380 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -158,17 +158,17 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q \qmlclass ParentChange QDeclarativeParentChange \brief The ParentChange element allows you to reparent an Item in a state change. - ParentChange reparents an Item while preserving its visual appearance (position, rotation, - and scale) on screen. You can then specify a transition to move/rotate/scale the Item to - its final intended appearance. + ParentChange reparents an item while preserving its visual appearance (position, size, + rotation, and scale) on screen. You can then specify a transition to move/resize/rotate/scale + the item to its final intended appearance. ParentChange can only preserve visual appearance if no complex transforms are involved. More specifically, it will not work if the transform property has been set for any - Items involved in the reparenting (defined as any Items in the common ancestor tree + items involved in the reparenting (i.e. items in the common ancestor tree for the original and new parent). You can specify at which point in a transition you want a ParentChange to occur by - using a ParentAction. + using a ParentAnimation or ParentAction. */ @@ -181,6 +181,16 @@ QDeclarativeParentChange::~QDeclarativeParentChange() { } +/*! + \qmlproperty real ParentChange::x + \qmlproperty real ParentChange::y + \qmlproperty real ParentChange::width + \qmlproperty real ParentChange::height + \qmlproperty real ParentChange::scale + \qmlproperty real ParentChange::rotation + These properties hold the new position, size, scale, and rotation + for the item in this state. +*/ qreal QDeclarativeParentChange::x() const { Q_D(const QDeclarativeParentChange); @@ -314,7 +324,7 @@ void QDeclarativeParentChange::setObject(QDeclarativeItem *target) /*! \qmlproperty Item ParentChange::parent - This property holds the parent for the item in this state + This property holds the new parent for the item in this state. */ QDeclarativeItem *QDeclarativeParentChange::parent() const diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h index 026a64d..dd4248023 100644 --- a/src/declarative/util/qdeclarativestateoperations_p.h +++ b/src/declarative/util/qdeclarativestateoperations_p.h @@ -45,7 +45,7 @@ #include "qdeclarativestate_p.h" #include <qdeclarativeitem.h> -#include "private/qdeclarativeanchors_p.h" +#include <private/qdeclarativeanchors_p.h> #include <qdeclarativescriptstring.h> QT_BEGIN_HEADER diff --git a/src/declarative/util/qdeclarativesystempalette.cpp b/src/declarative/util/qdeclarativesystempalette.cpp index 1e00f22..d819c27 100644 --- a/src/declarative/util/qdeclarativesystempalette.cpp +++ b/src/declarative/util/qdeclarativesystempalette.cpp @@ -58,6 +58,7 @@ public: /*! \qmlclass SystemPalette QDeclarativeSystemPalette + \since 4.7 \ingroup group_utility \brief The SystemPalette item gives access to the Qt palettes. \sa QPalette diff --git a/src/declarative/util/qdeclarativetimeline_p_p.h b/src/declarative/util/qdeclarativetimeline_p_p.h index c08c07c..598c897 100644 --- a/src/declarative/util/qdeclarativetimeline_p_p.h +++ b/src/declarative/util/qdeclarativetimeline_p_p.h @@ -160,7 +160,7 @@ public: QDeclarativeTimeLineObject *callbackObject() const; private: - friend class QDeclarativeTimeLinePrivate; + friend struct QDeclarativeTimeLinePrivate; Callback d0; void *d1; QDeclarativeTimeLineObject *d2; diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp index 89c461b..104e3ae 100644 --- a/src/declarative/util/qdeclarativetimer.cpp +++ b/src/declarative/util/qdeclarativetimer.cpp @@ -70,6 +70,7 @@ public: /*! \qmlclass Timer QDeclarativeTimer + \since 4.7 \brief The Timer item triggers a handler at a specified interval. A timer can be used to trigger an action either once, or repeatedly @@ -122,6 +123,7 @@ void QDeclarativeTimer::setInterval(int interval) if (interval != d->interval) { d->interval = interval; update(); + emit intervalChanged(); } } @@ -182,6 +184,7 @@ void QDeclarativeTimer::setRepeating(bool repeating) if (repeating != d->repeating) { d->repeating = repeating; update(); + emit repeatChanged(); } } @@ -214,6 +217,7 @@ void QDeclarativeTimer::setTriggeredOnStart(bool triggeredOnStart) if (d->triggeredOnStart != triggeredOnStart) { d->triggeredOnStart = triggeredOnStart; update(); + emit triggeredOnStartChanged(); } } diff --git a/src/declarative/util/qdeclarativetimer_p.h b/src/declarative/util/qdeclarativetimer_p.h index e063657..d1e6630 100644 --- a/src/declarative/util/qdeclarativetimer_p.h +++ b/src/declarative/util/qdeclarativetimer_p.h @@ -59,10 +59,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTimer : public QObject, public QDeclarati Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeTimer) Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(int interval READ interval WRITE setInterval) + Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating) - Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart) + Q_PROPERTY(bool repeat READ isRepeating WRITE setRepeating NOTIFY repeatChanged) + Q_PROPERTY(bool triggeredOnStart READ triggeredOnStart WRITE setTriggeredOnStart NOTIFY triggeredOnStartChanged) public: QDeclarativeTimer(QObject *parent=0); @@ -91,6 +91,9 @@ public Q_SLOTS: Q_SIGNALS: void triggered(); void runningChanged(); + void intervalChanged(); + void repeatChanged(); + void triggeredOnStartChanged(); private: void update(); diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp index 2b8c7de..65bfdc1 100644 --- a/src/declarative/util/qdeclarativeutilmodule.cpp +++ b/src/declarative/util/qdeclarativeutilmodule.cpp @@ -46,13 +46,11 @@ #include "qdeclarativebehavior_p.h" #include "qdeclarativebind_p.h" #include "qdeclarativeconnections_p.h" -#include "qdeclarativedatetimeformatter_p.h" #include "qdeclarativeeasefollow_p.h" #include "qdeclarativefontloader_p.h" #include "qdeclarativelistaccessor_p.h" #include "qdeclarativelistmodel_p.h" #include "qdeclarativenullablevalue_p_p.h" -#include "qdeclarativenumberformatter_p.h" #include "qdeclarativeopenmetaobject_p.h" #include "qdeclarativepackage_p.h" #include "qdeclarativepixmapcache_p.h" @@ -70,8 +68,9 @@ #include "qdeclarativetransitionmanager_p_p.h" #include "qdeclarativetransition_p.h" #include "qdeclarativeview.h" +#ifndef QT_NO_XMLPATTERNS #include "qdeclarativexmllistmodel_p.h" -#include "qnumberformat_p.h" +#endif #include "qperformancelog_p_p.h" void QDeclarativeUtilModule::defineModule() @@ -81,12 +80,10 @@ void QDeclarativeUtilModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,Binding,QDeclarativeBind); QML_REGISTER_TYPE(Qt,4,6,ColorAnimation,QDeclarativeColorAnimation); QML_REGISTER_TYPE(Qt,4,6,Connections,QDeclarativeConnections); - QML_REGISTER_TYPE(Qt,4,6,DateTimeFormatter,QDeclarativeDateTimeFormatter); QML_REGISTER_TYPE(Qt,4,6,EaseFollow,QDeclarativeEaseFollow);; QML_REGISTER_TYPE(Qt,4,6,FontLoader,QDeclarativeFontLoader); QML_REGISTER_TYPE(Qt,4,6,ListElement,QDeclarativeListElement); QML_REGISTER_TYPE(Qt,4,6,NumberAnimation,QDeclarativeNumberAnimation); - QML_REGISTER_TYPE(Qt,4,6,NumberFormatter,QDeclarativeNumberFormatter);; QML_REGISTER_TYPE(Qt,4,6,Package,QDeclarativePackage); QML_REGISTER_TYPE(Qt,4,6,ParallelAnimation,QDeclarativeParallelAnimation); QML_REGISTER_TYPE(Qt,4,6,ParentAction,QDeclarativeParentAction); @@ -114,7 +111,6 @@ void QDeclarativeUtilModule::defineModule() QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors); QML_REGISTER_NOCREATE_TYPE(QDeclarativeAbstractAnimation); QML_REGISTER_NOCREATE_TYPE(QDeclarativeStateOperation); - QML_REGISTER_NOCREATE_TYPE(QNumberFormat); QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, ListModel, QDeclarativeListModel, QDeclarativeListModelParser); QML_REGISTER_CUSTOM_TYPE(Qt, 4,6, PropertyChanges, QDeclarativePropertyChanges, QDeclarativePropertyChangesParser); diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 6fe5bf3..cd67aeb 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -51,6 +51,7 @@ #include <qdeclarativedebug_p.h> #include <qdeclarativedebugservice_p.h> #include <qdeclarativeglobal_p.h> +#include <qdeclarativeguard_p.h> #include <qscriptvalueiterator.h> #include <qdebug.h> @@ -136,8 +137,8 @@ public: QDeclarativeView *q; - QGuard<QGraphicsObject> root; - QGuard<QDeclarativeItem> qmlRoot; + QDeclarativeGuard<QGraphicsObject> root; + QDeclarativeGuard<QDeclarativeItem> qmlRoot; QUrl source; @@ -193,6 +194,7 @@ void QDeclarativeViewPrivate::execute() \o Initializes QGraphicsView for QML key handling: \list \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus); + \o QGraphicsView::setFocusPolicy(Qt::StrongFocus); \o QGraphicsScene::setStickyFocus(true); \endlist \endlist @@ -267,6 +269,7 @@ void QDeclarativeViewPrivate::init() q->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); scene.setItemIndexMethod(QGraphicsScene::NoIndex); q->viewport()->setFocusPolicy(Qt::NoFocus); + q->setFocusPolicy(Qt::StrongFocus); scene.setStickyFocus(true); //### needed for correct focus handling } @@ -282,13 +285,14 @@ QDeclarativeView::~QDeclarativeView() /*! Sets the source to the \a url, loads the QML component and instantiates it. + + Calling this methods multiple times with the same url will result + in the QML being reloaded. */ void QDeclarativeView::setSource(const QUrl& url) { - if (url != d->source) { - d->source = url; - d->execute(); - } + d->source = url; + d->execute(); } /*! diff --git a/src/declarative/util/qdeclarativeview.h b/src/declarative/util/qdeclarativeview.h index 03d8db3..107f3f9 100644 --- a/src/declarative/util/qdeclarativeview.h +++ b/src/declarative/util/qdeclarativeview.h @@ -43,6 +43,7 @@ #define QDECLARATIVEVIEW_H #include <QtCore/qdatetime.h> +#include <QtCore/qurl.h> #include <QtGui/qgraphicssceneevent.h> #include <QtGui/qgraphicsview.h> #include <QtGui/qwidget.h> @@ -64,7 +65,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeView : public QGraphicsView Q_OBJECT Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) Q_PROPERTY(Status status READ status NOTIFY statusChanged) - + Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true) + Q_ENUMS(ResizeMode Status) public: explicit QDeclarativeView(QWidget *parent = 0); QDeclarativeView(const QUrl &source, QWidget *parent = 0); diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 386df46..49dbb27 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -61,9 +61,6 @@ QT_BEGIN_NAMESPACE - - - typedef QPair<int, int> QDeclarativeXmlListRange; /*! @@ -114,9 +111,6 @@ class QDeclarativeXmlQuery : public QThread { Q_OBJECT public: - QDeclarativeXmlQuery(QObject *parent=0) - : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) { - } ~QDeclarativeXmlQuery() { m_mutex.lock(); m_quit = true; @@ -126,6 +120,11 @@ public: wait(); } + static QDeclarativeXmlQuery *instance() { + static QDeclarativeXmlQuery *query = new QDeclarativeXmlQuery; + return query; + } + void abort() { QMutexLocker locker(&m_mutex); m_abort = true; @@ -164,6 +163,11 @@ public: return m_removedItemRanges; } +private: + QDeclarativeXmlQuery(QObject *parent=0) + : QThread(parent), m_quit(false), m_restart(false), m_abort(false), m_queryId(0) { + } + Q_SIGNALS: void queryCompleted(int queryId, int size); @@ -213,6 +217,8 @@ private: QList<QDeclarativeXmlListRange> m_removedItemRanges; }; +//Q_GLOBAL_STATIC(QDeclarativeXmlQuery, QDeclarativeXmlQuery::instance()); + void QDeclarativeXmlQuery::doQueryJob() { QString r; @@ -404,7 +410,6 @@ public: QNetworkReply *reply; QDeclarativeXmlListModel::Status status; qreal progress; - QDeclarativeXmlQuery qmlXmlQuery; int queryId; QList<QDeclarativeXmlListModelRole *> roleObjects; static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role); @@ -488,8 +493,7 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent) : QListModelInterface(*(new QDeclarativeXmlListModelPrivate), parent) { - Q_D(QDeclarativeXmlListModel); - connect(&d->qmlXmlQuery, SIGNAL(queryCompleted(int,int)), + connect(QDeclarativeXmlQuery::instance(), SIGNAL(queryCompleted(int,int)), this, SLOT(queryCompleted(int,int))); } @@ -571,9 +575,10 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src) { Q_D(QDeclarativeXmlListModel); if (d->src != src) { - d->src = src; reload(); - } + d->src = src; + emit sourceChanged(); + } } /*! @@ -593,8 +598,11 @@ QString QDeclarativeXmlListModel::xml() const void QDeclarativeXmlListModel::setXml(const QString &xml) { Q_D(QDeclarativeXmlListModel); - d->xml = xml; - reload(); + if (d->xml != xml) { + d->xml = xml; + reload(); + emit xmlChanged(); + } } /*! @@ -619,6 +627,7 @@ void QDeclarativeXmlListModel::setQuery(const QString &query) if (d->query != query) { d->query = query; reload(); + emit queryChanged(); } } @@ -638,6 +647,7 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati if (d->namespaces != declarations) { d->namespaces = declarations; reload(); + emit namespaceDeclarationsChanged(); } } @@ -647,11 +657,21 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati This property holds the status of data source loading. It can be one of: \list \o Null - no data source has been set - \o Ready - nthe data source has been loaded + \o Ready - the data source has been loaded \o Loading - the data source is currently being loaded \o Error - an error occurred while loading the data source \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the XmlListModel internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: xmlListModel.status = XmlListModel.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. XmlListModel{id: xmlListModel; onStatusChanged: if(xmlListModel.status == XmlListModel.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(xmlListModel.status!=XmlListModel.Ready){'Not Loaded';}else{'Loaded';}} + \endlist + \sa progress */ @@ -706,11 +726,27 @@ void QDeclarativeXmlListModel::reload() if (!d->isComponentComplete) return; - d->qmlXmlQuery.abort(); + QDeclarativeXmlQuery::instance()->abort(); d->queryId = -1; - if (d->size < 0) + int count = d->size; + if (count < 0) + d->size = 0; + bool hasKeys = false; + for (int i=0; i<d->roleObjects.count(); i++) { + if (d->roleObjects[i]->isKey()) { + hasKeys = true; + break; + } + } + if (!hasKeys) { + d->data.clear(); d->size = 0; + if (count > 0) { + emit itemsRemoved(0, count); + emit countChanged(); + } + } if (d->src.isEmpty() && d->xml.isEmpty()) return; @@ -722,7 +758,7 @@ void QDeclarativeXmlListModel::reload() } if (!d->xml.isEmpty()) { - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects); + d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects); d->progress = 1.0; d->status = Ready; emit progressChanged(d->progress); @@ -753,7 +789,7 @@ void QDeclarativeXmlListModel::requestFinished() } else { d->status = Ready; QByteArray data = d->reply->readAll(); - d->queryId = d->qmlXmlQuery.doQuery(d->query, d->namespaces, data, &d->roleObjects); + d->queryId = QDeclarativeXmlQuery::instance()->doQuery(d->query, d->namespaces, data, &d->roleObjects); disconnect(d->reply, 0, this, 0); d->reply->deleteLater(); d->reply = 0; @@ -779,12 +815,13 @@ void QDeclarativeXmlListModel::queryCompleted(int id, int size) return; bool sizeChanged = size != d->size; d->size = size; - d->data = d->qmlXmlQuery.modelData(); + d->data = QDeclarativeXmlQuery::instance()->modelData(); + + QList<QDeclarativeXmlListRange> removed = QDeclarativeXmlQuery::instance()->removedItemRanges(); + QList<QDeclarativeXmlListRange> inserted = QDeclarativeXmlQuery::instance()->insertedItemRanges(); - QList<QDeclarativeXmlListRange> removed = d->qmlXmlQuery.removedItemRanges(); for (int i=0; i<removed.count(); i++) emit itemsRemoved(removed[i].first, removed[i].second); - QList<QDeclarativeXmlListRange> inserted = d->qmlXmlQuery.insertedItemRanges(); for (int i=0; i<inserted.count(); i++) emit itemsInserted(inserted[i].first, inserted[i].second); diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index 132a53c..23ff7ce 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -47,7 +47,7 @@ #include <QtCore/qurl.h> -#include "../3rdparty/qlistmodelinterface_p.h" +#include <private/qlistmodelinterface_p.h> QT_BEGIN_HEADER @@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(QString xml READ xml WRITE setXml) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QString xml READ xml WRITE setXml NOTIFY xmlChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations NOTIFY namespaceDeclarationsChanged) Q_PROPERTY(QDeclarativeListProperty<QDeclarativeXmlListModelRole> roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -111,6 +111,10 @@ Q_SIGNALS: void statusChanged(Status); void progressChanged(qreal progress); void countChanged(); + void sourceChanged(); + void xmlChanged(); + void queryChanged(); + void namespaceDeclarationsChanged(); public Q_SLOTS: // ### need to use/expose Expiry to guess when to call this? @@ -132,16 +136,20 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModelRole : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString query READ query WRITE setQuery) - Q_PROPERTY(bool isKey READ isKey WRITE setIsKey) - + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) + Q_PROPERTY(bool isKey READ isKey WRITE setIsKey NOTIFY isKeyChanged) public: QDeclarativeXmlListModelRole() : m_isKey(false) {} ~QDeclarativeXmlListModelRole() {} QString name() const { return m_name; } - void setName(const QString &name) { m_name = name; } + void setName(const QString &name) { + if (name == m_name) + return; + m_name = name; + emit nameChanged(); + } QString query() const { return m_query; } void setQuery(const QString &query) @@ -150,16 +158,29 @@ public: qmlInfo(this) << tr("An XmlRole query must not start with '/'"); return; } + if (m_query == query) + return; m_query = query; + emit queryChanged(); } bool isKey() const { return m_isKey; } - void setIsKey(bool b) { m_isKey = b; } + void setIsKey(bool b) { + if (m_isKey == b) + return; + m_isKey = b; + emit isKeyChanged(); + } bool isValid() { return !m_name.isEmpty() && !m_query.isEmpty(); } +Q_SIGNALS: + void nameChanged(); + void queryChanged(); + void isKeyChanged(); + private: QString m_name; QString m_query; diff --git a/src/declarative/util/qnumberformat.cpp b/src/declarative/util/qnumberformat.cpp deleted file mode 100644 index 81d0b90..0000000 --- a/src/declarative/util/qnumberformat.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 "qnumberformat_p.h" -#include <QtCore/qstringlist.h> - -QT_BEGIN_NAMESPACE - -QNumberFormat::QNumberFormat(QObject *parent) : QObject(parent), _number(0), _type(Decimal), - _groupingSize(0) -{ - _locale = QLocale::system(); - _groupingSeparator = _locale.groupSeparator(); - _decimalSeparator = _locale.decimalPoint(); - _currencySymbol = QLatin1Char('$'); -} - -QNumberFormat::~QNumberFormat() -{ - -} - -void QNumberFormat::updateText() -{ - QTime t; - t.start(); - static int totalTime; - - handleFormat(); - - totalTime += t.elapsed(); - emit textChanged(); -} - -void QNumberFormat::handleFormat() -{ - // ### is extremely messy - if (_format.isEmpty()) { - _text = QString::number(_number, 'f', -1); - return; - } - - QString inputString; - - // ### possible to use the following parsed data in the future - - int remainingLength = _format.size(); - int currentIndex = _format.size()-1; - - int maxDigits = 0; - int minDigits = 0; - int decimalLength = 0; - - while (remainingLength > 0) { - switch(_format.at(currentIndex).unicode()) { - case ',': - if (decimalLength && !_groupingSize) - setGroupingSize(maxDigits - decimalLength); - else if (!_groupingSize) - setGroupingSize(maxDigits); - break; - case '.': - if (!decimalLength) - decimalLength = maxDigits; - break; - case '0': - minDigits++; - case '#': - maxDigits++; - break; - default: - break; - } - currentIndex--; - remainingLength--; - } - - // round given the decimal length/precision - inputString = QString::number(_number, 'f', decimalLength); - - QStringList parts = inputString.split(QLatin1Char('.')); - QStringList formatParts = _format.split(QLatin1Char('.')); - - if (formatParts.size() > 2 || parts.size() > 2 ) - return; - - QString formatInt = formatParts.at(0); - - QString formatDec; - if (formatParts.size() == 2) - formatDec = formatParts.at(1); - - QString integer = parts.at(0); - - QString decimal; - if (parts.size() == 2) - decimal = parts.at(1); - - QString outputDecimal = formatDecimal(formatDec, decimal); - QString outputInteger = formatInteger(formatInt, integer); - - // insert separators - if (_groupingSize) { - unsigned int count = 0; - for (int i = outputInteger.size()-1; i > 0; i--) { - if (outputInteger.at(i).digitValue() >= 0) { - if (count == _groupingSize - 1) { - count = 0; - outputInteger.insert(i, _groupingSeparator); - } - else - count++; - } - } - } - if (!outputDecimal.isEmpty()) - _text = outputInteger + _decimalSeparator + outputDecimal; - else - _text = outputInteger; -} - -QString QNumberFormat::formatInteger(const QString &formatInt, const QString &integer) -{ - if (formatInt.isEmpty() || integer.isEmpty()) - return QString(); - - QString outputInteger; - int formatIndex = formatInt.size()-1; - - //easier for carry? - for (int index= integer.size()-1; index >= 0; index--) { - if (formatIndex < 0) { - outputInteger.push_front(integer.at(index)); - } - else { - switch(formatInt.at(formatIndex).unicode()) { - case '0': - if (index > integer.size()-1) { - outputInteger.push_front(QLatin1Char('0')); - break; - } - case '#': - outputInteger.push_front(integer.at(index)); - break; - case ',': - index++; - break; - default: - outputInteger.push_front(formatInt.at(formatIndex)); - index++; - break; - } - formatIndex--; - } - } - while (formatIndex >= 0) { - if (formatInt.at(formatIndex).unicode() != '#' && formatInt.at(formatIndex).unicode() != ',') - outputInteger.push_front(formatInt.at(formatIndex)); - formatIndex--; - } - return outputInteger; -} - -QString QNumberFormat::formatDecimal(const QString &formatDec, const QString &decimal) -{ - QString outputDecimal; - - // up to max 6 decimal places - for (int index=formatDec.size()-1; index >= 0; index--) { - switch(formatDec.at(index).unicode()) { - case '0': - outputDecimal.push_front(decimal.at(index)); - break; - case '#': - if (decimal.at(index) != QLatin1Char('0') || outputDecimal.size() > 0) - outputDecimal.push_front(decimal.at(index)); - break; - default: - outputDecimal.push_front(formatDec.at(index)); - break; - } - } - return outputDecimal; -} - -QT_END_NAMESPACE diff --git a/src/declarative/util/qnumberformat_p.h b/src/declarative/util/qnumberformat_p.h deleted file mode 100644 index ced4442..0000000 --- a/src/declarative/util/qnumberformat_p.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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$ -** -****************************************************************************/ - -#ifndef NUMBERFORMAT_H -#define NUMBERFORMAT_H - -#include <qdeclarative.h> - -#include <QtCore/QLocale> -#include <QtCore/QTime> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -// TODO -// be able to set Locale, instead of default system for dynamic formatting -// add currency support -// add additional syntax, extend to format scientific, percentiles, significant digits etc - - -class QNumberFormat : public QObject -{ - Q_OBJECT - Q_ENUMS(NumberType) -public: - QNumberFormat(QObject *parent=0); - ~QNumberFormat(); - - enum NumberType { - Percent, - Scientific, - Currency, - Decimal - }; - - //external property, only visible - Q_PROPERTY(QString text READ text NOTIFY textChanged) - - //mutatable properties to modify the output (text) - Q_PROPERTY(qreal number READ number WRITE setNumber) - Q_PROPERTY(QString format READ format WRITE setFormat) - Q_PROPERTY(QLocale locale READ locale WRITE setLocale) - - //Format specific settings - Q_PROPERTY(unsigned short groupingSeparator READ groupingSeparator WRITE setGroupingSeparator) - Q_PROPERTY(unsigned short decimalSeperator READ decimalSeparator WRITE setDecimalSeparator) - Q_PROPERTY(unsigned int groupingSize READ groupingSize WRITE setGroupingSize) - Q_PROPERTY(unsigned short currencySymbol READ currencySymbol WRITE setCurrencySymbol) - - - QString text() const { return _text; } - - qreal number() const { return _number; } - void setNumber(qreal n) { - if (_number == n) - return; - _number = n; - updateText(); - } - - QString format() const { return _format; } - void setFormat(const QString &format) { - if (format.isEmpty()) - _format = QString::null; - else if (_format == format) - return; - - _format = format; - updateText(); - } - - QLocale locale() const { return _locale; } - void setLocale(const QLocale &locale) { _locale = locale; updateText(); } - - //Do we deal with unicode standard? or create our own - // ### since this is the backend for the number conversions, we will use the unicode - // the front-end will handle the QChar/QString -> short int - - unsigned short groupingSeparator() { return _groupingSeparator.unicode(); } - void setGroupingSeparator(unsigned short unicodeSymbol) - { - _groupingSeparator = QChar(unicodeSymbol); - } - - unsigned short decimalSeparator() { return _decimalSeparator.unicode(); } - void setDecimalSeparator(unsigned short unicodeSymbol) - { - _decimalSeparator = QChar(unicodeSymbol); - } - - unsigned short currencySymbol() { return _currencySymbol.unicode(); } - void setCurrencySymbol(unsigned short unicodeSymbol) - { - _currencySymbol = QChar(unicodeSymbol); - } - - unsigned int groupingSize() { return _groupingSize; } - void setGroupingSize(unsigned int size) - { - _groupingSize = size; - } - -Q_SIGNALS: - void textChanged(); - -private: - void updateText(); - void handleFormat(); - QString formatInteger(const QString &formatInt, const QString &integer); - QString formatDecimal(const QString &formatDec, const QString &decimal); - - qreal _number; - NumberType _type; - QChar _groupingSeparator; - QChar _decimalSeparator; - QChar _currencySymbol; - unsigned int _groupingSize; - - QLocale _locale; - QString _format; - - // only hooked member at the moment - QString _text; - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QNumberFormat) - -QT_END_HEADER - -#endif diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 198e9e5..26edecc 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -25,9 +25,6 @@ SOURCES += \ $$PWD/qdeclarativebind.cpp \ $$PWD/qdeclarativepropertymap.cpp \ $$PWD/qdeclarativepixmapcache.cpp \ - $$PWD/qnumberformat.cpp \ - $$PWD/qdeclarativenumberformatter.cpp \ - $$PWD/qdeclarativedatetimeformatter.cpp \ $$PWD/qdeclarativebehavior.cpp \ $$PWD/qdeclarativefontloader.cpp \ $$PWD/qdeclarativestyledtext.cpp @@ -60,9 +57,6 @@ HEADERS += \ $$PWD/qdeclarativebind_p.h \ $$PWD/qdeclarativepropertymap.h \ $$PWD/qdeclarativepixmapcache_p.h \ - $$PWD/qnumberformat_p.h \ - $$PWD/qdeclarativenumberformatter_p.h \ - $$PWD/qdeclarativedatetimeformatter_p.h \ $$PWD/qdeclarativebehavior_p.h \ $$PWD/qdeclarativefontloader_p.h \ $$PWD/qdeclarativestyledtext_p.h |