diff options
author | David Boddie <dboddie@trolltech.com> | 2009-08-27 13:13:33 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2009-08-27 13:13:33 (GMT) |
commit | 919259cadd1adc18aaaef7e6f453e3fa005dd8b7 (patch) | |
tree | 4985e8f6b54dcf7bebf73c83cd955ec797784897 /src/corelib | |
parent | bb76203895a8a33bc76a4e4662492d1100c8b4fd (diff) | |
parent | 29488d2315c594a273da6b7adb8d238aeca23083 (diff) | |
download | Qt-919259cadd1adc18aaaef7e6f453e3fa005dd8b7.zip Qt-919259cadd1adc18aaaef7e6f453e3fa005dd8b7.tar.gz Qt-919259cadd1adc18aaaef7e6f453e3fa005dd8b7.tar.bz2 |
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into 4.6
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/animation/qpropertyanimation.cpp | 78 | ||||
-rw-r--r-- | src/corelib/animation/qpropertyanimation.h | 1 | ||||
-rw-r--r-- | src/corelib/animation/qpropertyanimation_p.h | 11 | ||||
-rw-r--r-- | src/corelib/animation/qvariantanimation_p.h | 6 | ||||
-rw-r--r-- | src/corelib/io/qprocess.cpp | 3 |
5 files changed, 37 insertions, 62 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 35d65d0..49862d2 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -92,8 +92,6 @@ #include "qanimationgroup.h" #include "qpropertyanimation_p.h" -#include <QtCore/qmath.h> -#include <QtCore/qmutex.h> #include <private/qmutexpool_p.h> #ifndef QT_NO_ANIMATION @@ -102,50 +100,38 @@ QT_BEGIN_NAMESPACE void QPropertyAnimationPrivate::updateMetaProperty() { - if (!target || propertyName.isEmpty()) + if (!target || propertyName.isEmpty()) { + propertyType = QVariant::Invalid; + propertyIndex = -1; return; - - if (!hasMetaProperty && !property.isValid()) { - const QMetaObject *mo = target->metaObject(); - propertyIndex = mo->indexOfProperty(propertyName); - if (propertyIndex != -1) { - hasMetaProperty = true; - property = mo->property(propertyIndex); - propertyType = property.userType(); - } else { - if (!target->dynamicPropertyNames().contains(propertyName)) - qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData()); - } } - if (property.isValid()) + propertyType = targetValue->property(propertyName).userType(); + propertyIndex = targetValue->metaObject()->indexOfProperty(propertyName); + if (propertyIndex == -1 && !targetValue->dynamicPropertyNames().contains(propertyName)) + qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData()); + + if (propertyType != QVariant::Invalid) convertValues(propertyType); } void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue) { - if (!target || state == QAbstractAnimation::Stopped) + if (state == QAbstractAnimation::Stopped) 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); - } else { - property.write(target, newValue); - } - } else { - target->setProperty(propertyName.constData(), newValue); + if (!target) { + q_func()->stop(); //the target was destroyed we need to stop the animation + return; } -} -void QPropertyAnimationPrivate::_q_targetDestroyed() -{ - Q_Q(QPropertyAnimation); - //we stop here so that this animation is removed from the global hash - q->stop(); - target = 0; + if (propertyIndex != -1 && newValue.userType() == propertyType) { + //no conversion is needed, we directly call the QObject::qt_metacall + void *data = const_cast<void*>(newValue.constData()); + targetValue->qt_metacall(QMetaObject::WriteProperty, propertyIndex, &data); + } else { + targetValue->setProperty(propertyName.constData(), newValue); + } } /*! @@ -187,14 +173,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,15 +187,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->hasMetaProperty = false; + d->target = d->targetValue = target; d->updateMetaProperty(); } @@ -236,7 +213,6 @@ void QPropertyAnimation::setPropertyName(const QByteArray &propertyName) } d->propertyName = propertyName; - d->hasMetaProperty = false; d->updateMetaProperty(); } @@ -273,7 +249,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 +262,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..3777aa0 100644 --- a/src/corelib/animation/qpropertyanimation_p.h +++ b/src/corelib/animation/qpropertyanimation_p.h @@ -54,7 +54,6 @@ // #include "qpropertyanimation.h" -#include <QtCore/qmetaobject.h> #include "private/qvariantanimation_p.h" @@ -67,20 +66,18 @@ class QPropertyAnimationPrivate : public QVariantAnimationPrivate Q_DECLARE_PUBLIC(QPropertyAnimation) public: QPropertyAnimationPrivate() - : target(0), propertyType(0), propertyIndex(0), hasMetaProperty(false) + : targetValue(0), propertyType(0), propertyIndex(-1) { } - 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; int propertyType; int propertyIndex; - bool hasMetaProperty; QByteArray propertyName; void updateProperty(const QVariant &); void updateMetaProperty(); diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h index ce625f1..da120df 100644 --- a/src/corelib/animation/qvariantanimation_p.h +++ b/src/corelib/animation/qvariantanimation_p.h @@ -78,10 +78,7 @@ public: void setDefaultStartEndValue(const QVariant &value); - int duration; - QEasingCurve easing; - QVariantAnimation::KeyValues keyValues; QVariant currentValue; QVariant defaultStartEndValue; @@ -91,6 +88,9 @@ public: QVariantAnimation::KeyValue start, end; } currentInterval; + QEasingCurve easing; + int duration; + QVariantAnimation::KeyValues keyValues; QVariantAnimation::Interpolator interpolator; void setCurrentValueForProgress(const qreal progress); diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 764304d..f4bf5cc 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1646,7 +1646,8 @@ bool QProcess::waitForBytesWritten(int msecs) has been emitted, or until \a msecs milliseconds have passed. Returns true if the process finished; otherwise returns false (if - the operation timed out or if an error occurred). + the operation timed out, if an error occurred, or if this QProcess + is already finished). This function can operate without an event loop. It is useful when writing non-GUI applications and when performing |