aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp')
-rw-r--r--src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp92
1 files changed, 90 insertions, 2 deletions
diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
index 453c1b31a4..b74179fdef 100644
--- a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
+++ b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp
@@ -32,6 +32,8 @@
#include <QDebug>
#include <QPainter>
+#include <QVector3D>
+#include <QVector2D>
QT_BEGIN_NAMESPACE
void qt_blurImage(QPainter *painter, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
@@ -306,8 +308,54 @@ 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::Vector2D) {
+ auto value = varValue.value<QVector2D>();
+ char subProp = name.right(1)[0];
+ float subValue = 0.f;
+ switch (subProp) {
+ case 'x':
+ subValue = value.x();
+ break;
+ case 'y':
+ subValue = value.y();
+ break;
+ default:
+ subValue = 0.f;
+ break;
+ }
+ return QVariant(subValue);
+ } else 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 +410,46 @@ 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);
+ QVariant newValueVar;
+ bool update = false;
+ if (oldValue.type() == QVariant::Vector2D) {
+ QVector2D newValue;
+ if (oldValue.type() == QVariant::Vector2D)
+ newValue = oldValue.value<QVector2D>();
+ if (name.endsWith(".x")) {
+ newValue.setX(value.toFloat());
+ update = true;
+ } else if (name.endsWith(".y")) {
+ newValue.setY(value.toFloat());
+ update = true;
+ }
+ newValueVar = newValue;
+ } else if (oldValue.type() == QVariant::Vector3D) {
+ QVector3D newValue;
+ if (oldValue.type() == QVariant::Vector3D)
+ newValue = oldValue.value<QVector3D>();
+ 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;
+ }
+ newValueVar = newValue;
+ }
+ if (update) {
+ d->propertyValues.insert(parentPropName, newValueVar);
+ return;
+ }
+ }
+
d->propertyValues.insert(name, value);
}