diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-20 09:42:25 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-20 09:42:25 (GMT) |
commit | c21803201a607dabc1d5a9345004d8f5dbc02d25 (patch) | |
tree | 3996719e27e7b839b6dbeae9c77575cf0f9c0cf4 | |
parent | 6501f21efeb9fb327be60b8d069cfad5f19f9ff7 (diff) | |
download | Qt-c21803201a607dabc1d5a9345004d8f5dbc02d25.zip Qt-c21803201a607dabc1d5a9345004d8f5dbc02d25.tar.gz Qt-c21803201a607dabc1d5a9345004d8f5dbc02d25.tar.bz2 |
Fix an issue that made appear warnings when the target of a property
animation was destroyed
The problem was that we were not really detecting when the target was
destroyed. So we weren't able to unregister it from the global internal
hash we have in QPropertyAnimation.
This happens if an animation is running and the target object is
destroyed.
-rw-r--r-- | src/corelib/animation/qpropertyanimation.cpp | 27 | ||||
-rw-r--r-- | src/corelib/animation/qpropertyanimation.h | 1 | ||||
-rw-r--r-- | src/corelib/animation/qpropertyanimation_p.h | 5 |
3 files changed, 31 insertions, 2 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 1755aa7..10fe8a2 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -146,6 +146,14 @@ void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue) } } +void QPropertyAnimationPrivate::_q_targetDestroyed() +{ + Q_Q(QPropertyAnimation); + //we stop here so that this animation is removed from the global hash + q->stop(); + target = 0; +} + /*! Construct a QPropertyAnimation object. \a parent is passed to QObject's constructor. @@ -188,12 +196,25 @@ QObject *QPropertyAnimation::targetObject() const Q_D(const QPropertyAnimation); return d->target; } + void QPropertyAnimation::setTargetObject(QObject *target) { Q_D(QPropertyAnimation); if (d->target == target) return; + if (d->state != QAbstractAnimation::Stopped) { + qWarning("QPropertyAnimation::setTargetObject: you can't change the target of a running animation"); + return; + } + + //we need to get notified when the target is destroyed + if (d->target) + disconnect(d->target, SIGNAL(destroyed()), this, SLOT(_q_targetDestroyed())); + + if (target) + connect(target, SIGNAL(destroyed()), SLOT(_q_targetDestroyed())); + d->target = target; d->hasMetaProperty = 0; d->updateMetaProperty(); @@ -211,9 +232,15 @@ QByteArray QPropertyAnimation::propertyName() const Q_D(const QPropertyAnimation); return d->propertyName; } + void QPropertyAnimation::setPropertyName(const QByteArray &propertyName) { Q_D(QPropertyAnimation); + if (d->state != QAbstractAnimation::Stopped) { + qWarning("QPropertyAnimation::setPropertyName: you can't change the property name of a running animation"); + return; + } + d->propertyName = propertyName; d->hasMetaProperty = 0; d->updateMetaProperty(); diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h index dbd118c..5b06bd2 100644 --- a/src/corelib/animation/qpropertyanimation.h +++ b/src/corelib/animation/qpropertyanimation.h @@ -75,6 +75,7 @@ protected: void updateCurrentValue(const QVariant &value); void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); + Q_PRIVATE_SLOT(d_func(), void _q_targetDestroyed()); private: Q_DISABLE_COPY(QPropertyAnimation) Q_DECLARE_PRIVATE(QPropertyAnimation) diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h index 9d9dd31..b51d039 100644 --- a/src/corelib/animation/qpropertyanimation_p.h +++ b/src/corelib/animation/qpropertyanimation_p.h @@ -55,7 +55,6 @@ #include "qpropertyanimation.h" #include <QtCore/qmetaobject.h> -#include <QtCore/qpointer.h> #include "qvariantanimation_p.h" @@ -70,7 +69,9 @@ public: { } - QPointer<QObject> target; + void _q_targetDestroyed(); + + QObject *target; //for the QProperty QMetaProperty property; |