From bb5d2af7677a14f2aaeffb0e29679d9dcce692e6 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Fri, 23 Apr 2021 14:31:26 +0200 Subject: 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 Reviewed-by: Sona Kurazyan --- .../qpropertyanimation/tst_qpropertyanimation.cpp | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp index 5286daec6a..1da69f8338 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp @@ -1403,11 +1403,26 @@ void tst_QPropertyAnimation::recursiveAnimations() void tst_QPropertyAnimation::bindings() { - AnimationObject o; - QPropertyAnimation a(&o, "value"); + std::unique_ptr o1(new AnimationObject); + std::unique_ptr o2(new AnimationObject); + QPropertyAnimation a(o1.get(), "value"); + + QTestPrivate::testReadWritePropertyBasics( + a, QByteArray("realValue"), QByteArray("value"), "propertyName"); + if (QTest::currentTestFailed()) { + qDebug() << "Failed property test for QPropertyAnimation::propertyName"; + return; + } + QTestPrivate::testReadWritePropertyBasics(a, o2.get(), o1.get(), + "targetObject"); + if (QTest::currentTestFailed()) { + qDebug() << "Failed property test for QPropertyAnimation::targetObject"; + return; + } - QTestPrivate::testReadWritePropertyBasics(a, QByteArray("value"), QByteArray("realValue"), - "propertyName"); + a.setTargetObject(o1.get()); + o1.reset(); + QCOMPARE(a.targetObject(), nullptr); } QTEST_MAIN(tst_QPropertyAnimation) -- cgit v1.2.3