diff options
author | Luca Di Sera <[email protected]> | 2024-03-20 16:04:27 +0100 |
---|---|---|
committer | Luca Di Sera <[email protected]> | 2024-03-21 21:00:18 +0100 |
commit | 9a67465e9e5fa4645a459b3ef9be6dbd53c272aa (patch) | |
tree | 7542d2aa38644950fe667862364e8fcba32b9e27 | |
parent | d1241024e6fe20445a1cd843969ec9f518357fb8 (diff) |
qmltc: Ensure usage of generated setters in `PropertyInitializer`
When `qmltc` compiles a QML type to C++, it generates a proxy object for
the compiled type, `PropertyInitializer`, that knows how to set the
top-level property of the component.
A user can then pass a call-back to the constructor for the compiled
type and use an instance of the generated `PropertyInitializer` to set
the initial values for the top-level properties of the component.
For each top-level property, the generated `PropertyInitializer`
generates a setter.
Based on various parameters, the generated setter can have a different
body.
Generally, the generated setter will prefer calling back to the
component setter for the properties when that is available.
When that is not the case, the generated setter would fall-back to a
more general approach based on `QObject::setProperty`, which has
additional overhead.
This second approach will currently be chosen, when generating the
setter for an owned property of the compiled type.
While `qmltc` will generate a typed setter for those properties, on the
C++ side, at the
point where `PropertyInitializer` is compiled, the inspected owned properties,
that come from the QML side, will not have a write accessor, which in
turn makes the generated code fall-back to the more general
implementation for the setter of those properties.
To ensure that the generated setters for `PropertyInitializer` use a
write accessor when present, `compilePropertyInitializer`, which takes
care of producing the code for the generated `PropertyInitializer`, was
modified to special case the generation of the setter for properties
that are owned by the compiled type, ensuring that the generated setter
will be used to set the initial value for the property.
Change-Id: I0c34d6dd9d85a613d1e8909e94a584bf976a009f
Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp index f632748241..9d7062cc17 100644 --- a/tools/qmltc/qmltccompiler.cpp +++ b/tools/qmltc/qmltccompiler.cpp @@ -450,6 +450,9 @@ static void compilePropertyInitializer(QmltcType ¤t, const QQmlJSScope::Co ) { compiledSetter.body << u"%1.%2().setValue(%3_);"_s.arg( current.propertyInitializer.component.name, property.bindable(), name); + } else if (type->hasOwnProperty(name)) { + compiledSetter.body << u"%1.%2(%3_);"_s.arg( + current.propertyInitializer.component.name, QmltcPropertyData(property).write, name); } else if (property.write().isEmpty() || isFromExtension(property, type)) { // We can end here if a WRITE method is not available or // if the method is available but not in this scope, so |