From d51c007ecc8aa6256cb95cf3992e5ac34a70fa3f Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 26 Feb 2020 16:04:23 +0100 Subject: Encapsulate QQmlContextData This class is not a private detail of QQmlContext. And it is incredibly hard to see who owns what in there. Let's add some civilization ... We enforce refcounting for QQmlContextData across the code base, with two exceptions: 1. QQmlContextPrivate may or may not own its QQmlContextData. 2. We may request a QQmlContextData owned by its parent QQmlContextData. For these two cases we keep flags in QQmlContextData and when the respective field (m_parent or m_publicContext) is reset, we release() once. Furthermore, QQmlContextData and QQmlGuardedContextData are moved to their own files, in order to de-spaghettify qqmlcontext_p.h and qqmlcontext.cpp. When the QQmlEngine is deleted, any QQmlComponents drop their object creators now, in order to release any context data held by those. Before, the context data would be deleted, but the object creators would retain the dangling pointer. [ChangeLog][QML][Important Behavior Changes] QQmlContext::baseUrl() does what the documentation says now: It prefers explicitly set baseUrls over compilation unit URLs. Only if no baseUrl is set, the CU's URL is returned. It used to prefer the CU's URL. Change-Id: Ieeb5dcb07b45d891526191321386d5443b8f5738 Reviewed-by: Fabian Kosmale --- src/qml/qml/qqmlpropertycache.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/qml/qml/qqmlpropertycache.cpp') diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index aa171c1c29..4b17760f8e 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -753,7 +753,9 @@ void QQmlPropertyCache::invalidate(const QMetaObject *metaObject) } } -QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, QObject *object, QQmlContextData *context) const +QQmlPropertyData *QQmlPropertyCache::findProperty( + StringCache::ConstIterator it, QObject *object, + const QQmlRefPointer &context) const { QQmlData *data = (object ? QQmlData::get(object) : nullptr); const QQmlVMEMetaObject *vmemo = nullptr; @@ -766,11 +768,11 @@ QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, namespace { -inline bool contextHasNoExtensions(QQmlContextData *context) +inline bool contextHasNoExtensions(const QQmlRefPointer &context) { // This context has no extension if its parent is the engine's rootContext, // which has children but no imports - return (!context->parent || !context->parent->imports); + return (!context->parent() || !context->parent()->imports()); } inline int maximumIndexForProperty(QQmlPropertyData *prop, const int methodCount, const int signalCount, const int propertyCount) @@ -782,7 +784,9 @@ inline int maximumIndexForProperty(QQmlPropertyData *prop, const int methodCount } -QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, const QQmlVMEMetaObject *vmemo, QQmlContextData *context) const +QQmlPropertyData *QQmlPropertyCache::findProperty( + StringCache::ConstIterator it, const QQmlVMEMetaObject *vmemo, + const QQmlRefPointer &context) const { StringCache::ConstIterator end = stringCache.end(); @@ -796,7 +800,7 @@ QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, if (vmemo && context && !contextHasNoExtensions(context)) { // Find the meta-object that corresponds to the supplied context do { - if (vmemo->ctxt == context) + if (vmemo->ctxt.contextData().data() == context.data()) break; vmemo = vmemo->parentVMEMetaObject(); @@ -1007,7 +1011,7 @@ static inline QByteArray qQmlPropertyCacheToString(const QV4::String *string) template QQmlPropertyData * qQmlPropertyCacheProperty(QJSEngine *engine, QObject *obj, T name, - QQmlContextData *context, QQmlPropertyData &local) + const QQmlRefPointer &context, QQmlPropertyData &local) { QQmlPropertyCache *cache = nullptr; @@ -1040,21 +1044,21 @@ qQmlPropertyCacheProperty(QJSEngine *engine, QObject *obj, T name, QQmlPropertyData * QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QV4::String *name, - QQmlContextData *context, QQmlPropertyData &local) + const QQmlRefPointer &context, QQmlPropertyData &local) { return qQmlPropertyCacheProperty(engine, obj, name, context, local); } QQmlPropertyData * QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QStringRef &name, - QQmlContextData *context, QQmlPropertyData &local) + const QQmlRefPointer &context, QQmlPropertyData &local) { return qQmlPropertyCacheProperty(engine, obj, name, context, local); } QQmlPropertyData * QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QLatin1String &name, - QQmlContextData *context, QQmlPropertyData &local) + const QQmlRefPointer &context, QQmlPropertyData &local) { return qQmlPropertyCacheProperty(engine, obj, name, context, local); } -- cgit v1.2.3