diff options
-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; |