aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2020-04-28 12:30:49 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2020-04-28 12:02:39 +0000
commit7300f6344a6a237262c41837b5da8a9eca813bf8 (patch)
tree5020ae5d0f4e4416d9cfdccb40e490f958592f14 /src/plugins/qmldesigner
parent6c2ae3519e39597191bbc6924637d36b824435d9 (diff)
QmlDesigner: Fix property handling for QVector3D properties
QVector3D properties were not consistently handled. Sometimes they were handled as QVector3D and sometimes handling expected a subproperty (e.g. scale.x). Made handling more flexible in a couple of places to fix various issues caused by this. Change-Id: Iacd08b1687efc1fab35742ed1aafda9a8712756b Fixes: QDS-1881 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner')
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp25
-rw-r--r--src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp59
-rw-r--r--src/plugins/qmldesigner/designercore/model/qmltimeline.cpp9
3 files changed, 82 insertions, 11 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
index ddded6400b..a9aad59fbf 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp
@@ -47,6 +47,7 @@
#include <QApplication>
#include <QDir>
#include <QFileInfo>
+#include <QVector3D>
#include <QLoggingCategory>
@@ -294,11 +295,25 @@ void PropertyEditorQmlBackend::createPropertyEditorValue(const QmlObjectNode &qm
void PropertyEditorQmlBackend::setValue(const QmlObjectNode & , const PropertyName &name, const QVariant &value)
{
- PropertyName propertyName = name;
- propertyName.replace('.', '_');
- auto propertyValue = qobject_cast<PropertyEditorValue*>(variantToQObject(m_backendValuesPropertyMap.value(QString::fromUtf8(propertyName))));
- if (propertyValue)
- propertyValue->setValue(value);
+ if (value.type() == QVariant::Vector3D) {
+ // Vector3D values need to be split into their subcomponents
+ const char *suffix[3] = {"_x", "_y", "_z"};
+ auto vecValue = value.value<QVector3D>();
+ for (int i = 0; i < 3; ++i) {
+ PropertyName subPropName(name.size() + 2, '\0');
+ subPropName.replace(0, name.size(), name);
+ subPropName.replace(name.size(), 2, suffix[i]);
+ auto propertyValue = qobject_cast<PropertyEditorValue *>(variantToQObject(m_backendValuesPropertyMap.value(QString::fromUtf8(subPropName))));
+ if (propertyValue)
+ propertyValue->setValue(QVariant(vecValue[i]));
+ }
+ } else {
+ PropertyName propertyName = name;
+ propertyName.replace('.', '_');
+ auto propertyValue = qobject_cast<PropertyEditorValue *>(variantToQObject(m_backendValuesPropertyMap.value(QString::fromUtf8(propertyName))));
+ if (propertyValue)
+ propertyValue->setValue(value);
+ }
}
QQmlContext *PropertyEditorQmlBackend::context() {
diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
index 453c1b31a4..535350055d 100644
--- a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
+++ b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
@@ -32,6 +32,7 @@
#include <QDebug>
#include <QPainter>
+#include <QVector3D>
QT_BEGIN_NAMESPACE
void qt_blurImage(QPainter *painter, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
@@ -306,8 +307,38 @@ int NodeInstance::penWidth() const
QVariant NodeInstance::property(const PropertyName &name) const
{
- if (isValid())
- return d->propertyValues.value(name);
+ if (isValid()) {
+ if (d->propertyValues.contains(name)) {
+ return d->propertyValues.value(name);
+ } else {
+ // Query may be for a subproperty, e.g. scale.x
+ const int index = name.indexOf('.');
+ if (index != -1) {
+ PropertyName parentPropName = name.left(index);
+ QVariant varValue = d->propertyValues.value(parentPropName);
+ if (varValue.type() == QVariant::Vector3D) {
+ auto value = varValue.value<QVector3D>();
+ char subProp = name.right(1)[0];
+ float subValue = 0.f;
+ switch (subProp) {
+ case 'x':
+ subValue = value.x();
+ break;
+ case 'y':
+ subValue = value.y();
+ break;
+ case 'z':
+ subValue = value.z();
+ break;
+ default:
+ subValue = 0.f;
+ break;
+ }
+ return QVariant(subValue);
+ }
+ }
+ }
+ }
return QVariant();
}
@@ -362,6 +393,30 @@ QPair<PropertyName, qint32> NodeInstance::anchor(const PropertyName &name) const
void NodeInstance::setProperty(const PropertyName &name, const QVariant &value)
{
+ const int index = name.indexOf('.');
+ if (index != -1) {
+ PropertyName parentPropName = name.left(index);
+ QVariant oldValue = d->propertyValues.value(parentPropName);
+ QVector3D newValue;
+ if (oldValue.type() == QVariant::Vector3D)
+ newValue = oldValue.value<QVector3D>();
+ bool update = false;
+ if (name.endsWith(".x")) {
+ newValue.setX(value.toFloat());
+ update = true;
+ } else if (name.endsWith(".y")) {
+ newValue.setY(value.toFloat());
+ update = true;
+ } else if (name.endsWith(".z")) {
+ newValue.setZ(value.toFloat());
+ update = true;
+ }
+ if (update) {
+ d->propertyValues.insert(parentPropName, newValue);
+ return;
+ }
+ }
+
d->propertyValues.insert(name, value);
}
diff --git a/src/plugins/qmldesigner/designercore/model/qmltimeline.cpp b/src/plugins/qmldesigner/designercore/model/qmltimeline.cpp
index a687853604..68738b06de 100644
--- a/src/plugins/qmldesigner/designercore/model/qmltimeline.cpp
+++ b/src/plugins/qmldesigner/designercore/model/qmltimeline.cpp
@@ -90,11 +90,12 @@ bool QmlTimeline::hasTimeline(const ModelNode &node, const PropertyName &propert
for (const ModelNode &childNode : modelNode().defaultNodeListProperty().toModelNodeList()) {
if (QmlTimelineKeyframeGroup::isValidQmlTimelineKeyframeGroup(childNode)) {
const QmlTimelineKeyframeGroup frames(childNode);
-
- if (frames.target().isValid()
- && frames.target() == node
- && frames.propertyName() == propertyName)
+ if (frames.target().isValid() && frames.target() == node
+ && (frames.propertyName() == propertyName
+ || (frames.propertyName().contains('.')
+ && frames.propertyName().startsWith(propertyName)))) {
return true;
+ }
}
}
}