qmltc: Do not generate bindables and setters for QQmlListProperty

Assigning to a QQmlListProperty does not do what you think it does.

Pick-to: 6.3
Change-Id: Ie6ac3208d552d8f40d9f2f4d7fb33c1cd64e4b79
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
Ulf Hermann 2022-01-13 16:18:22 +01:00
parent 0790bc85a1
commit 134f305b7f
4 changed files with 26 additions and 12 deletions

View File

@ -1,11 +1,15 @@
import QtQml 2.0
QtObject {
id: a
property string hello: "Hello from parent"
property list<QtObject> children
property list<QtObject> ids
children: [
QtObject { property string hello: "Hello from parent.children[0]" },
QtObject { property string hello: "Hello from parent.children[1]" }
QtObject { id: a1; property string hello: "Hello from parent.children[0]" },
QtObject { id: a2; property string hello: "Hello from parent.children[1]" }
]
ids: [a, a1, a2]
}

View File

@ -1050,6 +1050,12 @@ void tst_qmltc::listProperty()
QStringLiteral("Hello from parent.children[0]"));
QCOMPARE(children.at(1)->property("hello").toString(),
QStringLiteral("Hello from parent.children[1]"));
QQmlListReference refIds(&created, "ids");
QCOMPARE(refIds.count(), 3);
QCOMPARE(refIds.at(0), &created);
QCOMPARE(refIds.at(1), ref.at(0));
QCOMPARE(refIds.at(2), ref.at(1));
}
void tst_qmltc::listPropertiesWithTheSameName()

View File

@ -869,7 +869,9 @@ void CodeGenerator::compileProperty(QQmlJSAotObject &current, const QQmlJSMetaPr
Qml2CppPropertyData compilationData(p);
// 1. add setter and getter
if (p.isWritable()) {
// If p.isList(), it's a QQmlListProperty. Then you can write the underlying list through
// the QQmlListProperty object retrieved with the getter. Setting it would make no sense.
if (p.isWritable() && !p.isList()) {
QQmlJSAotMethod setter {};
setter.returnType = u"void"_qs;
setter.name = compilationData.write;
@ -890,13 +892,15 @@ void CodeGenerator::compileProperty(QQmlJSAotObject &current, const QQmlJSMetaPr
mocPieces << u"READ"_qs << getter.name;
// 2. add bindable
QQmlJSAotMethod bindable {};
bindable.returnType = u"QBindable<" + underlyingType + u">";
bindable.name = compilationData.bindable;
bindable.body << u"return QBindable<" + underlyingType + u">(std::addressof(" + variableName
+ u"));";
current.functions.emplaceBack(bindable);
mocPieces << u"BINDABLE"_qs << bindable.name;
if (!p.isList()) {
QQmlJSAotMethod bindable {};
bindable.returnType = u"QBindable<" + underlyingType + u">";
bindable.name = compilationData.bindable;
bindable.body << u"return QBindable<" + underlyingType + u">(std::addressof(" + variableName
+ u"));";
current.functions.emplaceBack(bindable);
mocPieces << u"BINDABLE"_qs << bindable.name;
}
// 3. add/check notify (actually, this is already done inside QmltcVisitor)

View File

@ -564,9 +564,9 @@ static void setupQmlCppType(const Qml2CppContext &context, const QQmlJSScope::Pt
Qml2CppPropertyData compiledData(p);
if (p.read().isEmpty())
p.setRead(compiledData.read);
if (p.write().isEmpty() && p.isWritable())
if (p.write().isEmpty() && p.isWritable() && !p.isList())
p.setWrite(compiledData.write);
if (p.bindable().isEmpty())
if (p.bindable().isEmpty() && !p.isList())
p.setBindable(compiledData.bindable);
// TODO: p.setNotify(compiledData.notify); - ?
type->addOwnProperty(p);