diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-06-09 13:23:33 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-06-22 16:05:07 +0200 |
commit | 2c0518eb62ebe475abf84b8ee2fd50c53720d3a4 (patch) | |
tree | 1e729142d25a1452d4be02fd743180ddc22f307e /src/tools/moc | |
parent | 073214fdf943e1a0beb660a039e39dc1ea43836e (diff) |
moc: Allow reading property values through bindables
The behavior is similar to MEMBER: If the READ accessor is "default",
synthesize it using the bindable.
[ChangeLog][QtCore] You can now specify "READ default" in a Q_PROPERTY
if you also specify a BINDABLE. moc will synthesize a READ accessor in
that case.
Task-number: QTBUG-97249
Change-Id: I4a275adabaed12df95dac505095f847c4be65dfe
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/generator.cpp | 3 | ||||
-rw-r--r-- | src/tools/moc/moc.cpp | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 9bcddd8670..d03d8513db 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1297,6 +1297,9 @@ void Generator::generateStaticMetacall() else if (cdef->enumDeclarations.value(p.type, false)) fprintf(out, " case %d: *reinterpret_cast<int*>(_v) = QFlag(%s%s()); break;\n", propindex, prefix.constData(), p.read.constData()); + else if (p.read == "default") + fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s().value(); break;\n", + propindex, p.type.constData(), prefix.constData(), p.bind.constData()); else if (!p.read.isEmpty()) fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s(); break;\n", propindex, p.type.constData(), prefix.constData(), p.read.constData()); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index f107a6f0d8..5ea79a4280 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1306,6 +1306,10 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef) v = lexem(); if (l != "REVISION") error(1); + } else if (test(DEFAULT)) { + v = lexem(); + if (l != "READ") + error(1); } else { next(IDENTIFIER); v = lexem(); @@ -1384,6 +1388,12 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef) propDef.constant = false; warning(msg.constData()); } + if (propDef.read == "default" && propDef.bind.isNull()) { + const QByteArray msg = "Property declaration " + propDef.name + + " is not BINDable but default-READable. READ will be ignored."; + propDef.read = ""; + warning(msg.constData()); + } } void Moc::parseProperty(ClassDef *def) |