From 85fd1c48f32c266168c2e3d8195f81e59a7dc5e6 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 22 Oct 2012 14:16:30 +0200 Subject: [PATCH] Adding invalidate function to QQmlPropertyCache This is required for tooling to update a QMetaObject inside a running QQmlEngine. Change-Id: I26d3aeed57d39c361c150261c4e1a84094e6f657 Reviewed-by: Christiaan Janssen --- src/qml/qml/qqmlpropertycache.cpp | 33 +++++++++++++++++++++++++++++++++ src/qml/qml/qqmlpropertycache_p.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 431a5be..c1c4a6c 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -849,6 +849,39 @@ void QQmlPropertyCache::update(QQmlEngine *engine, const QMetaObject *metaObject } /*! \internal + invalidates and updates the PropertyCache if the QMetaObject has changed. + This function is used in the tooling to update dynamic properties. +*/ +void QQmlPropertyCache::invalidate(QQmlEngine *engine, const QMetaObject *metaObject) +{ + stringCache.clear(); + propertyIndexCache.clear(); + methodIndexCache.clear(); + signalHandlerIndexCache.clear(); + + _hasPropertyOverrides = false; + argumentsCache = 0; + + int pc = metaObject->propertyCount(); + int mc = metaObject->methodCount(); + int sc = metaObjectSignalCount(metaObject); + int reserve = pc + mc + sc; + + if (parent()) { + propertyIndexCacheStart = parent()->propertyIndexCache.count() + parent()->propertyIndexCacheStart; + methodIndexCacheStart = parent()->methodIndexCache.count() + parent()->methodIndexCacheStart; + signalHandlerIndexCacheStart = parent()->signalHandlerIndexCache.count() + parent()->signalHandlerIndexCacheStart; + stringCache.linkAndReserve(parent()->stringCache, reserve); + append(engine, metaObject, -1); + } else { + propertyIndexCacheStart = 0; + methodIndexCacheStart = 0; + signalHandlerIndexCacheStart = 0; + update(engine, metaObject); + } +} + +/*! \internal \a index MUST be in the signal index range (see QObjectPrivate::signalIndex()). This is different from QMetaMethod::methodIndex(). */ diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 4310e4e..14be990 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -247,6 +247,7 @@ public: virtual ~QQmlPropertyCache(); void update(QQmlEngine *, const QMetaObject *); + void invalidate(QQmlEngine *, const QMetaObject *); QQmlPropertyCache *copy(); -- 2.7.4