summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-04-09 16:04:55 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-30 19:39:19 +0200
commitb480acb3720c0d61c5c69a2b861af63b9d7c9f86 (patch)
tree207d0110dd57a764ad710483bee78c0daa50fcb8 /src/tools
parent382577419a80a8aebaa7ac95682cdec46a487ace (diff)
Allow for private properties to be implemented using QProperty
Recently the moc learned that Q_PROPERTY(int x ...) can mean that "x" is implemented as QProperty and then allows installing bindings, etc. - this works by scanning the same class' members. For our own use of QProperty, we need to place the QProperty member itself into the d-pointer to be able to maintain the ability to add new properties without breaking binary compatibility. That however means that moc can't know that a certain property is backed by QProperty - we don't scan the members of the private class. As a workaround, this change enables the syntax where the property type used in Q_PRIVATE_PROPERTY may be wrapped with QProperty<T>. In addition this patch fixes the compilation of such declared properties by ensuring the accessor prefix (t->$accessor) is applied also for the QProperty related meta call variants. Change-Id: I8fbdc49319048b57f4eb0b65b56daba0459e9598 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/moc/generator.cpp16
-rw-r--r--src/tools/moc/moc.cpp16
2 files changed, 27 insertions, 5 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index c0e1dca748..acb7cdffe9 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -1504,8 +1504,12 @@ void Generator::generateStaticMetacall()
const PropertyDef &p = cdef->propertyList.at(propindex);
if (!p.isQProperty)
continue;
- fprintf(out, " case %d: observer->setSource(_t->%s); break;\n",
- propindex, p.name.constData());
+ QByteArray prefix = "_t->";
+ if (p.inPrivateClass.size()) {
+ prefix += p.inPrivateClass + "->";
+ }
+ fprintf(out, " case %d: observer->setSource(%s%s); break;\n",
+ propindex, prefix.constData(), p.name.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
@@ -1521,8 +1525,12 @@ void Generator::generateStaticMetacall()
const PropertyDef &p = cdef->propertyList.at(propindex);
if (!p.isQProperty)
continue;
- fprintf(out, " case %d: _t->%s.setBinding(*reinterpret_cast<QPropertyBinding<%s> *>(_a[0])); break;\n",
- propindex, p.name.constData(), p.type.constData());
+ QByteArray prefix = "_t->";
+ if (p.inPrivateClass.size()) {
+ prefix += p.inPrivateClass + "->";
+ }
+ fprintf(out, " case %d: %s%s.setBinding(*reinterpret_cast<QPropertyBinding<%s> *>(_a[0])); break;\n",
+ propindex, prefix.constData(), p.name.constData(), p.type.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index edef9d3f04..2444d0db90 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -1228,9 +1228,23 @@ void Moc::createPropertyDef(PropertyDef &propDef)
{
propDef.location = index;
+ const bool isPrivateProperty = !propDef.inPrivateClass.isEmpty();
+ bool typeWrappedInQProperty = false;
+ if (isPrivateProperty) {
+ const int rewind = index;
+ if (test(IDENTIFIER) && lexem() == "QProperty" && test(LANGLE)) {
+ typeWrappedInQProperty = true;
+ propDef.isQProperty = true;
+ } else {
+ index = rewind;
+ }
+ }
+
QByteArray type = parseType().name;
if (type.isEmpty())
error();
+ if (typeWrappedInQProperty)
+ next(RANGLE);
propDef.designable = propDef.scriptable = propDef.stored = "true";
propDef.user = "false";
@@ -1806,7 +1820,7 @@ void Moc::checkProperties(ClassDef *cdef)
definedProperties.insert(p.name);
if (p.read.isEmpty() && p.member.isEmpty()) {
- if (!cdef->qPropertyMembers.contains(p.name)) {
+ if (!cdef->qPropertyMembers.contains(p.name) && !p.isQProperty) {
const int rewind = index;
if (p.location >= 0)
index = p.location;