diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-10-14 08:22:57 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-10-14 08:23:52 (GMT) |
commit | c407d79f79c67f2f2bb84efc93061fd57fe4cf54 (patch) | |
tree | d56dcae60c345acaf5d4e3a0251dde99785b3ec6 /src/declarative/qml | |
parent | 1048ac9f491bf2e79c469d0451e437a1a485bef5 (diff) | |
download | Qt-c407d79f79c67f2f2bb84efc93061fd57fe4cf54.zip Qt-c407d79f79c67f2f2bb84efc93061fd57fe4cf54.tar.gz Qt-c407d79f79c67f2f2bb84efc93061fd57fe4cf54.tar.bz2 |
Correctly splice properties from derived metaobjects together
Task-number: QTBUG-14449
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qdeclarativepropertycache.cpp | 77 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativepropertycache_p.h | 9 |
2 files changed, 28 insertions, 58 deletions
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 9e1ceb8..82fa98f 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -252,7 +252,8 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb } int methodCount = metaObject->methodCount(); - int methodOffset = qMax(2, metaObject->methodOffset()); // 2 to block the destroyed signal + // 3 to block the destroyed signal and the deleteLater() slot + int methodOffset = qMax(3, metaObject->methodOffset()); methodIndexCache.resize(methodCount); for (int ii = methodOffset; ii < methodCount; ++ii) { @@ -268,17 +269,17 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName); - if (stringCache.contains(methodName)) { - stringCache[methodName]->release(); - identifierCache[data->identifier.identifier]->release(); - } - data->load(m); if (m.methodType() == QMetaMethod::Slot || m.methodType() == QMetaMethod::Method) data->flags |= methodFlags; else if (m.methodType() == QMetaMethod::Signal) data->flags |= signalFlags; + if (stringCache.contains(methodName)) { + stringCache[methodName]->release(); + identifierCache[data->identifier.identifier]->release(); + } + methodIndexCache[ii] = data; stringCache.insert(methodName, data); @@ -287,6 +288,16 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb } } +void QDeclarativePropertyCache::updateRecur(QDeclarativeEngine *engine, const QMetaObject *metaObject) +{ + if (!metaObject) + return; + + updateRecur(engine, metaObject->superClass()); + + append(engine, metaObject); +} + void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject) { Q_ASSERT(engine); @@ -295,57 +306,11 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb clear(); - // ### The properties/methods should probably be spliced on a per-metaobject basis - int propCount = metaObject->propertyCount(); - - indexCache.resize(propCount); - for (int ii = propCount - 1; ii >= 0; --ii) { - QMetaProperty p = metaObject->property(ii); - if (!p.isScriptable()) { - indexCache[ii] = 0; - continue; - } - QString propName = QString::fromUtf8(p.name()); + // Optimization to prevent unnecessary reallocation of lists + indexCache.reserve(metaObject->propertyCount()); + methodIndexCache.reserve(metaObject->methodCount()); - RData *data = new RData; - data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); - - data->load(p, engine); - - indexCache[ii] = data; - - if (stringCache.contains(propName)) - continue; - - stringCache.insert(propName, data); - identifierCache.insert(data->identifier.identifier, data); - data->addref(); - data->addref(); - } - - int methodCount = metaObject->methodCount(); - for (int ii = methodCount - 1; ii >= 3; --ii) { // >=3 to block the destroyed signal and deleteLater() slot - QMetaMethod m = metaObject->method(ii); - if (m.access() == QMetaMethod::Private) - continue; - QString methodName = QString::fromUtf8(m.signature()); - - int parenIdx = methodName.indexOf(QLatin1Char('(')); - Q_ASSERT(parenIdx != -1); - methodName = methodName.left(parenIdx); - - if (stringCache.contains(methodName)) - continue; - - RData *data = new RData; - data->identifier = enginePriv->objectClass->createPersistentIdentifier(methodName); - - data->load(m); - - stringCache.insert(methodName, data); - identifierCache.insert(data->identifier.identifier, data); - data->addref(); - } + updateRecur(engine,metaObject); } QDeclarativePropertyCache::Data * diff --git a/src/declarative/qml/qdeclarativepropertycache_p.h b/src/declarative/qml/qdeclarativepropertycache_p.h index 79b126d..922010d 100644 --- a/src/declarative/qml/qdeclarativepropertycache_p.h +++ b/src/declarative/qml/qdeclarativepropertycache_p.h @@ -96,7 +96,7 @@ public: IsVMEFunction = 0x00000400, HasArguments = 0x00000800, IsSignal = 0x00001000, - IsVMESignal = 0x00002000, + IsVMESignal = 0x00002000 }; Q_DECLARE_FLAGS(Flags, Flag) @@ -105,7 +105,10 @@ public: Flags flags; int propType; int coreIndex; - int notifyIndex; + union { + int notifyIndex; // When !IsFunction + int relatedIndex; // When IsFunction + }; static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0); void load(const QMetaProperty &, QDeclarativeEngine *engine = 0); @@ -152,6 +155,8 @@ private: typedef QHash<QString, RData *> StringCache; typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache; + void updateRecur(QDeclarativeEngine *, const QMetaObject *); + QDeclarativeEngine *engine; IndexCache indexCache; IndexCache methodIndexCache; |