diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2021-04-23 14:31:26 +0200 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-04-28 12:38:57 +0200 |
commit | bb5d2af7677a14f2aaeffb0e29679d9dcce692e6 (patch) | |
tree | 8460a0cead7134a2d203eb6fe46c414ce8afa05b /src/corelib/animation/qpropertyanimation_p.h | |
parent | ab43506910ebb520872afb42b641edae4c07808c (diff) |
Port QPropertyAnimation::targetObject to bindable properties
This is one of the more complicated ports. The target object
was represented by two variables in the past: A raw pointer and a
QPointer. The QPointer is checked in some cases to check whether
the target object still exists.
This patch introduces a targetObjectDestroyed() slot and connects
it to the destroyed(QObject*) signal of the target object.
In this slot, the animation is stopped. The checks become
obsolete thereby and it is sufficient to represent the target
Object in one raw pointer.
This raw pointer becomes a bindable property.
Fixes: QTBUG-92992
Change-Id: I7e2ddb5d8aed007400fe74bea1becf7bdfbf2563
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/animation/qpropertyanimation_p.h')
-rw-r--r-- | src/corelib/animation/qpropertyanimation_p.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h index 0b1bb2bd03..2552fec088 100644 --- a/src/corelib/animation/qpropertyanimation_p.h +++ b/src/corelib/animation/qpropertyanimation_p.h @@ -64,15 +64,21 @@ class QPropertyAnimationPrivate : public QVariantAnimationPrivate { Q_DECLARE_PUBLIC(QPropertyAnimation) public: - QPropertyAnimationPrivate() - : targetValue(nullptr), propertyType(0), propertyIndex(-1) + QPropertyAnimationPrivate() : propertyType(0), propertyIndex(-1) { } + + void setTargetObjectForwarder(QObject *target) { q_func()->setTargetObject(target); } + Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QPropertyAnimationPrivate, QObject *, targetObject, + &QPropertyAnimationPrivate::setTargetObjectForwarder, + nullptr) + void targetObjectDestroyed() { + // stop() has to be called before targetObject is set to nullptr. + // targetObject must not be nullptr in states unequal to "Stopped". + q_func()->stop(); + targetObject.setValueBypassingBindings(nullptr); + targetObject.notify(); } - QPointer<QObject> target; - //we use targetValue to be able to unregister the target from the global hash - QObject *targetValue; - //for the QProperty int propertyType; int propertyIndex; |