From 6263af19264a4d2cb9b0f2ae6d5801438204c601 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 11 May 2017 19:06:48 +0200 Subject: Pick the right type for QVariant channel targets Animating a Parameter node would be impossible otherwise since the 'value' property is a QVariant so QChannelMapping has no chance of know what really is expected there. If a value is already set, we can automatically determine the QVariant's underlying type. If not, show a warning since we have no chance then. Start handling QMetaType::Float as well since a QVariant will ofen contain this, not a Double. Change-Id: I0ba2abbb2c8d85f2aa1a152ed4b8c6cd26f1fc97 Reviewed-by: Sean Harmer --- src/animation/backend/animationutils.cpp | 2 ++ src/animation/frontend/qchannelmapping.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index c0287e9f2..c12ad99f7 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -61,6 +61,7 @@ int componentsForType(int type) { int componentCount = 1; switch (type) { + case QMetaType::Float: case QVariant::Double: componentCount = 1; break; @@ -237,6 +238,7 @@ QVector preparePropertyChanges(Qt3DCore::QNodeId anim // Build the new value from the channel/fcurve evaluation results QVariant v; switch (mappingData.type) { + case QMetaType::Float: case QVariant::Double: { v = QVariant::fromValue(channelResults[mappingData.channelIndices[0]]); break; diff --git a/src/animation/frontend/qchannelmapping.cpp b/src/animation/frontend/qchannelmapping.cpp index b3d3816a0..90504d942 100644 --- a/src/animation/frontend/qchannelmapping.cpp +++ b/src/animation/frontend/qchannelmapping.cpp @@ -74,6 +74,15 @@ void QChannelMappingPrivate::updatePropertyNameAndType() QMetaProperty mp = mo->property(propertyIndex); propertyName = mp.name(); type = mp.userType(); + if (type == QMetaType::QVariant) { + QVariant currentValue = m_target->property(mp.name()); + if (!currentValue.isNull()) { + type = currentValue.userType(); + } else { + qWarning("QChannelMapping: Attempted to target QVariant property with no value set." + "Set a value first in order to be able to determine the type."); + } + } } if (m_type != type) { -- cgit v1.2.3