From 95dc166ad2b9110c1147a77fe15e3d44ea1101f1 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 14 Jan 2017 15:23:49 +0000 Subject: Add QAnimationClip frontend class and test Represents an animation clip. To keep the public API minimal just use a source property for now. API can be extended later to allow the user to procedurally create animation clips. Assumption for now is that we can export a suitable format from a digital content creation tool such as blender. Change-Id: Ie18b642a92e3cedb1833f013ffe1f7c0f5d07dac Reviewed-by: Paul Lemire --- src/animation/frontend/frontend.pri | 7 +- src/animation/frontend/qanimationclip.cpp | 90 +++++++++++ src/animation/frontend/qanimationclip.h | 79 ++++++++++ src/animation/frontend/qanimationclip_p.h | 78 ++++++++++ tests/auto/animation/animation.pro | 3 +- .../animation/qanimationclip/qanimationclip.pro | 12 ++ .../qanimationclip/tst_qanimationclip.cpp | 165 +++++++++++++++++++++ 7 files changed, 431 insertions(+), 3 deletions(-) create mode 100644 src/animation/frontend/qanimationclip.cpp create mode 100644 src/animation/frontend/qanimationclip.h create mode 100644 src/animation/frontend/qanimationclip_p.h create mode 100644 tests/auto/animation/qanimationclip/qanimationclip.pro create mode 100644 tests/auto/animation/qanimationclip/tst_qanimationclip.cpp diff --git a/src/animation/frontend/frontend.pri b/src/animation/frontend/frontend.pri index 000766b87..c0165f0c7 100644 --- a/src/animation/frontend/frontend.pri +++ b/src/animation/frontend/frontend.pri @@ -1,8 +1,11 @@ HEADERS += \ $$PWD/qanimationaspect.h \ - $$PWD/qanimationaspect_p.h + $$PWD/qanimationaspect_p.h \ + $$PWD/qanimationclip.h \ + $$PWD/qanimationclip_p.h SOURCES += \ - $$PWD/qanimationaspect.cpp + $$PWD/qanimationaspect.cpp \ + $$PWD/qanimationclip.cpp INCLUDEPATH += $$PWD diff --git a/src/animation/frontend/qanimationclip.cpp b/src/animation/frontend/qanimationclip.cpp new file mode 100644 index 000000000..527f1cc30 --- /dev/null +++ b/src/animation/frontend/qanimationclip.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 "qanimationclip.h" +#include "qanimationclip_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +QAnimationClipPrivate::QAnimationClipPrivate() + : Qt3DCore::QNodePrivate() +{ +} + +QAnimationClip::QAnimationClip(Qt3DCore::QNode *parent) + : Qt3DCore::QNode(*new QAnimationClipPrivate, parent) +{ +} + +QAnimationClip::QAnimationClip(QAnimationClipPrivate &dd, Qt3DCore::QNode *parent) + : Qt3DCore::QNode(dd, parent) +{ +} + +QAnimationClip::~QAnimationClip() +{ +} + +QUrl QAnimationClip::source() const +{ + Q_D(const QAnimationClip); + return d->m_source; +} + +void QAnimationClip::setSource(QUrl source) +{ + Q_D(QAnimationClip); + if (d->m_source == source) + return; + + d->m_source = source; + emit sourceChanged(source); +} + +Qt3DCore::QNodeCreatedChangeBasePtr QAnimationClip::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr::create(this); + auto &data = creationChange->data; + Q_D(const QAnimationClip); + data.source = d->m_source; + return creationChange; +} + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/frontend/qanimationclip.h b/src/animation/frontend/qanimationclip.h new file mode 100644 index 000000000..f5394f8ff --- /dev/null +++ b/src/animation/frontend/qanimationclip.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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_QANIMATIONCLIP_H +#define QT3DANIMATION_QANIMATIONCLIP_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QAnimationClipPrivate; + +class QT3DANIMATIONSHARED_EXPORT QAnimationClip : public Qt3DCore::QNode +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + +public: + explicit QAnimationClip(Qt3DCore::QNode *parent = nullptr); + ~QAnimationClip(); + + QUrl source() const; + +public Q_SLOTS: + void setSource(QUrl source); + +Q_SIGNALS: + void sourceChanged(QUrl source); + +protected: + QAnimationClip(QAnimationClipPrivate &dd, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QAnimationClip) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QANIMATIONCLIP_H diff --git a/src/animation/frontend/qanimationclip_p.h b/src/animation/frontend/qanimationclip_p.h new file mode 100644 index 000000000..e55facfbf --- /dev/null +++ b/src/animation/frontend/qanimationclip_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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_QANIMATIONCLIP_P_H +#define QT3DANIMATION_QANIMATIONCLIP_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 +#include "qanimationclip.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QAnimationClipPrivate : public Qt3DCore::QNodePrivate +{ +public: + QAnimationClipPrivate(); + + Q_DECLARE_PUBLIC(QAnimationClip) + + QUrl m_source; +}; + +struct QAnimationClipData +{ + QUrl source; +}; + +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QANIMATIONCLIP_P_H diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 7efc686e1..6ec6d75fd 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += \ - qanimationaspect + qanimationaspect \ + qanimationclip diff --git a/tests/auto/animation/qanimationclip/qanimationclip.pro b/tests/auto/animation/qanimationclip/qanimationclip.pro new file mode 100644 index 000000000..5a9678496 --- /dev/null +++ b/tests/auto/animation/qanimationclip/qanimationclip.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qanimationclip + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qanimationclip.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qanimationclip/tst_qanimationclip.cpp b/tests/auto/animation/qanimationclip/tst_qanimationclip.cpp new file mode 100644 index 000000000..09f41ae99 --- /dev/null +++ b/tests/auto/animation/qanimationclip/tst_qanimationclip.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 +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_QAnimationClip : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAnimationClip clip; + + // THEN + QCOMPARE(clip.source(), QUrl()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAnimationClip clip; + + { + // WHEN + QSignalSpy spy(&clip, SIGNAL(sourceChanged(QUrl))); + const QUrl newValue(QStringLiteral("qrc:/walk.qlip")); + clip.setSource(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(clip.source(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + clip.setSource(newValue); + + // THEN + QCOMPARE(clip.source(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QAnimationClip clip; + + clip.setSource(QUrl(QStringLiteral("http://someRemoteURL.com"))); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAnimationClipData data = creationChangeData->data; + + QCOMPARE(clip.id(), creationChangeData->subjectId()); + QCOMPARE(clip.isEnabled(), true); + QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); + QCOMPARE(clip.source(), data.source); + } + + // WHEN + clip.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + + QCOMPARE(clip.id(), creationChangeData->subjectId()); + QCOMPARE(clip.isEnabled(), false); + QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); + } + } + + void checkSourceUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAnimationClip clip; + arbiter.setArbiterOnNode(&clip); + + { + // WHEN + clip.setSource(QUrl(QStringLiteral("qrc:/toyplane.qlip"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + clip.setSource(QStringLiteral("qrc:/toyplane.qlip")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } +}; + +QTEST_MAIN(tst_QAnimationClip) + +#include "tst_qanimationclip.moc" -- cgit v1.2.3