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:
parent
0790bc85a1
commit
134f305b7f
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -869,7 +869,9 @@ void CodeGenerator::compileProperty(QQmlJSAotObject ¤t, 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 ¤t, 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)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue