diff options
33 files changed, 1994 insertions, 8 deletions
diff --git a/src/animation/backend/backend.pri b/src/animation/backend/backend.pri index 86b2b9e15..1c1ccdb58 100644 --- a/src/animation/backend/backend.pri +++ b/src/animation/backend/backend.pri @@ -15,7 +15,9 @@ HEADERS += \ $$PWD/blendedclipanimator_p.h \ $$PWD/conductedclipanimator_p.h \ $$PWD/backendnode_p.h \ - $$PWD/loadanimationclipjob_p.h + $$PWD/loadanimationclipjob_p.h \ + $$PWD/channelmapping_p.h \ + $$PWD/channelmapper_p.h SOURCES += \ $$PWD/animationclip.cpp \ @@ -27,4 +29,6 @@ SOURCES += \ $$PWD/blendedclipanimator.cpp \ $$PWD/conductedclipanimator.cpp \ $$PWD/backendnode.cpp \ - $$PWD/loadanimationclipjob.cpp + $$PWD/loadanimationclipjob.cpp \ + $$PWD/channelmapping.cpp \ + $$PWD/channelmapper.cpp diff --git a/src/animation/backend/channelmapper.cpp b/src/animation/backend/channelmapper.cpp new file mode 100644 index 000000000..0e5555096 --- /dev/null +++ b/src/animation/backend/channelmapper.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 "channelmapper_p.h" +#include <Qt3DAnimation/qchannelmapper.h> +#include <Qt3DAnimation/private/qchannelmapper_p.h> +#include <Qt3DAnimation/private/animationlogging_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +ChannelMapper::ChannelMapper() + : BackendNode(ReadOnly) + , m_mappingIds() +{ +} + +void ChannelMapper::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QChannelMapperData>>(change); + const auto &data = typedChange->data; + m_mappingIds = data.mappingIds; +} + +void ChannelMapper::cleanup() +{ + setEnabled(false); + m_mappingIds.clear(); +} + +void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +{ + switch (e->type()) { + case Qt3DCore::PropertyValueAdded: { + const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e); + if (change->propertyName() == QByteArrayLiteral("mappings")) { + m_mappingIds.push_back(change->addedNodeId()); + setDirty(Handler::ChannelMappingsDirty); + } + break; + } + + case Qt3DCore::PropertyValueRemoved: { + const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e); + if (change->propertyName() == QByteArrayLiteral("mappings")) { + m_mappingIds.removeOne(change->removedNodeId()); + setDirty(Handler::ChannelMappingsDirty); + } + break; + } + + default: + break; + } + QBackendNode::sceneChangeEvent(e); +} + +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/channelmapper_p.h b/src/animation/backend/channelmapper_p.h new file mode 100644 index 000000000..66654d56d --- /dev/null +++ b/src/animation/backend/channelmapper_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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_CHANNELMAPPER_P_H +#define QT3DANIMATION_ANIMATION_CHANNELMAPPER_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/fcurve_p.h> + +#include <Qt3DCore/qnodeid.h> + +#include <QtCore/qvector.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +class Handler; + +class Q_AUTOTEST_EXPORT ChannelMapper : public BackendNode +{ +public: + ChannelMapper(); + + void cleanup(); + + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; + + QVector<Qt3DCore::QNodeId> mappingIds() const { return m_mappingIds; } + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + QVector<Qt3DCore::QNodeId> m_mappingIds; +}; + +} // namespace Animation +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_CHANNELMAPPER_P_H diff --git a/src/animation/backend/channelmapping.cpp b/src/animation/backend/channelmapping.cpp new file mode 100644 index 000000000..f28ab17ae --- /dev/null +++ b/src/animation/backend/channelmapping.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 "channelmapping_p.h" +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/private/qchannelmapping_p.h> +#include <Qt3DAnimation/private/animationlogging_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +ChannelMapping::ChannelMapping() + : BackendNode(ReadOnly) + , m_channelName() + , m_targetId() + , m_property() +{ +} + +void ChannelMapping::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QChannelMappingData>>(change); + const auto &data = typedChange->data; + m_channelName = data.channelName; + m_targetId = data.targetId; + m_property = data.property; +} + +void ChannelMapping::cleanup() +{ + setEnabled(false); + m_channelName.clear(); + m_targetId = Qt3DCore::QNodeId(); + m_property.clear(); +} + +void ChannelMapping::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +{ + switch (e->type()) { + case Qt3DCore::PropertyUpdated: { + const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e); + if (change->propertyName() == QByteArrayLiteral("channelName")) + m_channelName = change->value().toString(); + else if (change->propertyName() == QByteArrayLiteral("target")) + m_targetId = change->value().value<Qt3DCore::QNodeId>(); + else if (change->propertyName() == QByteArrayLiteral("property")) + m_property = change->value().toString(); + break; + } + + default: + break; + } + QBackendNode::sceneChangeEvent(e); +} + +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/channelmapping_p.h b/src/animation/backend/channelmapping_p.h new file mode 100644 index 000000000..958998520 --- /dev/null +++ b/src/animation/backend/channelmapping_p.h @@ -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$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_ANIMATION_CHANNELMAPPING_P_H +#define QT3DANIMATION_ANIMATION_CHANNELMAPPING_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/fcurve_p.h> + +#include <Qt3DCore/qnodeid.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +class Handler; + +class Q_AUTOTEST_EXPORT ChannelMapping : public BackendNode +{ +public: + ChannelMapping(); + + void cleanup(); + + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; + + QString channelName() const { return m_channelName; } + Qt3DCore::QNodeId targetId() const { return m_targetId; } + QString property() const { return m_property; } + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + QString m_channelName; + Qt3DCore::QNodeId m_targetId; + QString m_property; +}; + +} // namespace Animation +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_CHANNELMAPPING_P_H diff --git a/src/animation/backend/handle_types_p.h b/src/animation/backend/handle_types_p.h index 5147a984a..f2c6774d2 100644 --- a/src/animation/backend/handle_types_p.h +++ b/src/animation/backend/handle_types_p.h @@ -62,11 +62,15 @@ class AnimationClip; class ClipAnimator; class BlendedClipAnimator; class ConductedClipAnimator; +class ChannelMapping; +class ChannelMapper; typedef Qt3DCore::QHandle<AnimationClip, 16> HAnimationClip; typedef Qt3DCore::QHandle<ClipAnimator, 16> HClipAnimator; typedef Qt3DCore::QHandle<BlendedClipAnimator, 12> HBlendedClipAnimator; typedef Qt3DCore::QHandle<ConductedClipAnimator, 8> HConductedClipAnimator; +typedef Qt3DCore::QHandle<ChannelMapping, 16> HChannelMapping; +typedef Qt3DCore::QHandle<ChannelMapper, 16> HChannelMapper; } // namespace Animation } // namespace Qt3DAnimation diff --git a/src/animation/backend/handler.cpp b/src/animation/backend/handler.cpp index da0df67d1..f1b25ef4d 100644 --- a/src/animation/backend/handler.cpp +++ b/src/animation/backend/handler.cpp @@ -49,6 +49,8 @@ Handler::Handler() , m_clipAnimatorManager(new ClipAnimatorManager) , m_blendedClipAnimatorManager(new BlendedClipAnimatorManager) , m_conductedClipAnimatorManager(new ConductedClipAnimatorManager) + , m_channelMappingManager(new ChannelMappingManager) + , m_channelMapperManager(new ChannelMapperManager) , m_loadAnimationClipJob(new LoadAnimationClipJob) { m_loadAnimationClipJob->setHandler(this); @@ -66,6 +68,12 @@ void Handler::setDirty(DirtyFlag flag, Qt3DCore::QNodeId nodeId) m_dirtyAnimationClips.push_back(handle); break; } + + case ChannelMappingsDirty: { + const auto handle = m_channelMapperManager->lookupHandle(nodeId); + m_dirtyChannelMappers.push_back(handle); + break; + } } } @@ -105,6 +113,8 @@ QVector<Qt3DCore::QAspectJobPtr> Handler::jobsToExecute(qint64 time) m_dirtyAnimationClips.clear(); } + // TODO: Queue up a job to update the channel mapping table + return jobs; } diff --git a/src/animation/backend/handler_p.h b/src/animation/backend/handler_p.h index abcea1f7e..bcf7d4b77 100644 --- a/src/animation/backend/handler_p.h +++ b/src/animation/backend/handler_p.h @@ -71,6 +71,10 @@ class BlendedClipAnimator; class BlendedClipAnimatorManager; class ConductedClipAnimator; class ConductedClipAnimatorManager; +class ChannelMapping; +class ChannelMappingManager; +class ChannelMapper; +class ChannelMapperManager; class LoadAnimationClipJob; @@ -81,7 +85,8 @@ public: ~Handler(); enum DirtyFlag { - AnimationClipDirty + AnimationClipDirty, + ChannelMappingsDirty }; void setDirty(DirtyFlag flag, Qt3DCore::QNodeId nodeId); @@ -92,6 +97,8 @@ public: ClipAnimatorManager *clipAnimatorManager() const Q_DECL_NOTHROW { return m_clipAnimatorManager.data(); } BlendedClipAnimatorManager *blendedClipAnimatorManager() const Q_DECL_NOTHROW { return m_blendedClipAnimatorManager.data(); } ConductedClipAnimatorManager *conductedClipAnimatorManager() const Q_DECL_NOTHROW { return m_conductedClipAnimatorManager.data(); } + ChannelMappingManager *channelMappingManager() const Q_DECL_NOTHROW { return m_channelMappingManager.data(); } + ChannelMapperManager *channelMapperManager() const Q_DECL_NOTHROW { return m_channelMapperManager.data(); } QVector<Qt3DCore::QAspectJobPtr> jobsToExecute(qint64 time); @@ -100,8 +107,11 @@ private: QScopedPointer<ClipAnimatorManager> m_clipAnimatorManager; QScopedPointer<BlendedClipAnimatorManager> m_blendedClipAnimatorManager; QScopedPointer<ConductedClipAnimatorManager> m_conductedClipAnimatorManager; + QScopedPointer<ChannelMappingManager> m_channelMappingManager; + QScopedPointer<ChannelMapperManager> m_channelMapperManager; QVector<HAnimationClip> m_dirtyAnimationClips; + QVector<HChannelMapper> m_dirtyChannelMappers; QVector<HClipAnimator> m_runningClipAnimators; QSharedPointer<LoadAnimationClipJob> m_loadAnimationClipJob; diff --git a/src/animation/backend/managers_p.h b/src/animation/backend/managers_p.h index 5bcc9a52e..eb34ee5cd 100644 --- a/src/animation/backend/managers_p.h +++ b/src/animation/backend/managers_p.h @@ -57,6 +57,8 @@ #include <Qt3DAnimation/private/blendedclipanimator_p.h> #include <Qt3DAnimation/private/clipanimator_p.h> #include <Qt3DAnimation/private/conductedclipanimator_p.h> +#include <Qt3DAnimation/private/channelmapping_p.h> +#include <Qt3DAnimation/private/channelmapper_p.h> #include <Qt3DCore/private/qresourcemanager_p.h> QT_BEGIN_NAMESPACE @@ -104,6 +106,26 @@ public: ConductedClipAnimatorManager() {} }; +class ChannelMappingManager : public Qt3DCore::QResourceManager< + ChannelMapping, + Qt3DCore::QNodeId, + 16, + Qt3DCore::ArrayAllocatingPolicy> +{ +public: + ChannelMappingManager() {} +}; + +class ChannelMapperManager : public Qt3DCore::QResourceManager< + ChannelMapper, + Qt3DCore::QNodeId, + 16, + Qt3DCore::ArrayAllocatingPolicy> +{ +public: + ChannelMapperManager() {} +}; + } // namespace Animation } // namespace Qt3DAnimation @@ -111,6 +133,8 @@ Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::AnimationClip, Q_REQUIRES_CLEA Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::ClipAnimator, Q_REQUIRES_CLEANUP) Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::BlendedClipAnimator, Q_REQUIRES_CLEANUP) Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::ConductedClipAnimator, Q_REQUIRES_CLEANUP) +Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::ChannelMapping, Q_REQUIRES_CLEANUP) +Q_DECLARE_RESOURCE_INFO(Qt3DAnimation::Animation::ChannelMapper, Q_REQUIRES_CLEANUP) QT_END_NAMESPACE diff --git a/src/animation/frontend/frontend.pri b/src/animation/frontend/frontend.pri index bbffd1c9a..d9187f1f0 100644 --- a/src/animation/frontend/frontend.pri +++ b/src/animation/frontend/frontend.pri @@ -10,7 +10,11 @@ HEADERS += \ $$PWD/qblendedclipanimator.h \ $$PWD/qblendedclipanimator_p.h \ $$PWD/qconductedclipanimator.h \ - $$PWD/qconductedclipanimator_p.h + $$PWD/qconductedclipanimator_p.h \ + $$PWD/qchannelmapper.h \ + $$PWD/qchannelmapper_p.h \ + $$PWD/qchannelmapping.h \ + $$PWD/qchannelmapping_p.h SOURCES += \ $$PWD/qanimationaspect.cpp \ @@ -18,6 +22,8 @@ SOURCES += \ $$PWD/qabstractclipblendnode.cpp \ $$PWD/qclipanimator.cpp \ $$PWD/qblendedclipanimator.cpp \ - $$PWD/qconductedclipanimator.cpp + $$PWD/qconductedclipanimator.cpp \ + $$PWD/qchannelmapper.cpp \ + $$PWD/qchannelmapping.cpp INCLUDEPATH += $$PWD diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index abc3b2b2b..82c633220 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -43,6 +43,8 @@ #include <Qt3DAnimation/qblendedclipanimator.h> #include <Qt3DAnimation/qclipanimator.h> #include <Qt3DAnimation/qconductedclipanimator.h> +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/qchannelmapper.h> #include <Qt3DAnimation/private/handler_p.h> #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/nodefunctor_p.h> @@ -97,6 +99,12 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) registerBackendType<QConductedClipAnimator>( QSharedPointer<Animation::NodeFunctor<Animation::ConductedClipAnimator, Animation::ConductedClipAnimatorManager>>::create(d->m_handler.data(), d->m_handler->conductedClipAnimatorManager())); + registerBackendType<QChannelMapping>( + QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapping, Animation::ChannelMappingManager>>::create(d->m_handler.data(), + d->m_handler->channelMappingManager())); + registerBackendType<QChannelMapper>( + QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapper, Animation::ChannelMapperManager>>::create(d->m_handler.data(), + d->m_handler->channelMapperManager())); } /*! \internal */ diff --git a/src/animation/frontend/qchannelmapper.cpp b/src/animation/frontend/qchannelmapper.cpp new file mode 100644 index 000000000..ee2e54267 --- /dev/null +++ b/src/animation/frontend/qchannelmapper.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 "qchannelmapper.h" +#include "qchannelmapper_p.h" +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +QChannelMapperPrivate::QChannelMapperPrivate() + : Qt3DCore::QNodePrivate() +{ +} + +QChannelMapper::QChannelMapper(Qt3DCore::QNode *parent) + : Qt3DCore::QNode(*new QChannelMapperPrivate, parent) +{ +} + +QChannelMapper::QChannelMapper(QChannelMapperPrivate &dd, Qt3DCore::QNode *parent) + : Qt3DCore::QNode(dd, parent) +{ +} + +QChannelMapper::~QChannelMapper() +{ +} + +void QChannelMapper::addMapping(QChannelMapping *mapping) +{ + Q_ASSERT(mapping); + Q_D(QChannelMapper); + if (!d->m_mappings.contains(mapping)) { + d->m_mappings.append(mapping); + + // Ensures proper bookkeeping + d->registerDestructionHelper(mapping, &QChannelMapper::removeMapping, d->m_mappings); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!mapping->parent()) + mapping->setParent(this); + + if (d->m_changeArbiter != nullptr) { + const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), mapping); + change->setPropertyName("mappings"); + d->notifyObservers(change); + } + } +} + +void QChannelMapper::removeMapping(QChannelMapping *mapping) +{ + Q_ASSERT(mapping); + Q_D(QChannelMapper); + if (d->m_changeArbiter != nullptr) { + const auto change = Qt3DCore::QPropertyNodeRemovedChangePtr::create(id(), mapping); + change->setPropertyName("mappings"); + d->notifyObservers(change); + } + d->m_mappings.removeOne(mapping); + // Remove bookkeeping connection + d->unregisterDestructionHelper(mapping); +} + +QVector<QChannelMapping *> QChannelMapper::mappings() const +{ + Q_D(const QChannelMapper); + return d->m_mappings; +} + +Qt3DCore::QNodeCreatedChangeBasePtr QChannelMapper::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QChannelMapperData>::create(this); + auto &data = creationChange->data; + Q_D(const QChannelMapper); + data.mappingIds = Qt3DCore::qIdsForNodes(d->m_mappings); + return creationChange; +} + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/frontend/qchannelmapper.h b/src/animation/frontend/qchannelmapper.h new file mode 100644 index 000000000..399d92d5d --- /dev/null +++ b/src/animation/frontend/qchannelmapper.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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_QCHANNELMAPPER_H +#define QT3DANIMATION_QCHANNELMAPPER_H + +#include <Qt3DAnimation/qt3danimation_global.h> +#include <Qt3DCore/qnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QChannelMapperPrivate; +class QChannelMapping; + +class QT3DANIMATIONSHARED_EXPORT QChannelMapper : public Qt3DCore::QNode +{ + Q_OBJECT + +public: + explicit QChannelMapper(Qt3DCore::QNode *parent = nullptr); + ~QChannelMapper(); + + void addMapping(QChannelMapping *mapping); + void removeMapping(QChannelMapping *mapping); + QVector<QChannelMapping *> mappings() const; + +protected: + QChannelMapper(QChannelMapperPrivate &dd, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QChannelMapper) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCHANNELMAPPER_H diff --git a/src/animation/frontend/qchannelmapper_p.h b/src/animation/frontend/qchannelmapper_p.h new file mode 100644 index 000000000..d05ea3277 --- /dev/null +++ b/src/animation/frontend/qchannelmapper_p.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_QCHANNELMAPPER_P_H +#define QT3DANIMATION_QCHANNELMAPPER_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> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QChannelMapping; + +class QChannelMapperPrivate : public Qt3DCore::QNodePrivate +{ +public: + QChannelMapperPrivate(); + + Q_DECLARE_PUBLIC(QChannelMapper) + + QVector<QChannelMapping *> m_mappings; +}; + +struct QChannelMapperData +{ + QVector<Qt3DCore::QNodeId> mappingIds; +}; + +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCHANNELMAPPER_P_H diff --git a/src/animation/frontend/qchannelmapping.cpp b/src/animation/frontend/qchannelmapping.cpp new file mode 100644 index 000000000..a920ad6e0 --- /dev/null +++ b/src/animation/frontend/qchannelmapping.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 "qchannelmapping.h" +#include "qchannelmapping_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +QChannelMappingPrivate::QChannelMappingPrivate() + : Qt3DCore::QNodePrivate() + , m_channelName() + , m_target(nullptr) + , m_property() +{ +} + +QChannelMapping::QChannelMapping(Qt3DCore::QNode *parent) + : Qt3DCore::QNode(*new QChannelMappingPrivate, parent) +{ +} + +QChannelMapping::QChannelMapping(QChannelMappingPrivate &dd, Qt3DCore::QNode *parent) + : Qt3DCore::QNode(dd, parent) +{ +} + +QChannelMapping::~QChannelMapping() +{ +} + +QString QChannelMapping::channelName() const +{ + Q_D(const QChannelMapping); + return d->m_channelName; +} + +Qt3DCore::QNode *QChannelMapping::target() const +{ + Q_D(const QChannelMapping); + return d->m_target; +} + +QString QChannelMapping::property() const +{ + Q_D(const QChannelMapping); + return d->m_property; +} + +void QChannelMapping::setChannelName(const QString &channelName) +{ + Q_D(QChannelMapping); + if (d->m_channelName == channelName) + return; + + d->m_channelName = channelName; + emit channelNameChanged(channelName); +} + +void QChannelMapping::setTarget(Qt3DCore::QNode *target) +{ + Q_D(QChannelMapping); + if (d->m_target == target) + return; + + if (d->m_target) + d->unregisterDestructionHelper(d->m_target); + + if (target && !target->parent()) + target->setParent(this); + d->m_target = target; + + // Ensures proper bookkeeping + if (d->m_target) + d->registerDestructionHelper(d->m_target, &QChannelMapping::setTarget, d->m_target); + + emit targetChanged(target); +} + +void QChannelMapping::setProperty(const QString &property) +{ + Q_D(QChannelMapping); + if (d->m_property == property) + return; + + d->m_property = property; + emit propertyChanged(property); +} + +Qt3DCore::QNodeCreatedChangeBasePtr QChannelMapping::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QChannelMappingData>::create(this); + auto &data = creationChange->data; + Q_D(const QChannelMapping); + data.channelName = d->m_channelName; + data.targetId = Qt3DCore::qIdForNode(d->m_target); + data.property = d->m_property; + return creationChange; +} + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/frontend/qchannelmapping.h b/src/animation/frontend/qchannelmapping.h new file mode 100644 index 000000000..0c4ca07f4 --- /dev/null +++ b/src/animation/frontend/qchannelmapping.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_QCHANNELMAPPING_H +#define QT3DANIMATION_QCHANNELMAPPING_H + +#include <Qt3DAnimation/qt3danimation_global.h> +#include <Qt3DCore/qnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QChannelMappingPrivate; + +class QT3DANIMATIONSHARED_EXPORT QChannelMapping : public Qt3DCore::QNode +{ + Q_OBJECT + Q_PROPERTY(QString channelName READ channelName WRITE setChannelName NOTIFY channelNameChanged) + Q_PROPERTY(Qt3DCore::QNode *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged) + +public: + explicit QChannelMapping(Qt3DCore::QNode *parent = nullptr); + ~QChannelMapping(); + + QString channelName() const; + Qt3DCore::QNode *target() const; + QString property() const; + +public Q_SLOTS: + void setChannelName(const QString &channelName); + void setTarget(Qt3DCore::QNode *target); + void setProperty(const QString &property); + +Q_SIGNALS: + void channelNameChanged(QString channelName); + void targetChanged(Qt3DCore::QNode *target); + void propertyChanged(QString property); + +protected: + QChannelMapping(QChannelMappingPrivate &dd, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QChannelMapping) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // namespace Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCHANNELMAPPING_H diff --git a/src/animation/frontend/qchannelmapping_p.h b/src/animation/frontend/qchannelmapping_p.h new file mode 100644 index 000000000..736805375 --- /dev/null +++ b/src/animation/frontend/qchannelmapping_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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_QCHANNELMAPPING_P_H +#define QT3DANIMATION_QCHANNELMAPPING_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> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { + +class QChannelMappingPrivate : public Qt3DCore::QNodePrivate +{ +public: + QChannelMappingPrivate(); + + Q_DECLARE_PUBLIC(QChannelMapping) + + QString m_channelName; + Qt3DCore::QNode *m_target; + QString m_property; +}; + +struct QChannelMappingData +{ + QString channelName; + Qt3DCore::QNodeId targetId; + QString property; +}; + +} // namespace Qt3DAnimation + + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_QCHANNELMAPPING_P_H diff --git a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp index efaee2509..537c49b21 100644 --- a/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp +++ b/src/quick3d/imports/animation/qt3dquick3danimationplugin.cpp @@ -42,7 +42,9 @@ #include <Qt3DAnimation/qblendedclipanimator.h> #include <Qt3DAnimation/qclipanimator.h> #include <Qt3DAnimation/qconductedclipanimator.h> +#include <Qt3DAnimation/qchannelmapping.h> #include <Qt3DQuickAnimation/private/qt3dquickanimation_global_p.h> +#include <Qt3DQuickAnimation/private/quick3dchannelmapper_p.h> QT_BEGIN_NAMESPACE @@ -55,6 +57,9 @@ void Qt3DQuick3DAnimationPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3DAnimation::QClipAnimator>(uri, 2, 2, "ClipAnimator"); qmlRegisterType<Qt3DAnimation::QBlendedClipAnimator>(uri, 2, 2, "BlendedClipAnimator"); qmlRegisterType<Qt3DAnimation::QConductedClipAnimator>(uri, 2, 2, "ConductedClipAnimator"); + qmlRegisterType<Qt3DAnimation::QChannelMapping>(uri, 2, 2, "ChannelMapping"); + qmlRegisterExtendedType<Qt3DAnimation::QChannelMapper, + Qt3DAnimation::Animation::Quick::Quick3DChannelMapper>(uri, 2, 2, "ChannelMapper"); } QT_END_NAMESPACE diff --git a/src/quick3d/quick3danimation/items/items.pri b/src/quick3d/quick3danimation/items/items.pri new file mode 100644 index 000000000..c57a44de8 --- /dev/null +++ b/src/quick3d/quick3danimation/items/items.pri @@ -0,0 +1,7 @@ +SOURCES += \ + $$PWD/quick3dchannelmapper.cpp + +HEADERS += \ + $$PWD/quick3dchannelmapper_p.h + +INCLUDEPATH += $$PWD diff --git a/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp b/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp new file mode 100644 index 000000000..55eb04be1 --- /dev/null +++ b/src/quick3d/quick3danimation/items/quick3dchannelmapper.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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: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$ +** +****************************************************************************/ + +#include "quick3dchannelmapper_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { +namespace Quick { + +Quick3DChannelMapper::Quick3DChannelMapper(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<QChannelMapping> Quick3DChannelMapper::qmlMappings() +{ + return QQmlListProperty<QChannelMapping>(this, 0, + &Quick3DChannelMapper::appendMapping, + &Quick3DChannelMapper::mappingCount, + &Quick3DChannelMapper::mappingAt, + &Quick3DChannelMapper::clearMappings); +} + +void Quick3DChannelMapper::appendMapping(QQmlListProperty<QChannelMapping> *list, QChannelMapping *mapping) +{ + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + extension->parentMapper()->addMapping(mapping); +} + +QChannelMapping *Quick3DChannelMapper::mappingAt(QQmlListProperty<QChannelMapping> *list, int index) +{ + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + return extension->parentMapper()->mappings().at(index); +} + +int Quick3DChannelMapper::mappingCount(QQmlListProperty<QChannelMapping> *list) +{ + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + return extension->parentMapper()->mappings().count(); +} + +void Quick3DChannelMapper::clearMappings(QQmlListProperty<QChannelMapping> *list) +{ + Quick3DChannelMapper *extension = qobject_cast<Quick3DChannelMapper *>(list->object); + const auto mappings = extension->parentMapper()->mappings(); + for (QChannelMapping *mapping : mappings) + extension->parentMapper()->removeMapping(mapping); +} + +} // namespace Quick +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h b/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h new file mode 100644 index 000000000..fddaae72d --- /dev/null +++ b/src/quick3d/quick3danimation/items/quick3dchannelmapper_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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: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$ +** +****************************************************************************/ + +#ifndef QT3DANIMATION_ANIMATION_QUICK_QUICK3DBASICANIMATION_H +#define QT3DANIMATION_ANIMATION_QUICK_QUICK3DBASICANIMATION_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 <Qt3DQuickAnimation/private/qt3dquickanimation_global_p.h> +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/qchannelmapper.h> +#include <QQmlListProperty> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { +namespace Quick { + +class QT3DQUICKANIMATIONSHARED_PRIVATE_EXPORT Quick3DChannelMapper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DAnimation::QChannelMapping> mappings READ qmlMappings CONSTANT) +public: + explicit Quick3DChannelMapper(QObject *parent = nullptr); + + inline QChannelMapper *parentMapper() const { return qobject_cast<QChannelMapper *>(parent()); } + QQmlListProperty<QChannelMapping> qmlMappings(); + +private: + static void appendMapping(QQmlListProperty<QChannelMapping> *list, QChannelMapping *mapping); + static QChannelMapping *mappingAt(QQmlListProperty<QChannelMapping> *list, int index); + static int mappingCount(QQmlListProperty<QChannelMapping> *list); + static void clearMappings(QQmlListProperty<QChannelMapping> *list); +}; + +} // namespace Quick +} // namespace Animation +} // namespace Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_QUICK_QUICK3DBASICANIMATION_H diff --git a/src/quick3d/quick3danimation/quick3danimation.pro b/src/quick3d/quick3danimation/quick3danimation.pro index 213ba564b..770cbcdb1 100644 --- a/src/quick3d/quick3danimation/quick3danimation.pro +++ b/src/quick3d/quick3danimation/quick3danimation.pro @@ -25,4 +25,6 @@ HEADERS += \ # otherwise mingw headers do not declare common functions like ::strcasecmp win32-g++*:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x +include(./items/items.pri) + load(qt_module) diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 285b468a9..d8183988d 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -5,7 +5,9 @@ SUBDIRS += \ qanimationclip \ qclipanimator \ qblendedclipanimator \ - qconductedclipanimator + qconductedclipanimator \ + qchannelmapping \ + qchannelmapper qtConfig(private_tests) { SUBDIRS += \ @@ -16,5 +18,7 @@ qtConfig(private_tests) { bezierevaluator \ clipanimator \ blendedclipanimator \ - conductedclipanimator + conductedclipanimator \ + channelmapper \ + channelmapping } diff --git a/tests/auto/animation/channelmapper/channelmapper.pro b/tests/auto/animation/channelmapper/channelmapper.pro new file mode 100644 index 000000000..ceed9513f --- /dev/null +++ b/tests/auto/animation/channelmapper/channelmapper.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_channelmapper + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_channelmapper.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/channelmapper/tst_channelmapper.cpp b/tests/auto/animation/channelmapper/tst_channelmapper.cpp new file mode 100644 index 000000000..8a9b60bf5 --- /dev/null +++ b/tests/auto/animation/channelmapper/tst_channelmapper.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 <qbackendnodetester.h> +#include <Qt3DAnimation/private/handler_p.h> +#include <Qt3DAnimation/private/channelmapper_p.h> +#include <Qt3DAnimation/qchannelmapper.h> +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/private/qchannelmapper_p.h> +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> +#include <Qt3DCore/private/qbackendnode_p.h> +#include "testpostmanarbiter.h" + +class tst_ChannelMapper : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapper backendMapper; + backendMapper.setHandler(&handler); + Qt3DAnimation::QChannelMapper mapper; + + mapper.addMapping(new Qt3DAnimation::QChannelMapping); + mapper.addMapping(new Qt3DAnimation::QChannelMapping); + + // WHEN + simulateInitialization(&mapper, &backendMapper); + + // THEN + QCOMPARE(backendMapper.peerId(), mapper.id()); + QCOMPARE(backendMapper.isEnabled(), mapper.isEnabled()); + + const int mappingCount = backendMapper.mappingIds().size(); + if (mappingCount > 0) { + for (int i = 0; i < mappingCount; ++i) + QCOMPARE(backendMapper.mappingIds().at(i), mapper.mappings().at(i)->id()); + } + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapper backendMapper; + backendMapper.setHandler(&handler); + + // THEN + QVERIFY(backendMapper.peerId().isNull()); + QCOMPARE(backendMapper.isEnabled(), false); + QCOMPARE(backendMapper.mappingIds(), QVector<Qt3DCore::QNodeId>()); + + // GIVEN + Qt3DAnimation::QChannelMapper mapper; + mapper.addMapping(new Qt3DAnimation::QChannelMapping()); + + // WHEN + simulateInitialization(&mapper, &backendMapper); + backendMapper.cleanup(); + + // THEN + QCOMPARE(backendMapper.isEnabled(), false); + QCOMPARE(backendMapper.mappingIds(), QVector<Qt3DCore::QNodeId>()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapper backendMapper; + backendMapper.setHandler(&handler); + Qt3DCore::QPropertyUpdatedChangePtr updateChange; + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("enabled"); + updateChange->setValue(true); + backendMapper.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendMapper.isEnabled(), true); + + // WHEN + Qt3DAnimation::QChannelMapping mapping; + const Qt3DCore::QNodeId mappingId = mapping.id(); + const auto nodeAddedChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &mapping); + nodeAddedChange->setPropertyName("mappings"); + backendMapper.sceneChangeEvent(nodeAddedChange); + + // THEN + QCOMPARE(backendMapper.mappingIds().size(), 1); + QCOMPARE(backendMapper.mappingIds().first(), mappingId); + + // WHEN + const auto nodeRemovedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &mapping); + nodeRemovedChange->setPropertyName("mappings"); + backendMapper.sceneChangeEvent(nodeRemovedChange); + + // THEN + QCOMPARE(backendMapper.mappingIds().size(), 0); + } +}; + +QTEST_MAIN(tst_ChannelMapper) + +#include "tst_channelmapper.moc" diff --git a/tests/auto/animation/channelmapping/channelmapping.pro b/tests/auto/animation/channelmapping/channelmapping.pro new file mode 100644 index 000000000..eeae99a23 --- /dev/null +++ b/tests/auto/animation/channelmapping/channelmapping.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_channelmapping + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_channelmapping.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/channelmapping/tst_channelmapping.cpp b/tests/auto/animation/channelmapping/tst_channelmapping.cpp new file mode 100644 index 000000000..17e0418b5 --- /dev/null +++ b/tests/auto/animation/channelmapping/tst_channelmapping.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** 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 <qbackendnodetester.h> +#include <Qt3DAnimation/private/handler_p.h> +#include <Qt3DAnimation/private/channelmapping_p.h> +#include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/private/qchannelmapping_p.h> +#include <Qt3DCore/qentity.h> +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/private/qbackendnode_p.h> +#include "testpostmanarbiter.h" + +class tst_ChannelMapping : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapping backendMapping; + backendMapping.setHandler(&handler); + Qt3DAnimation::QChannelMapping mapping; + auto target = new Qt3DCore::QEntity; + + mapping.setChannelName(QLatin1String("Location")); + mapping.setTarget(target); + mapping.setProperty(QLatin1String("foo")); + + // WHEN + simulateInitialization(&mapping, &backendMapping); + + // THEN + QCOMPARE(backendMapping.peerId(), mapping.id()); + QCOMPARE(backendMapping.isEnabled(), mapping.isEnabled()); + QCOMPARE(backendMapping.channelName(), mapping.channelName()); + QCOMPARE(backendMapping.targetId(), mapping.target()->id()); + QCOMPARE(backendMapping.property(), mapping.property()); + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapping backendMapping; + backendMapping.setHandler(&handler); + + // THEN + QVERIFY(backendMapping.peerId().isNull()); + QCOMPARE(backendMapping.isEnabled(), false); + QCOMPARE(backendMapping.channelName(), QString()); + QCOMPARE(backendMapping.targetId(), Qt3DCore::QNodeId()); + QCOMPARE(backendMapping.property(), QString()); + + // GIVEN + Qt3DAnimation::QChannelMapping mapping; + auto target = new Qt3DCore::QEntity; + mapping.setChannelName(QLatin1String("Location")); + mapping.setTarget(target); + mapping.setProperty(QLatin1String("foo")); + + // WHEN + simulateInitialization(&mapping, &backendMapping); + backendMapping.cleanup(); + + // THEN + QCOMPARE(backendMapping.isEnabled(), false); + QCOMPARE(backendMapping.channelName(), QString()); + QCOMPARE(backendMapping.targetId(), Qt3DCore::QNodeId()); + QCOMPARE(backendMapping.property(), QString()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::Animation::Handler handler; + Qt3DAnimation::Animation::ChannelMapping backendMapping; + backendMapping.setHandler(&handler); + Qt3DCore::QPropertyUpdatedChangePtr updateChange; + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("enabled"); + updateChange->setValue(true); + backendMapping.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendMapping.isEnabled(), true); + + // WHEN + const QString channelName(QLatin1String("Rotation")); + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("channelName"); + updateChange->setValue(channelName); + backendMapping.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendMapping.channelName(), channelName); + + // WHEN + const auto id = Qt3DCore::QNodeId::createId(); + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("target"); + updateChange->setValue(QVariant::fromValue(id)); + backendMapping.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendMapping.targetId(), id); + + // WHEN + const QString property(QLatin1String("bar")); + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("property"); + updateChange->setValue(property); + backendMapping.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendMapping.property(), property); + } +}; + +QTEST_MAIN(tst_ChannelMapping) + +#include "tst_channelmapping.moc" diff --git a/tests/auto/animation/qchannelmapper/qchannelmapper.pro b/tests/auto/animation/qchannelmapper/qchannelmapper.pro new file mode 100644 index 000000000..d737c84d5 --- /dev/null +++ b/tests/auto/animation/qchannelmapper/qchannelmapper.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_qchannelmapper + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_qchannelmapper.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qchannelmapper/tst_qchannelmapper.cpp b/tests/auto/animation/qchannelmapper/tst_qchannelmapper.cpp new file mode 100644 index 000000000..bbc27fa41 --- /dev/null +++ b/tests/auto/animation/qchannelmapper/tst_qchannelmapper.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** 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 <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> + +#include <Qt3DAnimation/qchannelmapper.h> +#include <Qt3DAnimation/private/qchannelmapper_p.h> +#include <Qt3DAnimation/qchannelmapping.h> + +#include <Qt3DCore/QPropertyUpdatedChange> +#include <Qt3DCore/QPropertyNodeAddedChange> +#include <Qt3DCore/QPropertyNodeRemovedChange> + +#include "testpostmanarbiter.h" + +class tst_QChannelmapper : public Qt3DAnimation::QChannelMapper +{ + Q_OBJECT +public: + tst_QChannelmapper() + { + qRegisterMetaType<Qt3DCore::QNode *>(); + } + +private Q_SLOTS: + void checkCreationChange_data() + { + QTest::addColumn<Qt3DAnimation::QChannelMapper *>("mapper"); + + Qt3DAnimation::QChannelMapper *defaultConstructed = new Qt3DAnimation::QChannelMapper; + QTest::newRow("defaultConstructed") << defaultConstructed; + + Qt3DAnimation::QChannelMapper *mapperWithMappings = new Qt3DAnimation::QChannelMapper; + mapperWithMappings->addMapping(new Qt3DAnimation::QChannelMapping); + mapperWithMappings->addMapping(new Qt3DAnimation::QChannelMapping); + mapperWithMappings->addMapping(new Qt3DAnimation::QChannelMapping); + QTest::newRow("mapperWithMappings") << mapperWithMappings; + } + + void checkCreationChange() + { + // GIVEN + QFETCH(Qt3DAnimation::QChannelMapper *, mapper); + + // WHEN + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(mapper); + QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges(); + + const int mappingCount = mapper->mappings().count(); + + // THEN + QCOMPARE(creationChanges.size(), 1 + mappingCount); + + const Qt3DCore::QNodeCreatedChangePtr<Qt3DAnimation::QChannelMapperData> creationChange = + qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QChannelMapperData>>(creationChanges.first()); + const Qt3DAnimation::QChannelMapperData &creationData = creationChange->data; + + // THEN + QCOMPARE(mapper->id(), creationChange->subjectId()); + QCOMPARE(mapper->isEnabled(), creationChange->isNodeEnabled()); + QCOMPARE(mapper->metaObject(), creationChange->metaObject()); + QCOMPARE(mappingCount, creationData.mappingIds.count()); + + for (int i = 0; i < mappingCount; ++i) + QCOMPARE(mapper->mappings().at(i)->id(), creationData.mappingIds.at(i)); + } + + void checkPropertyUpdates() + { + // GIVEN + TestArbiter arbiter; + QScopedPointer<Qt3DAnimation::QChannelMapper> mapper(new Qt3DAnimation::QChannelMapper); + arbiter.setArbiterOnNode(mapper.data()); + + // WHEN + mapper->setEnabled(false); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr propertyChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(propertyChange->propertyName(), "enabled"); + QCOMPARE(propertyChange->value().toBool(), mapper->isEnabled()); + QCOMPARE(propertyChange->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + void checkMappingBookkeeping() + { + // GIVEN + QScopedPointer<Qt3DAnimation::QChannelMapper> mapper(new Qt3DAnimation::QChannelMapper); + { + // WHEN + Qt3DAnimation::QChannelMapping mapping; + mapper->addMapping(&mapping); + + // THEN + QCOMPARE(mapping.parent(), mapper.data()); + QCOMPARE(mapper->mappings().size(), 1); + } + // THEN (Should not crash and output be unset) + QVERIFY(mapper->mappings().empty()); + + { + // WHEN + Qt3DAnimation::QChannelMapper someOtherMapper; + QScopedPointer<Qt3DAnimation::QChannelMapping> mapping(new Qt3DAnimation::QChannelMapping(&someOtherMapper)); + mapper->addMapping(mapping.data()); + + // THEN + QCOMPARE(mapping->parent(), &someOtherMapper); + QCOMPARE(mapper->mappings().size(), 1); + + // WHEN + mapper.reset(); + mapping.reset(); + + // THEN Should not crash when the output is destroyed (tests for failed removal of destruction helper) + } + } +}; + +QTEST_MAIN(tst_QChannelmapper) + +#include "tst_qchannelmapper.moc" diff --git a/tests/auto/animation/qchannelmapping/qchannelmapping.pro b/tests/auto/animation/qchannelmapping/qchannelmapping.pro new file mode 100644 index 000000000..ba1577676 --- /dev/null +++ b/tests/auto/animation/qchannelmapping/qchannelmapping.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qchannelmapping + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qchannelmapping.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp b/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp new file mode 100644 index 000000000..9d356de4c --- /dev/null +++ b/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** 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/qchannelmapping.h> +#include <Qt3DAnimation/private/qchannelmapping_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qentity.h> +#include <Qt3DCore/qnodecreatedchange.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> +#include <QObject> +#include <QSignalSpy> +#include <testpostmanarbiter.h> + +class tst_QChannelMapping : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QChannelMapping mapping; + + // THEN + QCOMPARE(mapping.channelName(), QString()); + QCOMPARE(mapping.target(), static_cast<Qt3DCore::QNode *>(nullptr)); + QCOMPARE(mapping.property(), QString()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QChannelMapping mapping; + + { + // WHEN + QSignalSpy spy(&mapping, SIGNAL(channelNameChanged(QString))); + const QString newValue(QStringLiteral("Rotation")); + mapping.setChannelName(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(mapping.channelName(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + mapping.setChannelName(newValue); + + // THEN + QCOMPARE(mapping.channelName(), newValue); + QCOMPARE(spy.count(), 0); + } + + { + // WHEN + QSignalSpy spy(&mapping, SIGNAL(targetChanged(Qt3DCore::QNode*))); + auto newValue = new Qt3DCore::QEntity(); + mapping.setTarget(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(mapping.target(), newValue); + QCOMPARE(newValue->parent(), &mapping); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + mapping.setTarget(newValue); + + // THEN + QCOMPARE(mapping.target(), newValue); + QCOMPARE(spy.count(), 0); + } + + { + // WHEN + QSignalSpy spy(&mapping, SIGNAL(propertyChanged(QString))); + const QString newValue(QStringLiteral("rotation")); + mapping.setProperty(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(mapping.property(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + mapping.setProperty(newValue); + + // THEN + QCOMPARE(mapping.property(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QChannelMapping mapping; + auto target = new Qt3DCore::QEntity; + + mapping.setChannelName(QStringLiteral("Location")); + mapping.setTarget(target); + mapping.setProperty(QStringLiteral("translation")); + + // WHEN + QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&mapping); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // 1 for mapping, 1 for target + + const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QChannelMappingData>>(creationChanges.first()); + const Qt3DAnimation::QChannelMappingData data = creationChangeData->data; + + QCOMPARE(mapping.id(), creationChangeData->subjectId()); + QCOMPARE(mapping.isEnabled(), true); + QCOMPARE(mapping.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(mapping.metaObject(), creationChangeData->metaObject()); + QCOMPARE(mapping.channelName(), data.channelName); + QCOMPARE(mapping.target()->id(), data.targetId); + QCOMPARE(mapping.property(), data.property); + } + + // WHEN + mapping.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&mapping); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // 1 for mapping, 1 for target + + const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QChannelMappingData>>(creationChanges.first()); + const Qt3DAnimation::QChannelMappingData data = creationChangeData->data; + + QCOMPARE(mapping.id(), creationChangeData->subjectId()); + QCOMPARE(mapping.isEnabled(), false); + QCOMPARE(mapping.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(mapping.metaObject(), creationChangeData->metaObject()); + QCOMPARE(mapping.channelName(), data.channelName); + QCOMPARE(mapping.target()->id(), data.targetId); + QCOMPARE(mapping.property(), data.property); + } + } + + void checkPropertyUpdateChanges() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QChannelMapping mapping; + arbiter.setArbiterOnNode(&mapping); + + { + // WHEN + mapping.setChannelName(QStringLiteral("Scale")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "channelName"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->value().toString(), mapping.channelName()); + + arbiter.events.clear(); + + // WHEN + mapping.setChannelName(QStringLiteral("Scale")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + { + // WHEN + auto target = new Qt3DCore::QEntity(); + mapping.setTarget(target); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "target"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), mapping.target()->id()); + + arbiter.events.clear(); + + // WHEN + mapping.setTarget(target); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + { + // WHEN + mapping.setProperty(QStringLiteral("scale")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "property"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->value().toString(), mapping.property()); + + arbiter.events.clear(); + + // WHEN + mapping.setProperty(QStringLiteral("scale")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } +}; + +QTEST_MAIN(tst_QChannelMapping) + +#include "tst_qchannelmapping.moc" diff --git a/tests/auto/render/trianglesextractor/tst_trianglesextractor.cpp b/tests/auto/render/trianglesextractor/tst_trianglesextractor.cpp index 9132b87bd..c6db3f62d 100644 --- a/tests/auto/render/trianglesextractor/tst_trianglesextractor.cpp +++ b/tests/auto/render/trianglesextractor/tst_trianglesextractor.cpp @@ -312,6 +312,8 @@ Qt3DRender::QGeometryRenderer *customNonIndexedGeometryRenderer() return customMeshRenderer; } +QT_BEGIN_NAMESPACE + class TestAspect : public Qt3DRender::QRenderAspect { public: @@ -331,6 +333,8 @@ public: } }; +QT_END_NAMESPACE + class tst_TrianglesExtractor : public QObject { Q_OBJECT @@ -395,7 +399,6 @@ private Q_SLOTS: } }; - QTEST_MAIN(tst_TrianglesExtractor) #include "tst_trianglesextractor.moc" diff --git a/tests/manual/animation-keyframe-simple/main.qml b/tests/manual/animation-keyframe-simple/main.qml index 37f5eba2f..48a2a657f 100644 --- a/tests/manual/animation-keyframe-simple/main.qml +++ b/tests/manual/animation-keyframe-simple/main.qml @@ -23,6 +23,7 @@ DefaultSceneEntity { CuboidMesh { }, PhongMaterial { + id: cubeMaterial ambient: Qt.rgba(0.02, 0.02, 0.02, 1.0) diffuse: "blue" shininess: 50 @@ -35,6 +36,19 @@ DefaultSceneEntity { clip: AnimationClip { source: "cubeanimation.json" } + + // By default introspect parent Entity and try + // to map fcurve groups to properties of QTransform + // mapping: AutomaticAnimationMapping {} + + // To do more, we can be explicit + mapping: ChannelMapper { + mappings: [ + ChannelMapping { channelName: "Location"; target: cubeTransform; property: "translation" }, + ChannelMapping { channelName: "Rotation"; target: cubeTransform; property: "rotation" }, + ChannelMapping { channelName: "Diffuse Color"; target: cubeMaterial; property: "diffuse" } + ] + } } ] |