forked from qt-creator/qt-creator
QmlDesigner: Add support for Vector4D
SpriteParticle3D colorVariation is a Vector4D. Task-number: QDS-4876 Change-Id: I756f7a688266d67be1b275d4151874befefc0530 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -47,8 +47,9 @@
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QVector3D>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QVector4D>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
@@ -343,6 +344,18 @@ void PropertyEditorQmlBackend::setValue(const QmlObjectNode & , const PropertyNa
|
||||
if (propertyValue)
|
||||
propertyValue->setValue(QVariant(vecValue[i]));
|
||||
}
|
||||
} else if (value.type() == QVariant::Vector4D) {
|
||||
const char *suffix[4] = {"_x", "_y", "_z", "_w"};
|
||||
auto vecValue = value.value<QVector4D>();
|
||||
for (int i = 0; i < 4; ++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('.', '_');
|
||||
|
@@ -227,9 +227,10 @@ void PropertyEditorView::changeValue(const QString &name)
|
||||
removePropertyFromModel(propertyName);
|
||||
} else {
|
||||
// QVector*D(0, 0, 0) detects as null variant though it is valid value
|
||||
if (castedValue.isValid() && (!castedValue.isNull()
|
||||
|| castedValue.type() == QVariant::Vector2D
|
||||
|| castedValue.type() == QVariant::Vector3D)) {
|
||||
if (castedValue.isValid()
|
||||
&& (!castedValue.isNull() || castedValue.type() == QVariant::Vector2D
|
||||
|| castedValue.type() == QVariant::Vector3D
|
||||
|| castedValue.type() == QVariant::Vector4D)) {
|
||||
commitVariantValueToModel(propertyName, castedValue);
|
||||
}
|
||||
}
|
||||
|
@@ -32,8 +32,9 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QVector3D>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QVector4D>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
void qt_blurImage(QPainter *painter, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
|
||||
@@ -352,6 +353,28 @@ QVariant NodeInstance::property(const PropertyName &name) const
|
||||
break;
|
||||
}
|
||||
return QVariant(subValue);
|
||||
} else if (varValue.type() == QVariant::Vector4D) {
|
||||
auto value = varValue.value<QVector4D>();
|
||||
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;
|
||||
case 'w':
|
||||
subValue = value.w();
|
||||
break;
|
||||
default:
|
||||
subValue = 0.f;
|
||||
break;
|
||||
}
|
||||
return QVariant(subValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,6 +466,24 @@ void NodeInstance::setProperty(const PropertyName &name, const QVariant &value)
|
||||
update = true;
|
||||
}
|
||||
newValueVar = newValue;
|
||||
} else if (oldValue.type() == QVariant::Vector4D) {
|
||||
QVector4D newValue;
|
||||
if (oldValue.type() == QVariant::Vector4D)
|
||||
newValue = oldValue.value<QVector4D>();
|
||||
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;
|
||||
} else if (name.endsWith(".w")) {
|
||||
newValue.setW(value.toFloat());
|
||||
update = true;
|
||||
}
|
||||
newValueVar = newValue;
|
||||
}
|
||||
if (update) {
|
||||
d->propertyValues.insert(parentPropName, newValueVar);
|
||||
|
@@ -349,15 +349,35 @@ private:
|
||||
|
||||
static inline bool isValueType(const TypeName &type)
|
||||
{
|
||||
static const PropertyTypeList objectValuesList({"QFont", "QPoint", "QPointF",
|
||||
"QSize", "QSizeF", "QVector3D", "QVector2D", "vector2d", "vector3d", "font"});
|
||||
static const PropertyTypeList objectValuesList({"QFont",
|
||||
"QPoint",
|
||||
"QPointF",
|
||||
"QSize",
|
||||
"QSizeF",
|
||||
"QVector2D",
|
||||
"QVector3D",
|
||||
"QVector4D",
|
||||
"vector2d",
|
||||
"vector3d",
|
||||
"vector4d",
|
||||
"font"});
|
||||
return objectValuesList.contains(type);
|
||||
}
|
||||
|
||||
static inline bool isValueType(const QString &type)
|
||||
{
|
||||
static const QStringList objectValuesList({"QFont", "QPoint", "QPointF",
|
||||
"QSize", "QSizeF", "QVector3D", "QVector2D", "vector2d", "vector3d", "font"});
|
||||
static const QStringList objectValuesList({"QFont",
|
||||
"QPoint",
|
||||
"QPointF",
|
||||
"QSize",
|
||||
"QSizeF",
|
||||
"QVector2D",
|
||||
"QVector3D",
|
||||
"QVector4D",
|
||||
"vector2d",
|
||||
"vector3d",
|
||||
"vector4d",
|
||||
"font"});
|
||||
return objectValuesList.contains(type);
|
||||
}
|
||||
|
||||
@@ -1091,6 +1111,9 @@ QVariant::Type NodeMetaInfoPrivate::variantTypeId(const PropertyName &propertyNa
|
||||
if (typeName == "vector3d")
|
||||
return QVariant::Vector3D;
|
||||
|
||||
if (typeName == "vector4d")
|
||||
return QVariant::Vector4D;
|
||||
|
||||
return QVariant::nameToType(typeName.data());
|
||||
}
|
||||
|
||||
|
@@ -169,6 +169,14 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
|
||||
auto vec = value.value<QVector3D>();
|
||||
return QStringLiteral("Qt.vector3d(%1, %2, %3)").arg(vec.x()).arg(vec.y()).arg(vec.z());
|
||||
}
|
||||
case QMetaType::QVector4D: {
|
||||
auto vec = value.value<QVector4D>();
|
||||
return QStringLiteral("Qt.vector4d(%1, %2, %3, %4)")
|
||||
.arg(vec.x())
|
||||
.arg(vec.y())
|
||||
.arg(vec.z())
|
||||
.arg(vec.w());
|
||||
}
|
||||
default:
|
||||
return QStringLiteral("\"%1\"").arg(escape(stringValue));
|
||||
}
|
||||
|
Reference in New Issue
Block a user