diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-06-24 08:25:17 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-06-25 14:11:56 +0200 |
commit | 844e4f7b982f2622dbdce0c4b70775d5bd17f043 (patch) | |
tree | 9e08cb29125b2b3ef5198b98ad70ea4841198089 /src/tools | |
parent | b20c7df63aec36cb3cb871e4b898b0e684dcb59a (diff) |
moc: Fix QProperty code generation
This addresses two issues:
1. The generated code for QNotifiedProperty<T, ...> was broken when T is
a pointer. Notably, const S* & is not a constant reference to S*.
This is addressed by consistently using T const& instead of const T&.
2. The Q_PRIVATE_QPROPERTY approach assumed that the property name and
the getter are equal. This does break when they are not, and we are
unable to change either of them due to API compatibility concerns. An
example of this would be QQuickItem's parent property with a
parentItem getter. Therefore, we now allow the usage of NAME to
override the name of the property.
Change-Id: Idf2e85576c74371b5b0f6db15dbe6f2d17c5e33d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/moc/generator.cpp | 8 | ||||
-rw-r--r-- | src/tools/moc/moc.cpp | 7 | ||||
-rw-r--r-- | src/tools/moc/moc.h | 2 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 0d3a763a48..fcf6b37876 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1419,7 +1419,7 @@ void Generator::generateStaticMetacall() prefix += p.inPrivateClass + "->"; } fprintf(out, " case %d: observer->setSource(%s%s); break;\n", - propindex, prefix.constData(), p.name.constData()); + propindex, prefix.constData(), p.qpropertyname.isEmpty() ? p.name.constData() : p.qpropertyname.constData()); } fprintf(out, " default: break;\n"); fprintf(out, " }\n"); @@ -1447,7 +1447,7 @@ void Generator::generateStaticMetacall() else objectAccessor.clear(); fprintf(out, " case %d: %s%s.setBinding(%s*reinterpret_cast<QPropertyBinding<%s> *>(_a[0])); break;\n", - propindex, prefix.constData(), p.name.constData(), objectAccessor.constData(), p.type.constData()); + propindex, prefix.constData(), p.qpropertyname.isEmpty() ? p.name.constData() : p.qpropertyname.constData(), objectAccessor.constData(), p.type.constData()); } fprintf(out, " default: break;\n"); fprintf(out, " }\n"); @@ -1557,7 +1557,7 @@ void Generator::generateQPropertyApi() fprintf(out, "}\n"); // property value setter - fprintf(out, "\nvoid %s::_qt_property_api_%s::setValue(const %s &value)\n{\n", + fprintf(out, "\nvoid %s::_qt_property_api_%s::setValue(%s const &value)\n{\n", cdef->qualified.constData(), property.name.constData(), property.type.name.constData()); @@ -1629,7 +1629,7 @@ void Generator::generateQPropertyApi() fprintf(out, "}\n"); // property setter function - fprintf(out, "\nvoid %s::%s(const %s &value)\n{\n", + fprintf(out, "\nvoid %s::%s(%s const& value)\n{\n", cdef->qualified.constData(), property.setter.constData(), property.type.name.constData()); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 5a1f0afab6..e31bdfbb15 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1317,6 +1317,12 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef) } else if(l[0] == 'F' && l == "FINAL") { propDef.final = true; continue; + } else if (l[0] == 'N' && l == "NAME") { + if (!propDef.isQProperty) + error(1); + next(IDENTIFIER); + propDef.name = lexem(); + continue; } else if (l[0] == 'R' && l == "REQUIRED") { propDef.required = true; continue; @@ -1525,6 +1531,7 @@ void Moc::parsePrivateQProperty(ClassDef *def) PropertyDef propDef; propDef.name = name; + propDef.qpropertyname = name; propDef.type = type.name; propDef.read = name + ".value"; propDef.write = name + ".setValue"; diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 0f05685327..549b3cdd39 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -132,7 +132,7 @@ struct PropertyDef return (s == write); } - QByteArray name, type, member, read, write, reset, designable, scriptable, stored, user, notify, inPrivateClass; + QByteArray name, type, member, read, write, reset, designable, scriptable, stored, user, notify, inPrivateClass, qpropertyname; int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class enum Specification { ValueSpec, ReferenceSpec, PointerSpec }; Specification gspec = ValueSpec; |