From 65567b4717a1280a8c25c5690148067cec96011b Mon Sep 17 00:00:00 2001 From: Henning Gruendl Date: Tue, 10 Jan 2023 15:28:13 +0100 Subject: [PATCH] QmlDesigner: Fix value types in property editor Currently the value types of e.g. layer.textureSize and layer.sourceRect are only resolved for QML Item, but not QML Control. This patch increases the recursion depth while collecting the attributes of values types in order to be able to set layer.textureSize.width or layer.sourceRect.x. It also adds those attributes to be able to read the values. Change-Id: I61ba1468d1443953f0a5b6ab2241114dc441bb79 Reviewed-by: Thomas Hartmann Reviewed-by: Reviewed-by: Qt CI Bot --- .../designercore/metainfo/nodemetainfo.cpp | 19 +++++--- .../instances/objectnodeinstance.cpp | 45 ++++++++++++++++++- .../qml2puppet/instances/objectnodeinstance.h | 1 + 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp index 524ab45716e..b61dff80a45 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp @@ -409,7 +409,7 @@ QVector getQmlTypes(const CppComponentValue *objectValue, const Co if (objectValue->className().isEmpty()) return propertyList; - if (rec > 2) + if (rec > 4) return propertyList; PropertyMemberProcessor processor(context); @@ -431,9 +431,14 @@ QVector getQmlTypes(const CppComponentValue *objectValue, const Co } } if (isValueType(objectValue->propertyType(nameAsString))) { - const ObjectValue *dotObjectValue = value_cast(objectValue->lookupMember(nameAsString, context)); + const ObjectValue *dotObjectValue = value_cast( + objectValue->lookupMember(nameAsString, context)); + if (dotObjectValue) { - const QVector dotProperties = getObjectTypes(dotObjectValue, context, false, rec + 1); + const QVector dotProperties = getObjectTypes(dotObjectValue, + context, + false, + rec + 1); for (const PropertyInfo &propertyInfo : dotProperties) { const PropertyName dotName = name + '.' + propertyInfo.first; const TypeName type = propertyInfo.second; @@ -525,7 +530,7 @@ QVector getObjectTypes(const ObjectValue *objectValue, const Conte if (objectValue->className().isEmpty()) return propertyList; - if (rec > 2) + if (rec > 4) return propertyList; PropertyMemberProcessor processor(context); @@ -539,6 +544,7 @@ QVector getObjectTypes(const ObjectValue *objectValue, const Conte if (isValueType(property.second)) { const Value *dotValue = objectValue->lookupMember(nameAsString, context); + if (!dotValue) continue; @@ -546,7 +552,10 @@ QVector getObjectTypes(const ObjectValue *objectValue, const Conte dotValue = context->lookupReference(ref); if (const ObjectValue *dotObjectValue = dotValue->asObjectValue()) { - const QVector dotProperties = getObjectTypes(dotObjectValue, context, false, rec + 1); + const QVector dotProperties = getObjectTypes(dotObjectValue, + context, + false, + rec + 1); for (const PropertyInfo &propertyInfo : dotProperties) { const PropertyName dotName = name + '.' + propertyInfo.first; const TypeName type = propertyInfo.second; diff --git a/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.cpp b/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.cpp index 49720c38d46..0d601cb91e9 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.cpp @@ -567,6 +567,15 @@ void ObjectNodeInstance::doResetProperty(const PropertyName &propertyName) QmlPrivateGate::doResetProperty(object(), context(), propertyName); } +static bool isPropertyBlackListed(const PropertyName &propertyName) +{ + if (propertyName.contains(".") && propertyName.contains("__")) + return true; + if (propertyName.count(".") > 2) + return true; + return false; +} + QVariant ObjectNodeInstance::property(const PropertyName &name) const { if (ignoredProperties().contains(name)) @@ -574,7 +583,7 @@ QVariant ObjectNodeInstance::property(const PropertyName &name) const // TODO: handle model nodes - if (QmlPrivateGate::isPropertyBlackListed(name)) + if (isPropertyBlackListed(name)) return QVariant(); QQmlProperty property(object(), QString::fromUtf8(name), context()); @@ -612,6 +621,37 @@ void ObjectNodeInstance::ensureVector3DDotProperties(PropertyNameList &list) con } } +void ObjectNodeInstance::ensureValueTypeProperties(PropertyNameList &list) const +{ + const PropertyNameList pointDotProperties = {"x", "y"}; + const PropertyNameList sizeDotProperties = {"width", "height"}; + const PropertyNameList rectDotProperties = {"x", "y", "width", "height"}; + + PropertyNameList valueTypeProperties; + + for (const auto &property : list) { + const QString name = instanceType(property); + PropertyNameList dotProperties; + + if (name == "QPoint" || name == "QPointF") + dotProperties = pointDotProperties; + + if (name == "QSize" || name == "QSizeF") + dotProperties = sizeDotProperties; + + if (name == "QRect" || name == "QRectF") + dotProperties = rectDotProperties; + + for (const auto &dotProperty : dotProperties) + valueTypeProperties.append(property + "." + dotProperty); + } + + for (const auto &valueTypeProperty : valueTypeProperties) { + if (!list.contains(valueTypeProperty)) + list.append(valueTypeProperty); + } +} + PropertyNameList ObjectNodeInstance::propertyNames() const { PropertyNameList list; @@ -619,13 +659,14 @@ PropertyNameList ObjectNodeInstance::propertyNames() const list = QmlPrivateGate::allPropertyNames(object()); ensureVector3DDotProperties(list); + ensureValueTypeProperties(list); return list; } QString ObjectNodeInstance::instanceType(const PropertyName &name) const { - if (QmlPrivateGate::isPropertyBlackListed(name)) + if (isPropertyBlackListed(name)) return QLatin1String("undefined"); QQmlProperty property(object(), QString::fromUtf8(name), context()); diff --git a/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.h b/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.h index f4724e6cd71..0b2c0e6337c 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.h +++ b/src/tools/qml2puppet/qml2puppet/instances/objectnodeinstance.h @@ -199,6 +199,7 @@ protected: void initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance); void ensureVector3DDotProperties(PropertyNameList &list) const; + void ensureValueTypeProperties(PropertyNameList &list) const; private: QString m_id;