diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-14 11:07:19 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-05-09 11:55:05 +0000 |
commit | d1a28bd3731e188f5ce3c3f7d41d141d5ad0c17d (patch) | |
tree | 6121250216e4797bf4331117f63063005fa43557 /tools/qmltc | |
parent | 324fd7d58f88e814abf347eb43d5ed628318f9b7 (diff) |
qmltc: Support setting Gradient property of Rectangle
Fixes: QTBUG-102560
Change-Id: I7c339d2807a723f38e18e06b944362449d89ad7a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit e98faf1df401268dc6966b39963547a4de6f9171)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmltc')
-rw-r--r-- | tools/qmltc/prototype/codegenerator.cpp | 8 | ||||
-rw-r--r-- | tools/qmltc/prototype/codegeneratorutil.cpp | 13 |
2 files changed, 12 insertions, 9 deletions
diff --git a/tools/qmltc/prototype/codegenerator.cpp b/tools/qmltc/prototype/codegenerator.cpp index 84f49cd3f7..5ee1d980d5 100644 --- a/tools/qmltc/prototype/codegenerator.cpp +++ b/tools/qmltc/prototype/codegenerator.cpp @@ -1217,7 +1217,7 @@ void CodeGenerator::compileBinding(QQmlJSAotObject ¤t, const QmlIR::Bindin // Q_ASSERT(propertyType); // TODO: doesn't work with signals const auto addPropertyLine = [&](const QString &propertyName, const QQmlJSMetaProperty &p, - const QString &value, bool constructQVariant = false) { + const QString &value, bool constructFromQObject = false) { // TODO: there mustn't be this special case. instead, alias resolution // must be done in QQmlJSImportVisitor subclass, that would handle this // mess (see resolveValidateOrSkipAlias() in qml2cppdefaultpasses.cpp) @@ -1227,10 +1227,10 @@ void CodeGenerator::compileBinding(QQmlJSAotObject ¤t, const QmlIR::Bindin + u"' which is a QML type compiled to C++. The assignment is special " u"in this case"; current.endInit.body += CodeGeneratorUtility::generate_assignToSpecialAlias( - object.type, propertyName, p, value, accessor.name, constructQVariant); + object.type, propertyName, p, value, accessor.name, constructFromQObject); } else { current.endInit.body += CodeGeneratorUtility::generate_assignToProperty( - object.type, propertyName, p, value, accessor.name, constructQVariant); + object.type, propertyName, p, value, accessor.name, constructFromQObject); } }; @@ -1349,7 +1349,7 @@ void CodeGenerator::compileBinding(QQmlJSAotObject ¤t, const QmlIR::Bindin const QString refName = u"listref_" + propertyName; current.endInit.body << refName + u".append(" + value + u");"; } else { - addPropertyLine(propertyName, p, value, /* through QVariant = */ true); + addPropertyLine(propertyName, p, value, /* fromQObject = */ true); } }; diff --git a/tools/qmltc/prototype/codegeneratorutil.cpp b/tools/qmltc/prototype/codegeneratorutil.cpp index 3d7300e0d8..1b6a9ec851 100644 --- a/tools/qmltc/prototype/codegeneratorutil.cpp +++ b/tools/qmltc/prototype/codegeneratorutil.cpp @@ -63,12 +63,15 @@ wrapIfMismatchingType(const QQmlJSMetaProperty &p, QString value) prologue << variantName + u".setValue(" + value + u");"; epilogue << u"}"_qs; value = u"std::move(" + variantName + u")"; + } else if (isDerivedFromBuiltin(propType, u"QJSValue"_qs)) { + const QString jsvalueName = u"jsvalue_" + p.propertyName(); + prologue << u"{ // accepts QJSValue"_qs; + // Note: do not assume we have the engine, acquire it from `this` + prologue << u"auto e = qmlEngine(this);"_qs; + prologue << u"QJSValue " + jsvalueName + u" = e->toScriptValue(" + value + u");"; + epilogue << u"}"_qs; + value = u"std::move(" + jsvalueName + u")"; } - /*else if (isDerivedFromBuiltin(propType, u"QQmlComponent"_qs)) { - // assume value can always be converted to "QObject *" - prologue << u"// accepts QQmlComponent"_qs; - value = u"new QQmlComponent(" + value + u")"; - }*/ return { prologue, value, epilogue }; } |