diff options
-rw-r--r-- | src/animation/backend/backend.pri | 6 | ||||
-rw-r--r-- | src/animation/backend/clock.cpp | 71 | ||||
-rw-r--r-- | src/animation/backend/clock_p.h | 86 | ||||
-rw-r--r-- | src/animation/frontend/frontend.pri | 7 | ||||
-rw-r--r-- | src/animation/frontend/qclock.cpp | 109 | ||||
-rw-r--r-- | src/animation/frontend/qclock.h | 77 | ||||
-rw-r--r-- | src/animation/frontend/qclock_p.h | 80 | ||||
-rw-r--r-- | src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp | 2 | ||||
-rw-r--r-- | tests/auto/animation/animation.pro | 6 | ||||
-rw-r--r-- | tests/auto/animation/clock/clock.pro | 12 | ||||
-rw-r--r-- | tests/auto/animation/clock/tst_clock.cpp | 82 | ||||
-rw-r--r-- | tests/auto/animation/qclock/qclock.pro | 12 | ||||
-rw-r--r-- | tests/auto/animation/qclock/tst_qclock.cpp | 165 |
13 files changed, 709 insertions, 6 deletions
diff --git a/src/animation/backend/backend.pri b/src/animation/backend/backend.pri index 2bc72e1d3..5e4fa925f 100644 --- a/src/animation/backend/backend.pri +++ b/src/animation/backend/backend.pri @@ -26,7 +26,8 @@ HEADERS += \ $$PWD/lerpclipblend_p.h \ $$PWD/additiveclipblend_p.h \ $$PWD/clipblendvalue_p.h \ - $$PWD/animationclip_p.h + $$PWD/animationclip_p.h \ + $$PWD/clock_p.h SOURCES += \ $$PWD/handler.cpp \ @@ -50,4 +51,5 @@ SOURCES += \ $$PWD/lerpclipblend.cpp \ $$PWD/additiveclipblend.cpp \ $$PWD/clipblendvalue.cpp \ - $$PWD/animationclip.cpp + $$PWD/animationclip.cpp \ + $$PWD/clock.cpp diff --git a/src/animation/backend/clock.cpp b/src/animation/backend/clock.cpp new file mode 100644 index 000000000..870c79078 --- /dev/null +++ b/src/animation/backend/clock.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "clock_p.h" +#include <Qt3DAnimation/qclock.h> +#include <Qt3DAnimation/private/qclock_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +Clock::Clock() + : BackendNode(ReadOnly) + , m_startGlobalTime(0) + , m_playbackRate(1.f) +{ +} + +void Clock::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClockData>>(change); + const auto &data = typedChange->data; + m_playbackRate = data.playbackRate; +} + +void Clock::cleanup() +{ + m_startGlobalTime = 0; + m_playbackRate = 1.f; +} + +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/clock_p.h b/src/animation/backend/clock_p.h new file mode 100644 index 000000000..a8dd86890 --- /dev/null +++ b/src/animation/backend/clock_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_ANIMATION_CLOCK_P_H +#define QT3DANIMATION_ANIMATION_CLOCK_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DAnimation/private/backendnode_p.h> +#include <Qt3DAnimation/private/animationutils_p.h> +#include <Qt3DCore/qnodeid.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +class Q_AUTOTEST_EXPORT Clock : public BackendNode +{ +public: + Clock(); + + void cleanup(); + + void setPlaybackRate(float playbackRate) { m_playbackRate = playbackRate; } + int playbackRate() const { return m_playbackRate; } + + void setStartTime(qint64 globalTime) { m_startGlobalTime = globalTime; } + qint64 startTime() const { return m_startGlobalTime; } + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + qint64 m_startGlobalTime; + float m_playbackRate; +}; + +} // namespace Animation +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_CLOCK_P_H diff --git a/src/animation/frontend/frontend.pri b/src/animation/frontend/frontend.pri index 7f397462b..35835416b 100644 --- a/src/animation/frontend/frontend.pri +++ b/src/animation/frontend/frontend.pri @@ -46,7 +46,9 @@ HEADERS += \ $$PWD/qanimationclip.h \ $$PWD/qanimationclip_p.h \ $$PWD/qanimationcallback.h \ - $$PWD/qanimationcallbacktrigger_p.h + $$PWD/qanimationcallbacktrigger_p.h \ + $$PWD/qclock.h \ + $$PWD/qclock_p.h SOURCES += \ $$PWD/qanimationaspect.cpp \ @@ -74,6 +76,7 @@ SOURCES += \ $$PWD/qchannelcomponent.cpp \ $$PWD/qkeyframe.cpp \ $$PWD/qanimationclip.cpp \ - $$PWD/qanimationcallbacktrigger.cpp + $$PWD/qanimationcallbacktrigger.cpp \ + $$PWD/qclock.cpp INCLUDEPATH += $$PWD diff --git a/src/animation/frontend/qclock.cpp b/src/animation/frontend/qclock.cpp new file mode 100644 index 000000000..1a3649900 --- /dev/null +++ b/src/animation/frontend/qclock.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qclock.h" +#include "qclock_p.h" +#include <Qt3DCore/qpropertyupdatedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +QClockPrivate::QClockPrivate() + : Qt3DCore::QNodePrivate() + , m_playbackRate(1.0f) +{ +} + +void QClockPrivate::setPlaybackRate(float playbackRate) +{ + if (qFuzzyCompare(playbackRate, m_playbackRate)) + return; + + Q_Q(QClock); + m_playbackRate = playbackRate; + emit q->playbackRateChanged(playbackRate); +} + +QClock::QClock(Qt3DCore::QNode* parent) + : Qt3DCore::QNode(*new QClockPrivate, parent) +{ +} + +QClock::QClock(QClockPrivate &dd, Qt3DCore::QNode *parent) + : Qt3DCore::QNode(dd, parent) +{ +} + +QClock::~QClock() +{ +} + +float QClock::playbackRate() const +{ + Q_D(const QClock); + return d->m_playbackRate; +} + +void QClock::setPlaybackRate(float playbackRate) +{ + Q_D(QClock); + d->setPlaybackRate(playbackRate); +} + +void QClock::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) +{ + if (change->type() == Qt3DCore::PropertyUpdated) { + Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change); + if (e->propertyName() == QByteArrayLiteral("playbackRate")) { + Q_D(QClock); + d->setPlaybackRate(e->value().toFloat()); + } + } +} + +Qt3DCore::QNodeCreatedChangeBasePtr QClock::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QClockData>::create(this); + auto &data = creationChange->data; + Q_D(const QClock); + data.playbackRate = d->m_playbackRate; + return creationChange; +} + +} + +QT_END_NAMESPACE diff --git a/src/animation/frontend/qclock.h b/src/animation/frontend/qclock.h new file mode 100644 index 000000000..5b6790362 --- /dev/null +++ b/src/animation/frontend/qclock.h @@ -0,0 +1,77 @@ +/**************************************************************************** + ** + ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of the Qt3D module of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL3$ + ** 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 http://www.qt.io/terms-conditions. For further + ** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free + ** Software Foundation and appearing in the file LICENSE.GPL included in + ** the packaging of this file. Please review the following information to + ** ensure the GNU General Public License version 2.0 requirements will be + ** met: http://www.gnu.org/licenses/gpl-2.0.html. + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#ifndef QT3DANIMATION_QCLOCK_H +#define QT3DANIMATION_QCLOCK_H + +#include <Qt3DAnimation/qt3danimation_global.h> +#include <Qt3DCore/qnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QClockPrivate; + +class QT3DANIMATIONSHARED_EXPORT QClock : public Qt3DCore::QNode +{ + Q_OBJECT + Q_PROPERTY(float playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + +public: + explicit QClock(Qt3DCore::QNode *parent = nullptr); + ~QClock(); + + float playbackRate() const; + void setPlaybackRate(float playbackRate); + +Q_SIGNALS: + void playbackRateChanged(float playbackRate); + +protected: + QClock(QClockPrivate &dd, Qt3DCore::QNode *parent = nullptr); + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QClock) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCLOCK_H diff --git a/src/animation/frontend/qclock_p.h b/src/animation/frontend/qclock_p.h new file mode 100644 index 000000000..d633d071e --- /dev/null +++ b/src/animation/frontend/qclock_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_QCLOCK_P_H +#define QT3DANIMATION_QCLOCK_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/private/qnode_p.h> +#include "qclock.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QClockPrivate : public Qt3DCore::QNodePrivate +{ +public: + QClockPrivate(); + + Q_DECLARE_PUBLIC(QClock) + + void setPlaybackRate(float playbackRate); + + float m_playbackRate; +}; + +struct QClockData +{ + float playbackRate; +}; + +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCLOCK_P_H diff --git a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp index 7feeaf84c..eb9a32109 100644 --- a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp +++ b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp @@ -48,6 +48,7 @@ #include <Qt3DAnimation/qlerpclipblend.h> #include <Qt3DAnimation/qadditiveclipblend.h> #include <Qt3DAnimation/qclipblendvalue.h> +#include <Qt3DAnimation/qclock.h> #include <Qt3DAnimation/qkeyframeanimation.h> #include <Qt3DAnimation/qanimationcontroller.h> @@ -87,6 +88,7 @@ void Qt3DQuick3DAnimationPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3DAnimation::QLerpClipBlend>(uri, 2, 9, "LerpClipBlend"); qmlRegisterType<Qt3DAnimation::QAdditiveClipBlend>(uri, 2, 9, "AdditiveClipBlend"); qmlRegisterType<Qt3DAnimation::QClipBlendValue>(uri, 2, 9, "ClipBlendValue"); + qmlRegisterType<Qt3DAnimation::QClock>(uri, 2, 9, "Clock"); qmlRegisterUncreatableType<Qt3DAnimation::QAbstractAnimation>(uri, 2, 9, "AbstractAnimation", QStringLiteral("AbstractAnimation is abstract")); qmlRegisterExtendedType<Qt3DAnimation::QKeyframeAnimation, Qt3DAnimation::Quick::QQuick3DKeyframeAnimation>(uri, 2, 9, "KeyframeAnimation"); diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index b48fd347b..4bc1c9252 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -13,7 +13,8 @@ SUBDIRS += \ qkeyframeanimation \ qmorphinganimation \ qmorphtarget \ - qvertexblendanimation + qvertexblendanimation \ + qclock qtConfig(private_tests) { SUBDIRS += \ @@ -34,5 +35,6 @@ qtConfig(private_tests) { additiveclipblend \ clipblendvalue \ animationutils \ - qabstractanimation + qabstractanimation \ + clock } diff --git a/tests/auto/animation/clock/clock.pro b/tests/auto/animation/clock/clock.pro new file mode 100644 index 000000000..26b7a4b21 --- /dev/null +++ b/tests/auto/animation/clock/clock.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_clock + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_clock.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/clock/tst_clock.cpp b/tests/auto/animation/clock/tst_clock.cpp new file mode 100644 index 000000000..fa9b5892f --- /dev/null +++ b/tests/auto/animation/clock/tst_clock.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QTest> +#include <Qt3DAnimation/qclock.h> +#include <Qt3DAnimation/private/clock_p.h> +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/private/qbackendnode_p.h> +#include <qbackendnodetester.h> +#include <testpostmanarbiter.h> + +class tst_Clock: public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DAnimation::Animation::Clock backendClock; + Qt3DAnimation::QClock clock; + + clock.setPlaybackRate(10.f); + + // WHEN + simulateInitialization(&clock, &backendClock); + + // THEN + QCOMPARE(backendClock.playbackRate(), clock.playbackRate()); + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DAnimation::Animation::Clock backendClock; + + // THEN + QCOMPARE(backendClock.playbackRate(), 1.f); + + // GIVEN + Qt3DAnimation::QClock clock; + clock.setPlaybackRate(10.f); + + // WHEN + simulateInitialization(&clock, &backendClock); + backendClock.cleanup(); + + // THEN + QCOMPARE(backendClock.playbackRate(), 1.f); + } +}; + +QTEST_APPLESS_MAIN(tst_Clock) + +#include "tst_clock.moc" diff --git a/tests/auto/animation/qclock/qclock.pro b/tests/auto/animation/qclock/qclock.pro new file mode 100644 index 000000000..2b1194860 --- /dev/null +++ b/tests/auto/animation/qclock/qclock.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qclock + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qclock.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qclock/tst_qclock.cpp b/tests/auto/animation/qclock/tst_qclock.cpp new file mode 100644 index 000000000..048073066 --- /dev/null +++ b/tests/auto/animation/qclock/tst_qclock.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QTest> +#include <Qt3DAnimation/qclock.h> +#include <Qt3DAnimation/private/qclock_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qnodecreatedchange.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> +#include <QObject> +#include <QSignalSpy> +#include <testpostmanarbiter.h> + +class tst_QClock : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase() + { + qRegisterMetaType<Qt3DAnimation::QClock*>(); + } + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QClock clock; + + // THEN + QCOMPARE(clock.playbackRate(), 1.f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QClock clock; + + // WHEN + QSignalSpy spy(&clock, SIGNAL(playbackRateChanged(float))); + const float newValue = 5.f; + clock.setPlaybackRate(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(clock.playbackRate(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + clock.setPlaybackRate(newValue); + + // THEN + QCOMPARE(clock.playbackRate(), newValue); + QCOMPARE(spy.count(), 0); + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QClock clock; + clock.setPlaybackRate(10.f); + + // WHEN + QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clock); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClockData>>(creationChanges.first()); + const Qt3DAnimation::QClockData data = creationChangeData->data; + + QCOMPARE(clock.id(), creationChangeData->subjectId()); + QCOMPARE(clock.isEnabled(), true); + QCOMPARE(clock.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clock.metaObject(), creationChangeData->metaObject()); + QCOMPARE(clock.playbackRate(), data.playbackRate); + } + + // WHEN + clock.setEnabled(false); + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clock); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClockData>>(creationChanges.first()); + + QCOMPARE(clock.id(), creationChangeData->subjectId()); + QCOMPARE(clock.isEnabled(), false); + QCOMPARE(clock.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clock.metaObject(), creationChangeData->metaObject()); + } + } + + void checkPropertyUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QClock clock; + arbiter.setArbiterOnNode(&clock); + + { + // WHEN + clock.setPlaybackRate(10.f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "playbackRate"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->value().value<float>(), clock.playbackRate()); + + arbiter.events.clear(); + } + + { + // WHEN + clock.setPlaybackRate(10.f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } +}; + +QTEST_MAIN(tst_QClock) + +#include "tst_qclock.moc" |