summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-06-21 11:54:18 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-07-08 09:38:27 +0200
commit66a30b9a33aac288335f32ea9dc8dd8542abf69f (patch)
tree08aea336362ee58df8375681b5c8b5c982076acd /src/tools
parentd56f80fd9afd31d9458da87c64a41b15a67ba3cc (diff)
moc: Allow writing properties through bindables
BINDABLE should generally behave the same as MEMBER if "WRITE default", except where it cannot. In particular we cannot know if any NOTIFY signal should be sent from the synthetic WRITE accessor. [ChangeLog][QtCore] moc will now synthesize WRITE accessors for properties with BINDABLE if you specify "WRITE default". Task-number: QTBUG-97249 Change-Id: I883c40ba0dda7989c840971860addaeaa75a8c83 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/moc/generator.cpp6
-rw-r--r--src/tools/moc/moc.cpp8
2 files changed, 13 insertions, 1 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index f030bc8918..0e8ba0bb72 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -1315,6 +1315,12 @@ void Generator::generateStaticMetacall()
if (cdef->enumDeclarations.value(p.type, false)) {
fprintf(out, " case %d: %s%s(QFlag(*reinterpret_cast<int*>(_v))); break;\n",
propindex, prefix.constData(), p.write.constData());
+ } else if (p.write == "default") {
+ fprintf(out, " case %d: {\n", propindex);
+ fprintf(out, " %s%s().setValue(*reinterpret_cast< %s*>(_v));\n",
+ prefix.constData(), p.bind.constData(), p.type.constData());
+ fprintf(out, " break;\n");
+ fprintf(out, " }\n");
} else if (!p.write.isEmpty()) {
fprintf(out, " case %d: %s%s(*reinterpret_cast< %s*>(_v)); break;\n",
propindex, prefix.constData(), p.write.constData(), p.type.constData());
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index a14f0c1ccd..8a5abd3020 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -1301,7 +1301,7 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef)
error(1);
} else if (test(DEFAULT)) {
v = lexem();
- if (l != "READ")
+ if (l != "READ" && l != "WRITE")
error(1);
} else {
next(IDENTIFIER);
@@ -1387,6 +1387,12 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef)
propDef.read = "";
warning(msg.constData());
}
+ if (propDef.write == "default" && propDef.bind.isNull()) {
+ const QByteArray msg = "Property declaration " + propDef.name
+ + " is not BINDable but default-WRITEable. WRITE will be ignored.";
+ propDef.write = "";
+ warning(msg.constData());
+ }
}
void Moc::parseProperty(ClassDef *def)