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 <private/qqmlengine_p.h>
45 #include <private/qqmlbinding_p.h>
46 #include <private/qqmlvmemetaobject_p.h>
47 #include <private/qv8engine_p.h>
49 #include <private/qmetaobject_p.h>
50 #include <private/qqmlaccessors_p.h>
51 #include <private/qmetaobjectbuilder_p.h>
52 #include <private/qqmlrewrite_p.h>
54 #include <QtCore/qdebug.h>
56 #include <ctype.h> // for toupper
60 // nonstandard extension used : zero-sized array in struct/union.
61 # pragma warning( disable : 4200 )
64 Q_DECLARE_METATYPE(QJSValue)
65 Q_DECLARE_METATYPE(QQmlV8Handle);
69 #define Q_INT16_MAX 32767
71 class QQmlPropertyCacheMethodArguments
74 QQmlPropertyCacheMethodArguments *next;
76 //for signal handler rewrites
77 QString *signalParameterStringForJS;
78 int signalParameterCountForJS:30;
82 QList<QByteArray> *names;
86 // Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
88 static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p)
90 QQmlPropertyData::Flags flags;
93 flags |= QQmlPropertyData::IsConstant;
95 flags |= QQmlPropertyData::IsWritable;
97 flags |= QQmlPropertyData::IsResettable;
99 flags |= QQmlPropertyData::IsFinal;
101 flags |= QQmlPropertyData::IsEnumType;
106 // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
108 static QQmlPropertyData::Flags flagsForPropertyType(int propType, QQmlEngine *engine)
110 Q_ASSERT(propType != -1);
112 QQmlPropertyData::Flags flags;
114 if (propType == QMetaType::QObjectStar) {
115 flags |= QQmlPropertyData::IsQObjectDerived;
116 } else if (propType == QMetaType::QVariant) {
117 flags |= QQmlPropertyData::IsQVariant;
118 } else if (propType < (int)QVariant::UserType) {
119 } else if (propType == qMetaTypeId<QQmlBinding *>()) {
120 flags |= QQmlPropertyData::IsQmlBinding;
121 } else if (propType == qMetaTypeId<QJSValue>()) {
122 flags |= QQmlPropertyData::IsQJSValue;
123 } else if (propType == qMetaTypeId<QQmlV8Handle>()) {
124 flags |= QQmlPropertyData::IsV8Handle;
126 QQmlMetaType::TypeCategory cat =
127 engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType)
128 : QQmlMetaType::typeCategory(propType);
130 if (cat == QQmlMetaType::Object)
131 flags |= QQmlPropertyData::IsQObjectDerived;
132 else if (cat == QQmlMetaType::List)
133 flags |= QQmlPropertyData::IsQList;
139 static int metaObjectSignalCount(const QMetaObject *metaObject)
142 for (const QMetaObject *obj = metaObject; obj; obj = obj->superClass())
143 signalCount += QMetaObjectPrivate::get(obj)->signalCount;
147 QQmlPropertyData::Flags
148 QQmlPropertyData::flagsForProperty(const QMetaProperty &p, QQmlEngine *engine)
150 return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
153 void QQmlPropertyData::lazyLoad(const QMetaProperty &p, QQmlEngine *engine)
157 coreIndex = p.propertyIndex();
158 notifyIndex = QMetaObjectPrivate::signalIndex(p.notifySignal());
159 Q_ASSERT(p.revision() <= Q_INT16_MAX);
160 revision = p.revision();
162 flags = fastFlagsForProperty(p);
165 if (type == QMetaType::QObjectStar) {
167 flags |= QQmlPropertyData::IsQObjectDerived;
168 } else if (type == QMetaType::QVariant) {
170 flags |= QQmlPropertyData::IsQVariant;
171 } else if (type == QVariant::UserType || type == -1) {
172 propTypeName = p.typeName();
173 flags |= QQmlPropertyData::NotFullyResolved;
179 void QQmlPropertyData::load(const QMetaProperty &p, QQmlEngine *engine)
181 propType = p.userType();
182 coreIndex = p.propertyIndex();
183 notifyIndex = QMetaObjectPrivate::signalIndex(p.notifySignal());
184 flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
185 Q_ASSERT(p.revision() <= Q_INT16_MAX);
186 revision = p.revision();
189 void QQmlPropertyData::load(const QMetaMethod &m)
191 coreIndex = m.methodIndex();
194 if (m.methodType() == QMetaMethod::Signal)
196 propType = m.returnType();
198 if (m.parameterCount()) {
199 flags |= HasArguments;
200 if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
201 flags |= IsV8Function;
205 if (m.attributes() & QMetaMethod::Cloned)
208 Q_ASSERT(m.revision() <= Q_INT16_MAX);
209 revision = m.revision();
212 void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
214 coreIndex = m.methodIndex();
217 if (m.methodType() == QMetaMethod::Signal)
219 propType = QMetaType::Void;
221 const char *returnType = m.typeName();
224 if ((*returnType != 'v') || (qstrcmp(returnType+1, "oid") != 0)) {
225 propTypeName = returnType;
226 flags |= NotFullyResolved;
229 if (m.parameterCount()) {
230 flags |= HasArguments;
231 if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
232 flags |= IsV8Function;
236 if (m.attributes() & QMetaMethod::Cloned)
239 Q_ASSERT(m.revision() <= Q_INT16_MAX);
240 revision = m.revision();
244 Creates a new empty QQmlPropertyCache.
246 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e)
247 : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
248 signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
249 _metaObject(0), argumentsCache(0)
255 Creates a new QQmlPropertyCache of \a metaObject.
257 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e, const QMetaObject *metaObject)
258 : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
259 signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
260 _metaObject(0), argumentsCache(0)
263 Q_ASSERT(metaObject);
265 update(engine, metaObject);
268 QQmlPropertyCache::~QQmlPropertyCache()
272 QQmlPropertyCacheMethodArguments *args = argumentsCache;
274 QQmlPropertyCacheMethodArguments *next = args->next;
275 if (args->signalParameterStringForJS) delete args->signalParameterStringForJS;
276 if (args->names) delete args->names;
281 // We must clear this prior to releasing the parent incase it is a
284 if (_parent) _parent->release();
286 if (_ownMetaObject) free((void *)_metaObject);
292 void QQmlPropertyCache::destroy()
294 Q_ASSERT(engine || constructor.IsEmpty());
295 if (constructor.IsEmpty())
298 QQmlEnginePrivate::deleteInEngineThread(engine, this);
301 // This is inherited from QQmlCleanup, so it should only clear the things
302 // that are tied to the specific QQmlEngine.
303 void QQmlPropertyCache::clear()
305 qPersistentDispose(constructor);
309 QQmlPropertyCache *QQmlPropertyCache::copy(int reserve)
311 QQmlPropertyCache *cache = new QQmlPropertyCache(engine);
312 cache->_parent = this;
313 cache->_parent->addref();
314 cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
315 cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
316 cache->signalHandlerIndexCacheStart = signalHandlerIndexCache.count() + signalHandlerIndexCacheStart;
317 cache->stringCache.linkAndReserve(stringCache, reserve);
318 cache->allowedRevisionCache = allowedRevisionCache;
319 cache->_metaObject = _metaObject;
320 cache->_defaultPropertyName = _defaultPropertyName;
322 // We specifically do *NOT* copy the constructor
327 QQmlPropertyCache *QQmlPropertyCache::copy()
332 QQmlPropertyCache *QQmlPropertyCache::copyAndReserve(QQmlEngine *, int propertyCount, int methodCount,
335 QQmlPropertyCache *rv = copy(propertyCount + methodCount + signalCount);
336 rv->propertyIndexCache.reserve(propertyCount);
337 rv->methodIndexCache.reserve(methodCount);
338 rv->signalHandlerIndexCache.reserve(signalCount);
346 \a notifyIndex MUST be in the signal index range (see QObjectPrivate::signalIndex()).
347 This is different from QMetaMethod::methodIndex().
349 void QQmlPropertyCache::appendProperty(const QString &name,
350 quint32 flags, int coreIndex, int propType, int notifyIndex)
352 QQmlPropertyData data;
353 data.propType = propType;
354 data.coreIndex = coreIndex;
355 data.notifyIndex = notifyIndex;
358 QQmlPropertyData *old = findNamedProperty(name);
360 data.markAsOverrideOf(old);
362 int index = propertyIndexCache.count();
363 propertyIndexCache.append(data);
365 setNamedProperty(name, index + propertyOffset(), propertyIndexCache.data() + index, (old != 0));
368 void QQmlPropertyCache::appendProperty(const QHashedCStringRef &name,
369 quint32 flags, int coreIndex, int propType, int notifyIndex)
371 QQmlPropertyData data;
372 data.propType = propType;
373 data.coreIndex = coreIndex;
374 data.notifyIndex = notifyIndex;
377 QQmlPropertyData *old = findNamedProperty(name);
379 data.markAsOverrideOf(old);
381 int index = propertyIndexCache.count();
382 propertyIndexCache.append(data);
384 setNamedProperty(name, index + propertyOffset(), propertyIndexCache.data() + index, (old != 0));
387 void QQmlPropertyCache::appendSignal(const QString &name, quint32 flags, int coreIndex,
388 const int *types, const QList<QByteArray> &names)
390 QQmlPropertyData data;
391 data.propType = QVariant::Invalid;
392 data.coreIndex = coreIndex;
396 QQmlPropertyData handler = data;
397 handler.flags |= QQmlPropertyData::IsSignalHandler;
400 int argumentCount = *types;
401 typedef QQmlPropertyCacheMethodArguments A;
402 A *args = static_cast<A *>(malloc(sizeof(A) + (argumentCount + 1) * sizeof(int)));
403 ::memcpy(args->arguments, types, (argumentCount + 1) * sizeof(int));
404 args->argumentsValid = true;
405 args->signalParameterStringForJS = 0;
406 args->signalParameterCountForJS = 0;
407 args->parameterError = false;
408 args->names = new QList<QByteArray>(names);
409 args->next = argumentsCache;
410 argumentsCache = args;
411 data.arguments = args;
414 QQmlPropertyData *old = findNamedProperty(name);
416 data.markAsOverrideOf(old);
418 int methodIndex = methodIndexCache.count();
419 methodIndexCache.append(data);
421 int signalHandlerIndex = signalHandlerIndexCache.count();
422 signalHandlerIndexCache.append(handler);
424 QString handlerName = QLatin1String("on") + name;
425 handlerName[2] = handlerName[2].toUpper();
427 setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0));
428 setNamedProperty(handlerName, signalHandlerIndex + signalOffset(), signalHandlerIndexCache.data() + signalHandlerIndex, (old != 0));
431 void QQmlPropertyCache::appendSignal(const QHashedCStringRef &name, quint32 flags, int coreIndex,
432 const int *types, const QList<QByteArray> &names)
434 QQmlPropertyData data;
435 data.propType = QVariant::Invalid;
436 data.coreIndex = coreIndex;
440 QQmlPropertyData handler = data;
441 handler.flags |= QQmlPropertyData::IsSignalHandler;
444 int argumentCount = *types;
445 typedef QQmlPropertyCacheMethodArguments A;
446 A *args = static_cast<A *>(malloc(sizeof(A) + (argumentCount + 1) * sizeof(int)));
447 ::memcpy(args->arguments, types, (argumentCount + 1) * sizeof(int));
448 args->argumentsValid = true;
449 args->signalParameterStringForJS = 0;
450 args->signalParameterCountForJS = 0;
451 args->parameterError = false;
452 args->names = new QList<QByteArray>(names);
453 args->next = argumentsCache;
454 argumentsCache = args;
455 data.arguments = args;
458 QQmlPropertyData *old = findNamedProperty(name);
460 data.markAsOverrideOf(old);
462 int methodIndex = methodIndexCache.count();
463 methodIndexCache.append(data);
465 int signalHandlerIndex = signalHandlerIndexCache.count();
466 signalHandlerIndexCache.append(handler);
468 QString handlerName = QLatin1String("on") + name.toUtf16();
469 handlerName[2] = handlerName[2].toUpper();
471 setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0));
472 setNamedProperty(handlerName, signalHandlerIndex + signalOffset(), signalHandlerIndexCache.data() + signalHandlerIndex, (old != 0));
475 void QQmlPropertyCache::appendMethod(const QString &name, quint32 flags, int coreIndex,
476 const QList<QByteArray> &names)
478 int argumentCount = names.count();
480 QQmlPropertyData data;
481 data.propType = QMetaType::QVariant;
482 data.coreIndex = coreIndex;
484 typedef QQmlPropertyCacheMethodArguments A;
485 A *args = static_cast<A *>(malloc(sizeof(A) + (argumentCount + 1) * sizeof(int)));
486 args->arguments[0] = argumentCount;
487 for (int ii = 0; ii < argumentCount; ++ii)
488 args->arguments[ii + 1] = QMetaType::QVariant;
489 args->argumentsValid = true;
490 args->signalParameterStringForJS = 0;
491 args->signalParameterCountForJS = 0;
492 args->parameterError = false;
495 args->names = new QList<QByteArray>(names);
496 args->next = argumentsCache;
497 argumentsCache = args;
498 data.arguments = args;
502 QQmlPropertyData *old = findNamedProperty(name);
504 data.markAsOverrideOf(old);
506 int methodIndex = methodIndexCache.count();
507 methodIndexCache.append(data);
509 setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0));
512 void QQmlPropertyCache::appendMethod(const QHashedCStringRef &name, quint32 flags, int coreIndex,
513 const QList<QByteArray> &names)
515 int argumentCount = names.count();
517 QQmlPropertyData data;
518 data.propType = QMetaType::QVariant;
519 data.coreIndex = coreIndex;
521 typedef QQmlPropertyCacheMethodArguments A;
522 A *args = static_cast<A *>(malloc(sizeof(A) + (argumentCount + 1) * sizeof(int)));
523 args->arguments[0] = argumentCount;
524 for (int ii = 0; ii < argumentCount; ++ii)
525 args->arguments[ii + 1] = QMetaType::QVariant;
526 args->argumentsValid = true;
527 args->signalParameterStringForJS = 0;
528 args->signalParameterCountForJS = 0;
529 args->parameterError = false;
532 args->names = new QList<QByteArray>(names);
533 args->next = argumentsCache;
534 argumentsCache = args;
535 data.arguments = args;
539 QQmlPropertyData *old = findNamedProperty(name);
541 data.markAsOverrideOf(old);
543 int methodIndex = methodIndexCache.count();
544 methodIndexCache.append(data);
546 setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0));
549 // Returns this property cache's metaObject. May be null if it hasn't been created yet.
550 const QMetaObject *QQmlPropertyCache::metaObject() const
555 // Returns this property cache's metaObject, creating it if necessary.
556 const QMetaObject *QQmlPropertyCache::createMetaObject()
559 _ownMetaObject = true;
561 QMetaObjectBuilder builder;
562 toMetaObjectBuilder(builder);
563 builder.setSuperClass(_parent->createMetaObject());
564 _metaObject = builder.toMetaObject();
570 // Returns the name of the default property for this cache
571 QString QQmlPropertyCache::defaultPropertyName() const
573 return _defaultPropertyName;
576 QQmlPropertyData *QQmlPropertyCache::defaultProperty() const
578 return property(defaultPropertyName(), 0, 0);
581 QQmlPropertyCache *QQmlPropertyCache::parent() const
586 // Returns the first C++ type's QMetaObject - that is, the first QMetaObject not created by
588 const QMetaObject *QQmlPropertyCache::firstCppMetaObject() const
590 while (_parent && (_metaObject == 0 || _ownMetaObject))
591 return _parent->firstCppMetaObject();
596 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
597 QQmlPropertyData::Flag propertyFlags,
598 QQmlPropertyData::Flag methodFlags,
599 QQmlPropertyData::Flag signalFlags)
601 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
605 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
607 QQmlPropertyData::Flag propertyFlags,
608 QQmlPropertyData::Flag methodFlags,
609 QQmlPropertyData::Flag signalFlags)
611 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
613 // Reserve enough space in the name hash for all the methods (including signals), all the
614 // signal handlers and all the properties. This assumes no name clashes, but this is the
616 QQmlPropertyCache *rv = copy(QMetaObjectPrivate::get(metaObject)->methodCount +
617 QMetaObjectPrivate::get(metaObject)->signalCount +
618 QMetaObjectPrivate::get(metaObject)->propertyCount);
620 rv->append(engine, metaObject, revision, propertyFlags, methodFlags, signalFlags);
625 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
627 QQmlPropertyData::Flag propertyFlags,
628 QQmlPropertyData::Flag methodFlags,
629 QQmlPropertyData::Flag signalFlags)
632 Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache
634 _metaObject = metaObject;
636 bool dynamicMetaObject = isDynamicMetaObject(metaObject);
638 allowedRevisionCache.append(0);
640 int methodCount = metaObject->methodCount();
641 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
642 int signalCount = metaObjectSignalCount(metaObject);
643 int classInfoCount = QMetaObjectPrivate::get(metaObject)->classInfoCount;
645 QQmlAccessorProperties::Properties accessorProperties;
647 if (classInfoCount) {
648 int classInfoOffset = metaObject->classInfoOffset();
649 bool hasFastProperty = false;
650 for (int ii = 0; ii < classInfoCount; ++ii) {
651 int idx = ii + classInfoOffset;
653 if (0 == qstrcmp(metaObject->classInfo(idx).name(), "qt_HasQmlAccessors")) {
654 hasFastProperty = true;
655 } else if (0 == qstrcmp(metaObject->classInfo(idx).name(), "DefaultProperty")) {
656 _defaultPropertyName = QString::fromUtf8(metaObject->classInfo(idx).value());
660 if (hasFastProperty) {
661 accessorProperties = QQmlAccessorProperties::properties(metaObject);
662 if (accessorProperties.count == 0)
663 qFatal("QQmlPropertyCache: %s has FastProperty class info, but has not "
664 "installed property accessors", metaObject->className());
667 accessorProperties = QQmlAccessorProperties::properties(metaObject);
668 if (accessorProperties.count != 0)
669 qFatal("QQmlPropertyCache: %s has fast property accessors, but is missing "
670 "FastProperty class info", metaObject->className());
675 //Used to block access to QObject::destroyed() and QObject::deleteLater() from QML
676 static const int destroyedIdx1 = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)");
677 static const int destroyedIdx2 = QObject::staticMetaObject.indexOfSignal("destroyed()");
678 static const int deleteLaterIdx = QObject::staticMetaObject.indexOfSlot("deleteLater()");
680 int methodOffset = metaObject->methodOffset();
681 int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
683 // update() should have reserved enough space in the vector that this doesn't cause a realloc
684 // and invalidate the stringCache.
685 methodIndexCache.resize(methodCount - methodIndexCacheStart);
686 signalHandlerIndexCache.resize(signalCount - signalHandlerIndexCacheStart);
687 int signalHandlerIndex = signalOffset;
688 for (int ii = methodOffset; ii < methodCount; ++ii) {
689 if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
691 QMetaMethod m = metaObject->method(ii);
692 if (m.access() == QMetaMethod::Private)
695 // Extract method name
696 // It's safe to keep the raw name pointer
697 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 7);
698 const char *rawName = m.name().constData();
699 const char *cptr = rawName;
702 utf8 |= *cptr & 0x80;
706 QQmlPropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
707 QQmlPropertyData *sigdata = 0;
711 if (data->isSignal())
712 data->flags |= signalFlags;
714 data->flags |= methodFlags;
716 if (!dynamicMetaObject)
717 data->flags |= QQmlPropertyData::IsDirect;
719 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
720 data->metaObjectOffset = allowedRevisionCache.count() - 1;
722 if (data->isSignal()) {
723 sigdata = &signalHandlerIndexCache[signalHandlerIndex - signalHandlerIndexCacheStart];
725 sigdata->flags |= QQmlPropertyData::IsSignalHandler;
728 QQmlPropertyData *old = 0;
731 QHashedString methodName(QString::fromUtf8(rawName, cptr - rawName));
732 if (StringCache::mapped_type *it = stringCache.value(methodName))
734 setNamedProperty(methodName, ii, data, (old != 0));
736 if (data->isSignal()) {
737 QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1));
738 setNamedProperty(on, ii, sigdata, (old != 0));
739 ++signalHandlerIndex;
742 QHashedCStringRef methodName(rawName, cptr - rawName);
743 if (StringCache::mapped_type *it = stringCache.value(methodName))
745 setNamedProperty(methodName, ii, data, (old != 0));
747 if (data->isSignal()) {
748 int length = methodName.length();
750 QVarLengthArray<char, 128> str(length+3);
753 str[2] = toupper(rawName[0]);
755 memcpy(&str[3], &rawName[1], length - 1);
756 str[length + 2] = '\0';
758 QHashedString on(QString::fromLatin1(str.data()));
759 setNamedProperty(on, ii, data, (old != 0));
760 ++signalHandlerIndex;
765 // We only overload methods in the same class, exactly like C++
766 if (old->isFunction() && old->coreIndex >= methodOffset)
767 data->flags |= QQmlPropertyData::IsOverload;
769 data->markAsOverrideOf(old);
773 int propCount = metaObject->propertyCount();
774 int propOffset = metaObject->propertyOffset();
776 // update() should have reserved enough space in the vector that this doesn't cause a realloc
777 // and invalidate the stringCache.
778 propertyIndexCache.resize(propCount - propertyIndexCacheStart);
779 for (int ii = propOffset; ii < propCount; ++ii) {
780 QMetaProperty p = metaObject->property(ii);
781 if (!p.isScriptable())
784 const char *str = p.name();
786 const char *cptr = str;
788 utf8 |= *cptr & 0x80;
792 QQmlPropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
794 data->lazyLoad(p, engine);
795 data->flags |= propertyFlags;
797 if (!dynamicMetaObject)
798 data->flags |= QQmlPropertyData::IsDirect;
800 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
801 data->metaObjectOffset = allowedRevisionCache.count() - 1;
803 QQmlPropertyData *old = 0;
806 QHashedString propName(QString::fromUtf8(str, cptr - str));
807 if (StringCache::mapped_type *it = stringCache.value(propName))
809 setNamedProperty(propName, ii, data, (old != 0));
811 QHashedCStringRef propName(str, cptr - str);
812 if (StringCache::mapped_type *it = stringCache.value(propName))
814 setNamedProperty(propName, ii, data, (old != 0));
817 QQmlAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
819 // Fast properties may not be overrides or revisioned
820 Q_ASSERT(accessorProperty == 0 || (old == 0 && data->revision == 0));
822 if (accessorProperty) {
823 data->flags |= QQmlPropertyData::HasAccessors;
824 data->accessors = accessorProperty->accessors;
825 data->accessorData = accessorProperty->data;
827 data->markAsOverrideOf(old);
832 QQmlPropertyData *QQmlPropertyCache::ensureResolved(QQmlPropertyData *p) const
834 if (p && p->notFullyResolved())
840 void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
842 Q_ASSERT(data->notFullyResolved());
844 data->propType = QMetaType::type(data->propTypeName);
846 if (!data->isFunction())
847 data->flags |= flagsForPropertyType(data->propType, engine);
849 data->flags &= ~QQmlPropertyData::NotFullyResolved;
852 void QQmlPropertyCache::updateRecur(QQmlEngine *engine, const QMetaObject *metaObject)
857 updateRecur(engine, metaObject->superClass());
859 append(engine, metaObject, -1);
862 void QQmlPropertyCache::update(QQmlEngine *engine, const QMetaObject *metaObject)
865 Q_ASSERT(metaObject);
866 Q_ASSERT(stringCache.isEmpty());
868 // Preallocate enough space in the index caches for all the properties/methods/signals that
869 // are not cached in a parent cache so that the caches never need to be reallocated as this
870 // would invalidate pointers stored in the stringCache.
871 int pc = metaObject->propertyCount();
872 int mc = metaObject->methodCount();
873 int sc = metaObjectSignalCount(metaObject);
874 propertyIndexCache.reserve(pc - propertyIndexCacheStart);
875 methodIndexCache.reserve(mc - methodIndexCacheStart);
876 signalHandlerIndexCache.reserve(sc - signalHandlerIndexCacheStart);
878 // Reserve enough space in the stringCache for all properties/methods/signals including those
879 // cached in a parent cache.
880 stringCache.reserve(pc + mc + sc);
882 updateRecur(engine,metaObject);
886 \a index MUST be in the signal index range (see QObjectPrivate::signalIndex()).
887 This is different from QMetaMethod::methodIndex().
890 QQmlPropertyCache::signal(int index) const
892 if (index < 0 || index >= (signalHandlerIndexCacheStart + signalHandlerIndexCache.count()))
895 if (index < signalHandlerIndexCacheStart)
896 return _parent->signal(index);
898 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&methodIndexCache.at(index - signalHandlerIndexCacheStart));
899 if (rv->notFullyResolved()) resolve(rv);
900 Q_ASSERT(rv->isSignal() || rv->coreIndex == -1);
904 int QQmlPropertyCache::methodIndexToSignalIndex(int index) const
906 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
909 if (index < methodIndexCacheStart)
910 return _parent->methodIndexToSignalIndex(index);
912 return index - methodIndexCacheStart + signalHandlerIndexCacheStart;
916 QQmlPropertyCache::property(int index) const
918 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
921 if (index < propertyIndexCacheStart)
922 return _parent->property(index);
924 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
925 return ensureResolved(rv);
929 QQmlPropertyCache::method(int index) const
931 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
934 if (index < methodIndexCacheStart)
935 return _parent->method(index);
937 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
938 return ensureResolved(rv);
941 QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, QObject *object, QQmlContextData *context) const
943 QQmlData *data = (object ? QQmlData::get(object) : 0);
944 const QQmlVMEMetaObject *vmemo = (data && data->hasVMEMetaObject ? static_cast<const QQmlVMEMetaObject *>(object->metaObject()) : 0);
945 return findProperty(it, vmemo, context);
950 inline bool contextHasNoExtensions(QQmlContextData *context)
952 // This context has no extension if its parent is the engine's rootContext,
953 // which has children but no imports
954 return (!context->parent || !context->parent->imports);
957 inline int maximumIndexForProperty(QQmlPropertyData *prop, const QQmlVMEMetaObject *vmemo)
959 return (prop->isFunction() ? vmemo->methodCount()
960 : prop->isSignalHandler() ? vmemo->signalCount()
961 : vmemo->propertyCount());
966 QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, const QQmlVMEMetaObject *vmemo, QQmlContextData *context) const
968 StringCache::ConstIterator end = stringCache.end();
971 if (vmemo && context && !contextHasNoExtensions(context)) {
972 // Find the highest property offset known to the supplied context
974 if (vmemo->ctxt == context)
977 vmemo = vmemo->parentVMEMetaObject();
982 // Is this property available to this context?
983 const StringCache::mapped_type &property(it.value());
984 if (!vmemo || (property.first < maximumIndexForProperty(property.second, vmemo)))
985 return ensureResolved(property.second);
987 it = stringCache.findNext(it);
994 QString QQmlPropertyData::name(QObject *object)
999 return name(object->metaObject());
1002 QString QQmlPropertyData::name(const QMetaObject *metaObject)
1004 if (!metaObject || coreIndex == -1)
1007 if (flags & IsFunction) {
1008 QMetaMethod m = metaObject->method(coreIndex);
1010 return QString::fromUtf8(m.name().constData());
1012 QMetaProperty p = metaObject->property(coreIndex);
1013 return QString::fromUtf8(p.name());
1017 void QQmlPropertyData::markAsOverrideOf(QQmlPropertyData *predecessor)
1019 overrideIndexIsProperty = !predecessor->isFunction();
1020 overrideIndex = predecessor->coreIndex;
1022 predecessor->flags |= QQmlPropertyData::IsOverridden;
1025 QStringList QQmlPropertyCache::propertyNames() const
1028 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
1029 keys.append(iter.key());
1033 struct StaticQtMetaObject : public QObject
1035 static const QMetaObject *get()
1036 { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
1039 static int EnumType(const QMetaObject *metaobj, const QByteArray &str, int type)
1043 int scopeIdx = str.lastIndexOf("::");
1044 if (scopeIdx != -1) {
1045 scope = str.left(scopeIdx);
1046 name = str.mid(scopeIdx + 2);
1050 const QMetaObject *meta;
1052 meta = StaticQtMetaObject::get();
1055 for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
1056 QMetaEnum m = meta->enumerator(i);
1057 if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
1058 return QVariant::Int;
1064 \a index MUST be in the signal index range (see QObjectPrivate::signalIndex()).
1065 This is different from QMetaMethod::methodIndex().
1067 QString QQmlPropertyCache::signalParameterStringForJS(int index, int *count, QString *errorString)
1069 QQmlPropertyData *signalData = signal(index);
1073 typedef QQmlPropertyCacheMethodArguments A;
1075 if (signalData->arguments) {
1076 A *arguments = static_cast<A *>(signalData->arguments);
1077 if (arguments->signalParameterStringForJS) {
1079 *count = arguments->signalParameterCountForJS;
1080 if (arguments->parameterError) {
1082 *errorString = *arguments->signalParameterStringForJS;
1085 return *arguments->signalParameterStringForJS;
1089 QList<QByteArray> parameterNameList = signalParameterNames(index);
1091 if (!signalData->arguments) {
1092 int argc = parameterNameList.count();
1093 A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
1094 args->arguments[0] = argc;
1095 args->argumentsValid = false;
1096 args->signalParameterStringForJS = 0;
1097 args->signalParameterCountForJS = 0;
1098 args->parameterError = false;
1099 args->names = new QList<QByteArray>(parameterNameList);
1100 signalData->arguments = args;
1103 QQmlRewrite::RewriteSignalHandler rewriter;
1104 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
1105 const QString ¶meters = rewriter.createParameterString(parameterNameList,
1106 ep->v8engine()->illegalNames());
1108 bool error = rewriter.hasParameterError();
1109 A *arguments = static_cast<A *>(signalData->arguments);
1110 arguments->signalParameterStringForJS = new QString(error ? rewriter.parameterError() : parameters);
1111 arguments->signalParameterCountForJS = rewriter.parameterCountForJS();
1113 *count = arguments->signalParameterCountForJS;
1115 arguments->parameterError = true;
1117 *errorString = *arguments->signalParameterStringForJS;
1120 return *arguments->signalParameterStringForJS;
1123 // Returns an array of the arguments for method \a index. The first entry in the array
1124 // is the number of arguments.
1125 int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
1126 QVarLengthArray<int, 9> &dummy,
1127 QByteArray *unknownTypeError)
1129 Q_ASSERT(object && index >= 0);
1131 QQmlData *ddata = QQmlData::get(object, false);
1133 if (ddata && ddata->propertyCache) {
1134 typedef QQmlPropertyCacheMethodArguments A;
1136 QQmlPropertyCache *c = ddata->propertyCache;
1137 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
1139 while (index < c->methodIndexCacheStart)
1142 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
1144 if (rv->arguments && static_cast<A *>(rv->arguments)->argumentsValid)
1145 return static_cast<A *>(rv->arguments)->arguments;
1147 const QMetaObject *metaObject = c->createMetaObject();
1148 Q_ASSERT(metaObject);
1149 QMetaMethod m = metaObject->method(index);
1151 int argc = m.parameterCount();
1152 if (!rv->arguments) {
1153 A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
1154 args->arguments[0] = argc;
1155 args->argumentsValid = false;
1156 args->signalParameterStringForJS = 0;
1157 args->signalParameterCountForJS = 0;
1158 args->parameterError = false;
1160 rv->arguments = args;
1162 A *args = static_cast<A *>(rv->arguments);
1164 QList<QByteArray> argTypeNames; // Only loaded if needed
1166 for (int ii = 0; ii < argc; ++ii) {
1167 int type = m.parameterType(ii);
1168 QMetaType::TypeFlags flags = QMetaType::typeFlags(type);
1169 if (flags & QMetaType::IsEnumeration)
1170 type = QVariant::Int;
1171 else if (type == QMetaType::UnknownType ||
1172 (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
1173 type != qMetaTypeId<QJSValue>())) {
1174 //the UserType clause is to catch registered QFlags
1175 if (argTypeNames.isEmpty())
1176 argTypeNames = m.parameterTypes();
1177 type = EnumType(object->metaObject(), argTypeNames.at(ii), type);
1179 if (type == QMetaType::UnknownType) {
1180 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
1183 args->arguments[ii + 1] = type;
1185 args->argumentsValid = true;
1187 args->next = c->argumentsCache;
1188 c->argumentsCache = args;
1189 return static_cast<A *>(rv->arguments)->arguments;
1192 QMetaMethod m = object->metaObject()->method(index);
1193 int argc = m.parameterCount();
1194 dummy.resize(argc + 1);
1196 QList<QByteArray> argTypeNames; // Only loaded if needed
1198 for (int ii = 0; ii < argc; ++ii) {
1199 int type = m.parameterType(ii);
1200 QMetaType::TypeFlags flags = QMetaType::typeFlags(type);
1201 if (flags & QMetaType::IsEnumeration)
1202 type = QVariant::Int;
1203 else if (type == QMetaType::UnknownType ||
1204 (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
1205 type != qMetaTypeId<QJSValue>())) {
1206 //the UserType clause is to catch registered QFlags)
1207 if (argTypeNames.isEmpty())
1208 argTypeNames = m.parameterTypes();
1209 type = EnumType(object->metaObject(), argTypeNames.at(ii), type);
1211 if (type == QMetaType::UnknownType) {
1212 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
1215 dummy[ii + 1] = type;
1218 return dummy.data();
1222 // Returns the return type of the method.
1223 int QQmlPropertyCache::methodReturnType(QObject *object, const QQmlPropertyData &data,
1224 QByteArray *unknownTypeError)
1226 Q_ASSERT(object && data.coreIndex >= 0);
1228 int type = data.propType;
1230 const char *propTypeName = 0;
1232 if (type == QMetaType::UnknownType) {
1233 // Find the return type name from the method info
1236 QQmlData *ddata = QQmlData::get(object, false);
1237 if (ddata && ddata->propertyCache) {
1238 QQmlPropertyCache *c = ddata->propertyCache;
1239 Q_ASSERT(data.coreIndex < c->methodIndexCacheStart + c->methodIndexCache.count());
1241 while (data.coreIndex < c->methodIndexCacheStart)
1244 const QMetaObject *metaObject = c->createMetaObject();
1245 Q_ASSERT(metaObject);
1246 m = metaObject->method(data.coreIndex);
1248 m = object->metaObject()->method(data.coreIndex);
1251 type = m.returnType();
1252 propTypeName = m.typeName();
1255 QMetaType::TypeFlags flags = QMetaType::typeFlags(type);
1256 if (flags & QMetaType::IsEnumeration) {
1257 type = QVariant::Int;
1258 } else if (type == QMetaType::UnknownType ||
1259 (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
1260 type != qMetaTypeId<QJSValue>())) {
1261 //the UserType clause is to catch registered QFlags
1262 type = EnumType(object->metaObject(), propTypeName, type);
1265 if (type == QMetaType::UnknownType) {
1266 if (unknownTypeError) *unknownTypeError = propTypeName;
1272 int QQmlPropertyCache::originalClone(int index)
1274 while (signal(index)->isCloned())
1279 int QQmlPropertyCache::originalClone(QObject *object, int index)
1281 QQmlData *data = QQmlData::get(object, false);
1282 if (data && data->propertyCache) {
1283 QQmlPropertyCache *cache = data->propertyCache;
1284 while (cache->signal(index)->isCloned())
1287 while (QMetaObjectPrivate::signal(object->metaObject(), index).attributes() & QMetaMethod::Cloned)
1293 QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QString &property)
1295 Q_ASSERT(metaObject);
1297 QQmlPropertyData rv;
1299 const QMetaObject *cmo = metaObject;
1300 const QByteArray propertyName = property.toUtf8();
1302 int idx = cmo->indexOfProperty(propertyName);
1304 QMetaProperty p = cmo->property(idx);
1305 if (p.isScriptable()) {
1309 while (cmo && cmo->propertyOffset() >= idx)
1310 cmo = cmo->superClass();
1318 //Used to block access to QObject::destroyed() and QObject::deleteLater() from QML
1319 static const int destroyedIdx1 = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)");
1320 static const int destroyedIdx2 = QObject::staticMetaObject.indexOfSignal("destroyed()");
1321 static const int deleteLaterIdx = QObject::staticMetaObject.indexOfSlot("deleteLater()");
1323 int methodCount = metaObject->methodCount();
1324 for (int ii = methodCount - 1; ii >= 0; --ii) {
1325 if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
1327 QMetaMethod m = metaObject->method(ii);
1328 if (m.access() == QMetaMethod::Private)
1330 QString methodName = QString::fromUtf8(m.name().constData());
1332 if (methodName == property) {
1341 inline const QString &qQmlPropertyCacheToString(const QString &string)
1346 inline QString qQmlPropertyCacheToString(const QHashedV8String &string)
1348 return QV8Engine::toStringStatic(string.string());
1351 template<typename T>
1353 qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, const T &name,
1354 QQmlContextData *context, QQmlPropertyData &local)
1356 QQmlPropertyCache *cache = 0;
1358 QQmlData *ddata = QQmlData::get(obj, false);
1360 if (ddata && ddata->propertyCache) {
1361 cache = ddata->propertyCache;
1362 } else if (engine) {
1363 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
1364 cache = ep->cache(obj);
1366 ddata = QQmlData::get(obj, true);
1368 ddata->propertyCache = cache;
1372 QQmlPropertyData *rv = 0;
1375 rv = cache->property(name, obj, context);
1377 local = qQmlPropertyCacheCreate(obj->metaObject(), qQmlPropertyCacheToString(name));
1378 if (local.isValid())
1386 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj, const QHashedV8String &name,
1387 QQmlContextData *context, QQmlPropertyData &local)
1389 return qQmlPropertyCacheProperty<QHashedV8String>(engine, obj, name, context, local);
1393 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
1394 const QString &name, QQmlContextData *context, QQmlPropertyData &local)
1396 return qQmlPropertyCacheProperty<QString>(engine, obj, name, context, local);
1399 static inline const QMetaObjectPrivate *priv(const uint* data)
1400 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
1402 bool QQmlPropertyCache::isDynamicMetaObject(const QMetaObject *mo)
1404 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;
1407 const char *QQmlPropertyCache::className() const
1409 if (!_ownMetaObject && _metaObject)
1410 return _metaObject->className();
1412 return _dynamicClassName.constData();
1415 void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder)
1417 struct Sort { static bool lt(const QPair<QString, QQmlPropertyData *> &lhs,
1418 const QPair<QString, QQmlPropertyData *> &rhs) {
1419 return lhs.second->coreIndex < rhs.second->coreIndex;
1422 struct Insert { static void in(QQmlPropertyCache *This,
1423 QList<QPair<QString, QQmlPropertyData *> > &properties,
1424 QList<QPair<QString, QQmlPropertyData *> > &methods,
1425 StringCache::ConstIterator iter, QQmlPropertyData *data) {
1426 if (data->isSignalHandler())
1429 if (data->isFunction()) {
1430 if (data->coreIndex < This->methodIndexCacheStart)
1433 QPair<QString, QQmlPropertyData *> entry = qMakePair((QString)iter.key(), data);
1434 // Overrides can cause the entry to already exist
1435 if (!methods.contains(entry)) methods.append(entry);
1437 data = This->overrideData(data);
1438 if (data && !data->isFunction()) Insert::in(This, properties, methods, iter, data);
1440 if (data->coreIndex < This->propertyIndexCacheStart)
1443 QPair<QString, QQmlPropertyData *> entry = qMakePair((QString)iter.key(), data);
1444 // Overrides can cause the entry to already exist
1445 if (!properties.contains(entry)) properties.append(entry);
1447 data = This->overrideData(data);
1448 if (data) Insert::in(This, properties, methods, iter, data);
1453 builder.setClassName(_dynamicClassName);
1455 QList<QPair<QString, QQmlPropertyData *> > properties;
1456 QList<QPair<QString, QQmlPropertyData *> > methods;
1458 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
1459 Insert::in(this, properties, methods, iter, iter.value().second);
1461 Q_ASSERT(properties.count() == propertyIndexCache.count());
1462 Q_ASSERT(methods.count() == methodIndexCache.count());
1464 qSort(properties.begin(), properties.end(), Sort::lt);
1465 qSort(methods.begin(), methods.end(), Sort::lt);
1467 for (int ii = 0; ii < properties.count(); ++ii) {
1468 QQmlPropertyData *data = properties.at(ii).second;
1470 int notifierId = -1;
1471 if (data->notifyIndex != -1)
1472 notifierId = data->notifyIndex - signalHandlerIndexCacheStart;
1474 QMetaPropertyBuilder property = builder.addProperty(properties.at(ii).first.toUtf8(),
1475 QMetaType::typeName(data->propType),
1478 property.setReadable(true);
1479 property.setWritable(data->isWritable());
1480 property.setResettable(data->isResettable());
1483 for (int ii = 0; ii < methods.count(); ++ii) {
1484 QQmlPropertyData *data = methods.at(ii).second;
1486 QByteArray returnType;
1487 if (data->propType != 0)
1488 returnType = QMetaType::typeName(data->propType);
1490 QByteArray signature = methods.at(ii).first.toUtf8() + "(";
1492 QQmlPropertyCacheMethodArguments *arguments = 0;
1493 if (data->hasArguments()) {
1494 arguments = (QQmlPropertyCacheMethodArguments *)data->arguments;
1495 Q_ASSERT(arguments->argumentsValid);
1496 for (int ii = 0; ii < arguments->arguments[0]; ++ii) {
1497 if (ii != 0) signature.append(",");
1498 signature.append(QMetaType::typeName(arguments->arguments[1 + ii]));
1502 signature.append(")");
1504 QMetaMethodBuilder method;
1505 if (data->isSignal()) {
1506 method = builder.addSignal(signature);
1508 method = builder.addSlot(signature);
1510 method.setAccess(QMetaMethod::Protected);
1512 if (arguments && arguments->names)
1513 method.setParameterNames(*arguments->names);
1515 if (!returnType.isEmpty())
1516 method.setReturnType(returnType);
1519 if (!_defaultPropertyName.isEmpty()) {
1520 QQmlPropertyData *dp = property(_defaultPropertyName, 0, 0);
1521 if (dp && dp->coreIndex >= propertyIndexCacheStart) {
1522 Q_ASSERT(!dp->isFunction());
1523 builder.addClassInfo("DefaultProperty", _defaultPropertyName.toUtf8());
1529 \a index MUST be in the signal index range (see QObjectPrivate::signalIndex()).
1530 This is different from QMetaMethod::methodIndex().
1532 QList<QByteArray> QQmlPropertyCache::signalParameterNames(int index) const
1534 QQmlPropertyData *signalData = signal(index);
1535 if (signalData && signalData->hasArguments()) {
1536 QQmlPropertyCacheMethodArguments *args = (QQmlPropertyCacheMethodArguments *)signalData->arguments;
1537 if (args && args->names)
1538 return *args->names;
1539 const QMetaMethod &method = QMetaObjectPrivate::signal(firstCppMetaObject(), index);
1540 return method.parameterNames();
1542 return QList<QByteArray>();
1545 // Returns true if \a from is assignable to a property of type \a to
1546 bool QQmlMetaObject::canConvert(const QQmlMetaObject &from, const QQmlMetaObject &to)
1548 Q_ASSERT(!from.isNull() && !to.isNull());
1550 struct I { static bool equal(const QMetaObject *lhs, const QMetaObject *rhs) {
1551 return lhs == rhs || (lhs && rhs && lhs->d.stringdata == rhs->d.stringdata);
1554 const QMetaObject *tom = to._m.isT1()?to._m.asT1()->metaObject():to._m.asT2();
1555 if (tom == &QObject::staticMetaObject) return true;
1557 if (from._m.isT1() && to._m.isT1()) { // QQmlPropertyCache -> QQmlPropertyCache
1558 QQmlPropertyCache *fromp = from._m.asT1();
1559 QQmlPropertyCache *top = to._m.asT1();
1562 if (fromp == top) return true;
1563 fromp = fromp->parent();
1565 } else if (from._m.isT1() && to._m.isT2()) { // QQmlPropertyCache -> QMetaObject
1566 QQmlPropertyCache *fromp = from._m.asT1();
1569 const QMetaObject *fromm = fromp->metaObject();
1570 if (fromm && I::equal(fromm, tom)) return true;
1571 fromp = fromp->parent();
1573 } else if (from._m.isT2() && to._m.isT1()) { // QMetaObject -> QQmlPropertyCache
1574 const QMetaObject *fromm = from._m.asT2();
1576 if (!tom) return false;
1579 if (I::equal(fromm, tom)) return true;
1580 fromm = fromm->superClass();
1582 } else { // QMetaObject -> QMetaObject
1583 const QMetaObject *fromm = from._m.asT2();
1586 if (I::equal(fromm, tom)) return true;
1587 fromm = fromm->superClass();
1594 QQmlPropertyCache *QQmlMetaObject::propertyCache(QQmlEnginePrivate *e) const
1596 if (_m.isNull()) return 0;
1597 if (_m.isT1()) return _m.asT1();
1598 else return e->cache(_m.asT2());