From 7f73eb160e0499750c42224afc34a9432afa1b48 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 2 Jul 2009 10:45:24 +1000 Subject: PropertyAnimation optimization and animation code cleanup. --- src/declarative/util/qmlanimation.cpp | 45 ++++++++++++----------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 6ad47f5..c0d6481 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -58,12 +58,6 @@ #include #include -/* TODO: - Check for any memory leaks - easing should be a QEasingCurve-type property - All other XXXs and ###s -*/ - QT_BEGIN_NAMESPACE QEasingCurve stringToCurve(const QString &curve) @@ -1108,7 +1102,7 @@ void QmlParentChangeActionPrivate::init() void QmlParentChangeActionPrivate::doAction() { - //XXX property.write(value); + //### property.write(value); } void QmlParentChangeAction::prepare(QmlMetaProperty &p) @@ -1120,7 +1114,7 @@ void QmlParentChangeAction::prepare(QmlMetaProperty &p) else d->property = d->userProperty; - //XXX + //### } QAbstractAnimation *QmlParentChangeAction::qtAnimation() @@ -1239,7 +1233,7 @@ QmlNumberAnimation::~QmlNumberAnimation() qreal QmlNumberAnimation::from() const { Q_D(const QmlPropertyAnimation); - return d->from.toDouble(); //### toFloat? + return d->from.toDouble(); } void QmlNumberAnimation::setFrom(qreal f) @@ -1259,7 +1253,7 @@ void QmlNumberAnimation::setFrom(qreal f) qreal QmlNumberAnimation::to() const { Q_D(const QmlPropertyAnimation); - return d->to.toDouble(); //### toFloat? + return d->to.toDouble(); } void QmlNumberAnimation::setTo(qreal t) @@ -1346,7 +1340,7 @@ void QmlSequentialAnimation::transition(QmlStateActions &actions, from = d->animations.count() - 1; } - //### needed for Behavior + //needed for Behavior if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { for (int i = 0; i < d->animations.count(); ++i) d->animations.at(i)->setTarget(d->userProperty); @@ -1428,7 +1422,7 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, { Q_D(QmlAnimationGroup); - //### needed for Behavior + //needed for Behavior if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { for (int i = 0; i < d->animations.count(); ++i) d->animations.at(i)->setTarget(d->userProperty); @@ -1441,22 +1435,8 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, QML_DEFINE_TYPE(QmlParallelAnimation,ParallelAnimation) -//### profile and optimize -QVariant QmlPropertyAnimationPrivate::interpolateVariant(const QVariant &from, const QVariant &to, qreal progress) -{ - if (from.userType() != to.userType()) - return QVariant(); - - QVariantAnimation::Interpolator interpolator = QVariantAnimationPrivate::getInterpolator(from.userType()); - if (interpolator) - return interpolator(from.constData(), to.constData(), progress); - else - return QVariant(); -} - //convert a variant from string type to another animatable type //### should use any registered string convertor -//### profile and optimize void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, QVariant::Type type) { if (variant.type() != QVariant::String) { @@ -1743,6 +1723,7 @@ void QmlPropertyAnimationPrivate::valueChanged(qreal r) if (!fromIsDefined) { from = property.read(); convertVariant(from, (QVariant::Type)(interpolatorType ? interpolatorType : property.propertyType())); + //### check for invalid variant if using property type } fromSourced = true; } @@ -1752,8 +1733,6 @@ void QmlPropertyAnimationPrivate::valueChanged(qreal r) } else { if (interpolator) property.write(interpolator(from.constData(), to.constData(), r)); - else - property.write(interpolateVariant(from, to, r)); //### optimize } } @@ -1771,9 +1750,15 @@ void QmlPropertyAnimation::prepare(QmlMetaProperty &p) else d->property = d->userProperty; - d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + int propType = d->property.propertyType(); + d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : propType)); if (d->fromIsDefined) - d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : propType)); + + if (!d->interpolatorType) { + //### check for invalid variants + d->interpolator = QVariantAnimationPrivate::getInterpolator(propType); + } d->fromSourced = false; d->value.QmlTimeLineValue::setValue(0.); -- cgit v0.12