summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation/qpropertyanimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/animation/qpropertyanimation.cpp')
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp75
1 files changed, 23 insertions, 52 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index fe7ab0c070..d461668dbb 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QPropertyAnimation
@@ -58,6 +22,10 @@
\snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \note You can also control an animation's lifespan by choosing a
+ \l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting the
+ animation.
+
The property name and the QObject instance of which property
should be animated are passed to the constructor. You can then
specify the start and end value of the property. The procedure is
@@ -85,13 +53,15 @@
#include "qpropertyanimation_p.h"
#include <QtCore/QMutex>
+#include <QtCore/QHash>
#include <QtCore/private/qlocking_p.h>
QT_BEGIN_NAMESPACE
void QPropertyAnimationPrivate::updateMetaProperty()
{
- if (!targetObject || propertyName.value().isEmpty()) {
+ const QObject *target = targetObject.valueBypassingBindings();
+ if (!target || propertyName.value().isEmpty()) {
propertyType = QMetaType::UnknownType;
propertyIndex = -1;
return;
@@ -99,19 +69,19 @@ void QPropertyAnimationPrivate::updateMetaProperty()
//propertyType will be set to a valid type only if there is a Q_PROPERTY
//otherwise it will be set to QVariant::Invalid at the end of this function
- propertyType = targetObject->property(propertyName.value()).userType();
- propertyIndex = targetObject->metaObject()->indexOfProperty(propertyName.value());
+ propertyType = target->property(propertyName.value()).userType();
+ propertyIndex = target->metaObject()->indexOfProperty(propertyName.value());
if (propertyType != QMetaType::UnknownType)
convertValues(propertyType);
if (propertyIndex == -1) {
//there is no Q_PROPERTY on the object
propertyType = QMetaType::UnknownType;
- if (!targetObject->dynamicPropertyNames().contains(propertyName))
+ if (!target->dynamicPropertyNames().contains(propertyName))
qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of "
"your QObject",
propertyName.value().constData());
- } else if (!targetObject->metaObject()->property(propertyIndex).isWritable()) {
+ } else if (!target->metaObject()->property(propertyIndex).isWritable()) {
qWarning("QPropertyAnimation: you're trying to animate the non-writable property %s of "
"your QObject",
propertyName.value().constData());
@@ -194,15 +164,16 @@ void QPropertyAnimation::setTargetObject(QObject *target)
}
d->targetObject.removeBindingUnlessInWrapper();
- if (d->targetObject == target)
+ const QObject *oldTarget = d->targetObject.valueBypassingBindings();
+ if (oldTarget == target)
return;
- if (d->targetObject != nullptr)
- QObject::disconnect(d->targetObject, &QObject::destroyed, this, nullptr);
+ if (oldTarget != nullptr)
+ QObject::disconnect(oldTarget, &QObject::destroyed, this, nullptr);
d->targetObject.setValueBypassingBindings(target);
- if (d->targetObject != nullptr) {
- QObject::connect(d->targetObject, &QObject::destroyed, this,
+ if (target != nullptr) {
+ QObject::connect(target, &QObject::destroyed, this,
[d] { d->targetObjectDestroyed(); });
}
d->updateMetaProperty();
@@ -232,7 +203,7 @@ void QPropertyAnimation::setPropertyName(const QByteArray &propertyName)
d->propertyName.removeBindingUnlessInWrapper();
- if (d->propertyName == propertyName)
+ if (d->propertyName.valueBypassingBindings() == propertyName)
return;
d->propertyName.setValueBypassingBindings(propertyName);
@@ -288,11 +259,11 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState,
QPropertyAnimation *animToStop = nullptr;
{
- static QBasicMutex mutex;
+ Q_CONSTINIT static QBasicMutex mutex;
auto locker = qt_unique_lock(mutex);
- typedef QPair<QObject *, QByteArray> QPropertyAnimationPair;
+ using QPropertyAnimationPair = std::pair<QObject *, QByteArray>;
typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash;
- static QPropertyAnimationHash hash;
+ Q_CONSTINIT static QPropertyAnimationHash hash;
// in case the targetObject gets deleted, the following happens:
// 1. targetObject's destroyed signal calls our targetObjectDestroyed.