1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qqmlpropertycache_p.h"
44 #include "qqmlengine_p.h"
45 #include "qqmlbinding_p.h"
46 #include <private/qv8engine_p.h>
48 #include <private/qmetaobject_p.h>
49 #include <private/qqmlaccessors_p.h>
51 #include <QtCore/qdebug.h>
53 #include <ctype.h> // for toupper
55 Q_DECLARE_METATYPE(QJSValue)
56 Q_DECLARE_METATYPE(QQmlV8Handle);
60 #define Q_INT16_MAX 32767
62 class QQmlPropertyCacheMethodArguments
65 QQmlPropertyCacheMethodArguments *next;
69 // Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
71 static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p)
73 QQmlPropertyData::Flags flags;
76 flags |= QQmlPropertyData::IsConstant;
78 flags |= QQmlPropertyData::IsWritable;
80 flags |= QQmlPropertyData::IsResettable;
82 flags |= QQmlPropertyData::IsFinal;
84 flags |= QQmlPropertyData::IsEnumType;
89 // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
91 static QQmlPropertyData::Flags flagsForPropertyType(int propType, QQmlEngine *engine)
93 Q_ASSERT(propType != -1);
95 QQmlPropertyData::Flags flags;
97 if (propType == QMetaType::QObjectStar || propType == QMetaType::QWidgetStar) {
98 flags |= QQmlPropertyData::IsQObjectDerived;
99 } else if (propType == QMetaType::QVariant) {
100 flags |= QQmlPropertyData::IsQVariant;
101 } else if (propType < (int)QVariant::UserType) {
102 } else if (propType == qMetaTypeId<QQmlBinding *>()) {
103 flags |= QQmlPropertyData::IsQmlBinding;
104 } else if (propType == qMetaTypeId<QJSValue>()) {
105 flags |= QQmlPropertyData::IsQJSValue;
106 } else if (propType == qMetaTypeId<QQmlV8Handle>()) {
107 flags |= QQmlPropertyData::IsV8Handle;
109 QQmlMetaType::TypeCategory cat =
110 engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType)
111 : QQmlMetaType::typeCategory(propType);
113 if (cat == QQmlMetaType::Object)
114 flags |= QQmlPropertyData::IsQObjectDerived;
115 else if (cat == QQmlMetaType::List)
116 flags |= QQmlPropertyData::IsQList;
122 static int metaObjectSignalCount(const QMetaObject *metaObject)
125 for (const QMetaObject *obj = metaObject; obj; obj = obj->superClass())
126 signalCount += QMetaObjectPrivate::get(obj)->signalCount;
130 QQmlPropertyData::Flags
131 QQmlPropertyData::flagsForProperty(const QMetaProperty &p, QQmlEngine *engine)
133 return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
136 void QQmlPropertyData::lazyLoad(const QMetaProperty &p, QQmlEngine *engine)
140 coreIndex = p.propertyIndex();
141 notifyIndex = p.notifySignalIndex();
142 Q_ASSERT(p.revision() <= Q_INT16_MAX);
143 revision = p.revision();
145 flags = fastFlagsForProperty(p);
148 if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
150 flags |= QQmlPropertyData::IsQObjectDerived;
151 } else if (type == QMetaType::QVariant) {
153 flags |= QQmlPropertyData::IsQVariant;
154 } else if (type == QVariant::UserType || type == -1) {
155 propTypeName = p.typeName();
156 flags |= QQmlPropertyData::NotFullyResolved;
162 void QQmlPropertyData::load(const QMetaProperty &p, QQmlEngine *engine)
164 propType = p.userType();
165 coreIndex = p.propertyIndex();
166 notifyIndex = p.notifySignalIndex();
167 flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
168 Q_ASSERT(p.revision() <= Q_INT16_MAX);
169 revision = p.revision();
172 void QQmlPropertyData::load(const QMetaMethod &m)
174 coreIndex = m.methodIndex();
177 if (m.methodType() == QMetaMethod::Signal)
179 propType = m.returnType();
181 if (m.parameterCount()) {
182 flags |= HasArguments;
183 if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
184 flags |= IsV8Function;
188 Q_ASSERT(m.revision() <= Q_INT16_MAX);
189 revision = m.revision();
192 void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
194 coreIndex = m.methodIndex();
197 if (m.methodType() == QMetaMethod::Signal)
199 propType = QVariant::Invalid;
201 const char *returnType = m.typeName();
202 if (returnType && *returnType) {
203 propTypeName = returnType;
204 flags |= NotFullyResolved;
207 if (m.parameterCount()) {
208 flags |= HasArguments;
209 if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
210 flags |= IsV8Function;
214 Q_ASSERT(m.revision() <= Q_INT16_MAX);
215 revision = m.revision();
219 Creates a new empty QQmlPropertyCache.
221 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e)
222 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
223 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
229 Creates a new QQmlPropertyCache of \a metaObject.
231 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e, const QMetaObject *metaObject)
232 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
233 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
236 Q_ASSERT(metaObject);
238 update(engine, metaObject);
241 QQmlPropertyCache::~QQmlPropertyCache()
245 QQmlPropertyCacheMethodArguments *args = argumentsCache;
247 QQmlPropertyCacheMethodArguments *next = args->next;
252 // We must clear this prior to releasing the parent incase it is a
255 if (parent) parent->release();
260 void QQmlPropertyCache::destroy()
262 Q_ASSERT(engine || constructor.IsEmpty());
263 if (constructor.IsEmpty())
266 QQmlEnginePrivate::deleteInEngineThread(engine, this);
269 // This is inherited from QQmlCleanup, so it should only clear the things
270 // that are tied to the specific QQmlEngine.
271 void QQmlPropertyCache::clear()
273 qPersistentDispose(constructor);
277 QQmlPropertyCache *QQmlPropertyCache::copy(int reserve)
279 QQmlPropertyCache *cache = new QQmlPropertyCache(engine);
280 cache->parent = this;
281 cache->parent->addref();
282 cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
283 cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
284 cache->signalHanderIndexCacheStart = signalHandlerIndexCache.count() + signalHanderIndexCacheStart;
285 cache->stringCache.linkAndReserve(stringCache, reserve);
286 cache->allowedRevisionCache = allowedRevisionCache;
287 cache->metaObject = metaObject;
289 // We specifically do *NOT* copy the constructor
294 QQmlPropertyCache *QQmlPropertyCache::copy()
300 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
301 QQmlPropertyData::Flag propertyFlags,
302 QQmlPropertyData::Flag methodFlags,
303 QQmlPropertyData::Flag signalFlags)
305 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
309 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
311 QQmlPropertyData::Flag propertyFlags,
312 QQmlPropertyData::Flag methodFlags,
313 QQmlPropertyData::Flag signalFlags)
315 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
317 // Reserve enough space in the name hash for all the methods (including signals), all the
318 // signal handlers and all the properties. This assumes no name clashes, but this is the
320 QQmlPropertyCache *rv = copy(QMetaObjectPrivate::get(metaObject)->methodCount +
321 QMetaObjectPrivate::get(metaObject)->signalCount +
322 QMetaObjectPrivate::get(metaObject)->propertyCount);
324 rv->append(engine, metaObject, revision, propertyFlags, methodFlags, signalFlags);
329 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
330 QQmlPropertyData::Flag propertyFlags,
331 QQmlPropertyData::Flag methodFlags,
332 QQmlPropertyData::Flag signalFlags)
334 append(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
337 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
339 QQmlPropertyData::Flag propertyFlags,
340 QQmlPropertyData::Flag methodFlags,
341 QQmlPropertyData::Flag signalFlags)
344 Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache
346 this->metaObject = metaObject;
348 bool dynamicMetaObject = isDynamicMetaObject(metaObject);
350 allowedRevisionCache.append(0);
352 int methodCount = metaObject->methodCount();
353 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
354 int signalCount = metaObjectSignalCount(metaObject);
355 int classInfoCount = QMetaObjectPrivate::get(metaObject)->classInfoCount;
357 QQmlAccessorProperties::Properties accessorProperties;
359 // Special case QObject as we don't want to add a qt_HasQmlAccessors classinfo to it
360 if (metaObject == &QObject::staticMetaObject) {
361 accessorProperties = QQmlAccessorProperties::properties(metaObject);
362 } else if (classInfoCount) {
363 int classInfoOffset = metaObject->classInfoOffset();
364 bool hasFastProperty = false;
365 for (int ii = 0; ii < classInfoCount; ++ii) {
366 int idx = ii + classInfoOffset;
368 if (0 == qstrcmp(metaObject->classInfo(idx).name(), "qt_HasQmlAccessors")) {
369 hasFastProperty = true;
374 if (hasFastProperty) {
375 accessorProperties = QQmlAccessorProperties::properties(metaObject);
376 if (accessorProperties.count == 0)
377 qFatal("QQmlPropertyCache: %s has FastProperty class info, but has not "
378 "installed property accessors", metaObject->className());
381 accessorProperties = QQmlAccessorProperties::properties(metaObject);
382 if (accessorProperties.count != 0)
383 qFatal("QQmlPropertyCache: %s has fast property accessors, but is missing "
384 "FastProperty class info", metaObject->className());
389 // qMax(defaultMethods, methodOffset) to block the signals and slots of QObject::staticMetaObject
390 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
391 int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
392 int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
394 // update() should have reserved enough space in the vector that this doesn't cause a realloc
395 // and invalidate the stringCache.
396 methodIndexCache.resize(methodCount - methodIndexCacheStart);
397 signalHandlerIndexCache.resize(signalCount - signalHanderIndexCacheStart);
398 int signalHandlerIndex = signalOffset;
399 for (int ii = methodOffset; ii < methodCount; ++ii) {
400 QMetaMethod m = metaObject->method(ii);
401 if (m.access() == QMetaMethod::Private)
404 // Extract method name
405 const char *signature;
406 if (QMetaObjectPrivate::get(metaObject)->revision >= 7) {
407 // Safe to use the raw name pointer
408 signature = m.name().constData();
410 // Safe to use the raw signature pointer
411 signature = m.methodSignature().constData();
413 const char *cptr = signature;
415 while (*cptr && *cptr != '(') {
416 Q_ASSERT(*cptr != 0);
417 utf8 |= *cptr & 0x80;
421 QQmlPropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
422 QQmlPropertyData *sigdata = 0;
426 if (data->isSignal())
427 data->flags |= signalFlags;
429 data->flags |= methodFlags;
431 if (!dynamicMetaObject)
432 data->flags |= QQmlPropertyData::IsDirect;
434 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
435 data->metaObjectOffset = allowedRevisionCache.count() - 1;
437 if (data->isSignal()) {
438 sigdata = &signalHandlerIndexCache[signalHandlerIndex - signalHanderIndexCacheStart];
440 sigdata->flags |= QQmlPropertyData::IsSignalHandler;
443 QQmlPropertyData *old = 0;
446 QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
447 if (QQmlPropertyData **it = stringCache.value(methodName))
449 stringCache.insert(methodName, data);
451 if (data->isSignal()) {
452 QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1));
453 stringCache.insert(on, sigdata);
454 ++signalHandlerIndex;
457 QHashedCStringRef methodName(signature, cptr - signature);
458 if (QQmlPropertyData **it = stringCache.value(methodName))
460 stringCache.insert(methodName, data);
462 if (data->isSignal()) {
463 int length = methodName.length();
465 QVarLengthArray<char, 128> str(length+3);
468 str[2] = toupper(signature[0]);
470 memcpy(&str[3], &signature[1], length - 1);
471 str[length + 2] = '\0';
473 QHashedString on(QString::fromLatin1(str.data()));
474 stringCache.insert(on, sigdata);
475 ++signalHandlerIndex;
480 // We only overload methods in the same class, exactly like C++
481 if (old->isFunction() && old->coreIndex >= methodOffset)
482 data->flags |= QQmlPropertyData::IsOverload;
483 data->overrideIndexIsProperty = !old->isFunction();
484 data->overrideIndex = old->coreIndex;
488 int propCount = metaObject->propertyCount();
489 int propOffset = metaObject->propertyOffset();
491 // update() should have reserved enough space in the vector that this doesn't cause a realloc
492 // and invalidate the stringCache.
493 propertyIndexCache.resize(propCount - propertyIndexCacheStart);
494 for (int ii = propOffset; ii < propCount; ++ii) {
495 QMetaProperty p = metaObject->property(ii);
496 if (!p.isScriptable())
499 const char *str = p.name();
501 const char *cptr = str;
503 utf8 |= *cptr & 0x80;
507 QQmlPropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
509 data->lazyLoad(p, engine);
510 data->flags |= propertyFlags;
512 if (!dynamicMetaObject)
513 data->flags |= QQmlPropertyData::IsDirect;
515 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
516 data->metaObjectOffset = allowedRevisionCache.count() - 1;
518 QQmlPropertyData *old = 0;
521 QHashedString propName(QString::fromUtf8(str, cptr - str));
522 if (QQmlPropertyData **it = stringCache.value(propName))
524 stringCache.insert(propName, data);
526 QHashedCStringRef propName(str, cptr - str);
527 if (QQmlPropertyData **it = stringCache.value(propName))
529 stringCache.insert(propName, data);
532 QQmlAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
534 // Fast properties may not be overrides or revisioned
535 Q_ASSERT(accessorProperty == 0 || (old == 0 && data->revision == 0));
537 if (accessorProperty) {
538 data->flags |= QQmlPropertyData::HasAccessors;
539 data->accessors = accessorProperty->accessors;
540 data->accessorData = accessorProperty->data;
542 data->overrideIndexIsProperty = !old->isFunction();
543 data->overrideIndex = old->coreIndex;
548 void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
550 Q_ASSERT(data->notFullyResolved());
552 data->propType = QMetaType::type(data->propTypeName);
554 if (!data->isFunction())
555 data->flags |= flagsForPropertyType(data->propType, engine);
557 data->flags &= ~QQmlPropertyData::NotFullyResolved;
560 void QQmlPropertyCache::updateRecur(QQmlEngine *engine, const QMetaObject *metaObject)
565 updateRecur(engine, metaObject->superClass());
567 append(engine, metaObject);
570 void QQmlPropertyCache::update(QQmlEngine *engine, const QMetaObject *metaObject)
573 Q_ASSERT(metaObject);
574 Q_ASSERT(stringCache.isEmpty());
576 // Preallocate enough space in the index caches for all the properties/methods/signals that
577 // are not cached in a parent cache so that the caches never need to be reallocated as this
578 // would invalidate pointers stored in the stringCache.
579 int pc = metaObject->propertyCount();
580 int mc = metaObject->methodCount();
581 int sc = metaObjectSignalCount(metaObject);
582 propertyIndexCache.reserve(pc - propertyIndexCacheStart);
583 methodIndexCache.reserve(mc - methodIndexCacheStart);
584 signalHandlerIndexCache.reserve(sc - signalHanderIndexCacheStart);
586 // Reserve enough space in the stringCache for all properties/methods/signals including those
587 // cached in a parent cache.
588 stringCache.reserve(pc + mc + sc);
590 updateRecur(engine,metaObject);
594 QQmlPropertyCache::property(int index) const
596 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
599 if (index < propertyIndexCacheStart)
600 return parent->property(index);
602 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
603 if (rv->notFullyResolved()) resolve(rv);
608 QQmlPropertyCache::method(int index) const
610 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
613 if (index < methodIndexCacheStart)
614 return parent->method(index);
616 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
617 if (rv->notFullyResolved()) resolve(rv);
622 QQmlPropertyCache::property(const QHashedStringRef &str) const
624 QQmlPropertyData **rv = stringCache.value(str);
625 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
630 QQmlPropertyCache::property(const QHashedCStringRef &str) const
632 QQmlPropertyData **rv = stringCache.value(str);
633 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
638 QQmlPropertyCache::property(const QString &str) const
640 QQmlPropertyData **rv = stringCache.value(str);
641 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
645 QString QQmlPropertyData::name(QObject *object)
650 return name(object->metaObject());
653 QString QQmlPropertyData::name(const QMetaObject *metaObject)
655 if (!metaObject || coreIndex == -1)
658 if (flags & IsFunction) {
659 QMetaMethod m = metaObject->method(coreIndex);
661 return QString::fromUtf8(m.name().constData());
663 QMetaProperty p = metaObject->property(coreIndex);
664 return QString::fromUtf8(p.name());
668 QStringList QQmlPropertyCache::propertyNames() const
671 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
672 keys.append(iter.key());
676 static int EnumType(const QMetaObject *meta, const QByteArray &str)
680 int scopeIdx = str.lastIndexOf("::");
681 if (scopeIdx != -1) {
682 scope = str.left(scopeIdx);
683 name = str.mid(scopeIdx + 2);
687 for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
688 QMetaEnum m = meta->enumerator(i);
689 if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
690 return QVariant::Int;
692 return QVariant::Invalid;
695 // Returns an array of the arguments for method \a index. The first entry in the array
696 // is the number of arguments.
697 int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
698 QVarLengthArray<int, 9> &dummy,
699 QByteArray *unknownTypeError)
701 Q_ASSERT(object && index >= 0);
703 QQmlData *ddata = QQmlData::get(object, false);
705 if (ddata && ddata->propertyCache) {
706 typedef QQmlPropertyCacheMethodArguments A;
708 QQmlPropertyCache *c = ddata->propertyCache;
709 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
711 while (index < c->methodIndexCacheStart)
714 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
717 return static_cast<A *>(rv->arguments)->arguments;
719 const QMetaObject *metaObject = object->metaObject();
720 QMetaMethod m = metaObject->method(index);
722 int argc = m.parameterCount();
723 A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
724 args->arguments[0] = argc;
725 QList<QByteArray> argTypeNames; // Only loaded if needed
727 for (int ii = 0; ii < argc; ++ii) {
728 int type = m.parameterType(ii);
729 if (type == QVariant::Invalid) {
730 if (argTypeNames.isEmpty())
731 argTypeNames = m.parameterTypes();
732 type = EnumType(object->metaObject(), argTypeNames.at(ii));
734 if (type == QVariant::Invalid) {
735 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
739 args->arguments[ii + 1] = type;
742 rv->arguments = args;
743 args->next = c->argumentsCache;
744 c->argumentsCache = args;
745 return static_cast<A *>(rv->arguments)->arguments;
748 QMetaMethod m = object->metaObject()->method(index);
749 int argc = m.parameterCount();
750 dummy.resize(argc + 1);
752 QList<QByteArray> argTypeNames; // Only loaded if needed
754 for (int ii = 0; ii < argc; ++ii) {
755 int type = m.parameterType(ii);
756 if (type == QVariant::Invalid) {
757 if (argTypeNames.isEmpty())
758 argTypeNames = m.parameterTypes();
759 type = EnumType(object->metaObject(), argTypeNames.at(ii));
761 if (type == QVariant::Invalid) {
762 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
765 dummy[ii + 1] = type;
772 QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject,
773 const QString &property)
775 Q_ASSERT(metaObject);
779 const QMetaObject *cmo = metaObject;
780 const QByteArray propertyName = property.toUtf8();
782 int idx = cmo->indexOfProperty(propertyName);
784 QMetaProperty p = cmo->property(idx);
785 if (p.isScriptable()) {
789 while (cmo && cmo->propertyOffset() >= idx)
790 cmo = cmo->superClass();
798 int methodCount = metaObject->methodCount();
799 int defaultMethods = QObject::staticMetaObject.methodCount();
800 for (int ii = methodCount - 1; ii >= defaultMethods; --ii) {
801 // >=defaultMethods to block the signals and slots of QObject::staticMetaObject
802 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
803 QMetaMethod m = metaObject->method(ii);
804 if (m.access() == QMetaMethod::Private)
806 QString methodName = QString::fromUtf8(m.name().constData());
808 if (methodName == property) {
817 inline const QString &qQmlPropertyCacheToString(const QString &string)
822 inline QString qQmlPropertyCacheToString(const QHashedV8String &string)
824 return QV8Engine::toStringStatic(string.string());
829 qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj,
830 const T &name, QQmlPropertyData &local)
832 QQmlPropertyCache *cache = 0;
835 QQmlData *ddata = QQmlData::get(obj);
837 if (ddata && ddata->propertyCache) {
838 cache = ddata->propertyCache;
840 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
841 cache = ep->cache(obj);
843 ddata = QQmlData::get(obj, true);
845 ddata->propertyCache = cache;
850 QQmlPropertyData *rv = 0;
853 rv = cache->property(name);
855 local = qQmlPropertyCacheCreate(obj->metaObject(),
856 qQmlPropertyCacheToString(name));
865 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
866 const QHashedV8String &name, QQmlPropertyData &local)
868 return qQmlPropertyCacheProperty<QHashedV8String>(engine, obj, name, local);
872 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
873 const QString &name, QQmlPropertyData &local)
875 return qQmlPropertyCacheProperty<QString>(engine, obj, name, local);
878 static inline const QMetaObjectPrivate *priv(const uint* data)
879 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
881 bool QQmlPropertyCache::isDynamicMetaObject(const QMetaObject *mo)
883 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;