diff options
| -rw-r--r-- | .cmake.conf | 2 | ||||
| -rw-r--r-- | dependencies.yaml | 4 | ||||
| -rw-r--r-- | src/timeline/qquickkeyframe.cpp | 19 | ||||
| -rw-r--r-- | tests/auto/qtquicktimeline/data/restorebindingtest.qml | 68 | ||||
| -rw-r--r-- | tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp | 52 |
5 files changed, 139 insertions, 6 deletions
diff --git a/.cmake.conf b/.cmake.conf index d453dc6..25c70b0 100644 --- a/.cmake.conf +++ b/.cmake.conf @@ -1,4 +1,4 @@ -set(QT_REPO_MODULE_VERSION "6.5.7") +set(QT_REPO_MODULE_VERSION "6.5.8") set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1") # Use cpp-based syncqt diff --git a/dependencies.yaml b/dependencies.yaml index bd25292..4af4d8f 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,7 +1,7 @@ dependencies: ../tqtc-qtbase: - ref: fc0e66eefe3a08428ca4a6e92c66f37ac126d3c4 + ref: 0fe1875684a77d985277eaf58741e64ef6514bca required: true ../tqtc-qtdeclarative: - ref: 844f9b9b376838bcb44324984876f8bf99d85d38 + ref: 22032227d16c39211e2ebceef97d21f4d89c7c87 required: true diff --git a/src/timeline/qquickkeyframe.cpp b/src/timeline/qquickkeyframe.cpp index 64bb8da..fe28ba8 100644 --- a/src/timeline/qquickkeyframe.cpp +++ b/src/timeline/qquickkeyframe.cpp @@ -19,6 +19,7 @@ #include <QtCore/QCborStreamReader> #include <private/qvariantanimation_p.h> +#include <private/qqmlproperty_p.h> #include <algorithm> @@ -51,6 +52,7 @@ protected: QVariant originalValue; QVariant lastValue; + QQmlAnyBinding originalBinding; }; void QQuickKeyframeGroupPrivate::setupKeyframes() @@ -428,8 +430,12 @@ void QQuickKeyframeGroup::init() { Q_D(QQuickKeyframeGroup); if (target()) { + QQmlProperty qmlProperty(target(), property()); d->originalValue = QQmlProperty::read(target(), property()); - d->userType = QQmlProperty(target(), property()).property().userType(); + d->userType = qmlProperty.property().userType(); + if (d->originalBinding) + d->originalBinding = nullptr; + d->originalBinding = QQmlAnyBinding::ofProperty(qmlProperty); if (property().contains(QLatin1Char('.'))) { if (d->userType == QMetaType::QVector2D || d->userType == QMetaType::QVector3D @@ -444,8 +450,15 @@ void QQuickKeyframeGroup::resetDefaultValue() { Q_D(QQuickKeyframeGroup); - if (QQmlProperty::read(target(), property()) == d->lastValue) - QQmlProperty::write(target(), property(), d->originalValue); + if (QQmlProperty::read(target(), property()) == d->lastValue) { + if (d->originalBinding) { + QQmlProperty qmlProperty(target(), property()); + d->originalBinding.installOn(qmlProperty); + d->originalBinding = nullptr; + } else { + QQmlProperty::write(target(), property(), d->originalValue); + } + } } void QQuickKeyframeGroup::reset() diff --git a/tests/auto/qtquicktimeline/data/restorebindingtest.qml b/tests/auto/qtquicktimeline/data/restorebindingtest.qml new file mode 100644 index 0000000..062aa4a --- /dev/null +++ b/tests/auto/qtquicktimeline/data/restorebindingtest.qml @@ -0,0 +1,68 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Timeline + +Item { + Item { + width: 480 + height: 480 + + Timeline { + id: timeline + + objectName: "timeline" + + startFrame: 0 + endFrame: 100 + currentFrame: 50 + + enabled: false + + KeyframeGroup { + objectName: "group01" + target: rectangle + property: "x" + + Keyframe { + frame: 0 + value: 140 + } + + Keyframe { + frame: 100 + value: rectangle.offset + } + } + + KeyframeGroup { + target: rectangle + property: "anchors.topMargin" + + Keyframe { + frame: 0 + value: rectangle.offset + } + + Keyframe { + frame: 100 + value: 140 + } + } + } + + Rectangle { + id: rectangle + objectName: "rectangle" + property int offset: 0 + + x: offset + width: 20 + height: 20 + color: "red" + anchors.top: parent.top + anchors.topMargin: offset + } + } +} diff --git a/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp b/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp index f458389..b939bf4 100644 --- a/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp +++ b/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp @@ -20,6 +20,7 @@ private Q_SLOTS: void deltaFunction(); void keyframeUpdate(); void easingcurveInterpolation(); + void restoreBindingTest(); }; inline QUrl testFileUrl(const QString &fileName) @@ -393,6 +394,57 @@ void Tst_QtQuickTimeline::easingcurveInterpolation() QCOMPARE(rectangle->property("y").toReal(), final); } +void Tst_QtQuickTimeline::restoreBindingTest() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("restorebindingtest.qml")); + + QScopedPointer<QObject> object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *rectangle = object->findChild<QObject *>("rectangle"); + QVERIFY(rectangle); + + QCOMPARE(rectangle->property("offset").toInt(), 0); + QCOMPARE(rectangle->property("x").toInt(), 0); + QCOMPARE(rectangle->property("y").toInt(), 0); + + auto *timeline = object->findChild<QObject *>("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), false); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 100); + QCOMPARE(timeline->property("currentFrame").toInt(), 50); + + // currentFrame == 50 + timeline->setProperty("enabled", true); + QCOMPARE(rectangle->property("x").toInt(), 70); + QCOMPARE(rectangle->property("y").toInt(), 70); + + timeline->setProperty("currentFrame", 0); + QCOMPARE(rectangle->property("x").toInt(), 140); + QCOMPARE(rectangle->property("y").toInt(), 0); + + timeline->setProperty("currentFrame", 100); + QCOMPARE(rectangle->property("x").toInt(), 0); + QCOMPARE(rectangle->property("y").toInt(), 140); + + + timeline->setProperty("enabled", false); + // check restoring of the original binding + QCOMPARE(rectangle->property("x").toInt(), 0); + QCOMPARE(rectangle->property("y").toInt(), 0); + rectangle->setProperty("offset", 50); + QCOMPARE(rectangle->property("x").toInt(), 50); + QCOMPARE(rectangle->property("y").toInt(), 50); + + timeline->setProperty("enabled", true); + // currentFrame == 100, offset == 50 + QCOMPARE(rectangle->property("x").toInt(), 50); + QCOMPARE(rectangle->property("y").toInt(), 140); +} QTEST_MAIN(Tst_QtQuickTimeline) #include "tst_qtquicktimeline.moc" |
