diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-10-31 14:51:13 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-11-10 15:00:11 +0100 |
commit | 7b67d4061974de01eb5387199fe18e67a400545f (patch) | |
tree | 66231ec93d5d9a08b90c86313724c04c44c04e31 /src/qml/qml/qqmlcomponent_p.h | |
parent | f086d452503a9e3703484921939593f7ff35cd47 (diff) |
Required properties: Use pointers instead of references
This allows for a more natural handling of the case where there are no
required properties, and will enable further refactoring of
ConstructionState.
Unfortunately, we lack a way to mark pointers as always non-null in Qt,
else we could mark all required property pointers originating from
QQmlObjectCreatorSharedState as such.
Change-Id: Icaccb27654130fb57daf924bb44a70a5cf114fed
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlcomponent_p.h')
-rw-r--r-- | src/qml/qml/qqmlcomponent_p.h | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h index e61fd1ca69..064b609b19 100644 --- a/src/qml/qml/qqmlcomponent_p.h +++ b/src/qml/qml/qqmlcomponent_p.h @@ -47,8 +47,8 @@ public: QObject *beginCreate(QQmlRefPointer<QQmlContextData>); void completeCreate(); - void initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext, const QV4::Value &valuemap, QObject *toCreate, RequiredProperties &requiredProperties); - static void setInitialProperties(QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &o, const QV4::Value &v, RequiredProperties &requiredProperties, QObject *createdComponent); + void initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext, const QV4::Value &valuemap, QObject *toCreate, RequiredProperties *requiredProperties); + static void setInitialProperties(QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &o, const QV4::Value &v, RequiredProperties *requiredProperties, QObject *createdComponent); static QQmlError unsetRequiredPropertyToQQmlError(const RequiredPropertyInfo &unsetRequiredProperty); virtual void incubateObject( @@ -99,25 +99,27 @@ public: \internal A list of pending required properties that need to be set in order for object construction to be successful. */ - RequiredProperties &requiredProperties() { + RequiredProperties *requiredProperties() { if (hasCreator()) return m_creator->requiredProperties(); else - return m_requiredProperties; + return &m_requiredProperties; } void addPendingRequiredProperty(const QQmlPropertyData *propData, const RequiredPropertyInfo &info) { - requiredProperties().insert(propData, info); + Q_ASSERT(requiredProperties()); + requiredProperties()->insert(propData, info); } bool hasUnsetRequiredProperties() const { - return !const_cast<ConstructionState *>(this)->requiredProperties().isEmpty(); + return !const_cast<ConstructionState *>(this)->requiredProperties()->isEmpty(); } void clearRequiredProperties() { - requiredProperties().clear(); + if (auto reqProps = requiredProperties()) + reqProps->clear(); } @@ -167,8 +169,7 @@ public: static void completeDeferred(QQmlEnginePrivate *enginePriv, DeferredState *deferredState); static void complete(QQmlEnginePrivate *enginePriv, ConstructionState *state); - static QQmlProperty removePropertyFromRequired( - QObject *createdComponent, const QString &name, RequiredProperties &requiredProperties, + static QQmlProperty removePropertyFromRequired(QObject *createdComponent, const QString &name, RequiredProperties *requiredProperties, QQmlEngine *engine, bool *wasInRequiredProperties = nullptr); QQmlEngine *engine; |