diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-09-19 21:45:25 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-09-23 06:27:37 +0100 |
commit | c7f10617a0be44cf2b61fdc0809fafe7a0aef49a (patch) | |
tree | 26d1a362e9966e77eafe4d4d766f4312557de864 | |
parent | 42e11789e4a2de7729ccba30dc465ca48e09e5e7 (diff) |
Update mapping classes to use direct sync
QChannelMapping, QSkeletonMapping and QCallbackMapping updated.
Change-Id: I10b78d86856f6ad01fbb313fdcbe9f87f6d926ac
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/animation/backend/channelmapping.cpp | 96 | ||||
-rw-r--r-- | src/animation/backend/channelmapping_p.h | 4 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 2 | ||||
-rw-r--r-- | src/animation/frontend/qcallbackmapping.cpp | 15 | ||||
-rw-r--r-- | src/animation/frontend/qchannelmapping.cpp | 25 | ||||
-rw-r--r-- | src/core/nodes/qnode.cpp | 5 | ||||
-rw-r--r-- | src/core/nodes/qnode_p.h | 1 | ||||
-rw-r--r-- | tests/auto/animation/channelmapping/tst_channelmapping.cpp | 82 | ||||
-rw-r--r-- | tests/auto/animation/qcallbackmapping/tst_qcallbackmapping.cpp | 21 | ||||
-rw-r--r-- | tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp | 28 |
10 files changed, 90 insertions, 189 deletions
diff --git a/src/animation/backend/channelmapping.cpp b/src/animation/backend/channelmapping.cpp index 2323182c6..83e7322da 100644 --- a/src/animation/backend/channelmapping.cpp +++ b/src/animation/backend/channelmapping.cpp @@ -36,13 +36,15 @@ #include "channelmapping_p.h" #include <Qt3DAnimation/qchannelmapping.h> +#include <Qt3DAnimation/qskeletonmapping.h> +#include <Qt3DAnimation/qcallbackmapping.h> #include <Qt3DAnimation/private/qcallbackmapping_p.h> #include <Qt3DAnimation/private/qchannelmapping_p.h> #include <Qt3DAnimation/private/qskeletonmapping_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> #include <Qt3DAnimation/private/qchannelmappingcreatedchange_p.h> #include <Qt3DAnimation/private/managers_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/qabstractskeleton.h> QT_BEGIN_NAMESPACE @@ -63,43 +65,6 @@ ChannelMapping::ChannelMapping() { } -void ChannelMapping::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) -{ - const auto createdChange = qSharedPointerCast<QChannelMappingCreatedChangeBase>(change); - switch (createdChange->type()) { - case QChannelMappingCreatedChangeBase::ChannelMapping: { - const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QChannelMappingData>>(change); - const auto &data = typedChange->data; - m_channelName = data.channelName; - m_targetId = data.targetId; - m_type = data.type; - m_componentCount = data.componentCount; - m_propertyName = data.propertyName; - m_mappingType = ChannelMappingType; - break; - } - - case QChannelMappingCreatedChangeBase::SkeletonMapping: { - const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QSkeletonMappingData>>(change); - const auto &data = typedChange->data; - m_skeletonId = data.skeletonId; - m_mappingType = SkeletonMappingType; - break; - } - - case QChannelMappingCreatedChangeBase::CallbackMapping: { - const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QCallbackMappingData>>(change); - const auto &data = typedChange->data; - m_channelName = data.channelName; - m_type = data.type; - m_callback = data.callback; - m_callbackFlags = data.callbackFlags; - m_mappingType = ChannelMappingType; - break; - } - } -} - void ChannelMapping::cleanup() { setEnabled(false); @@ -113,34 +78,41 @@ void ChannelMapping::cleanup() m_skeletonId = Qt3DCore::QNodeId(); } -void ChannelMapping::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +void ChannelMapping::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - 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("type")) - m_type = change->value().toInt(); - else if (change->propertyName() == QByteArrayLiteral("propertyName")) - m_propertyName = static_cast<const char *>(const_cast<const void *>(change->value().value<void *>())); - else if (change->propertyName() == QByteArrayLiteral("componentCount")) - m_componentCount = change->value().toInt(); - else if (change->propertyName() == QByteArrayLiteral("callback")) - m_callback = static_cast<QAnimationCallback *>(change->value().value<void *>()); - else if (change->propertyName() == QByteArrayLiteral("callbackFlags")) - m_callbackFlags = QAnimationCallback::Flags(change->value().toInt()); - else if (change->propertyName() == QByteArrayLiteral("skeleton")) - m_skeletonId = change->value().value<Qt3DCore::QNodeId>(); - break; + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + const QAbstractChannelMapping *node = qobject_cast<const QAbstractChannelMapping *>(frontEnd); + if (!node) + return; + + const QChannelMapping *channelMapping = qobject_cast<const QChannelMapping *>(frontEnd); + if (channelMapping) { + m_mappingType = ChannelMappingType; + m_channelName = channelMapping->channelName(); + m_targetId = Qt3DCore::qIdForNode(channelMapping->target()); + + QChannelMappingPrivate *d = static_cast<QChannelMappingPrivate *>(Qt3DCore::QNodePrivate::get(const_cast<QChannelMapping *>(channelMapping))); + m_type = d->m_type; + m_propertyName = d->m_propertyName; + m_componentCount = d->m_componentCount; } - default: - break; + const QSkeletonMapping *skeletonMapping = qobject_cast<const QSkeletonMapping *>(frontEnd); + if (skeletonMapping) { + m_mappingType = SkeletonMappingType; + m_skeletonId = Qt3DCore::qIdForNode(skeletonMapping->skeleton()); + } + + const QCallbackMapping *callbackMapping = qobject_cast<const QCallbackMapping *>(frontEnd); + if (callbackMapping) { + m_mappingType = ChannelMappingType; + m_channelName = channelMapping->channelName(); + + const QCallbackMappingPrivate *d = static_cast<const QCallbackMappingPrivate *>(Qt3DCore::QNodePrivate::get(channelMapping)); + m_type = d->m_type; + m_callback = d->m_callback; + m_callbackFlags = d->m_callbackFlags; } - QBackendNode::sceneChangeEvent(e); } Skeleton *ChannelMapping::skeleton() const diff --git a/src/animation/backend/channelmapping_p.h b/src/animation/backend/channelmapping_p.h index aa30e84ee..a0ff5f1ca 100644 --- a/src/animation/backend/channelmapping_p.h +++ b/src/animation/backend/channelmapping_p.h @@ -76,7 +76,7 @@ public: void cleanup(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; void setChannelName(const QString &channelName) { m_channelName = channelName; } QString channelName() const { return m_channelName; } @@ -107,8 +107,6 @@ public: MappingType mappingType() const { return m_mappingType; } private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final; - // Properties from QChannelMapping QString m_channelName; Qt3DCore::QNodeId m_targetId; diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index 986ab3d22..c0659a809 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -116,7 +116,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) registerBackendType<QBlendedClipAnimator, true>( QSharedPointer<Animation::NodeFunctor<Animation::BlendedClipAnimator, Animation::BlendedClipAnimatorManager>>::create(d->m_handler.data(), d->m_handler->blendedClipAnimatorManager())); - registerBackendType<QAbstractChannelMapping>( + registerBackendType<QAbstractChannelMapping, true>( QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapping, Animation::ChannelMappingManager>>::create(d->m_handler.data(), d->m_handler->channelMappingManager())); registerBackendType<QChannelMapper>( diff --git a/src/animation/frontend/qcallbackmapping.cpp b/src/animation/frontend/qcallbackmapping.cpp index c0163da80..f312ddaa5 100644 --- a/src/animation/frontend/qcallbackmapping.cpp +++ b/src/animation/frontend/qcallbackmapping.cpp @@ -130,24 +130,15 @@ void QCallbackMapping::setCallback(int type, QAnimationCallback *callback, QAnim Q_D(QCallbackMapping); if (d->m_type != type) { d->m_type = type; - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id()); - e->setPropertyName("type"); - e->setValue(QVariant(d->m_type)); - notifyObservers(e); + d->update(); } if (d->m_callback != callback) { d->m_callback = callback; - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id()); - e->setPropertyName("callback"); - e->setValue(QVariant::fromValue(static_cast<void *>(d->m_callback))); - notifyObservers(e); + d->update(); } if (d->m_callbackFlags != flags) { d->m_callbackFlags = flags; - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id()); - e->setPropertyName("callbackFlags"); - e->setValue(QVariant::fromValue(int(d->m_callbackFlags))); - notifyObservers(e); + d->update(); } } diff --git a/src/animation/frontend/qchannelmapping.cpp b/src/animation/frontend/qchannelmapping.cpp index 8f6ebe9ab..fa89d5042 100644 --- a/src/animation/frontend/qchannelmapping.cpp +++ b/src/animation/frontend/qchannelmapping.cpp @@ -147,37 +147,20 @@ void QChannelMappingPrivate::updatePropertyNameTypeAndComponentCount() if (m_type != type) { m_type = type; - - // Send update to the backend - Q_Q(QChannelMapping); - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id()); - e->setPropertyName("type"); - e->setValue(QVariant(m_type)); - notifyObservers(e); + update(); } if (m_componentCount != componentCount) { m_componentCount = componentCount; - - // Send update to the backend - Q_Q(QChannelMapping); - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id()); - e->setPropertyName("componentCount"); - e->setValue(QVariant(m_componentCount)); - notifyObservers(e); + update(); } if (qstrcmp(m_propertyName, propertyName) != 0) { m_propertyName = propertyName; - - // Send update to the backend - Q_Q(QChannelMapping); - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id()); - e->setPropertyName("propertyName"); - e->setValue(QVariant::fromValue(const_cast<void *>(static_cast<const void *>(m_propertyName)))); - notifyObservers(e); + update(); } } + /*! \class QChannelMapping \inherits Qt3DCore::QNode diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp index b41f5b3e2..5c37e337e 100644 --- a/src/core/nodes/qnode.cpp +++ b/src/core/nodes/qnode.cpp @@ -687,6 +687,11 @@ QNodePrivate *QNodePrivate::get(QNode *q) return q->d_func(); } +const QNodePrivate *QNodePrivate::get(const QNode *q) +{ + return q->d_func(); +} + /*! \internal */ diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h index d8310731c..839751a5e 100644 --- a/src/core/nodes/qnode_p.h +++ b/src/core/nodes/qnode_p.h @@ -108,6 +108,7 @@ public: QHash<QString, QNode::PropertyTrackingMode> m_trackedPropertiesOverrides; static QNodePrivate *get(QNode *q); + static const QNodePrivate *get(const QNode *q); static void nodePtrDeleter(QNode *q); template<typename Caller, typename NodeType> diff --git a/tests/auto/animation/channelmapping/tst_channelmapping.cpp b/tests/auto/animation/channelmapping/tst_channelmapping.cpp index 35ffcb10a..e108e3d26 100644 --- a/tests/auto/animation/channelmapping/tst_channelmapping.cpp +++ b/tests/auto/animation/channelmapping/tst_channelmapping.cpp @@ -34,6 +34,7 @@ #include <Qt3DAnimation/qskeletonmapping.h> #include <Qt3DAnimation/private/qchannelmapping_p.h> #include <Qt3DCore/qentity.h> +#include <Qt3DCore/qtransform.h> #include <Qt3DCore/qskeleton.h> #include <Qt3DCore/private/qnode_p.h> #include <Qt3DCore/private/qscene_p.h> @@ -72,7 +73,7 @@ private Q_SLOTS: mapping.setProperty(QLatin1String("foo")); // WHEN - simulateInitialization(&mapping, &backendMapping); + simulateInitializationSync(&mapping, &backendMapping); // THEN QCOMPARE(backendMapping.peerId(), mapping.id()); @@ -93,7 +94,7 @@ private Q_SLOTS: skeletonMapping.setSkeleton(skeleton); // WHEN - simulateInitialization(&skeletonMapping, &backendSkeletonMapping); + simulateInitializationSync(&skeletonMapping, &backendSkeletonMapping); // THEN QCOMPARE(backendSkeletonMapping.peerId(), skeletonMapping.id()); @@ -128,7 +129,7 @@ private Q_SLOTS: mapping.setProperty(QLatin1String("foo")); // WHEN - simulateInitialization(&mapping, &backendMapping); + simulateInitializationSync(&mapping, &backendMapping); backendMapping.setSkeletonId(Qt3DCore::QNodeId::createId()); backendMapping.cleanup(); @@ -146,77 +147,50 @@ private Q_SLOTS: void checkPropertyChanges() { // GIVEN + Qt3DAnimation::QChannelMapping mapping; Qt3DAnimation::Animation::Handler handler; Qt3DAnimation::Animation::ChannelMapping backendMapping; backendMapping.setHandler(&handler); - Qt3DCore::QPropertyUpdatedChangePtr updateChange; + simulateInitializationSync(&mapping, &backendMapping); // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("enabled"); - updateChange->setValue(true); - backendMapping.sceneChangeEvent(updateChange); + mapping.setEnabled(false); + backendMapping.syncFromFrontEnd(&mapping, false); // THEN - QCOMPARE(backendMapping.isEnabled(), true); + QCOMPARE(backendMapping.isEnabled(), false); // WHEN - const QString channelName(QLatin1String("Rotation")); - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("channelName"); - updateChange->setValue(channelName); - backendMapping.sceneChangeEvent(updateChange); + const QString channelName(QLatin1String("Translation")); + mapping.setChannelName(channelName); + backendMapping.syncFromFrontEnd(&mapping, false); // THEN QCOMPARE(backendMapping.channelName(), channelName); // WHEN - const auto id = Qt3DCore::QNodeId::createId(); - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("target"); - updateChange->setValue(QVariant::fromValue(id)); - backendMapping.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendMapping.targetId(), id); - - // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("type"); - updateChange->setValue(QVariant(static_cast<int>(QVariant::Vector3D))); - backendMapping.sceneChangeEvent(updateChange); + const auto target = new Qt3DCore::QTransform(); + mapping.setTarget(target); + mapping.setProperty("translation"); + backendMapping.syncFromFrontEnd(&mapping, false); // THEN + QCOMPARE(backendMapping.targetId(), target->id()); QCOMPARE(backendMapping.type(), static_cast<int>(QVariant::Vector3D)); + QCOMPARE(backendMapping.componentCount(), 3); - // WHEN - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("componentCount"); - updateChange->setValue(4); - backendMapping.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendMapping.componentCount(), 4); - - // WHEN - const char *testName = "883"; - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("propertyName"); - updateChange->setValue(QVariant::fromValue(reinterpret_cast<void *>(const_cast<char *>(testName)))); - backendMapping.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendMapping.propertyName(), testName); + const char *testName = "translation"; + QCOMPARE(qstrcmp(testName, backendMapping.propertyName()), 0); - // WHEN - const auto skeletonId = Qt3DCore::QNodeId::createId(); - updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); - updateChange->setPropertyName("skeleton"); - updateChange->setValue(QVariant::fromValue(skeletonId)); - backendMapping.sceneChangeEvent(updateChange); +// // WHEN +// const auto skeletonId = Qt3DCore::QNodeId::createId(); +// updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId()); +// updateChange->setPropertyName("skeleton"); +// updateChange->setValue(QVariant::fromValue(skeletonId)); +// backendMapping.sceneChangeEvent(updateChange); - // THEN - QCOMPARE(backendMapping.skeletonId(), skeletonId); +// // THEN +// QCOMPARE(backendMapping.skeletonId(), skeletonId); } }; diff --git a/tests/auto/animation/qcallbackmapping/tst_qcallbackmapping.cpp b/tests/auto/animation/qcallbackmapping/tst_qcallbackmapping.cpp index d217f3b0f..591ff54ce 100644 --- a/tests/auto/animation/qcallbackmapping/tst_qcallbackmapping.cpp +++ b/tests/auto/animation/qcallbackmapping/tst_qcallbackmapping.cpp @@ -185,23 +185,11 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 3); - auto change = arbiter.events.at(0).staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "type"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), int(QVariant::Vector3D)); - - change = arbiter.events.at(1).staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "callback"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(reinterpret_cast<DummyCallback *>(change->value().value<void *>()), callback); - - change = arbiter.events.at(2).staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "callbackFlags"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), static_cast<int>(Qt3DAnimation::QAnimationCallback::OnThreadPool)); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), &mapping); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); // WHEN mapping.setCallback(QVariant::Vector3D, callback, Qt3DAnimation::QAnimationCallback::OnThreadPool); @@ -209,6 +197,7 @@ private Q_SLOTS: // THEN QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 0); } } }; diff --git a/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp b/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp index 37bd3e241..a47061077 100644 --- a/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp +++ b/tests/auto/animation/qchannelmapping/tst_qchannelmapping.cpp @@ -284,24 +284,11 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 3); - - auto change = arbiter.events.takeFirst().staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "type"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), static_cast<int>(QVariant::Vector3D)); - - change = arbiter.events.takeFirst().staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "componentCount"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), 3); - - change = arbiter.events.takeFirst().staticCast<Qt3DCore::QPropertyUpdatedChange>(); - QCOMPARE(change->propertyName(), "propertyName"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QVERIFY(qstrcmp(reinterpret_cast<const char *>(change->value().value<void *>()), "scale") == 0); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), &mapping); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); // WHEN mapping.setProperty(QStringLiteral("scale")); @@ -309,6 +296,7 @@ private Q_SLOTS: // THEN QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 0); } } @@ -340,8 +328,8 @@ private Q_SLOTS: QFETCH(int, expectedType); QFETCH(int, expectedComponentCount); - Q_UNUSED(expectedType); - Q_UNUSED(expectedComponentCount); + Q_UNUSED(expectedType) + Q_UNUSED(expectedComponentCount) TestArbiter arbiter; Qt3DAnimation::QChannelMapping mapping; @@ -363,7 +351,7 @@ private Q_SLOTS: mapping.setProperty(QString::fromLatin1(propertyName)); // THEN - QCOMPARE(arbiter.dirtyNodes.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); } } |