diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-02-01 14:00:30 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-02-01 16:22:41 +0000 |
commit | f603bfe7cc518046bd7cc76b4d02aac2227f5636 (patch) | |
tree | e3835c36f6e183d127ca58029be243346308434a | |
parent | 4d169f51c016073f61677dd1ad9281bfc10b3dcf (diff) | |
download | qt-creator-f603bfe7cc518046bd7cc76b4d02aac2227f5636.tar.gz |
QmlDesigner: Change convertToEnum to use NodeMetaInfo
Task-number: QDS-8800
Change-Id: I6daef87ba87ce477edeb0c202a2d23af36474467
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
-rw-r--r-- | src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index a4fd078b76..99cb44487c 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -685,7 +685,11 @@ public: return value; } - QVariant convertToEnum(AST::Statement *rhs, const QString &propertyPrefix, AST::UiQualifiedId *propertyId, const QString &astValue) + QVariant convertToEnum(AST::Statement *rhs, + const NodeMetaInfo &metaInfo, + const QString &propertyPrefix, + AST::UiQualifiedId *propertyId, + const QString &astValue) { QStringList astValueList = astValue.split(QStringLiteral(".")); @@ -704,42 +708,12 @@ public: if (!eStmt || !eStmt->expression) return QVariant(); - const ObjectValue *containingObject = nullptr; - QString name; - if (!lookupProperty(propertyPrefix, propertyId, nullptr, &containingObject, &name)) - return QVariant(); - - if (containingObject) - containingObject->lookupMember(name, m_context, &containingObject); - const CppComponentValue * lhsCppComponent = value_cast<CppComponentValue>(containingObject); - if (!lhsCppComponent) - return QVariant(); - const QString lhsPropertyTypeName = lhsCppComponent->propertyType(name); - - const ObjectValue *rhsValueObject = nullptr; - QString rhsValueName; - if (auto idExp = AST::cast<AST::IdentifierExpression *>(eStmt->expression)) { - if (!m_scopeChain.qmlScopeObjects().isEmpty()) - rhsValueObject = m_scopeChain.qmlScopeObjects().constLast(); - if (!idExp->name.isEmpty()) - rhsValueName = idExp->name.toString(); - } else if (auto memberExp = AST::cast<AST::FieldMemberExpression *>(eStmt->expression)) { - Evaluate evaluate(&m_scopeChain); - const Value *result = evaluate(memberExp->base); - rhsValueObject = result->asObjectValue(); - - if (!memberExp->name.isEmpty()) - rhsValueName = memberExp->name.toString(); - } + const QString propertyName = propertyPrefix.isEmpty() ? propertyId->name.toString() + : propertyPrefix; - if (rhsValueObject) - rhsValueObject->lookupMember(rhsValueName, m_context, &rhsValueObject); - - const CppComponentValue *rhsCppComponentValue = value_cast<CppComponentValue>(rhsValueObject); - if (!rhsCppComponentValue) - return QVariant(); + const PropertyMetaInfo pInfo = metaInfo.property(propertyName.toUtf8()); - if (rhsCppComponentValue->getEnum(lhsPropertyTypeName).hasKey(rhsValueName)) + if (pInfo.isEnumType()) return QVariant::fromValue(Enumeration(astValue)); else return QVariant(); @@ -1539,7 +1513,11 @@ QmlDesigner::PropertyName TextToModelMerger::syncScriptBinding(ModelNode &modelN } } - const QVariant enumValue = context->convertToEnum(script->statement, prefix, script->qualifiedId, astValue); + const QVariant enumValue = context->convertToEnum(script->statement, + modelNode.metaInfo(), + prefix, + script->qualifiedId, + astValue); if (enumValue.isValid()) { // It is a qualified enum: AbstractProperty modelProperty = modelNode.property(astPropertyName.toUtf8()); syncVariantProperty(modelProperty, enumValue, TypeName(), differenceHandler); // TODO: parse type |