diff options
author | Christiaan Janssen <christiaan.janssen@nokia.com> | 2011-05-23 14:44:29 (GMT) |
---|---|---|
committer | Christiaan Janssen <christiaan.janssen@nokia.com> | 2011-05-31 10:43:13 (GMT) |
commit | bedf245d3ee7c5760d56bb67e97d6a62a34105e9 (patch) | |
tree | 24e09a0f0ed4e44483e7a491181f23b060e41ae2 | |
parent | 0b4e028ec294992df01430bdf978982835c7df5c (diff) | |
download | Qt-bedf245d3ee7c5760d56bb67e97d6a62a34105e9.zip Qt-bedf245d3ee7c5760d56bb67e97d6a62a34105e9.tar.gz Qt-bedf245d3ee7c5760d56bb67e97d6a62a34105e9.tar.bz2 |
QDeclarative: fixed clean animation lists
Change-Id: I9dd8b4fcd3f04193410710981a511b9f69e5dc19
-rw-r--r-- | src/declarative/util/qdeclarativeanimation.cpp | 10 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativetransition.cpp | 30 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativetransitionmanager.cpp | 6 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index efaa7f0..ce21bcd 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1522,6 +1522,7 @@ void QDeclarativeAnimationGroupPrivate::append_animation(QDeclarativeListPropert QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object); if (q) { a->setGroup(q); + // This is an optimization for the parenting that already occurs via addAnimation QDeclarative_setParent_noEvent(a->qtAnimation(), q->d_func()->ag); q->d_func()->ag->addAnimation(a->qtAnimation()); } @@ -1531,9 +1532,12 @@ void QDeclarativeAnimationGroupPrivate::clear_animation(QDeclarativeListProperty { QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object); if (q) { - for (int i = 0; i < q->d_func()->animations.count(); ++i) - q->d_func()->animations.at(i)->setGroup(0); - q->d_func()->animations.clear(); + while (q->d_func()->animations.count()) { + QDeclarativeAbstractAnimation *firstAnim = q->d_func()->animations.at(0); + QDeclarative_setParent_noEvent(firstAnim->qtAnimation(), 0); + q->d_func()->ag->removeAnimation(firstAnim->qtAnimation()); + firstAnim->setGroup(0); + } } } diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index 273060b..b63407c 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -130,6 +130,9 @@ public: endState->complete(); } static void append_animation(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list, QDeclarativeAbstractAnimation *a); + static int animation_count(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list); + static QDeclarativeAbstractAnimation* animation_at(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list, int pos); + static void clear_animations(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list); QList<QDeclarativeAbstractAnimation *> animations; }; @@ -141,6 +144,28 @@ void QDeclarativeTransitionPrivate::append_animation(QDeclarativeListProperty<QD a->setDisableUserControl(); } +int QDeclarativeTransitionPrivate::animation_count(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list) +{ + QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object); + return q->d_func()->animations.count(); +} + +QDeclarativeAbstractAnimation* QDeclarativeTransitionPrivate::animation_at(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list, int pos) +{ + QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object); + return q->d_func()->animations.at(pos); +} + +void QDeclarativeTransitionPrivate::clear_animations(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list) +{ + QDeclarativeTransition *q = static_cast<QDeclarativeTransition *>(list->object); + while (q->d_func()->animations.count()) { + QDeclarativeAbstractAnimation *firstAnim = q->d_func()->animations.at(0); + q->d_func()->group.removeAnimation(firstAnim->qtAnimation()); + q->d_func()->animations.removeAll(firstAnim); + } +} + void ParallelAnimationWrapper::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { QParallelAnimationGroup::updateState(newState, oldState); @@ -309,7 +334,10 @@ void QDeclarativeTransition::setToState(const QString &t) QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeTransition::animations() { Q_D(QDeclarativeTransition); - return QDeclarativeListProperty<QDeclarativeAbstractAnimation>(this, &d->animations, QDeclarativeTransitionPrivate::append_animation); + return QDeclarativeListProperty<QDeclarativeAbstractAnimation>(this, &d->animations, QDeclarativeTransitionPrivate::append_animation, + QDeclarativeTransitionPrivate::animation_count, + QDeclarativeTransitionPrivate::animation_at, + QDeclarativeTransitionPrivate::clear_animations); } QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativetransitionmanager.cpp b/src/declarative/util/qdeclarativetransitionmanager.cpp index 944b37f..6e96ac9 100644 --- a/src/declarative/util/qdeclarativetransitionmanager.cpp +++ b/src/declarative/util/qdeclarativetransitionmanager.cpp @@ -56,12 +56,12 @@ class QDeclarativeTransitionManagerPrivate { public: QDeclarativeTransitionManagerPrivate() - : state(0), transition(0) {} + : state(0) {} void applyBindings(); typedef QList<QDeclarativeSimpleAction> SimpleActionList; QDeclarativeState *state; - QDeclarativeTransition *transition; + QDeclarativeGuard<QDeclarativeTransition> transition; QDeclarativeStateOperation::ActionList bindingsList; SimpleActionList completeList; }; @@ -253,7 +253,7 @@ void QDeclarativeTransitionManager::cancel() { if (d->transition) { // ### this could potentially trigger a complete in rare circumstances - d->transition->stop(); + d->transition->stop(); d->transition = 0; } |