1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtDeclarative/qdeclarativeprivate.h>
43 #include "private/qdeclarativemetatype_p.h"
45 #include <private/qdeclarativeproxymetaobject_p.h>
46 #include <private/qdeclarativecustomparser_p.h>
47 #include <private/qdeclarativeguard_p.h>
48 #include <private/qhashedstring_p.h>
50 #include <QtCore/qdebug.h>
51 #include <QtCore/qstringlist.h>
52 #include <QtCore/qmetaobject.h>
53 #include <QtCore/qbitarray.h>
54 #include <QtCore/qreadwritelock.h>
55 #include <QtCore/private/qmetaobject_p.h>
57 #include <qmetatype.h>
58 #include <qobjectdefs.h>
59 #include <qdatetime.h>
60 #include <qbytearray.h>
61 #include <qreadwritelock.h>
63 #include <qstringlist.h>
66 #include <QtCore/qcryptographichash.h>
67 #include <QtDeclarative/qjsvalue.h>
71 #ifdef QT_BOOTSTRAPPED
72 # ifndef QT_NO_GEOM_VARIANT
73 # define QT_NO_GEOM_VARIANT
76 # include <qbitarray.h>
78 # include <qvariant.h>
81 #ifndef QT_NO_GEOM_VARIANT
86 # include <qvector3d.h>
88 #define NS(x) QT_PREPEND_NAMESPACE(x)
92 struct QDeclarativeMetaTypeData
94 QDeclarativeMetaTypeData();
95 ~QDeclarativeMetaTypeData();
96 QList<QDeclarativeType *> types;
97 typedef QHash<int, QDeclarativeType *> Ids;
99 typedef QHash<QString, QDeclarativeType *> Names;
101 typedef QHash<const QMetaObject *, QDeclarativeType *> MetaObjects;
102 MetaObjects metaObjectToType;
103 typedef QHash<int, QDeclarativeMetaType::StringConverter> StringConverters;
104 StringConverters stringConverters;
106 struct VersionedUri {
109 VersionedUri(const QString &uri, int majorVersion)
110 : uri(uri), majorVersion(majorVersion) {}
111 bool operator==(const VersionedUri &other) const {
112 return other.majorVersion == majorVersion && other.uri == uri;
117 typedef QHash<VersionedUri, QDeclarativeTypeModule *> TypeModules;
118 TypeModules uriToModule;
120 struct ModuleApiList {
121 ModuleApiList() : sorted(true) {}
122 QList<QDeclarativeMetaType::ModuleApi> moduleApis;
125 typedef QHash<QString, ModuleApiList> ModuleApis;
126 ModuleApis moduleApis;
130 QBitArray interfaces;
133 QList<QDeclarativePrivate::AutoParentFunction> parentFunctions;
136 class QDeclarativeTypeModulePrivate
139 QDeclarativeTypeModulePrivate()
140 : minMinorVersion(INT_MAX), maxMinorVersion(0) {}
142 QDeclarativeMetaTypeData::VersionedUri uri;
147 void add(QDeclarativeType *);
149 QStringHash<QList<QDeclarativeType *> > typeHash;
150 QList<QDeclarativeType *> types;
153 Q_GLOBAL_STATIC(QDeclarativeMetaTypeData, metaTypeData)
154 Q_GLOBAL_STATIC(QReadWriteLock, metaTypeDataLock)
156 static uint qHash(const QDeclarativeMetaTypeData::VersionedUri &v)
158 return qHash(v.uri) ^ qHash(v.majorVersion);
161 QDeclarativeMetaTypeData::QDeclarativeMetaTypeData()
166 QDeclarativeMetaTypeData::~QDeclarativeMetaTypeData()
168 for (int i = 0; i < types.count(); ++i)
172 class QDeclarativeTypePrivate
175 QDeclarativeTypePrivate();
178 void initEnums() const;
180 bool m_isInterface : 1;
184 QString m_elementName;
187 int m_typeId; int m_listId;
189 mutable bool m_containsRevisionedAttributes;
190 mutable QDeclarativeType *m_superType;
192 int m_allocationSize;
193 void (*m_newFunc)(void *);
194 QString m_noCreationReason;
196 const QMetaObject *m_baseMetaObject;
197 QDeclarativeAttachedPropertiesFunc m_attachedPropertiesFunc;
198 const QMetaObject *m_attachedPropertiesType;
199 int m_attachedPropertiesId;
200 int m_parserStatusCast;
201 int m_propertyValueSourceCast;
202 int m_propertyValueInterceptorCast;
203 QObject *(*m_extFunc)(QObject *);
204 const QMetaObject *m_extMetaObject;
206 QDeclarativeCustomParser *m_customParser;
207 mutable volatile bool m_isSetup:1;
208 mutable volatile bool m_isEnumSetup:1;
209 mutable bool m_haveSuperType:1;
210 mutable QList<QDeclarativeProxyMetaObject::ProxyData> m_metaObjects;
211 mutable QStringHash<int> m_enums;
213 static QHash<const QMetaObject *, int> m_attachedPropertyIds;
216 QHash<const QMetaObject *, int> QDeclarativeTypePrivate::m_attachedPropertyIds;
218 QDeclarativeTypePrivate::QDeclarativeTypePrivate()
219 : m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_revision(0), m_containsRevisionedAttributes(false),
220 m_superType(0), m_allocationSize(0), m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0),
221 m_attachedPropertiesType(0), m_parserStatusCast(-1), m_propertyValueSourceCast(-1),
222 m_propertyValueInterceptorCast(-1), m_extFunc(0), m_extMetaObject(0), m_index(-1), m_customParser(0),
223 m_isSetup(false), m_isEnumSetup(false), m_haveSuperType(false)
228 QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::RegisterInterface &interface)
229 : d(new QDeclarativeTypePrivate)
231 d->m_isInterface = true;
232 d->m_iid = interface.iid;
233 d->m_typeId = interface.typeId;
234 d->m_listId = interface.listId;
238 d->m_version_maj = 0;
239 d->m_version_min = 0;
242 QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::RegisterType &type)
243 : d(new QDeclarativeTypePrivate)
245 QByteArray name = type.uri;
246 if (type.uri) name += '/';
247 name += type.elementName;
249 d->m_module = QString::fromUtf8(type.uri);
251 d->m_version_maj = type.versionMajor;
252 d->m_version_min = type.versionMinor;
253 if (type.version >= 1) // revisions added in version 1
254 d->m_revision = type.revision;
255 d->m_typeId = type.typeId;
256 d->m_listId = type.listId;
257 d->m_allocationSize = type.objectSize;
258 d->m_newFunc = type.create;
259 d->m_noCreationReason = type.noCreationReason;
260 d->m_baseMetaObject = type.metaObject;
261 d->m_attachedPropertiesFunc = type.attachedPropertiesFunction;
262 d->m_attachedPropertiesType = type.attachedPropertiesMetaObject;
263 if (d->m_attachedPropertiesType) {
264 QHash<const QMetaObject *, int>::Iterator iter = d->m_attachedPropertyIds.find(d->m_baseMetaObject);
265 if (iter == d->m_attachedPropertyIds.end())
266 iter = d->m_attachedPropertyIds.insert(d->m_baseMetaObject, index);
267 d->m_attachedPropertiesId = *iter;
269 d->m_attachedPropertiesId = -1;
271 d->m_parserStatusCast = type.parserStatusCast;
272 d->m_propertyValueSourceCast = type.valueSourceCast;
273 d->m_propertyValueInterceptorCast = type.valueInterceptorCast;
274 d->m_extFunc = type.extensionObjectCreate;
276 d->m_customParser = type.customParser;
278 if (type.extensionMetaObject)
279 d->m_extMetaObject = type.extensionMetaObject;
282 QDeclarativeType::~QDeclarativeType()
284 delete d->m_customParser;
288 QString QDeclarativeType::module() const
293 int QDeclarativeType::majorVersion() const
295 return d->m_version_maj;
298 int QDeclarativeType::minorVersion() const
300 return d->m_version_min;
303 bool QDeclarativeType::availableInVersion(int vmajor, int vminor) const
305 Q_ASSERT(vmajor >= 0 && vminor >= 0);
306 return vmajor == d->m_version_maj && vminor >= d->m_version_min;
309 bool QDeclarativeType::availableInVersion(const QString &module, int vmajor, int vminor) const
311 Q_ASSERT(vmajor >= 0 && vminor >= 0);
312 return module == d->m_module && vmajor == d->m_version_maj && vminor >= d->m_version_min;
315 // returns the nearest _registered_ super class
316 QDeclarativeType *QDeclarativeType::superType() const
318 if (!d->m_haveSuperType) {
319 const QMetaObject *mo = d->m_baseMetaObject->superClass();
320 while (mo && !d->m_superType) {
321 d->m_superType = QDeclarativeMetaType::qmlType(mo, d->m_module, d->m_version_maj, d->m_version_min);
322 mo = mo->superClass();
324 d->m_haveSuperType = true;
327 return d->m_superType;
330 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
331 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
334 builder.setClassName(ignoreEnd->className());
337 for (int ii = mo->classInfoOffset(); ii < mo->classInfoCount(); ++ii) {
338 QMetaClassInfo info = mo->classInfo(ii);
340 int otherIndex = ignoreEnd->indexOfClassInfo(info.name());
341 if (otherIndex >= ignoreStart->classInfoOffset() + ignoreStart->classInfoCount()) {
344 builder.addClassInfo(info.name(), info.value());
349 for (int ii = mo->propertyOffset(); ii < mo->propertyCount(); ++ii) {
350 QMetaProperty property = mo->property(ii);
352 int otherIndex = ignoreEnd->indexOfProperty(property.name());
353 if (otherIndex >= ignoreStart->propertyOffset() + ignoreStart->propertyCount()) {
354 builder.addProperty(QByteArray("__qml_ignore__") + property.name(), QByteArray("void"));
357 builder.addProperty(property);
362 for (int ii = mo->methodOffset(); ii < mo->methodCount(); ++ii) {
363 QMetaMethod method = mo->method(ii);
365 // More complex - need to search name
366 QByteArray name = method.signature();
367 int parenIdx = name.indexOf('(');
368 if (parenIdx != -1) name = name.left(parenIdx);
373 for (int ii = ignoreStart->methodOffset() + ignoreStart->methodCount();
374 !found && ii < ignoreEnd->methodOffset() + ignoreEnd->methodCount();
377 QMetaMethod other = ignoreEnd->method(ii);
378 QByteArray othername = other.signature();
379 int parenIdx = othername.indexOf('(');
380 if (parenIdx != -1) othername = othername.left(parenIdx);
382 found = name == othername;
385 QMetaMethodBuilder m = builder.addMethod(method);
387 m.setAccess(QMetaMethod::Private);
391 for (int ii = mo->enumeratorOffset(); ii < mo->enumeratorCount(); ++ii) {
392 QMetaEnum enumerator = mo->enumerator(ii);
394 int otherIndex = ignoreEnd->indexOfEnumerator(enumerator.name());
395 if (otherIndex >= ignoreStart->enumeratorOffset() + ignoreStart->enumeratorCount()) {
398 builder.addEnumerator(enumerator);
403 static bool isPropertyRevisioned(const QMetaObject *mo, int index)
406 i -= mo->propertyOffset();
407 if (i < 0 && mo->d.superdata)
408 return isPropertyRevisioned(mo->d.superdata, index);
410 const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate*>(mo->d.data);
411 if (i >= 0 && i < mop->propertyCount) {
412 int handle = mop->propertyData + 3*i;
413 int flags = mo->d.data[handle + 2];
415 return (flags & Revisioned);
421 void QDeclarativeTypePrivate::init() const
423 if (m_isSetup) return;
425 QWriteLocker lock(metaTypeDataLock());
429 // Setup extended meta object
430 // XXX - very inefficient
431 const QMetaObject *mo = m_baseMetaObject;
433 QMetaObject *mmo = new QMetaObject;
434 *mmo = *m_extMetaObject;
435 mmo->d.superdata = mo;
436 QDeclarativeProxyMetaObject::ProxyData data = { mmo, m_extFunc, 0, 0 };
437 m_metaObjects << data;
440 mo = mo->d.superdata;
442 QDeclarativeType *t = metaTypeData()->metaObjectToType.value(mo);
444 if (t->d->m_extFunc) {
445 QMetaObjectBuilder builder;
446 clone(builder, t->d->m_extMetaObject, t->d->m_baseMetaObject, m_baseMetaObject);
447 QMetaObject *mmo = builder.toMetaObject();
448 mmo->d.superdata = m_baseMetaObject;
449 if (!m_metaObjects.isEmpty())
450 m_metaObjects.last().metaObject->d.superdata = mmo;
451 QDeclarativeProxyMetaObject::ProxyData data = { mmo, t->d->m_extFunc, 0, 0 };
452 m_metaObjects << data;
455 mo = mo->d.superdata;
458 for (int ii = 0; ii < m_metaObjects.count(); ++ii) {
459 m_metaObjects[ii].propertyOffset =
460 m_metaObjects.at(ii).metaObject->propertyOffset();
461 m_metaObjects[ii].methodOffset =
462 m_metaObjects.at(ii).metaObject->methodOffset();
465 // Check for revisioned details
467 const QMetaObject *mo = 0;
468 if (m_metaObjects.isEmpty())
469 mo = m_baseMetaObject;
471 mo = m_metaObjects.first().metaObject;
473 for (int ii = 0; !m_containsRevisionedAttributes && ii < mo->propertyCount(); ++ii) {
474 if (isPropertyRevisioned(mo, ii))
475 m_containsRevisionedAttributes = true;
478 for (int ii = 0; !m_containsRevisionedAttributes && ii < mo->methodCount(); ++ii) {
479 if (mo->method(ii).revision() != 0)
480 m_containsRevisionedAttributes = true;
488 void QDeclarativeTypePrivate::initEnums() const
490 if (m_isEnumSetup) return;
494 QWriteLocker lock(metaTypeDataLock());
495 if (m_isEnumSetup) return;
497 const QMetaObject *metaObject = m_baseMetaObject;
498 for (int ii = 0; ii < metaObject->enumeratorCount(); ++ii) {
500 QMetaEnum e = metaObject->enumerator(ii);
502 for (int jj = 0; jj < e.keyCount(); ++jj)
503 m_enums.insert(QString::fromUtf8(e.key(jj)), e.value(jj));
506 m_isEnumSetup = true;
509 QByteArray QDeclarativeType::typeName() const
511 if (d->m_baseMetaObject)
512 return d->m_baseMetaObject->className();
517 const QString &QDeclarativeType::elementName() const
519 if (d->m_elementName.isEmpty()) {
520 QByteArray n = qmlTypeName();
521 int idx = n.lastIndexOf('/');
522 d->m_elementName = QString::fromUtf8(n.mid(idx + 1));
524 return d->m_elementName;
527 const QByteArray &QDeclarativeType::qmlTypeName() const
532 QObject *QDeclarativeType::create() const
536 QObject *rv = (QObject *)operator new(d->m_allocationSize);
539 if (rv && !d->m_metaObjects.isEmpty())
540 (void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects);
545 void QDeclarativeType::create(QObject **out, void **memory, size_t additionalMemory) const
549 QObject *rv = (QObject *)operator new(d->m_allocationSize + additionalMemory);
552 if (rv && !d->m_metaObjects.isEmpty())
553 (void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects);
556 *memory = ((char *)rv) + d->m_allocationSize;
559 QDeclarativeCustomParser *QDeclarativeType::customParser() const
561 return d->m_customParser;
564 QDeclarativeType::CreateFunc QDeclarativeType::createFunction() const
569 QString QDeclarativeType::noCreationReason() const
571 return d->m_noCreationReason;
574 int QDeclarativeType::createSize() const
576 return d->m_allocationSize;
579 bool QDeclarativeType::isCreatable() const
581 return d->m_newFunc != 0;
584 bool QDeclarativeType::isExtendedType() const
588 return !d->m_metaObjects.isEmpty();
591 bool QDeclarativeType::isInterface() const
593 return d->m_isInterface;
596 int QDeclarativeType::typeId() const
601 int QDeclarativeType::qListTypeId() const
606 const QMetaObject *QDeclarativeType::metaObject() const
610 if (d->m_metaObjects.isEmpty())
611 return d->m_baseMetaObject;
613 return d->m_metaObjects.first().metaObject;
617 const QMetaObject *QDeclarativeType::baseMetaObject() const
619 return d->m_baseMetaObject;
622 bool QDeclarativeType::containsRevisionedAttributes() const
626 return d->m_containsRevisionedAttributes;
629 int QDeclarativeType::metaObjectRevision() const
631 return d->m_revision;
634 QDeclarativeAttachedPropertiesFunc QDeclarativeType::attachedPropertiesFunction() const
636 return d->m_attachedPropertiesFunc;
639 const QMetaObject *QDeclarativeType::attachedPropertiesType() const
641 return d->m_attachedPropertiesType;
645 This is the id passed to qmlAttachedPropertiesById(). This is different from the index
646 for the case that a single class is registered under two or more names (eg. Item in
647 Qt 4.7 and QtQuick 1.0).
649 int QDeclarativeType::attachedPropertiesId() const
651 return d->m_attachedPropertiesId;
654 int QDeclarativeType::parserStatusCast() const
656 return d->m_parserStatusCast;
659 int QDeclarativeType::propertyValueSourceCast() const
661 return d->m_propertyValueSourceCast;
664 int QDeclarativeType::propertyValueInterceptorCast() const
666 return d->m_propertyValueInterceptorCast;
669 const char *QDeclarativeType::interfaceIId() const
674 int QDeclarativeType::index() const
679 int QDeclarativeType::enumValue(const QHashedStringRef &name) const
683 int *rv = d->m_enums.value(name);
687 int QDeclarativeType::enumValue(const QHashedV8String &name) const
691 int *rv = d->m_enums.value(name);
695 QDeclarativeTypeModule::QDeclarativeTypeModule()
696 : d(new QDeclarativeTypeModulePrivate)
700 QDeclarativeTypeModule::~QDeclarativeTypeModule()
705 QString QDeclarativeTypeModule::module() const
710 int QDeclarativeTypeModule::majorVersion() const
712 return d->uri.majorVersion;
715 int QDeclarativeTypeModule::minimumMinorVersion() const
717 return d->minMinorVersion;
720 int QDeclarativeTypeModule::maximumMinorVersion() const
722 return d->maxMinorVersion;
725 void QDeclarativeTypeModulePrivate::add(QDeclarativeType *type)
729 minMinorVersion = qMin(minMinorVersion, type->minorVersion());
730 maxMinorVersion = qMax(maxMinorVersion, type->minorVersion());
732 QList<QDeclarativeType *> &list = typeHash[type->elementName()];
733 for (int ii = 0; ii < list.count(); ++ii) {
734 if (list.at(ii)->minorVersion() < type->minorVersion()) {
735 list.insert(ii, type);
742 QList<QDeclarativeType *> QDeclarativeTypeModule::types()
744 QList<QDeclarativeType *> rv;
745 QReadLocker lock(metaTypeDataLock());
750 QList<QDeclarativeType *> QDeclarativeTypeModule::type(const QString &name)
752 QReadLocker lock(metaTypeDataLock());
753 QList<QDeclarativeType *> rv;
754 for (int ii = 0; ii < d->types.count(); ++ii) {
755 if (d->types.at(ii)->elementName() == name)
756 rv << d->types.at(ii);
761 QDeclarativeType *QDeclarativeTypeModule::type(const QHashedStringRef &name, int minor)
763 QReadLocker lock(metaTypeDataLock());
765 QList<QDeclarativeType *> *types = d->typeHash.value(name);
766 if (!types) return 0;
768 for (int ii = 0; ii < types->count(); ++ii)
769 if (types->at(ii)->minorVersion() <= minor)
770 return types->at(ii);
775 QDeclarativeType *QDeclarativeTypeModule::type(const QHashedV8String &name, int minor)
777 QReadLocker lock(metaTypeDataLock());
779 QList<QDeclarativeType *> *types = d->typeHash.value(name);
780 if (!types) return 0;
782 for (int ii = 0; ii < types->count(); ++ii)
783 if (types->at(ii)->minorVersion() <= minor)
784 return types->at(ii);
790 QDeclarativeTypeModuleVersion::QDeclarativeTypeModuleVersion()
791 : m_module(0), m_minor(0)
795 QDeclarativeTypeModuleVersion::QDeclarativeTypeModuleVersion(QDeclarativeTypeModule *module, int minor)
796 : m_module(module), m_minor(minor)
799 Q_ASSERT(m_minor >= 0);
802 QDeclarativeTypeModuleVersion::QDeclarativeTypeModuleVersion(const QDeclarativeTypeModuleVersion &o)
803 : m_module(o.m_module), m_minor(o.m_minor)
807 QDeclarativeTypeModuleVersion &QDeclarativeTypeModuleVersion::operator=(const QDeclarativeTypeModuleVersion &o)
809 m_module = o.m_module;
814 QDeclarativeTypeModule *QDeclarativeTypeModuleVersion::module() const
819 int QDeclarativeTypeModuleVersion::minorVersion() const
824 QDeclarativeType *QDeclarativeTypeModuleVersion::type(const QHashedStringRef &name) const
826 if (m_module) return m_module->type(name, m_minor);
830 QDeclarativeType *QDeclarativeTypeModuleVersion::type(const QHashedV8String &name) const
832 if (m_module) return m_module->type(name, m_minor);
837 int registerAutoParentFunction(QDeclarativePrivate::RegisterAutoParent &autoparent)
839 QWriteLocker lock(metaTypeDataLock());
840 QDeclarativeMetaTypeData *data = metaTypeData();
842 data->parentFunctions.append(autoparent.function);
844 return data->parentFunctions.count() - 1;
847 int registerInterface(const QDeclarativePrivate::RegisterInterface &interface)
849 if (interface.version > 0)
850 qFatal("qmlRegisterType(): Cannot mix incompatible QML versions.");
852 QWriteLocker lock(metaTypeDataLock());
853 QDeclarativeMetaTypeData *data = metaTypeData();
855 int index = data->types.count();
857 QDeclarativeType *type = new QDeclarativeType(index, interface);
859 data->types.append(type);
860 data->idToType.insert(type->typeId(), type);
861 data->idToType.insert(type->qListTypeId(), type);
862 // XXX No insertMulti, so no multi-version interfaces?
863 if (!type->qmlTypeName().isEmpty())
864 data->nameToType.insert(QString::fromUtf8(type->qmlTypeName()), type);
866 if (data->interfaces.size() <= interface.typeId)
867 data->interfaces.resize(interface.typeId + 16);
868 if (data->lists.size() <= interface.listId)
869 data->lists.resize(interface.listId + 16);
870 data->interfaces.setBit(interface.typeId, true);
871 data->lists.setBit(interface.listId, true);
876 int registerType(const QDeclarativePrivate::RegisterType &type)
878 if (type.elementName) {
879 for (int ii = 0; type.elementName[ii]; ++ii) {
880 if (!isalnum(type.elementName[ii])) {
881 qWarning("qmlRegisterType(): Invalid QML element name \"%s\"", type.elementName);
887 QWriteLocker lock(metaTypeDataLock());
888 QDeclarativeMetaTypeData *data = metaTypeData();
889 int index = data->types.count();
891 QDeclarativeType *dtype = new QDeclarativeType(index, type);
893 data->types.append(dtype);
894 data->idToType.insert(dtype->typeId(), dtype);
895 if (dtype->qListTypeId()) data->idToType.insert(dtype->qListTypeId(), dtype);
897 if (!dtype->qmlTypeName().isEmpty())
898 data->nameToType.insertMulti(QString::fromUtf8(dtype->qmlTypeName()), dtype);
900 data->metaObjectToType.insertMulti(dtype->baseMetaObject(), dtype);
902 if (data->objects.size() <= type.typeId)
903 data->objects.resize(type.typeId + 16);
904 if (data->lists.size() <= type.listId)
905 data->lists.resize(type.listId + 16);
906 data->objects.setBit(type.typeId, true);
907 if (type.listId) data->lists.setBit(type.listId, true);
910 QString mod = QString::fromUtf8(type.uri);
912 QDeclarativeMetaTypeData::VersionedUri versionedUri(mod, type.versionMajor);
913 QDeclarativeTypeModule *module = data->uriToModule.value(versionedUri);
915 module = new QDeclarativeTypeModule;
916 module->d->uri = versionedUri;
917 data->uriToModule.insert(versionedUri, module);
919 module->d->add(dtype);
925 int registerModuleApi(const QDeclarativePrivate::RegisterModuleApi &api)
927 QWriteLocker lock(metaTypeDataLock());
929 QDeclarativeMetaTypeData *data = metaTypeData();
930 QString uri = QString::fromUtf8(api.uri);
931 QDeclarativeMetaType::ModuleApi import;
932 import.major = api.versionMajor;
933 import.minor = api.versionMinor;
934 import.script = api.scriptApi;
935 import.qobject = api.qobjectApi;
937 int index = data->moduleApiCount++;
939 QDeclarativeMetaTypeData::ModuleApis::Iterator iter = data->moduleApis.find(uri);
940 if (iter == data->moduleApis.end()) {
941 QDeclarativeMetaTypeData::ModuleApiList apis;
942 apis.moduleApis << import;
943 data->moduleApis.insert(uri, apis);
945 iter->moduleApis << import;
946 iter->sorted = false;
954 This method is "over generalized" to allow us to (potentially) register more types of things in
955 the future without adding exported symbols.
957 int QDeclarativePrivate::qmlregister(RegistrationType type, void *data)
959 if (type == TypeRegistration) {
960 return registerType(*reinterpret_cast<RegisterType *>(data));
961 } else if (type == InterfaceRegistration) {
962 return registerInterface(*reinterpret_cast<RegisterInterface *>(data));
963 } else if (type == AutoParentRegistration) {
964 return registerAutoParentFunction(*reinterpret_cast<RegisterAutoParent *>(data));
965 } else if (type == ModuleApiRegistration) {
966 return registerModuleApi(*reinterpret_cast<RegisterModuleApi *>(data));
972 Returns true if a module \a uri of any version is installed.
974 bool QDeclarativeMetaType::isAnyModule(const QString &uri)
976 QReadLocker lock(metaTypeDataLock());
977 QDeclarativeMetaTypeData *data = metaTypeData();
979 for (QDeclarativeMetaTypeData::TypeModules::ConstIterator iter = data->uriToModule.begin();
980 iter != data->uriToModule.end(); ++iter) {
981 if ((*iter)->module() == uri)
989 Returns true if any type or API has been registered for the given \a module with at least
990 versionMajor.versionMinor, or if types have been registered for \a module with at most
991 versionMajor.versionMinor.
993 So if only 4.7 and 4.9 have been registered, 4.7,4.8, and 4.9 are valid, but not 4.6 nor 4.10.
995 bool QDeclarativeMetaType::isModule(const QString &module, int versionMajor, int versionMinor)
997 Q_ASSERT(versionMajor >= 0 && versionMinor >= 0);
998 QReadLocker lock(metaTypeDataLock());
1000 QDeclarativeMetaTypeData *data = metaTypeData();
1002 // first, check Types
1003 QDeclarativeTypeModule *tm =
1004 data->uriToModule.value(QDeclarativeMetaTypeData::VersionedUri(module, versionMajor));
1005 if (tm && tm->minimumMinorVersion() <= versionMinor && tm->maximumMinorVersion() >= versionMinor)
1008 // then, check ModuleApis
1009 foreach (const QDeclarativeMetaType::ModuleApi &mApi, data->moduleApis.value(module).moduleApis) {
1010 if (mApi.major == versionMajor && mApi.minor == versionMinor) // XXX is this correct?
1017 QDeclarativeTypeModule *QDeclarativeMetaType::typeModule(const QString &uri, int majorVersion)
1019 QReadLocker lock(metaTypeDataLock());
1020 QDeclarativeMetaTypeData *data = metaTypeData();
1021 return data->uriToModule.value(QDeclarativeMetaTypeData::VersionedUri(uri, majorVersion));
1024 QList<QDeclarativePrivate::AutoParentFunction> QDeclarativeMetaType::parentFunctions()
1026 QReadLocker lock(metaTypeDataLock());
1027 QDeclarativeMetaTypeData *data = metaTypeData();
1028 return data->parentFunctions;
1031 static bool operator<(const QDeclarativeMetaType::ModuleApi &lhs, const QDeclarativeMetaType::ModuleApi &rhs)
1033 return lhs.major < rhs.major || (lhs.major == rhs.major && lhs.minor < rhs.minor);
1036 QDeclarativeMetaType::ModuleApi
1037 QDeclarativeMetaType::moduleApi(const QString &uri, int versionMajor, int versionMinor)
1039 QReadLocker lock(metaTypeDataLock());
1040 QDeclarativeMetaTypeData *data = metaTypeData();
1042 QDeclarativeMetaTypeData::ModuleApis::Iterator iter = data->moduleApis.find(uri);
1043 if (iter == data->moduleApis.end())
1046 if (iter->sorted == false) {
1047 qSort(iter->moduleApis.begin(), iter->moduleApis.end());
1048 iter->sorted = true;
1051 for (int ii = iter->moduleApis.count() - 1; ii >= 0; --ii) {
1052 const ModuleApi &import = iter->moduleApis.at(ii);
1053 if (import.major == versionMajor && import.minor <= versionMinor)
1060 QObject *QDeclarativeMetaType::toQObject(const QVariant &v, bool *ok)
1062 if (!isQObject(v.userType())) {
1063 if (ok) *ok = false;
1069 return *(QObject **)v.constData();
1072 bool QDeclarativeMetaType::isQObject(int userType)
1074 if (userType == QMetaType::QObjectStar)
1077 QReadLocker lock(metaTypeDataLock());
1078 QDeclarativeMetaTypeData *data = metaTypeData();
1079 return userType >= 0 && userType < data->objects.size() && data->objects.testBit(userType);
1083 Returns the item type for a list of type \a id.
1085 int QDeclarativeMetaType::listType(int id)
1087 QReadLocker lock(metaTypeDataLock());
1088 QDeclarativeMetaTypeData *data = metaTypeData();
1089 QDeclarativeType *type = data->idToType.value(id);
1090 if (type && type->qListTypeId() == id)
1091 return type->typeId();
1096 int QDeclarativeMetaType::attachedPropertiesFuncId(const QMetaObject *mo)
1098 QReadLocker lock(metaTypeDataLock());
1099 QDeclarativeMetaTypeData *data = metaTypeData();
1101 QDeclarativeType *type = data->metaObjectToType.value(mo);
1102 if (type && type->attachedPropertiesFunction())
1103 return type->attachedPropertiesId();
1108 QDeclarativeAttachedPropertiesFunc QDeclarativeMetaType::attachedPropertiesFuncById(int id)
1112 QReadLocker lock(metaTypeDataLock());
1113 QDeclarativeMetaTypeData *data = metaTypeData();
1114 return data->types.at(id)->attachedPropertiesFunction();
1117 QMetaProperty QDeclarativeMetaType::defaultProperty(const QMetaObject *metaObject)
1119 int idx = metaObject->indexOfClassInfo("DefaultProperty");
1121 return QMetaProperty();
1123 QMetaClassInfo info = metaObject->classInfo(idx);
1125 return QMetaProperty();
1127 idx = metaObject->indexOfProperty(info.value());
1129 return QMetaProperty();
1131 return metaObject->property(idx);
1134 QMetaProperty QDeclarativeMetaType::defaultProperty(QObject *obj)
1137 return QMetaProperty();
1139 const QMetaObject *metaObject = obj->metaObject();
1140 return defaultProperty(metaObject);
1143 QMetaMethod QDeclarativeMetaType::defaultMethod(const QMetaObject *metaObject)
1145 int idx = metaObject->indexOfClassInfo("DefaultMethod");
1147 return QMetaMethod();
1149 QMetaClassInfo info = metaObject->classInfo(idx);
1151 return QMetaMethod();
1153 idx = metaObject->indexOfMethod(info.value());
1155 return QMetaMethod();
1157 return metaObject->method(idx);
1160 QMetaMethod QDeclarativeMetaType::defaultMethod(QObject *obj)
1163 return QMetaMethod();
1165 const QMetaObject *metaObject = obj->metaObject();
1166 return defaultMethod(metaObject);
1169 QDeclarativeMetaType::TypeCategory QDeclarativeMetaType::typeCategory(int userType)
1173 if (userType == QMetaType::QObjectStar)
1176 QReadLocker lock(metaTypeDataLock());
1177 QDeclarativeMetaTypeData *data = metaTypeData();
1178 if (userType < data->objects.size() && data->objects.testBit(userType))
1180 else if (userType < data->lists.size() && data->lists.testBit(userType))
1186 bool QDeclarativeMetaType::isInterface(int userType)
1188 QReadLocker lock(metaTypeDataLock());
1189 QDeclarativeMetaTypeData *data = metaTypeData();
1190 return userType >= 0 && userType < data->interfaces.size() && data->interfaces.testBit(userType);
1193 const char *QDeclarativeMetaType::interfaceIId(int userType)
1195 QReadLocker lock(metaTypeDataLock());
1196 QDeclarativeMetaTypeData *data = metaTypeData();
1197 QDeclarativeType *type = data->idToType.value(userType);
1199 if (type && type->isInterface() && type->typeId() == userType)
1200 return type->interfaceIId();
1205 bool QDeclarativeMetaType::isList(int userType)
1207 QReadLocker lock(metaTypeDataLock());
1208 QDeclarativeMetaTypeData *data = metaTypeData();
1209 return userType >= 0 && userType < data->lists.size() && data->lists.testBit(userType);
1213 A custom string convertor allows you to specify a function pointer that
1214 returns a variant of \a type. For example, if you have written your own icon
1215 class that you want to support as an object property assignable in QML:
1218 int type = qRegisterMetaType<SuperIcon>("SuperIcon");
1219 QML::addCustomStringConvertor(type, &SuperIcon::pixmapFromString);
1222 The function pointer must be of the form:
1224 QVariant (*StringConverter)(const QString &);
1227 void QDeclarativeMetaType::registerCustomStringConverter(int type, StringConverter converter)
1229 QWriteLocker lock(metaTypeDataLock());
1231 QDeclarativeMetaTypeData *data = metaTypeData();
1232 if (data->stringConverters.contains(type))
1234 data->stringConverters.insert(type, converter);
1238 Return the custom string converter for \a type, previously installed through
1239 registerCustomStringConverter()
1241 QDeclarativeMetaType::StringConverter QDeclarativeMetaType::customStringConverter(int type)
1243 QReadLocker lock(metaTypeDataLock());
1245 QDeclarativeMetaTypeData *data = metaTypeData();
1246 return data->stringConverters.value(type);
1250 Returns the type (if any) of URI-qualified named \a name in version specified
1251 by \a version_major and \a version_minor.
1253 QDeclarativeType *QDeclarativeMetaType::qmlType(const QString &name, int version_major, int version_minor)
1255 Q_ASSERT(version_major >= 0 && version_minor >= 0);
1256 QReadLocker lock(metaTypeDataLock());
1257 QDeclarativeMetaTypeData *data = metaTypeData();
1259 QDeclarativeMetaTypeData::Names::ConstIterator it = data->nameToType.find(name);
1260 while (it != data->nameToType.end()) {
1261 // XXX version_major<0 just a kludge for QDeclarativePropertyPrivate::initProperty
1262 if (it.key() == name && (version_major<0 || (*it)->availableInVersion(version_major,version_minor)))
1271 Returns the type (if any) that corresponds to the \a metaObject. Returns null if no
1274 QDeclarativeType *QDeclarativeMetaType::qmlType(const QMetaObject *metaObject)
1276 QReadLocker lock(metaTypeDataLock());
1277 QDeclarativeMetaTypeData *data = metaTypeData();
1279 return data->metaObjectToType.value(metaObject);
1283 Returns the type (if any) that corresponds to the \a metaObject in version specified
1284 by \a version_major and \a version_minor in module specified by \a uri. Returns null if no
1287 QDeclarativeType *QDeclarativeMetaType::qmlType(const QMetaObject *metaObject, const QString &module, int version_major, int version_minor)
1289 Q_ASSERT(version_major >= 0 && version_minor >= 0);
1290 QReadLocker lock(metaTypeDataLock());
1291 QDeclarativeMetaTypeData *data = metaTypeData();
1293 QDeclarativeMetaTypeData::MetaObjects::const_iterator it = data->metaObjectToType.find(metaObject);
1294 while (it != data->metaObjectToType.end() && it.key() == metaObject) {
1295 QDeclarativeType *t = *it;
1296 if (version_major < 0 || t->availableInVersion(module, version_major,version_minor))
1305 Returns the type (if any) that corresponds to the QVariant::Type \a userType.
1306 Returns null if no type is registered.
1308 QDeclarativeType *QDeclarativeMetaType::qmlType(int userType)
1310 QReadLocker lock(metaTypeDataLock());
1311 QDeclarativeMetaTypeData *data = metaTypeData();
1313 QDeclarativeType *type = data->idToType.value(userType);
1314 if (type && type->typeId() == userType)
1321 Returns the list of registered QML type names.
1323 QList<QString> QDeclarativeMetaType::qmlTypeNames()
1325 QReadLocker lock(metaTypeDataLock());
1326 QDeclarativeMetaTypeData *data = metaTypeData();
1328 return data->nameToType.keys();
1332 Returns the list of registered QML types.
1334 QList<QDeclarativeType*> QDeclarativeMetaType::qmlTypes()
1336 QReadLocker lock(metaTypeDataLock());
1337 QDeclarativeMetaTypeData *data = metaTypeData();
1339 return data->nameToType.values();
1344 #include <QtGui/qfont.h>
1345 #include <QtGui/qpixmap.h>
1346 #include <QtGui/qbrush.h>
1347 #include <QtGui/qcolor.h>
1348 #include <QtGui/qpalette.h>
1349 #include <QtGui/qicon.h>
1350 #include <QtGui/qimage.h>
1351 #include <QtGui/qpolygon.h>
1352 #include <QtGui/qregion.h>
1353 #include <QtGui/qbitmap.h>
1354 #include <QtGui/qcursor.h>
1355 #include <QtGui/qsizepolicy.h>
1356 #include <QtGui/qkeysequence.h>
1357 #include <QtGui/qpen.h>
1359 //#include <QtGui/qtextlength.h>
1360 #include <QtGui/qtextformat.h>
1361 #include <QtGui/qmatrix.h>
1362 #include <QtGui/qtransform.h>
1363 #include <QtGui/qmatrix4x4.h>
1364 #include <QtGui/qvector2d.h>
1365 #include <QtGui/qvector3d.h>
1366 #include <QtGui/qvector4d.h>
1367 #include <QtGui/qquaternion.h>
1368 #include <private/qv8engine_p.h>
1370 Q_DECLARE_METATYPE(QJSValue);
1371 Q_DECLARE_METATYPE(QDeclarativeV8Handle);
1375 bool QDeclarativeMetaType::canCopy(int type)
1378 case QMetaType::VoidStar:
1379 case QMetaType::QObjectStar:
1380 case QMetaType::QWidgetStar:
1381 case QMetaType::Long:
1382 case QMetaType::Int:
1383 case QMetaType::Short:
1384 case QMetaType::Char:
1385 case QMetaType::ULong:
1386 case QMetaType::UInt:
1387 case QMetaType::LongLong:
1388 case QMetaType::ULongLong:
1389 case QMetaType::UShort:
1390 case QMetaType::UChar:
1391 case QMetaType::Bool:
1392 case QMetaType::Float:
1393 case QMetaType::Double:
1394 case QMetaType::QChar:
1395 case QMetaType::QVariantMap:
1396 case QMetaType::QVariantHash:
1397 case QMetaType::QVariantList:
1398 case QMetaType::QByteArray:
1399 case QMetaType::QString:
1400 case QMetaType::QStringList:
1401 case QMetaType::QBitArray:
1402 case QMetaType::QDate:
1403 case QMetaType::QTime:
1404 case QMetaType::QDateTime:
1405 case QMetaType::QUrl:
1406 case QMetaType::QLocale:
1407 case QMetaType::QRect:
1408 case QMetaType::QRectF:
1409 case QMetaType::QSize:
1410 case QMetaType::QSizeF:
1411 case QMetaType::QLine:
1412 case QMetaType::QLineF:
1413 case QMetaType::QPoint:
1414 case QMetaType::QPointF:
1415 case QMetaType::QVector3D:
1416 #ifndef QT_NO_REGEXP
1417 case QMetaType::QRegExp:
1419 case QMetaType::Void:
1421 case QMetaType::QColorGroup:
1423 case QMetaType::QFont:
1424 case QMetaType::QPixmap:
1425 case QMetaType::QBrush:
1426 case QMetaType::QColor:
1427 case QMetaType::QPalette:
1428 case QMetaType::QIcon:
1429 case QMetaType::QImage:
1430 case QMetaType::QPolygon:
1431 case QMetaType::QRegion:
1432 case QMetaType::QBitmap:
1433 #ifndef QT_NO_CURSOR
1434 case QMetaType::QCursor:
1436 case QMetaType::QSizePolicy:
1437 case QMetaType::QKeySequence:
1438 case QMetaType::QPen:
1439 case QMetaType::QTextLength:
1440 case QMetaType::QTextFormat:
1441 case QMetaType::QMatrix:
1442 case QMetaType::QTransform:
1443 case QMetaType::QMatrix4x4:
1444 case QMetaType::QVector2D:
1445 case QMetaType::QVector4D:
1446 case QMetaType::QQuaternion:
1450 if (type == qMetaTypeId<QVariant>() ||
1451 type == qMetaTypeId<QJSValue>() ||
1452 type == qMetaTypeId<QDeclarativeV8Handle>() ||
1453 typeCategory(type) != Unknown) {
1463 Copies \a copy into \a data, assuming they both are of type \a type. If
1464 \a copy is zero, a default type is copied. Returns true if the copy was
1465 successful and false if not.
1467 \note This should move into QMetaType once complete
1470 bool QDeclarativeMetaType::copy(int type, void *data, const void *copy)
1474 case QMetaType::VoidStar:
1475 case QMetaType::QObjectStar:
1476 case QMetaType::QWidgetStar:
1477 *static_cast<void **>(data) = *static_cast<void* const *>(copy);
1479 case QMetaType::Long:
1480 *static_cast<long *>(data) = *static_cast<const long*>(copy);
1482 case QMetaType::Int:
1483 *static_cast<int *>(data) = *static_cast<const int*>(copy);
1485 case QMetaType::Short:
1486 *static_cast<short *>(data) = *static_cast<const short*>(copy);
1488 case QMetaType::Char:
1489 *static_cast<char *>(data) = *static_cast<const char*>(copy);
1491 case QMetaType::ULong:
1492 *static_cast<ulong *>(data) = *static_cast<const ulong*>(copy);
1494 case QMetaType::UInt:
1495 *static_cast<uint *>(data) = *static_cast<const uint*>(copy);
1497 case QMetaType::LongLong:
1498 *static_cast<qlonglong *>(data) = *static_cast<const qlonglong*>(copy);
1500 case QMetaType::ULongLong:
1501 *static_cast<qulonglong *>(data) = *static_cast<const qulonglong*>(copy);
1503 case QMetaType::UShort:
1504 *static_cast<ushort *>(data) = *static_cast<const ushort*>(copy);
1506 case QMetaType::UChar:
1507 *static_cast<uchar *>(data) = *static_cast<const uchar*>(copy);
1509 case QMetaType::Bool:
1510 *static_cast<bool *>(data) = *static_cast<const bool*>(copy);
1512 case QMetaType::Float:
1513 *static_cast<float *>(data) = *static_cast<const float*>(copy);
1515 case QMetaType::Double:
1516 *static_cast<double *>(data) = *static_cast<const double*>(copy);
1518 case QMetaType::QChar:
1519 *static_cast<NS(QChar) *>(data) = *static_cast<const NS(QChar)*>(copy);
1521 case QMetaType::QVariantMap:
1522 *static_cast<NS(QVariantMap) *>(data) = *static_cast<const NS(QVariantMap)*>(copy);
1524 case QMetaType::QVariantHash:
1525 *static_cast<NS(QVariantHash) *>(data) = *static_cast<const NS(QVariantHash)*>(copy);
1527 case QMetaType::QVariantList:
1528 *static_cast<NS(QVariantList) *>(data) = *static_cast<const NS(QVariantList)*>(copy);
1530 case QMetaType::QByteArray:
1531 *static_cast<NS(QByteArray) *>(data) = *static_cast<const NS(QByteArray)*>(copy);
1533 case QMetaType::QString:
1534 *static_cast<NS(QString) *>(data) = *static_cast<const NS(QString)*>(copy);
1536 case QMetaType::QStringList:
1537 *static_cast<NS(QStringList) *>(data) = *static_cast<const NS(QStringList)*>(copy);
1539 case QMetaType::QBitArray:
1540 *static_cast<NS(QBitArray) *>(data) = *static_cast<const NS(QBitArray)*>(copy);
1542 case QMetaType::QDate:
1543 *static_cast<NS(QDate) *>(data) = *static_cast<const NS(QDate)*>(copy);
1545 case QMetaType::QTime:
1546 *static_cast<NS(QTime) *>(data) = *static_cast<const NS(QTime)*>(copy);
1548 case QMetaType::QDateTime:
1549 *static_cast<NS(QDateTime) *>(data) = *static_cast<const NS(QDateTime)*>(copy);
1551 case QMetaType::QUrl:
1552 *static_cast<NS(QUrl) *>(data) = *static_cast<const NS(QUrl)*>(copy);
1554 case QMetaType::QLocale:
1555 *static_cast<NS(QLocale) *>(data) = *static_cast<const NS(QLocale)*>(copy);
1557 case QMetaType::QRect:
1558 *static_cast<NS(QRect) *>(data) = *static_cast<const NS(QRect)*>(copy);
1560 case QMetaType::QRectF:
1561 *static_cast<NS(QRectF) *>(data) = *static_cast<const NS(QRectF)*>(copy);
1563 case QMetaType::QSize:
1564 *static_cast<NS(QSize) *>(data) = *static_cast<const NS(QSize)*>(copy);
1566 case QMetaType::QSizeF:
1567 *static_cast<NS(QSizeF) *>(data) = *static_cast<const NS(QSizeF)*>(copy);
1569 case QMetaType::QLine:
1570 *static_cast<NS(QLine) *>(data) = *static_cast<const NS(QLine)*>(copy);
1572 case QMetaType::QLineF:
1573 *static_cast<NS(QLineF) *>(data) = *static_cast<const NS(QLineF)*>(copy);
1575 case QMetaType::QPoint:
1576 *static_cast<NS(QPoint) *>(data) = *static_cast<const NS(QPoint)*>(copy);
1578 case QMetaType::QPointF:
1579 *static_cast<NS(QPointF) *>(data) = *static_cast<const NS(QPointF)*>(copy);
1581 case QMetaType::QVector3D:
1582 *static_cast<NS(QVector3D) *>(data) = *static_cast<const NS(QVector3D)*>(copy);
1584 #ifndef QT_NO_REGEXP
1585 case QMetaType::QRegExp:
1586 *static_cast<NS(QRegExp) *>(data) = *static_cast<const NS(QRegExp)*>(copy);
1589 case QMetaType::Void:
1594 case QMetaType::QColorGroup:
1595 *static_cast<NS(QColorGroup) *>(data) = *static_cast<const NS(QColorGroup)*>(copy);
1599 case QMetaType::QFont:
1600 *static_cast<NS(QFont) *>(data) = *static_cast<const NS(QFont)*>(copy);
1602 case QMetaType::QPixmap:
1603 *static_cast<NS(QPixmap) *>(data) = *static_cast<const NS(QPixmap)*>(copy);
1605 case QMetaType::QBrush:
1606 *static_cast<NS(QBrush) *>(data) = *static_cast<const NS(QBrush)*>(copy);
1608 case QMetaType::QColor:
1609 *static_cast<NS(QColor) *>(data) = *static_cast<const NS(QColor)*>(copy);
1611 case QMetaType::QPalette:
1612 *static_cast<NS(QPalette) *>(data) = *static_cast<const NS(QPalette)*>(copy);
1614 case QMetaType::QIcon:
1615 *static_cast<NS(QIcon) *>(data) = *static_cast<const NS(QIcon)*>(copy);
1617 case QMetaType::QImage:
1618 *static_cast<NS(QImage) *>(data) = *static_cast<const NS(QImage)*>(copy);
1620 case QMetaType::QPolygon:
1621 *static_cast<NS(QPolygon) *>(data) = *static_cast<const NS(QPolygon)*>(copy);
1623 case QMetaType::QRegion:
1624 *static_cast<NS(QRegion) *>(data) = *static_cast<const NS(QRegion)*>(copy);
1626 case QMetaType::QBitmap:
1627 *static_cast<NS(QBitmap) *>(data) = *static_cast<const NS(QBitmap)*>(copy);
1629 #ifndef QT_NO_CURSOR
1630 case QMetaType::QCursor:
1631 *static_cast<NS(QCursor) *>(data) = *static_cast<const NS(QCursor)*>(copy);
1634 case QMetaType::QSizePolicy:
1635 *static_cast<NS(QSizePolicy) *>(data) = *static_cast<const NS(QSizePolicy)*>(copy);
1637 case QMetaType::QKeySequence:
1638 *static_cast<NS(QKeySequence) *>(data) = *static_cast<const NS(QKeySequence)*>(copy);
1640 case QMetaType::QPen:
1641 *static_cast<NS(QPen) *>(data) = *static_cast<const NS(QPen)*>(copy);
1643 case QMetaType::QTextLength:
1644 *static_cast<NS(QTextLength) *>(data) = *static_cast<const NS(QTextLength)*>(copy);
1646 case QMetaType::QTextFormat:
1647 *static_cast<NS(QTextFormat) *>(data) = *static_cast<const NS(QTextFormat)*>(copy);
1649 case QMetaType::QMatrix:
1650 *static_cast<NS(QMatrix) *>(data) = *static_cast<const NS(QMatrix)*>(copy);
1652 case QMetaType::QTransform:
1653 *static_cast<NS(QTransform) *>(data) = *static_cast<const NS(QTransform)*>(copy);
1655 case QMetaType::QMatrix4x4:
1656 *static_cast<NS(QMatrix4x4) *>(data) = *static_cast<const NS(QMatrix4x4)*>(copy);
1658 case QMetaType::QVector2D:
1659 *static_cast<NS(QVector2D) *>(data) = *static_cast<const NS(QVector2D)*>(copy);
1661 case QMetaType::QVector4D:
1662 *static_cast<NS(QVector4D) *>(data) = *static_cast<const NS(QVector4D)*>(copy);
1664 case QMetaType::QQuaternion:
1665 *static_cast<NS(QQuaternion) *>(data) = *static_cast<const NS(QQuaternion)*>(copy);
1669 if (type == qMetaTypeId<QVariant>()) {
1670 *static_cast<NS(QVariant) *>(data) = *static_cast<const NS(QVariant)*>(copy);
1672 } else if (type == qMetaTypeId<QJSValue>()) {
1673 *static_cast<NS(QJSValue) *>(data) = *static_cast<const NS(QJSValue)*>(copy);
1675 } else if (type == qMetaTypeId<QDeclarativeV8Handle>()) {
1676 *static_cast<NS(QDeclarativeV8Handle) *>(data) = *static_cast<const NS(QDeclarativeV8Handle)*>(copy);
1678 } else if (typeCategory(type) != Unknown) {
1679 *static_cast<void **>(data) = *static_cast<void* const *>(copy);
1686 case QMetaType::VoidStar:
1687 case QMetaType::QObjectStar:
1688 case QMetaType::QWidgetStar:
1689 *static_cast<void **>(data) = 0;
1691 case QMetaType::Long:
1692 *static_cast<long *>(data) = long(0);
1694 case QMetaType::Int:
1695 *static_cast<int *>(data) = int(0);
1697 case QMetaType::Short:
1698 *static_cast<short *>(data) = short(0);
1700 case QMetaType::Char:
1701 *static_cast<char *>(data) = char(0);
1703 case QMetaType::ULong:
1704 *static_cast<ulong *>(data) = ulong(0);
1706 case QMetaType::UInt:
1707 *static_cast<uint *>(data) = uint(0);
1709 case QMetaType::LongLong:
1710 *static_cast<qlonglong *>(data) = qlonglong(0);
1712 case QMetaType::ULongLong:
1713 *static_cast<qulonglong *>(data) = qulonglong(0);
1715 case QMetaType::UShort:
1716 *static_cast<ushort *>(data) = ushort(0);
1718 case QMetaType::UChar:
1719 *static_cast<uchar *>(data) = uchar(0);
1721 case QMetaType::Bool:
1722 *static_cast<bool *>(data) = bool(false);
1724 case QMetaType::Float:
1725 *static_cast<float *>(data) = float(0);
1727 case QMetaType::Double:
1728 *static_cast<double *>(data) = double(0);
1730 case QMetaType::QChar:
1731 *static_cast<NS(QChar) *>(data) = NS(QChar)();
1733 case QMetaType::QVariantMap:
1734 *static_cast<NS(QVariantMap) *>(data) = NS(QVariantMap)();
1736 case QMetaType::QVariantHash:
1737 *static_cast<NS(QVariantHash) *>(data) = NS(QVariantHash)();
1739 case QMetaType::QVariantList:
1740 *static_cast<NS(QVariantList) *>(data) = NS(QVariantList)();
1742 case QMetaType::QByteArray:
1743 *static_cast<NS(QByteArray) *>(data) = NS(QByteArray)();
1745 case QMetaType::QString:
1746 *static_cast<NS(QString) *>(data) = NS(QString)();
1748 case QMetaType::QStringList:
1749 *static_cast<NS(QStringList) *>(data) = NS(QStringList)();
1751 case QMetaType::QBitArray:
1752 *static_cast<NS(QBitArray) *>(data) = NS(QBitArray)();
1754 case QMetaType::QDate:
1755 *static_cast<NS(QDate) *>(data) = NS(QDate)();
1757 case QMetaType::QTime:
1758 *static_cast<NS(QTime) *>(data) = NS(QTime)();
1760 case QMetaType::QDateTime:
1761 *static_cast<NS(QDateTime) *>(data) = NS(QDateTime)();
1763 case QMetaType::QUrl:
1764 *static_cast<NS(QUrl) *>(data) = NS(QUrl)();
1766 case QMetaType::QLocale:
1767 *static_cast<NS(QLocale) *>(data) = NS(QLocale)();
1769 case QMetaType::QRect:
1770 *static_cast<NS(QRect) *>(data) = NS(QRect)();
1772 case QMetaType::QRectF:
1773 *static_cast<NS(QRectF) *>(data) = NS(QRectF)();
1775 case QMetaType::QSize:
1776 *static_cast<NS(QSize) *>(data) = NS(QSize)();
1778 case QMetaType::QSizeF:
1779 *static_cast<NS(QSizeF) *>(data) = NS(QSizeF)();
1781 case QMetaType::QLine:
1782 *static_cast<NS(QLine) *>(data) = NS(QLine)();
1784 case QMetaType::QLineF:
1785 *static_cast<NS(QLineF) *>(data) = NS(QLineF)();
1787 case QMetaType::QPoint:
1788 *static_cast<NS(QPoint) *>(data) = NS(QPoint)();
1790 case QMetaType::QPointF:
1791 *static_cast<NS(QPointF) *>(data) = NS(QPointF)();
1793 case QMetaType::QVector3D:
1794 *static_cast<NS(QVector3D) *>(data) = NS(QVector3D)();
1796 #ifndef QT_NO_REGEXP
1797 case QMetaType::QRegExp:
1798 *static_cast<NS(QRegExp) *>(data) = NS(QRegExp)();
1801 case QMetaType::Void:
1805 case QMetaType::QColorGroup:
1806 *static_cast<NS(QColorGroup) *>(data) = NS(QColorGroup)();
1810 case QMetaType::QFont:
1811 *static_cast<NS(QFont) *>(data) = NS(QFont)();
1813 case QMetaType::QPixmap:
1814 *static_cast<NS(QPixmap) *>(data) = NS(QPixmap)();
1816 case QMetaType::QBrush:
1817 *static_cast<NS(QBrush) *>(data) = NS(QBrush)();
1819 case QMetaType::QColor:
1820 *static_cast<NS(QColor) *>(data) = NS(QColor)();
1822 case QMetaType::QPalette:
1823 *static_cast<NS(QPalette) *>(data) = NS(QPalette)();
1825 case QMetaType::QIcon:
1826 *static_cast<NS(QIcon) *>(data) = NS(QIcon)();
1828 case QMetaType::QImage:
1829 *static_cast<NS(QImage) *>(data) = NS(QImage)();
1831 case QMetaType::QPolygon:
1832 *static_cast<NS(QPolygon) *>(data) = NS(QPolygon)();
1834 case QMetaType::QRegion:
1835 *static_cast<NS(QRegion) *>(data) = NS(QRegion)();
1837 case QMetaType::QBitmap:
1838 *static_cast<NS(QBitmap) *>(data) = NS(QBitmap)();
1840 #ifndef QT_NO_CURSOR
1841 case QMetaType::QCursor:
1842 *static_cast<NS(QCursor) *>(data) = NS(QCursor)();
1845 case QMetaType::QSizePolicy:
1846 *static_cast<NS(QSizePolicy) *>(data) = NS(QSizePolicy)();
1848 case QMetaType::QKeySequence:
1849 *static_cast<NS(QKeySequence) *>(data) = NS(QKeySequence)();
1851 case QMetaType::QPen:
1852 *static_cast<NS(QPen) *>(data) = NS(QPen)();
1854 case QMetaType::QTextLength:
1855 *static_cast<NS(QTextLength) *>(data) = NS(QTextLength)();
1857 case QMetaType::QTextFormat:
1858 *static_cast<NS(QTextFormat) *>(data) = NS(QTextFormat)();
1860 case QMetaType::QMatrix:
1861 *static_cast<NS(QMatrix) *>(data) = NS(QMatrix)();
1863 case QMetaType::QTransform:
1864 *static_cast<NS(QTransform) *>(data) = NS(QTransform)();
1866 case QMetaType::QMatrix4x4:
1867 *static_cast<NS(QMatrix4x4) *>(data) = NS(QMatrix4x4)();
1869 case QMetaType::QVector2D:
1870 *static_cast<NS(QVector2D) *>(data) = NS(QVector2D)();
1872 case QMetaType::QVector4D:
1873 *static_cast<NS(QVector4D) *>(data) = NS(QVector4D)();
1875 case QMetaType::QQuaternion:
1876 *static_cast<NS(QQuaternion) *>(data) = NS(QQuaternion)();
1879 if (type == qMetaTypeId<QVariant>()) {
1880 *static_cast<NS(QVariant) *>(data) = NS(QVariant)();
1882 } else if (type == qMetaTypeId<QJSValue>()) {
1883 *static_cast<NS(QJSValue) *>(data) = NS(QJSValue)();
1885 } else if (type == qMetaTypeId<QDeclarativeV8Handle>()) {
1886 *static_cast<NS(QDeclarativeV8Handle) *>(data) = NS(QDeclarativeV8Handle)();
1888 } else if (typeCategory(type) != Unknown) {
1889 *static_cast<void **>(data) = 0;