summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-27 11:43:29 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-27 11:44:56 (GMT)
commit3192b8cec804e0c294a88e788392915e95faf435 (patch)
treec206d45d216fac5980f0b8882fbfc1d58a323d5d /src/corelib/animation
parent3a35d00f7ee780ec3b36c8b959c1e3f964b0fb87 (diff)
downloadQt-3192b8cec804e0c294a88e788392915e95faf435.zip
Qt-3192b8cec804e0c294a88e788392915e95faf435.tar.gz
Qt-3192b8cec804e0c294a88e788392915e95faf435.tar.bz2
QPropertyAnimation: use of QWeakPointer instead of QObject::connect
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp47
-rw-r--r--src/corelib/animation/qpropertyanimation.h1
-rw-r--r--src/corelib/animation/qpropertyanimation_p.h8
3 files changed, 23 insertions, 33 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 35d65d0..2795208 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -106,14 +106,14 @@ void QPropertyAnimationPrivate::updateMetaProperty()
return;
if (!hasMetaProperty && !property.isValid()) {
- const QMetaObject *mo = target->metaObject();
+ const QMetaObject *mo = targetValue->metaObject();
propertyIndex = mo->indexOfProperty(propertyName);
if (propertyIndex != -1) {
hasMetaProperty = true;
property = mo->property(propertyIndex);
propertyType = property.userType();
} else {
- if (!target->dynamicPropertyNames().contains(propertyName))
+ if (!targetValue->dynamicPropertyNames().contains(propertyName))
qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData());
}
}
@@ -124,30 +124,27 @@ void QPropertyAnimationPrivate::updateMetaProperty()
void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue)
{
- if (!target || state == QAbstractAnimation::Stopped)
+ if (state == QAbstractAnimation::Stopped)
return;
+ if (!target) {
+ q_func()->stop(); //the target was destroyed we need to stop the animation
+ return;
+ }
+
if (hasMetaProperty) {
if (newValue.userType() == propertyType) {
//no conversion is needed, we directly call the QObject::qt_metacall
void *data = const_cast<void*>(newValue.constData());
- target->qt_metacall(QMetaObject::WriteProperty, propertyIndex, &data);
+ targetValue->qt_metacall(QMetaObject::WriteProperty, propertyIndex, &data);
} else {
- property.write(target, newValue);
+ property.write(targetValue, newValue);
}
} else {
- target->setProperty(propertyName.constData(), newValue);
+ targetValue->setProperty(propertyName.constData(), 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.
@@ -187,14 +184,13 @@ QPropertyAnimation::~QPropertyAnimation()
*/
QObject *QPropertyAnimation::targetObject() const
{
- Q_D(const QPropertyAnimation);
- return d->target;
+ return d_func()->target.data();
}
void QPropertyAnimation::setTargetObject(QObject *target)
{
Q_D(QPropertyAnimation);
- if (d->target == target)
+ if (d->targetValue == target)
return;
if (d->state != QAbstractAnimation::Stopped) {
@@ -202,14 +198,7 @@ void QPropertyAnimation::setTargetObject(QObject *target)
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->target = d->targetValue = target;
d->hasMetaProperty = false;
d->updateMetaProperty();
}
@@ -273,7 +262,7 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState,
{
Q_D(QPropertyAnimation);
- if (!d->target) {
+ if (!d->target && oldState == Stopped) {
qWarning("QPropertyAnimation::updateState: Changing state of an animation without target");
return;
}
@@ -286,14 +275,16 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState,
typedef QPair<QObject *, QByteArray> QPropertyAnimationPair;
typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash;
static QPropertyAnimationHash hash;
- QPropertyAnimationPair key(d->target, d->propertyName);
+ //here we need to use value because we need to know to which pointer
+ //the animation was referring in case stopped because the target was destroyed
+ QPropertyAnimationPair key(d->targetValue, d->propertyName);
if (newState == Running) {
d->updateMetaProperty();
animToStop = hash.value(key, 0);
hash.insert(key, this);
// update the default start value
if (oldState == Stopped) {
- d->setDefaultStartEndValue(d->target->property(d->propertyName.constData()));
+ d->setDefaultStartEndValue(d->targetValue->property(d->propertyName.constData()));
//let's check if we have a start value and an end value
if (d->direction == Forward && !startValue().isValid() && !d->defaultStartEndValue.isValid())
qWarning("QPropertyAnimation::updateState: starting an animation without start value");
diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h
index e12508d..56fb4b1 100644
--- a/src/corelib/animation/qpropertyanimation.h
+++ b/src/corelib/animation/qpropertyanimation.h
@@ -76,7 +76,6 @@ protected:
void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
private:
- Q_PRIVATE_SLOT(d_func(), void _q_targetDestroyed())
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 ffa6114..4c9360b 100644
--- a/src/corelib/animation/qpropertyanimation_p.h
+++ b/src/corelib/animation/qpropertyanimation_p.h
@@ -67,13 +67,13 @@ class QPropertyAnimationPrivate : public QVariantAnimationPrivate
Q_DECLARE_PUBLIC(QPropertyAnimation)
public:
QPropertyAnimationPrivate()
- : target(0), propertyType(0), propertyIndex(0), hasMetaProperty(false)
+ : targetValue(0), propertyType(0), propertyIndex(0), hasMetaProperty(false)
{
}
- void _q_targetDestroyed();
-
- QObject *target;
+ QWeakPointer<QObject> target;
+ //we use targetValue to be able to unregister the target from the global hash
+ QObject *targetValue;
//for the QProperty
QMetaProperty property;