From 49a11e882059ee1729f776722e085dd21d378c36 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 23 Jun 2017 13:20:23 +0200 Subject: Use QQmlType by value QQmlType is now refcounted, and we need to use it by value, to control it's lifetime properly. This is required, so we can clean up the QQmlMetaTypeData cache on engine destruction and with trimComponentCache() Task-number: QTBUG-61536 Change-Id: If86391c86ea20a646ded7c9925d8f743f628fb91 Reviewed-by: Simon Hausmann --- src/imports/testlib/main.cpp | 8 +- .../qmldbg_debugger/qqmlenginedebugservice.cpp | 5 +- src/qml/compiler/qqmlirbuilder.cpp | 12 +- src/qml/compiler/qqmlpropertycachecreator_p.h | 34 ++--- src/qml/compiler/qqmlpropertyvalidator.cpp | 20 +-- src/qml/compiler/qqmltypecompiler.cpp | 53 ++++---- src/qml/compiler/qv4compileddata.cpp | 20 +-- src/qml/compiler/qv4compileddata_p.h | 5 +- src/qml/jsruntime/qv4engine.cpp | 6 +- src/qml/jsruntime/qv4qmlcontext.cpp | 4 +- src/qml/jsruntime/qv4qobjectwrapper.cpp | 4 +- src/qml/qml/qqmlcustomparser.cpp | 10 +- src/qml/qml/qqmlengine.cpp | 47 ++++--- src/qml/qml/qqmlengine_p.h | 14 +- src/qml/qml/qqmlimport.cpp | 56 ++++---- src/qml/qml/qqmlimport_p.h | 12 +- src/qml/qml/qqmllist.cpp | 2 +- src/qml/qml/qqmlmetatype.cpp | 147 +++++++++++---------- src/qml/qml/qqmlmetatype_p.h | 52 +++++--- src/qml/qml/qqmlobjectcreator.cpp | 34 ++--- src/qml/qml/qqmlproperty.cpp | 23 ++-- src/qml/qml/qqmltypeloader.cpp | 46 +++---- src/qml/qml/qqmltypeloader_p.h | 4 +- src/qml/qml/qqmltypenamecache.cpp | 8 +- src/qml/qml/qqmltypenamecache_p.h | 22 +-- src/qml/qml/qqmltypewrapper.cpp | 6 +- src/quick/designer/qquickdesignersupportitems.cpp | 41 +++--- .../designer/qquickdesignersupportmetainfo.cpp | 4 +- tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp | 6 +- tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 104 +++++++-------- tests/benchmarks/qml/creation/tst_creation.cpp | 4 +- tools/qmlplugindump/main.cpp | 22 +-- 32 files changed, 424 insertions(+), 411 deletions(-) diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index 3c28000e35..fc013d5afc 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -91,14 +91,14 @@ public Q_SLOTS: { QString name(v.typeName()); if (v.canConvert()) { - QQmlType *type = 0; + QQmlType type; const QMetaObject *mo = v.value()->metaObject(); - while (!type && mo) { + while (!type.isValid() && mo) { type = QQmlMetaType::qmlType(mo); mo = mo->superClass(); } - if (type) { - name = type->qmlTypeName(); + if (type.isValid()) { + name = type.qmlTypeName(); } } diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp index f0bb4de016..3d08c4c809 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp @@ -695,8 +695,9 @@ bool QQmlEngineDebugServiceImpl::resetBinding(int objectId, const QString &prope property.reset(); } else { // overwrite with default value - if (QQmlType *objType = QQmlMetaType::qmlType(object->metaObject())) { - if (QObject *emptyObject = objType->create()) { + QQmlType objType = QQmlMetaType::qmlType(object->metaObject()); + if (objType.isValid()) { + if (QObject *emptyObject = objType.create()) { if (emptyObject->property(parentProperty).isValid()) { QVariant defaultValue = QQmlProperty(emptyObject, propertyName).read(); if (defaultValue.isValid()) { diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 60045952c9..5bbf067320 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1767,14 +1767,14 @@ static QV4::IR::DiscoveredType resolveImportNamespace( if (r.scriptIndex != -1) { // TODO: remember the index and replace with subscript later. result = QV4::IR::VarType; - } else if (r.type) { + } else if (r.type.isValid()) { // TODO: Propagate singleton information, so that it is loaded // through the singleton getter in the run-time. Until then we // can't accelerate access :( - if (!r.type->isSingleton()) { + if (!r.type.isSingleton()) { auto newResolver = resolver->owner->New(); newResolver->owner = resolver->owner; - initQmlTypeResolver(newResolver, *r.type); + initQmlTypeResolver(newResolver, r.type); return QV4::IR::DiscoveredType(newResolver); } } else { @@ -1950,10 +1950,10 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int if (r.scriptIndex != -1) { return _block->SUBSCRIPT(_block->TEMP(_importedScriptsTemp), _block->CONST(QV4::IR::SInt32Type, r.scriptIndex)); - } else if (r.type) { + } else if (r.type.isValid()) { QV4::IR::Name *typeName = _block->NAME(name, line, col); // Make sure the run-time loads this through the more efficient singleton getter. - typeName->qmlSingleton = r.type->isCompositeSingleton(); + typeName->qmlSingleton = r.type.isCompositeSingleton(); typeName->freeOfSideEffects = true; QV4::IR::Temp *result = _block->TEMP(_block->newTemp()); _block->MOVE(result, typeName); @@ -1961,7 +1961,7 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int result = _block->TEMP(result->index); result->memberResolver = _function->New(); result->memberResolver->owner = _function; - initQmlTypeResolver(result->memberResolver, *r.type); + initQmlTypeResolver(result->memberResolver, r.type); return result; } else { Q_ASSERT(r.importNamespace); diff --git a/src/qml/compiler/qqmlpropertycachecreator_p.h b/src/qml/compiler/qqmlpropertycachecreator_p.h index 3c14abc019..8fc8943366 100644 --- a/src/qml/compiler/qqmlpropertycachecreator_p.h +++ b/src/qml/compiler/qqmlpropertycachecreator_p.h @@ -211,12 +211,12 @@ inline QQmlPropertyCache *QQmlPropertyCacheCreator::propertyCac } else if (context.instantiatingBinding && context.instantiatingBinding->isAttachedProperty()) { auto *typeRef = objectContainer->resolvedTypes.value(context.instantiatingBinding->propertyNameIndex); Q_ASSERT(typeRef); - QQmlType *qmltype = typeRef->type; - if (!qmltype) { + QQmlType qmltype = typeRef->type; + if (!qmltype.isValid()) { QString propertyName = stringAt(context.instantiatingBinding->propertyNameIndex); if (imports->resolveType(propertyName, &qmltype, 0, 0, 0)) { - if (qmltype->isComposite()) { - QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype->sourceUrl()); + if (qmltype.isComposite()) { + QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl()); Q_ASSERT(tdata); Q_ASSERT(tdata->isComplete()); @@ -228,7 +228,7 @@ inline QQmlPropertyCache *QQmlPropertyCacheCreator::propertyCac } } - const QMetaObject *attachedMo = qmltype ? qmltype->attachedPropertiesType(enginePrivate) : 0; + const QMetaObject *attachedMo = qmltype.attachedPropertiesType(enginePrivate); if (!attachedMo) { *error = QQmlCompileError(context.instantiatingBinding->location, QQmlPropertyCacheCreatorBase::tr("Non-existent attached object")); return nullptr; @@ -395,12 +395,12 @@ inline QQmlCompileError QQmlPropertyCacheCreator::createMetaObj // lazily resolved type Q_ASSERT(param->type == QV4::CompiledData::Property::Custom); const QString customTypeName = stringAt(param->customTypeNameIndex); - QQmlType *qmltype = 0; + QQmlType qmltype; if (!imports->resolveType(customTypeName, &qmltype, 0, 0, 0)) return QQmlCompileError(s->location, QQmlPropertyCacheCreatorBase::tr("Invalid signal parameter type: %1").arg(customTypeName)); - if (qmltype->isComposite()) { - QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype->sourceUrl()); + if (qmltype.isComposite()) { + QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl()); Q_ASSERT(tdata); Q_ASSERT(tdata->isComplete()); @@ -410,7 +410,7 @@ inline QQmlCompileError QQmlPropertyCacheCreator::createMetaObj tdata->release(); } else { - paramTypes[i + 1] = qmltype->typeId(); + paramTypes[i + 1] = qmltype.typeId(); } } } @@ -475,14 +475,14 @@ inline QQmlCompileError QQmlPropertyCacheCreator::createMetaObj Q_ASSERT(p->type == QV4::CompiledData::Property::CustomList || p->type == QV4::CompiledData::Property::Custom); - QQmlType *qmltype = 0; + QQmlType qmltype; if (!imports->resolveType(stringAt(p->customTypeNameIndex), &qmltype, 0, 0, 0)) { return QQmlCompileError(p->location, QQmlPropertyCacheCreatorBase::tr("Invalid property type")); } - Q_ASSERT(qmltype); - if (qmltype->isComposite()) { - QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype->sourceUrl()); + Q_ASSERT(qmltype.isValid()); + if (qmltype.isComposite()) { + QQmlTypeData *tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl()); Q_ASSERT(tdata); Q_ASSERT(tdata->isComplete()); @@ -497,9 +497,9 @@ inline QQmlCompileError QQmlPropertyCacheCreator::createMetaObj tdata->release(); } else { if (p->type == QV4::CompiledData::Property::Custom) { - propertyType = qmltype->typeId(); + propertyType = qmltype.typeId(); } else { - propertyType = qmltype->qListTypeId(); + propertyType = qmltype.qListTypeId(); } } @@ -675,8 +675,8 @@ inline void QQmlPropertyCacheAliasCreator::propertyDataForAlias auto *typeRef = objectContainer->resolvedTypes.value(targetObject.inheritedTypeNameIndex); Q_ASSERT(typeRef); - if (typeRef->type) - *type = typeRef->type->typeId(); + if (typeRef->type.isValid()) + *type = typeRef->type.typeId(); else *type = typeRef->compilationUnit->metaTypeId; diff --git a/src/qml/compiler/qqmlpropertyvalidator.cpp b/src/qml/compiler/qqmlpropertyvalidator.cpp index da652e8f5d..4ac7aad553 100644 --- a/src/qml/compiler/qqmlpropertyvalidator.cpp +++ b/src/qml/compiler/qqmlpropertyvalidator.cpp @@ -106,8 +106,8 @@ QVector QQmlPropertyValidator::validateObject(int objectIndex, QQmlCustomParser *customParser = 0; if (auto typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex)) { - if (typeRef->type) - customParser = typeRef->type->customParser(); + if (typeRef->type.isValid()) + customParser = typeRef->type.customParser(); } QList customBindings; @@ -178,8 +178,8 @@ QVector QQmlPropertyValidator::validateObject(int objectIndex, if (notInRevision) { QString typeName = stringAt(obj->inheritedTypeNameIndex); auto *objectType = resolvedTypes.value(obj->inheritedTypeNameIndex); - if (objectType && objectType->type) { - return recordError(binding->location, tr("\"%1.%2\" is not available in %3 %4.%5.").arg(typeName).arg(name).arg(objectType->type->module()).arg(objectType->majorVersion).arg(objectType->minorVersion)); + if (objectType && objectType->type.isValid()) { + return recordError(binding->location, tr("\"%1.%2\" is not available in %3 %4.%5.").arg(typeName).arg(name).arg(objectType->type.module()).arg(objectType->majorVersion).arg(objectType->minorVersion)); } else { return recordError(binding->location, tr("\"%1.%2\" is not available due to component versioning.").arg(typeName).arg(name)); } @@ -197,7 +197,7 @@ QVector QQmlPropertyValidator::validateObject(int objectIndex, collectedBindingPropertyData[i] = pd; if (name.constData()->isUpper() && !binding->isAttachedProperty()) { - QQmlType *type = 0; + QQmlType type; QQmlImportNamespace *typeNamespace = 0; imports.resolveType(stringAt(binding->propertyNameIndex), &type, 0, 0, &typeNamespace); if (typeNamespace) @@ -632,15 +632,15 @@ QQmlCompileError QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData * if (auto *typeRef = resolvedTypes.value(targetObject->inheritedTypeNameIndex)) { QQmlPropertyCache *cache = typeRef->createPropertyCache(QQmlEnginePrivate::get(enginePrivate)); const QMetaObject *mo = cache->firstCppMetaObject(); - QQmlType *qmlType = 0; - while (mo && !qmlType) { + QQmlType qmlType; + while (mo && !qmlType.isValid()) { qmlType = QQmlMetaType::qmlType(mo); mo = mo->superClass(); } - Q_ASSERT(qmlType); + Q_ASSERT(qmlType.isValid()); - isValueSource = qmlType->propertyValueSourceCast() != -1; - isPropertyInterceptor = qmlType->propertyValueInterceptorCast() != -1; + isValueSource = qmlType.propertyValueSourceCast() != -1; + isPropertyInterceptor = qmlType.propertyValueInterceptorCast() != -1; } if (!isValueSource && !isPropertyInterceptor) { diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index d1d22be0ac..f5cb468479 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -75,7 +75,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile() for (auto it = resolvedTypes.constBegin(), end = resolvedTypes.constEnd(); it != end; ++it) { - QQmlCustomParser *customParser = (*it)->type ? (*it)->type->customParser() : 0; + QQmlCustomParser *customParser = (*it)->type.customParser(); if (customParser) customParsers.insert(it.key(), customParser); } @@ -171,7 +171,6 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile() compilationUnit->propertyCaches = std::move(m_propertyCaches); Q_ASSERT(compilationUnit->propertyCaches.count() == static_cast(compilationUnit->data->nObjects)); - if (errors.isEmpty()) return compilationUnit; else @@ -345,11 +344,11 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio if (binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) { const QmlIR::Object *attachedObj = qmlObjects.at(binding->value.objectIndex); auto *typeRef = resolvedTypes.value(binding->propertyNameIndex); - QQmlType *type = typeRef ? typeRef->type : 0; - if (!type) { + QQmlType type = typeRef ? typeRef->type : nullptr; + if (!type.isValid()) { if (imports->resolveType(propertyName, &type, 0, 0, 0)) { - if (type->isComposite()) { - QQmlTypeData *tdata = enginePrivate->typeLoader.getType(type->sourceUrl()); + if (type.isComposite()) { + QQmlTypeData *tdata = enginePrivate->typeLoader.getType(type.sourceUrl()); Q_ASSERT(tdata); Q_ASSERT(tdata->isComplete()); @@ -361,7 +360,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio } } - const QMetaObject *attachedType = type ? type->attachedPropertiesType(enginePrivate) : 0; + const QMetaObject *attachedType = type.attachedPropertiesType(enginePrivate); if (!attachedType) COMPILE_EXCEPTION(binding, tr("Non-existent attached object")); QQmlPropertyCache *cache = compiler->enginePrivate()->cache(attachedType); @@ -418,9 +417,9 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio const QString &originalPropertyName = stringAt(binding->propertyNameIndex); auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex); - const QQmlType *type = typeRef ? typeRef->type : 0; - if (type) { - COMPILE_EXCEPTION(binding, tr("\"%1.%2\" is not available in %3 %4.%5.").arg(typeName).arg(originalPropertyName).arg(type->module()).arg(type->majorVersion()).arg(type->minorVersion())); + const QQmlType type = typeRef->type; + if (type.isValid()) { + COMPILE_EXCEPTION(binding, tr("\"%1.%2\" is not available in %3 %4.%5.").arg(typeName).arg(originalPropertyName).arg(type.module()).arg(type.majorVersion()).arg(type.minorVersion())); } else { COMPILE_EXCEPTION(binding, tr("\"%1.%2\" is not available due to component versioning.").arg(typeName).arg(originalPropertyName)); } @@ -612,17 +611,17 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj, } return true; } - QQmlType *type = 0; + QQmlType type; imports->resolveType(typeName, &type, 0, 0, 0); - if (!type && !isQtObject) + if (!type.isValid() && !isQtObject) return true; int value = 0; bool ok = false; auto *tr = resolvedTypes->value(obj->inheritedTypeNameIndex); - if (type && tr && tr->type == type) { + if (type.isValid() && tr && tr->type == type) { QMetaProperty mprop = propertyCache->firstCppMetaObject()->property(prop->coreIndex()); // When these two match, we can short cut the search @@ -633,8 +632,8 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj, } } else { // Otherwise we have to search the whole type - if (type) { - value = type->enumValue(compiler->enginePrivate(), QHashedStringRef(enumValue), &ok); + if (type.isValid()) { + value = type.enumValue(compiler->enginePrivate(), QHashedStringRef(enumValue), &ok); } else { QByteArray enumName = enumValue.toUtf8(); const QMetaObject *metaObject = StaticQtMetaObject::get(); @@ -657,11 +656,9 @@ int QQmlEnumTypeResolver::evaluateEnum(const QString &scope, const QByteArray &e *ok = false; if (scope != QLatin1String("Qt")) { - QQmlType *type = 0; + QQmlType type; imports->resolveType(scope, &type, 0, 0, 0); - if (!type) - return -1; - return type->enumValue(compiler->enginePrivate(), QHashedCStringRef(enumValue.constData(), enumValue.length()), ok); + return type.enumValue(compiler->enginePrivate(), QHashedCStringRef(enumValue.constData(), enumValue.length()), ok); } const QMetaObject *mo = StaticQtMetaObject::get(); @@ -799,8 +796,8 @@ void QQmlComponentAndAliasResolver::findAndRegisterImplicitComponents(const QmlI const QmlIR::Object *targetObject = qmlObjects->at(binding->value.objectIndex); auto *tr = resolvedTypes->value(targetObject->inheritedTypeNameIndex); Q_ASSERT(tr); - if (QQmlType *targetType = tr->type) { - if (targetType->metaObject() == &QQmlComponent::staticMetaObject) + if (tr->type.isValid()) { + if (tr->type.metaObject() == &QQmlComponent::staticMetaObject) continue; } else if (tr->compilationUnit) { if (tr->compilationUnit->rootPropertyCache()->firstCppMetaObject() == &QQmlComponent::staticMetaObject) @@ -829,22 +826,22 @@ void QQmlComponentAndAliasResolver::findAndRegisterImplicitComponents(const QmlI continue; // emulate "import Qml 2.0 as QmlInternals" and then wrap the component in "QmlInternals.Component {}" - QQmlType *componentType = QQmlMetaType::qmlType(&QQmlComponent::staticMetaObject); - Q_ASSERT(componentType); + QQmlType componentType = QQmlMetaType::qmlType(&QQmlComponent::staticMetaObject); + Q_ASSERT(componentType.isValid()); const QString qualifier = QStringLiteral("QmlInternals"); - compiler->addImport(componentType->module(), qualifier, componentType->majorVersion(), componentType->minorVersion()); + compiler->addImport(componentType.module(), qualifier, componentType.majorVersion(), componentType.minorVersion()); QmlIR::Object *syntheticComponent = pool->New(); - syntheticComponent->init(pool, compiler->registerString(qualifier + QLatin1Char('.') + componentType->elementName()), compiler->registerString(QString())); + syntheticComponent->init(pool, compiler->registerString(qualifier + QLatin1Char('.') + componentType.elementName()), compiler->registerString(QString())); syntheticComponent->location = binding->valueLocation; syntheticComponent->flags |= QV4::CompiledData::Object::IsComponent; if (!resolvedTypes->contains(syntheticComponent->inheritedTypeNameIndex)) { auto typeRef = new QV4::CompiledData::ResolvedTypeReference; typeRef->type = componentType; - typeRef->majorVersion = componentType->majorVersion(); - typeRef->minorVersion = componentType->minorVersion(); + typeRef->majorVersion = componentType.majorVersion(); + typeRef->minorVersion = componentType.minorVersion(); resolvedTypes->insert(syntheticComponent->inheritedTypeNameIndex, typeRef); } @@ -885,7 +882,7 @@ bool QQmlComponentAndAliasResolver::resolve() if (obj->inheritedTypeNameIndex) { auto *tref = resolvedTypes->value(obj->inheritedTypeNameIndex); Q_ASSERT(tref); - if (tref->type && tref->type->metaObject() == &QQmlComponent::staticMetaObject) + if (tref->type.metaObject() == &QQmlComponent::staticMetaObject) isExplicitComponent = true; } if (!isExplicitComponent) { diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index db707061fe..6223c4b3a1 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -295,8 +295,8 @@ void CompilationUnit::finalize(QQmlEnginePrivate *engine) metaTypeId = typeRef->compilationUnit->metaTypeId; listMetaTypeId = typeRef->compilationUnit->listMetaTypeId; } else { - metaTypeId = typeRef->type->typeId(); - listMetaTypeId = typeRef->type->qListTypeId(); + metaTypeId = typeRef->type.typeId(); + listMetaTypeId = typeRef->type.qListTypeId(); } } @@ -308,8 +308,8 @@ void CompilationUnit::finalize(QQmlEnginePrivate *engine) const QV4::CompiledData::Object *obj = data->objectAt(i); bindingCount += obj->nBindings; if (auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex)) { - if (QQmlType *qmlType = typeRef->type) { - if (qmlType->parserStatusCast() != -1) + if (typeRef->type.isValid()) { + if (typeRef->type.parserStatusCast() != -1) ++parserStatusCount; } ++objectCount; @@ -673,7 +673,7 @@ Returns the property cache, if one alread exists. The cache is not referenced. */ QQmlPropertyCache *ResolvedTypeReference::propertyCache() const { - if (type) + if (type.isValid()) return typePropertyCache; else return compilationUnit->rootPropertyCache(); @@ -686,8 +686,8 @@ QQmlPropertyCache *ResolvedTypeReference::createPropertyCache(QQmlEngine *engine { if (typePropertyCache) { return typePropertyCache; - } else if (type) { - typePropertyCache = QQmlEnginePrivate::get(engine)->cache(type->metaObject()); + } else if (type.isValid()) { + typePropertyCache = QQmlEnginePrivate::get(engine)->cache(type.metaObject()); return typePropertyCache; } else { return compilationUnit->rootPropertyCache(); @@ -696,7 +696,7 @@ QQmlPropertyCache *ResolvedTypeReference::createPropertyCache(QQmlEngine *engine bool ResolvedTypeReference::addToHash(QCryptographicHash *hash, QQmlEngine *engine) { - if (type) { + if (type.isValid()) { bool ok = false; hash->addData(createPropertyCache(engine)->checksum(&ok)); return ok; @@ -720,8 +720,8 @@ void ResolvedTypeReference::doDynamicTypeCheck() const QMetaObject *mo = 0; if (typePropertyCache) mo = typePropertyCache->firstCppMetaObject(); - else if (type) - mo = type->metaObject(); + else if (type.isValid()) + mo = type.metaObject(); else if (compilationUnit) mo = compilationUnit->rootPropertyCache()->firstCppMetaObject(); isFullyDynamicType = qtTypeInherits(mo); diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 23f5e31ebe..bca0dcdf8f 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -923,13 +923,12 @@ protected: struct ResolvedTypeReference { ResolvedTypeReference() - : type(0) - , majorVersion(0) + : majorVersion(0) , minorVersion(0) , isFullyDynamicType(false) {} - QQmlType *type; + QQmlType type; QQmlRefPointer typePropertyCache; QQmlRefPointer compilationUnit; diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 0cb1b1ee13..0c4facda4d 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -785,10 +785,10 @@ ReturnedValue ExecutionEngine::qmlSingletonWrapper(String *name) QQmlTypeNameCache::Result r = ctx->imports->query(name); Q_ASSERT(r.isValid()); - Q_ASSERT(r.type); - Q_ASSERT(r.type->isSingleton()); + Q_ASSERT(r.type.isValid()); + Q_ASSERT(r.type.isSingleton()); - QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); + QQmlType::SingletonInstanceInfo *siinfo = r.type.singletonInstanceInfo(); QQmlEngine *e = qmlEngine(); siinfo->init(e); diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp index 9411e2b8e0..144ab1b1a5 100644 --- a/src/qml/jsruntime/qv4qmlcontext.cpp +++ b/src/qml/jsruntime/qv4qmlcontext.cpp @@ -142,8 +142,8 @@ ReturnedValue QmlContextWrapper::get(const Managed *m, String *name, bool *hasPr if (r.scriptIndex != -1) { QV4::ScopedObject scripts(scope, context->importedScripts.valueRef()); return scripts->getIndexed(r.scriptIndex); - } else if (r.type) { - return QmlTypeWrapper::create(v4, scopeObject, *r.type); + } else if (r.type.isValid()) { + return QmlTypeWrapper::create(v4, scopeObject, r.type); } else if (r.importNamespace) { return QmlTypeWrapper::create(v4, scopeObject, context->imports, r.importNamespace); } diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 73a6ab7503..5dc5f5d568 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -249,9 +249,9 @@ ReturnedValue QObjectWrapper::getQmlProperty(QQmlContextData *qmlContext, String if (r.isValid()) { if (r.scriptIndex != -1) { return QV4::Encode::undefined(); - } else if (r.type) { + } else if (r.type.isValid()) { return QmlTypeWrapper::create(v4, d()->object(), - *r.type, Heap::QmlTypeWrapper::ExcludeEnums); + r.type, Heap::QmlTypeWrapper::ExcludeEnums); } else if (r.importNamespace) { return QmlTypeWrapper::create(v4, d()->object(), qmlContext->imports, r.importNamespace, Heap::QmlTypeWrapper::ExcludeEnums); diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index 0b0bbef795..ecdaf41523 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -132,7 +132,7 @@ int QQmlCustomParser::evaluateEnum(const QByteArray& script, bool *ok) const if (scope != QLatin1String("Qt")) { if (imports.isNull()) return -1; - QQmlType *type = 0; + QQmlType type; if (imports.isT1()) { imports.asT1()->resolveType(scope, &type, 0, 0, 0); @@ -142,7 +142,7 @@ int QQmlCustomParser::evaluateEnum(const QByteArray& script, bool *ok) const type = result.type; } - return type ? type->enumValue(engine, QHashedCStringRef(enumValue.constData(), enumValue.length()), ok) : -1; + return type.enumValue(engine, QHashedCStringRef(enumValue.constData(), enumValue.length()), ok); } const QMetaObject *mo = StaticQtMetaObject::get(); @@ -163,12 +163,10 @@ const QMetaObject *QQmlCustomParser::resolveType(const QString& name) const { if (!imports.isT1()) return nullptr; - QQmlType *qmltype = 0; + QQmlType qmltype; if (!imports.asT1()->resolveType(name, &qmltype, 0, 0, 0)) return nullptr; - if (!qmltype) - return nullptr; - return qmltype->metaObject(); + return qmltype.metaObject(); } QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index ba22bfde76..7aae994c29 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -677,7 +677,7 @@ QQmlEnginePrivate::QQmlEnginePrivate(QQmlEngine *e) QQmlEnginePrivate::~QQmlEnginePrivate() { - typedef QHash, QQmlPropertyCache *>::const_iterator TypePropertyCacheIt; + typedef QHash, QQmlPropertyCache *>::const_iterator TypePropertyCacheIt; if (inProgressCreations) qWarning() << QQmlEngine::tr("There are still \"%1\" items in the process of being created at engine destruction.").arg(inProgressCreations); @@ -1022,9 +1022,9 @@ QQmlEngine::~QQmlEngine() // we do this here and not in the private dtor since otherwise a crash can // occur (if we are the QObject parent of the QObject singleton instance) // XXX TODO: performance -- store list of singleton types separately? - const QList singletonTypes = QQmlMetaType::qmlSingletonTypes(); - for (QQmlType *currType : singletonTypes) - currType->singletonInstanceInfo()->destroy(this); + QList singletonTypes = QQmlMetaType::qmlSingletonTypes(); + for (const QQmlType &currType : singletonTypes) + currType.singletonInstanceInfo()->destroy(this); delete d->rootContext; d->rootContext = 0; @@ -2194,19 +2194,18 @@ QString QQmlEnginePrivate::offlineStorageDatabaseDirectory() const return q->offlineStoragePath() + QDir::separator() + QLatin1String("Databases") + QDir::separator(); } -QQmlPropertyCache *QQmlEnginePrivate::createCache(QQmlType *type, int minorVersion) +QQmlPropertyCache *QQmlEnginePrivate::createCache(const QQmlType &type, int minorVersion) { - QList types; + QVector types; int maxMinorVersion = 0; - const QMetaObject *metaObject = type->metaObject(); + const QMetaObject *metaObject = type.metaObject(); while (metaObject) { - QQmlType *t = QQmlMetaType::qmlType(metaObject, type->module(), - type->majorVersion(), minorVersion); - if (t) { - maxMinorVersion = qMax(maxMinorVersion, t->minorVersion()); + QQmlType t = QQmlMetaType::qmlType(metaObject, type.module(), type.majorVersion(), minorVersion); + if (t.isValid()) { + maxMinorVersion = qMax(maxMinorVersion, t.minorVersion()); types << t; } else { types << 0; @@ -2221,16 +2220,16 @@ QQmlPropertyCache *QQmlEnginePrivate::createCache(QQmlType *type, int minorVersi return c; } - QQmlPropertyCache *raw = cache(type->metaObject()); + QQmlPropertyCache *raw = cache(type.metaObject()); bool hasCopied = false; for (int ii = 0; ii < types.count(); ++ii) { - QQmlType *currentType = types.at(ii); - if (!currentType) + QQmlType currentType = types.at(ii); + if (!currentType.isValid()) continue; - int rev = currentType->metaObjectRevision(); + int rev = currentType.metaObjectRevision(); int moIndex = types.count() - 1 - ii; if (raw->allowedRevisionCache[moIndex] != rev) { @@ -2280,7 +2279,7 @@ QQmlPropertyCache *QQmlEnginePrivate::createCache(QQmlType *type, int minorVersi if (overloadError) { if (hasCopied) raw->release(); - error.setDescription(QLatin1String("Type ") + type->qmlTypeName() + QLatin1Char(' ') + QString::number(type->majorVersion()) + QLatin1Char('.') + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation.")); + error.setDescription(QLatin1String("Type ") + type.qmlTypeName() + QLatin1Char(' ') + QString::number(type.majorVersion()) + QLatin1Char('.') + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation.")); return 0; } #endif @@ -2348,8 +2347,8 @@ QQmlMetaObject QQmlEnginePrivate::rawMetaObjectForType(int t) const if (iter != m_compositeTypes.cend()) { return QQmlMetaObject((*iter)->rootPropertyCache()); } else { - QQmlType *type = QQmlMetaType::qmlType(t); - return QQmlMetaObject(type?type->baseMetaObject():0); + QQmlType type = QQmlMetaType::qmlType(t); + return QQmlMetaObject(type.baseMetaObject()); } } @@ -2360,8 +2359,8 @@ QQmlMetaObject QQmlEnginePrivate::metaObjectForType(int t) const if (iter != m_compositeTypes.cend()) { return QQmlMetaObject((*iter)->rootPropertyCache()); } else { - QQmlType *type = QQmlMetaType::qmlType(t); - return QQmlMetaObject(type?type->metaObject():0); + QQmlType type = QQmlMetaType::qmlType(t); + return QQmlMetaObject(type.metaObject()); } } @@ -2372,9 +2371,9 @@ QQmlPropertyCache *QQmlEnginePrivate::propertyCacheForType(int t) if (iter != m_compositeTypes.cend()) { return (*iter)->rootPropertyCache(); } else { - QQmlType *type = QQmlMetaType::qmlType(t); + QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); - return type?cache(type->metaObject()):0; + return type.isValid() ? cache(type.metaObject()) : 0; } } @@ -2385,9 +2384,9 @@ QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t) if (iter != m_compositeTypes.cend()) { return (*iter)->rootPropertyCache(); } else { - QQmlType *type = QQmlMetaType::qmlType(t); + QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); - return type?cache(type->baseMetaObject()):0; + return type.isValid() ? cache(type.baseMetaObject()) : 0; } } diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index 1bdeacd524..3ed8dbccff 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -208,7 +208,7 @@ public: QString offlineStorageDatabaseDirectory() const; // These methods may be called from the loader thread - inline QQmlPropertyCache *cache(QQmlType *, int); + inline QQmlPropertyCache *cache(const QQmlType &, int); using QJSEnginePrivate::cache; // These methods may be called from the loader thread @@ -260,11 +260,11 @@ public: private: // Must be called locked - QQmlPropertyCache *createCache(QQmlType *, int); + QQmlPropertyCache *createCache(const QQmlType &, int); // These members must be protected by a QQmlEnginePrivate::Locker as they are required by // the threaded loader. Only access them through their respective accessor methods. - QHash, QQmlPropertyCache *> typePropertyCache; + QHash, QQmlPropertyCache *> typePropertyCache; QHash m_qmlLists; QHash m_compositeTypes; static bool s_designerMode; @@ -375,12 +375,12 @@ Returns a QQmlPropertyCache for \a type with \a minorVersion. The returned cache is not referenced, so if it is to be stored, call addref(). */ -QQmlPropertyCache *QQmlEnginePrivate::cache(QQmlType *type, int minorVersion) +QQmlPropertyCache *QQmlEnginePrivate::cache(const QQmlType &type, int minorVersion) { - Q_ASSERT(type); + Q_ASSERT(type.isValid()); - if (minorVersion == -1 || !type->containsRevisionedAttributes()) - return cache(type->metaObject()); + if (minorVersion == -1 || !type.containsRevisionedAttributes()) + return cache(type.metaObject()); Locker locker(this); QQmlPropertyCache *rv = typePropertyCache.value(qMakePair(type, minorVersion)); diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index ec748d1ca9..89c7fd3214 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -142,13 +142,13 @@ bool isPathAbsolute(const QString &path) Errors (if there are any) are placed into \a errors, if it is nonzero. Note that errors are treated as fatal if \a errors is not set. */ -QQmlType *fetchOrCreateTypeForUrl(const QString &urlString, const QHashedStringRef& typeName, +QQmlType fetchOrCreateTypeForUrl(const QString &urlString, const QHashedStringRef& typeName, bool isCompositeSingleton, QList *errors, int majorVersion=-1, int minorVersion=-1) { QUrl url(urlString); // ### unfortunate (costly) conversion - QQmlType *ret = QQmlMetaType::qmlType(url); - if (ret) + QQmlType ret = QQmlMetaType::qmlType(url); + if (ret.isValid()) return ret; int dot = typeName.indexOf(QLatin1Char('.')); @@ -198,7 +198,7 @@ QQmlType *fetchOrCreateTypeForUrl(const QString &urlString, const QHashedStringR // This means that the type couldn't be found by URL, but could not be // registered either, meaning we most likely were passed some kind of bad // data. - if (!ret) { + if (!ret.isValid()) { if (!errors) // Cannot list errors properly, just quit qFatal("%s", QQmlMetaType::typeRegistrationFailures().join('\n').toLatin1().constData()); QQmlError error; @@ -295,7 +295,7 @@ public: QList *errors); bool resolveType(const QHashedStringRef &type, int *vmajor, int *vminor, - QQmlType** type_return, QList *errors); + QQmlType *type_return, QList *errors); QUrl baseUrl; QString base; @@ -619,7 +619,7 @@ QString QQmlImports::versionString(int vmaj, int vmin, ImportVersion version) \sa addFileImport(), addLibraryImport */ bool QQmlImports::resolveType(const QHashedStringRef &type, - QQmlType** type_return, int *vmaj, int *vmin, + QQmlType *type_return, int *vmaj, int *vmin, QQmlImportNamespace** ns_return, QList *errors) const { QQmlImportNamespace* ns = d->findQualifiedNamespace(type); @@ -629,17 +629,19 @@ bool QQmlImports::resolveType(const QHashedStringRef &type, return true; } if (type_return) { - if (d->resolveType(type,vmaj,vmin,type_return, errors)) { + if (d->resolveType(type, vmaj, vmin, type_return, errors)) { if (qmlImportTrace()) { #define RESOLVE_TYPE_DEBUG qDebug().nospace() << "QQmlImports(" << qPrintable(baseUrl().toString()) \ << ')' << "::resolveType: " << type.toString() << " => " - if (type_return && *type_return && (*type_return)->isCompositeSingleton()) - RESOLVE_TYPE_DEBUG << (*type_return)->typeName() << ' ' << (*type_return)->sourceUrl() << " TYPE/URL-SINGLETON"; - else if (type_return && *type_return && (*type_return)->isComposite()) - RESOLVE_TYPE_DEBUG << (*type_return)->typeName() << ' ' << (*type_return)->sourceUrl() << " TYPE/URL"; - else if (type_return && *type_return) - RESOLVE_TYPE_DEBUG << (*type_return)->typeName() << " TYPE"; + if (type_return && type_return->isValid()) { + if (type_return->isCompositeSingleton()) + RESOLVE_TYPE_DEBUG << type_return->typeName() << ' ' << type_return->sourceUrl() << " TYPE/URL-SINGLETON"; + else if (type_return->isComposite()) + RESOLVE_TYPE_DEBUG << type_return->typeName() << ' ' << type_return->sourceUrl() << " TYPE/URL"; + else + RESOLVE_TYPE_DEBUG << type_return->typeName() << " TYPE"; + } #undef RESOLVE_TYPE_DEBUG } return true; @@ -704,19 +706,19 @@ QQmlDirScripts QQmlImportInstance::getVersionedScripts(const QQmlDirScripts &qml If the return pointer is 0, the corresponding search is not done. */ -bool QQmlImports::resolveType(QQmlImportNamespace* ns, const QHashedStringRef &type, - QQmlType** type_return, int *vmaj, int *vmin) const +bool QQmlImports::resolveType(QQmlImportNamespace *ns, const QHashedStringRef &type, + QQmlType *type_return, int *vmaj, int *vmin) const { - return ns->resolveType(d->typeLoader,type,vmaj,vmin,type_return); + return ns->resolveType(d->typeLoader, type, vmaj, vmin, type_return); } bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type, int *vmajor, int *vminor, - QQmlType** type_return, QString *base, bool *typeRecursionDetected) const + QQmlType* type_return, QString *base, bool *typeRecursionDetected) const { if (majversion >= 0 && minversion >= 0) { - QQmlType *t = QQmlMetaType::qmlType(type, uri, majversion, minversion); - if (t) { + QQmlType t = QQmlMetaType::qmlType(type, uri, majversion, minversion); + if (t.isValid()) { if (vmajor) *vmajor = majversion; if (vminor) *vminor = minversion; if (type_return) @@ -766,11 +768,11 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, componentUrl = resolveLocalUrl(QString(url + candidate->typeName + dotqml_string), candidate->fileName); int major = vmajor ? *vmajor : -1; int minor = vminor ? *vminor : -1; - QQmlType *returnType = fetchOrCreateTypeForUrl(componentUrl, type, isCompositeSingleton, 0, + QQmlType returnType = fetchOrCreateTypeForUrl(componentUrl, type, isCompositeSingleton, 0, major, minor); if (type_return) *type_return = returnType; - return returnType != 0; + return returnType.isValid(); } } else if (!isLibrary) { QString qmlUrl; @@ -794,10 +796,10 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, if (typeRecursionDetected) *typeRecursionDetected = true; } else { - QQmlType *returnType = fetchOrCreateTypeForUrl(qmlUrl, type, false, 0); + QQmlType returnType = fetchOrCreateTypeForUrl(qmlUrl, type, false, 0); if (type_return) *type_return = returnType; - return returnType != 0; + return returnType.isValid(); } } } @@ -806,7 +808,7 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, } bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor, int *vminor, - QQmlType** type_return, QList *errors) + QQmlType *type_return, QList *errors) { QQmlImportNamespace *s = 0; int dot = type.indexOf(Dot); @@ -835,12 +837,12 @@ bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor, } QHashedStringRef unqualifiedtype = dot < 0 ? type : QHashedStringRef(type.constData()+dot+1, type.length()-dot-1); if (s) { - if (s->resolveType(typeLoader,unqualifiedtype,vmajor,vminor,type_return, &base, errors)) + if (s->resolveType(typeLoader, unqualifiedtype, vmajor, vminor, type_return, &base, errors)) return true; if (s->imports.count() == 1 && !s->imports.at(0)->isLibrary && type_return && s != &unqualifiedset) { // qualified, and only 1 url *type_return = fetchOrCreateTypeForUrl(resolveLocalUrl(s->imports.at(0)->url, unqualifiedtype.toString() + QLatin1String(".qml")), type, false, errors); - return (*type_return != 0); + return type_return->isValid(); } } @@ -857,7 +859,7 @@ QQmlImportInstance *QQmlImportNamespace::findImport(const QString &uri) const } bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type, - int *vmajor, int *vminor, QQmlType** type_return, + int *vmajor, int *vminor, QQmlType *type_return, QString *base, QList *errors) { bool typeRecursionDetected = false; diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index 7c691a468c..8a0a4ea4f1 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -86,7 +86,7 @@ struct QQmlImportInstance static QQmlDirScripts getVersionedScripts(const QQmlDirScripts &qmldirscripts, int vmaj, int vmin); bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type, - int *vmajor, int *vminor, QQmlType** type_return, + int *vmajor, int *vminor, QQmlType* type_return, QString *base = 0, bool *typeRecursionDetected = 0) const; }; @@ -101,7 +101,7 @@ public: QQmlImportInstance *findImport(const QString &uri) const; bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type, - int *vmajor, int *vminor, QQmlType** type_return, + int *vmajor, int *vminor, QQmlType* type_return, QString *base = 0, QList *errors = 0); // Prefix when used as a qualified import. Otherwise empty. @@ -125,13 +125,13 @@ public: QUrl baseUrl() const; bool resolveType(const QHashedStringRef &type, - QQmlType** type_return, + QQmlType *type_return, int *version_major, int *version_minor, - QQmlImportNamespace** ns_return, + QQmlImportNamespace **ns_return, QList *errors = 0) const; - bool resolveType(QQmlImportNamespace*, + bool resolveType(QQmlImportNamespace *, const QHashedStringRef& type, - QQmlType** type_return, int *version_major, int *version_minor) const; + QQmlType *type_return, int *version_major, int *version_minor) const; bool addImplicitImport(QQmlImportDatabase *importDb, QList *errors); diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp index 2c71293363..71be2e82a3 100644 --- a/src/qml/qml/qqmllist.cpp +++ b/src/qml/qml/qqmllist.cpp @@ -148,7 +148,7 @@ QQmlListReference::QQmlListReference(QObject *object, const char *property, QQml d = new QQmlListReferencePrivate; d->object = object; - d->elementType = p?p->rawMetaObjectForType(listType):QQmlMetaType::qmlType(listType)->baseMetaObject(); + d->elementType = p ? p->rawMetaObjectForType(listType) : QQmlMetaType::qmlType(listType).baseMetaObject(); d->propertyType = data->propType(); void *args[] = { &d->property, 0 }; diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 2ff2cdc189..3e29222200 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -209,7 +209,7 @@ public: int listId; int revision; mutable bool containsRevisionedAttributes; - mutable QQmlType *superType; + mutable QQmlType superType; const QMetaObject *baseMetaObject; int index; @@ -281,7 +281,7 @@ QHash QQmlTypePrivate::attachedPropertyIds; QQmlTypePrivate::QQmlTypePrivate(QQmlType::RegistrationType type) : refCount(1), regType(type), iid(0), typeId(0), listId(0), revision(0), - containsRevisionedAttributes(false), superType(0), baseMetaObject(0), + containsRevisionedAttributes(false), baseMetaObject(0), index(-1), isSetup(false), isEnumSetup(false), haveSuperType(false) { switch (type) { @@ -476,6 +476,27 @@ QQmlType::~QQmlType() delete d; } +QQmlType::QQmlType(QQmlType *otherPointer) + : d(0) +{ + if (otherPointer) { + d = otherPointer->d; + if (d) + d->refCount.ref(); + } +} + +QQmlType &QQmlType::operator =(QQmlType *otherPointer) { + if (otherPointer && otherPointer->d != d) { + if (d && !d->refCount.deref()) + delete d; + d = otherPointer->d; + if (d) + d->refCount.ref(); + } + return *this; +} + QHashedString QQmlType::module() const { if (!d) @@ -514,13 +535,13 @@ bool QQmlType::availableInVersion(const QHashedStringRef &module, int vmajor, in } // returns the nearest _registered_ super class -QQmlType *QQmlType::superType() const +QQmlType QQmlType::superType() const { if (!d) return 0; if (!d->haveSuperType && d->baseMetaObject) { const QMetaObject *mo = d->baseMetaObject->superClass(); - while (mo && !d->superType) { + while (mo && !d->superType.isValid()) { d->superType = QQmlMetaType::qmlType(mo, d->module, d->version_maj, d->version_min); mo = mo->superClass(); } @@ -530,7 +551,7 @@ QQmlType *QQmlType::superType() const return d->superType; } -QQmlType *QQmlType::resolveCompositeBaseType(QQmlEnginePrivate *engine) const +QQmlType QQmlType::resolveCompositeBaseType(QQmlEnginePrivate *engine) const { Q_ASSERT(isComposite()); if (!engine || !d) @@ -549,10 +570,8 @@ int QQmlType::resolveCompositeEnumValue(QQmlEnginePrivate *engine, const QString if (!d) return -1; *ok = false; - QQmlType *type = resolveCompositeBaseType(engine); - if (!type) - return -1; - return type->enumValue(engine, name, ok); + QQmlType type = resolveCompositeBaseType(engine); + return type.enumValue(engine, name, ok); } static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo, @@ -942,10 +961,10 @@ QQmlAttachedPropertiesFunc QQmlType::attachedPropertiesFunction(QQmlEnginePrivat if (d->regType == CppType) return d->extraData.cd->attachedPropertiesFunc; - QQmlType *base = 0; + QQmlType base; if (d->regType == CompositeType) base = resolveCompositeBaseType(engine); - return base ? base->attachedPropertiesFunction(engine) : 0; + return base.attachedPropertiesFunction(engine); } const QMetaObject *QQmlType::attachedPropertiesType(QQmlEnginePrivate *engine) const @@ -955,10 +974,10 @@ const QMetaObject *QQmlType::attachedPropertiesType(QQmlEnginePrivate *engine) c if (d->regType == CppType) return d->extraData.cd->attachedPropertiesType; - QQmlType *base = 0; + QQmlType base; if (d->regType == CompositeType) base = resolveCompositeBaseType(engine); - return base ? base->attachedPropertiesType(engine) : 0; + return base.attachedPropertiesType(engine); } /* @@ -973,10 +992,10 @@ int QQmlType::attachedPropertiesId(QQmlEnginePrivate *engine) const if (d->regType == CppType) return d->extraData.cd->attachedPropertiesId; - QQmlType *base = 0; + QQmlType base; if (d->regType == CompositeType) base = resolveCompositeBaseType(engine); - return base ? base->attachedPropertiesId(engine) : 0; + return base.attachedPropertiesId(engine); } int QQmlType::parserStatusCast() const @@ -1137,46 +1156,32 @@ void QQmlTypeModulePrivate::add(QQmlType *type) list.append(type); } -QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor) const +QQmlType QQmlTypeModule::type(const QHashedStringRef &name, int minor) const { QMutexLocker lock(metaTypeDataLock()); QList *types = d->typeHash.value(name); - if (!types) return 0; - - for (int ii = 0; ii < types->count(); ++ii) - if (types->at(ii)->minorVersion() <= minor) - return types->at(ii); + if (types) { + for (int ii = 0; ii < types->count(); ++ii) + if (types->at(ii)->minorVersion() <= minor) + return types->at(ii); + } - return 0; + return QQmlType(); } -QQmlType *QQmlTypeModule::type(const QV4::String *name, int minor) const +QQmlType QQmlTypeModule::type(const QV4::String *name, int minor) const { QMutexLocker lock(metaTypeDataLock()); QList *types = d->typeHash.value(name); - if (!types) return 0; - - for (int ii = 0; ii < types->count(); ++ii) - if (types->at(ii)->minorVersion() <= minor) - return types->at(ii); - - return 0; -} - -QList QQmlTypeModule::singletonTypes(int minor) const -{ - QMutexLocker lock(metaTypeDataLock()); - - QList retn; - for (int ii = 0; ii < d->types.count(); ++ii) { - QQmlType *curr = d->types.at(ii); - if (curr->isSingleton() && curr->minorVersion() <= minor) - retn.append(curr); + if (types) { + for (int ii = 0; ii < types->count(); ++ii) + if (types->at(ii)->minorVersion() <= minor) + return types->at(ii); } - return retn; + return QQmlType(); } QQmlTypeModuleVersion::QQmlTypeModuleVersion() @@ -1213,16 +1218,18 @@ int QQmlTypeModuleVersion::minorVersion() const return m_minor; } -QQmlType *QQmlTypeModuleVersion::type(const QHashedStringRef &name) const +QQmlType QQmlTypeModuleVersion::type(const QHashedStringRef &name) const { - if (m_module) return m_module->type(name, m_minor); - else return 0; + if (!m_module) + return QQmlType(); + return m_module->type(name, m_minor); } -QQmlType *QQmlTypeModuleVersion::type(const QV4::String *name) const +QQmlType QQmlTypeModuleVersion::type(const QV4::String *name) const { - if (m_module) return m_module->type(name, m_minor); - else return 0; + if (!m_module) + return QQmlType(); + return m_module->type(name, m_minor); } void qmlClearTypeRegistrations() // Declared in qqml.h @@ -1369,7 +1376,7 @@ QQmlTypeModule *getTypeModule(const QHashedString &uri, int majorVersion, QQmlMe } // NOTE: caller must hold a QMutexLocker on "data" -void addTypeToData(QQmlType* type, QQmlMetaTypeData *data) +void addTypeToData(QQmlType *type, QQmlMetaTypeData *data) { if (!type->elementName().isEmpty()) data->nameToType.insertMulti(type->elementName(), type); @@ -1855,7 +1862,7 @@ QQmlMetaType::StringConverter QQmlMetaType::customStringConverter(int type) Returns the type (if any) of URI-qualified named \a qualifiedName and version specified by \a version_major and \a version_minor. */ -QQmlType *QQmlMetaType::qmlType(const QString &qualifiedName, int version_major, int version_minor) +QQmlType QQmlMetaType::qmlType(const QString &qualifiedName, int version_major, int version_minor) { int slash = qualifiedName.indexOf(QLatin1Char('/')); if (slash <= 0) @@ -1871,7 +1878,7 @@ QQmlType *QQmlMetaType::qmlType(const QString &qualifiedName, int version_major, Returns the type (if any) of \a name in \a module and version specified by \a version_major and \a version_minor. */ -QQmlType *QQmlMetaType::qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int version_major, int version_minor) +QQmlType QQmlMetaType::qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int version_major, int version_minor) { Q_ASSERT(version_major >= 0 && version_minor >= 0); QMutexLocker lock(metaTypeDataLock()); @@ -1881,18 +1888,18 @@ QQmlType *QQmlMetaType::qmlType(const QHashedStringRef &name, const QHashedStrin while (it != data->nameToType.cend() && it.key() == name) { // XXX version_major<0 just a kludge for QQmlPropertyPrivate::initProperty if (version_major < 0 || module.isEmpty() || (*it)->availableInVersion(module, version_major,version_minor)) - return (*it); + return *(*it); ++it; } - return 0; + return QQmlType(); } /*! Returns the type (if any) that corresponds to the \a metaObject. Returns null if no type is registered. */ -QQmlType *QQmlMetaType::qmlType(const QMetaObject *metaObject) +QQmlType QQmlMetaType::qmlType(const QMetaObject *metaObject) { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -1905,7 +1912,7 @@ QQmlType *QQmlMetaType::qmlType(const QMetaObject *metaObject) by \a version_major and \a version_minor in module specified by \a uri. Returns null if no type is registered. */ -QQmlType *QQmlMetaType::qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor) +QQmlType QQmlMetaType::qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor) { Q_ASSERT(version_major >= 0 && version_minor >= 0); QMutexLocker lock(metaTypeDataLock()); @@ -1926,7 +1933,7 @@ QQmlType *QQmlMetaType::qmlType(const QMetaObject *metaObject, const QHashedStri Returns the type (if any) that corresponds to the QVariant::Type \a userType. Returns null if no type is registered. */ -QQmlType *QQmlMetaType::qmlType(int userType) +QQmlType QQmlMetaType::qmlType(int userType) { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -1944,7 +1951,7 @@ QQmlType *QQmlMetaType::qmlType(int userType) Returns null if no such type is registered. */ -QQmlType *QQmlMetaType::qmlType(const QUrl &url, bool includeNonFileImports /* = false */) +QQmlType QQmlMetaType::qmlType(const QUrl &url, bool includeNonFileImports /* = false */) { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -1954,9 +1961,9 @@ QQmlType *QQmlMetaType::qmlType(const QUrl &url, bool includeNonFileImports /* = type = data->urlToNonFileImportType.value(url); if (type && type->sourceUrl() == url) - return type; + return *type; else - return 0; + return QQmlType(); } /*! @@ -1964,7 +1971,7 @@ QQmlType *QQmlMetaType::qmlType(const QUrl &url, bool includeNonFileImports /* = This is for use when you just got the index back from a qmlRegister function. Returns null if the index is out of bounds. */ -QQmlType *QQmlMetaType::qmlTypeFromIndex(int idx) +QQmlType QQmlMetaType::qmlTypeFromIndex(int idx) { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -1996,7 +2003,7 @@ QList QQmlMetaType::qmlTypeNames() /*! Returns the list of registered QML types. */ -QList QQmlMetaType::qmlTypes() +QList QQmlMetaType::qmlTypes() { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -2007,7 +2014,7 @@ QList QQmlMetaType::qmlTypes() /*! Returns the list of all registered types. */ -QList QQmlMetaType::qmlAllTypes() +QList QQmlMetaType::qmlAllTypes() { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); @@ -2018,15 +2025,15 @@ QList QQmlMetaType::qmlAllTypes() /*! Returns the list of registered QML singleton types. */ -QList QQmlMetaType::qmlSingletonTypes() +QList QQmlMetaType::qmlSingletonTypes() { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); - QList retn; + QList retn; for (const auto type : qAsConst(data->nameToType)) { if (type->isSingleton()) - retn.append(type); + retn.append(*type); } return retn; } @@ -2053,9 +2060,9 @@ QString QQmlMetaType::prettyTypeName(const QObject *object) if (!object) return typeName; - const QQmlType *type = QQmlMetaType::qmlType(object->metaObject()); - if (type) { - typeName = type->qmlTypeName(); + QQmlType type = QQmlMetaType::qmlType(object->metaObject()); + if (type.isValid()) { + typeName = type.qmlTypeName(); const int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); if (lastSlash != -1) typeName = typeName.mid(lastSlash + 1); @@ -2071,8 +2078,8 @@ QString QQmlMetaType::prettyTypeName(const QObject *object) if (marker != -1) { typeName = typeName.leftRef(marker) + QLatin1Char('*'); type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1())); - if (type) { - QString qmlTypeName = type->qmlTypeName(); + if (type.isValid()) { + QString qmlTypeName = type.qmlTypeName(); const int lastSlash = qmlTypeName.lastIndexOf(QLatin1Char('/')); if (lastSlash != -1) qmlTypeName = qmlTypeName.mid(lastSlash + 1); diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 08198340f3..d17172a917 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -77,17 +77,17 @@ class Q_QML_PRIVATE_EXPORT QQmlMetaType { public: static QList qmlTypeNames(); - static QList qmlTypes(); - static QList qmlSingletonTypes(); - static QList qmlAllTypes(); - - static QQmlType *qmlType(const QString &qualifiedName, int, int); - static QQmlType *qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int); - static QQmlType *qmlType(const QMetaObject *); - static QQmlType *qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor); - static QQmlType *qmlType(int); - static QQmlType *qmlType(const QUrl &url, bool includeNonFileImports = false); - static QQmlType *qmlTypeFromIndex(int); + static QList qmlTypes(); + static QList qmlSingletonTypes(); + static QList qmlAllTypes(); + + static QQmlType qmlType(const QString &qualifiedName, int, int); + static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int); + static QQmlType qmlType(const QMetaObject *); + static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor); + static QQmlType qmlType(int); + static QQmlType qmlType(const QUrl &url, bool includeNonFileImports = false); + static QQmlType qmlTypeFromIndex(int); static QMetaProperty defaultProperty(const QMetaObject *); static QMetaProperty defaultProperty(QObject *); @@ -144,7 +144,16 @@ public: explicit QQmlType(QQmlTypePrivate *priv); ~QQmlType(); + // ### get rid of these two again + QQmlType(QQmlType *otherPointer); + QQmlType &operator =(QQmlType *otherPointer); + + bool operator ==(const QQmlType &other) const { + return d == other.d; + } + bool isValid() const { return d != 0; } + const QQmlTypePrivate *key() const { return d; } QByteArray typeName() const; QString qmlTypeName() const; @@ -229,8 +238,8 @@ public: static void refHandle(QQmlTypePrivate *priv); static void derefHandle(QQmlTypePrivate *priv); private: - QQmlType *superType() const; - QQmlType *resolveCompositeBaseType(QQmlEnginePrivate *engine) const; + QQmlType superType() const; + QQmlType resolveCompositeBaseType(QQmlEnginePrivate *engine) const; int resolveCompositeEnumValue(QQmlEnginePrivate *engine, const QString &name, bool *ok) const; friend class QQmlTypePrivate; friend struct QQmlMetaTypeData; @@ -250,6 +259,7 @@ private: friend int registerCompositeType(const QQmlPrivate::RegisterCompositeType &); friend int registerCompositeSingletonType(const QQmlPrivate::RegisterCompositeSingletonType &); friend int registerQmlUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &); + friend uint qHash(const QQmlType &t, uint seed); friend Q_QML_EXPORT void qmlClearTypeRegistrations(); QQmlType(int, const QQmlPrivate::RegisterInterface &); QQmlType(int, const QString &, const QQmlPrivate::RegisterSingletonType &); @@ -260,6 +270,12 @@ private: QQmlTypePrivate *d; }; +Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE); + + +inline uint qHash(const QQmlType &t, uint seed = 0) { return qHash(reinterpret_cast(t.d), seed); } + + class QQmlTypeModulePrivate; class QQmlTypeModule { @@ -270,10 +286,8 @@ public: int minimumMinorVersion() const; int maximumMinorVersion() const; - QQmlType *type(const QHashedStringRef &, int) const; - QQmlType *type(const QV4::String *, int) const; - - QList singletonTypes(int) const; + QQmlType type(const QHashedStringRef &, int) const; + QQmlType type(const QV4::String *, int) const; private: //Used by register functions and creates the QQmlTypeModule for them @@ -299,8 +313,8 @@ public: QQmlTypeModule *module() const; int minorVersion() const; - QQmlType *type(const QHashedStringRef &) const; - QQmlType *type(const QV4::String *) const; + QQmlType type(const QHashedStringRef &) const; + QQmlType type(const QV4::String *) const; private: QQmlTypeModule *m_module; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 2cbcfbbfb6..6867aaad75 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -613,11 +613,11 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const } } -static QQmlType *qmlTypeForObject(QObject *object) +static QQmlType qmlTypeForObject(QObject *object) { - QQmlType *type = 0; + QQmlType type; const QMetaObject *mo = object->metaObject(); - while (mo && !type) { + while (mo && !type.isValid()) { type = QQmlMetaType::qmlType(mo); mo = mo->superClass(); } @@ -654,7 +654,7 @@ void QQmlObjectCreator::setupBindings(bool applyDeferredBindings) } else if (binding) { QQmlValueTypeProxyBinding *proxy = static_cast(binding); - if (qmlTypeForObject(_bindingTarget)) { + if (qmlTypeForObject(_bindingTarget).isValid()) { quint32 bindingSkipList = 0; QQmlPropertyData *defaultProperty = _compiledObject->indexOfDefaultPropertyOrAlias != -1 ? _propertyCache->parent()->defaultProperty() : _propertyCache->defaultProperty(); @@ -712,15 +712,15 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con Q_ASSERT(stringAt(qmlUnit->objectAt(binding->value.objectIndex)->inheritedTypeNameIndex).isEmpty()); QV4::CompiledData::ResolvedTypeReference *tr = resolvedTypes.value(binding->propertyNameIndex); Q_ASSERT(tr); - QQmlType *attachedType = tr->type; - if (!attachedType) { + QQmlType attachedType = tr->type; + if (!attachedType.isValid()) { QQmlTypeNameCache::Result res = context->imports->query(stringAt(binding->propertyNameIndex)); if (res.isValid()) attachedType = res.type; else return false; } - const int id = attachedType->attachedPropertiesId(QQmlEnginePrivate::get(engine)); + const int id = attachedType.attachedPropertiesId(QQmlEnginePrivate::get(engine)); QObject *qmlObject = qmlAttachedPropertiesObjectById(id, _qobject); if (!populateInstance(binding->value.objectIndex, qmlObject, qmlObject, /*value type property*/0)) return false; @@ -850,10 +850,10 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con if (binding->type == QV4::CompiledData::Binding::Type_Object) { if (binding->flags & QV4::CompiledData::Binding::IsOnAssignment) { // ### determine value source and interceptor casts ahead of time. - QQmlType *type = qmlTypeForObject(createdSubObject); - Q_ASSERT(type); + QQmlType type = qmlTypeForObject(createdSubObject); + Q_ASSERT(type.isValid()); - int valueSourceCast = type->propertyValueSourceCast(); + int valueSourceCast = type.propertyValueSourceCast(); if (valueSourceCast != -1) { QQmlPropertyValueSource *vs = reinterpret_cast(reinterpret_cast(createdSubObject) + valueSourceCast); QObject *target = createdSubObject->parent(); @@ -865,7 +865,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con vs->setTarget(prop); return true; } - int valueInterceptorCast = type->propertyValueInterceptorCast(); + int valueInterceptorCast = type.propertyValueInterceptorCast(); if (valueInterceptorCast != -1) { QQmlPropertyValueInterceptor *vi = reinterpret_cast(reinterpret_cast(createdSubObject) + valueInterceptorCast); QObject *target = createdSubObject->parent(); @@ -1060,13 +1060,13 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo QV4::CompiledData::ResolvedTypeReference *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex); Q_ASSERT(typeRef); installPropertyCache = !typeRef->isFullyDynamicType; - QQmlType *type = typeRef->type; - if (type) { + QQmlType type = typeRef->type; + if (type.isValid()) { Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( - compilationUnit, obj, type->qmlTypeName(), context->url())); + compilationUnit, obj, type.qmlTypeName(), context->url())); void *ddataMemory = 0; - type->create(&instance, &ddataMemory, sizeof(QQmlData)); + type.create(&instance, &ddataMemory, sizeof(QQmlData)); if (!instance) { recordError(obj->location, tr("Unable to create object of type %1").arg(stringAt(obj->inheritedTypeNameIndex))); return 0; @@ -1080,11 +1080,11 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo p->declarativeData = ddata; } - const int parserStatusCast = type->parserStatusCast(); + const int parserStatusCast = type.parserStatusCast(); if (parserStatusCast != -1) parserStatus = reinterpret_cast(reinterpret_cast(instance) + parserStatusCast); - customParser = type->customParser(); + customParser = type.customParser(); if (sharedState->rootContext && sharedState->rootContext->isRootObjectInCreation) { QQmlData *ddata = QQmlData::get(instance, /*create*/true); diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 9b5f7b0a06..21bbcadb1c 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -253,24 +253,24 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) if (typeNameCache) { QQmlTypeNameCache::Result r = typeNameCache->query(pathName); if (r.isValid()) { - if (r.type) { + if (r.type.isValid()) { QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type->attachedPropertiesFunction(enginePrivate); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); if (!func) return; // Not an attachable type - currentObject = qmlAttachedPropertiesObjectById(r.type->attachedPropertiesId(enginePrivate), currentObject); + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); if (!currentObject) return; // Something is broken with the attachable type } else if (r.importNamespace) { if ((ii + 1) == path.count()) return; // No type following the namespace ++ii; r = typeNameCache->query(path.at(ii), r.importNamespace); - if (!r.type) return; // Invalid type in namespace + if (!r.type.isValid()) return; // Invalid type in namespace QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type->attachedPropertiesFunction(enginePrivate); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); if (!func) return; // Not an attachable type - currentObject = qmlAttachedPropertiesObjectById(r.type->attachedPropertiesId(enginePrivate), currentObject); + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); if (!currentObject) return; // Something is broken with the attachable type } else if (r.scriptIndex != -1) { @@ -1275,10 +1275,10 @@ bool QQmlPropertyPrivate::write(QObject *object, if (enginePriv) { listType = enginePriv->rawMetaObjectForType(enginePriv->listType(property.propType())); } else { - QQmlType *type = QQmlMetaType::qmlType(QQmlMetaType::listType(property.propType())); - if (!type) + QQmlType type = QQmlMetaType::qmlType(QQmlMetaType::listType(property.propType())); + if (!type.isValid()) return false; - listType = type->baseMetaObject(); + listType = type.baseMetaObject(); } if (listType.isNull()) return false; @@ -1393,8 +1393,9 @@ QQmlMetaObject QQmlPropertyPrivate::rawMetaObjectForType(QQmlEnginePrivate *engi return metaType.metaObject(); if (engine) return engine->rawMetaObjectForType(userType); - if (QQmlType *type = QQmlMetaType::qmlType(userType)) - return QQmlMetaObject(type->baseMetaObject()); + QQmlType type = QQmlMetaType::qmlType(userType); + if (type.isValid()) + return QQmlMetaObject(type.baseMetaObject()); return QQmlMetaObject(); } diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index e4293596d8..fbb04af165 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2013,7 +2013,7 @@ QString QQmlTypeData::TypeReference::qualifiedName() const if (!prefix.isEmpty()) { result = prefix + QLatin1Char('.'); } - result.append(type->qmlTypeName()); + result.append(type.qmlTypeName()); return result; } @@ -2168,8 +2168,8 @@ static bool addTypeReferenceChecksumsToHash(const QListcompilationUnit(); hash->addData(unit->data->md5Checksum, sizeof(unit->data->md5Checksum)); - } else if (typeRef.type) { - const auto propertyCache = QQmlEnginePrivate::get(engine)->cache(typeRef.type->metaObject()); + } else if (typeRef.type.isValid()) { + const auto propertyCache = QQmlEnginePrivate::get(engine)->cache(typeRef.type.metaObject()); bool ok = false; hash->addData(propertyCache->checksum(&ok)); if (!ok) @@ -2233,7 +2233,7 @@ void QQmlTypeData::done() const TypeReference &type = m_compositeSingletons.at(ii); Q_ASSERT(!type.typeData || type.typeData->isCompleteOrError()); if (type.typeData && type.typeData->isError()) { - QString typeName = type.type->qmlTypeName(); + QString typeName = type.type.qmlTypeName(); QList errors = type.typeData->errors(); QQmlError error; @@ -2300,24 +2300,24 @@ void QQmlTypeData::done() } { - QQmlType *type = QQmlMetaType::qmlType(finalUrl(), true); + QQmlType type = QQmlMetaType::qmlType(finalUrl(), true); if (m_compiledData && m_compiledData->data->flags & QV4::CompiledData::Unit::IsSingleton) { - if (!type) { + if (!type.isValid()) { QQmlError error; error.setDescription(QQmlTypeLoader::tr("No matching type found, pragma Singleton files cannot be used by QQmlComponent.")); setError(error); return; - } else if (!type->isCompositeSingleton()) { + } else if (!type.isCompositeSingleton()) { QQmlError error; - error.setDescription(QQmlTypeLoader::tr("pragma Singleton used with a non composite singleton type %1").arg(type->qmlTypeName())); + error.setDescription(QQmlTypeLoader::tr("pragma Singleton used with a non composite singleton type %1").arg(type.qmlTypeName())); setError(error); return; } } else { // If the type is CompositeSingleton but there was no pragma Singleton in the // QML file, lets report an error. - if (type && type->isCompositeSingleton()) { - QString typeName = type->qmlTypeName(); + if (type.isValid() && type.isCompositeSingleton()) { + QString typeName = type.qmlTypeName(); setError(QQmlTypeLoader::tr("qmldir defines type as singleton, but no pragma Singleton found in type %1.").arg(typeName)); return; } @@ -2609,8 +2609,8 @@ void QQmlTypeData::resolveTypes() if (!resolveType(typeName, majorVersion, minorVersion, ref)) return; - if (ref.type->isCompositeSingleton()) { - ref.typeData = typeLoader()->getType(ref.type->sourceUrl()); + if (ref.type.isCompositeSingleton()) { + ref.typeData = typeLoader()->getType(ref.type.sourceUrl()); addDependency(ref.typeData); ref.prefix = csRef.prefix; @@ -2637,8 +2637,8 @@ void QQmlTypeData::resolveTypes() if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line, unresolvedRef->location.column, reportErrors) && reportErrors) return; - if (ref.type && ref.type->isComposite()) { - ref.typeData = typeLoader()->getType(ref.type->sourceUrl()); + if (ref.type.isComposite()) { + ref.typeData = typeLoader()->getType(ref.type.sourceUrl()); addDependency(ref.typeData); } ref.majorVersion = majorVersion; @@ -2665,7 +2665,7 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( // Add any Composite Singletons that were used to the import cache for (const QQmlTypeData::TypeReference &singleton: m_compositeSingletons) - (*typeNameCache)->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix); + (*typeNameCache)->add(singleton.type.qmlTypeName(), singleton.type.sourceUrl(), singleton.prefix); m_importCache.populateCache(*typeNameCache); @@ -2673,24 +2673,24 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( for (auto resolvedType = m_resolvedTypes.constBegin(), end = m_resolvedTypes.constEnd(); resolvedType != end; ++resolvedType) { QScopedPointer ref(new QV4::CompiledData::ResolvedTypeReference); - QQmlType *qmlType = resolvedType->type; + QQmlType qmlType = resolvedType->type; if (resolvedType->typeData) { - if (resolvedType->needsCreation && qmlType->isCompositeSingleton()) { - return QQmlCompileError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName())); + if (resolvedType->needsCreation && qmlType.isCompositeSingleton()) { + return QQmlCompileError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType.qmlTypeName())); } ref->compilationUnit = resolvedType->typeData->compilationUnit(); - } else if (qmlType) { + } else if (qmlType.isValid()) { ref->type = qmlType; - Q_ASSERT(ref->type); + Q_ASSERT(ref->type.isValid()); - if (resolvedType->needsCreation && !ref->type->isCreatable()) { - QString reason = ref->type->noCreationReason(); + if (resolvedType->needsCreation && !ref->type.isCreatable()) { + QString reason = ref->type.noCreationReason(); if (reason.isEmpty()) reason = tr("Element is not creatable."); return QQmlCompileError(resolvedType->location, reason); } - if (ref->type->containsRevisionedAttributes()) { + if (ref->type.containsRevisionedAttributes()) { ref->typePropertyCache = engine->cache(ref->type, resolvedType->minorVersion); } diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index f367fa6f58..762fcdac65 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -393,10 +393,10 @@ class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob public: struct TypeReference { - TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0), needsCreation(true) {} + TypeReference() : majorVersion(0), minorVersion(0), typeData(0), needsCreation(true) {} QV4::CompiledData::Location location; - QQmlType *type; + QQmlType type; int majorVersion; int minorVersion; QQmlTypeData *typeData; diff --git a/src/qml/qml/qqmltypenamecache.cpp b/src/qml/qml/qqmltypenamecache.cpp index c8e2b92c29..a8f55d2e48 100644 --- a/src/qml/qml/qqmltypenamecache.cpp +++ b/src/qml/qml/qqmltypenamecache.cpp @@ -100,7 +100,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name) // Look up anonymous types from the imports of this document QQmlImportNamespace *typeNamespace = 0; QList errors; - QQmlType *t = 0; + QQmlType t; bool typeFound = m_imports.resolveType(name, &t, 0, 0, &typeNamespace, &errors); if (typeFound) { return Result(t); @@ -130,7 +130,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name, QString qualifiedTypeName = i->m_qualifier + QLatin1Char('.') + name.toString(); QQmlImportNamespace *typeNamespace = 0; QList errors; - QQmlType *t = 0; + QQmlType t; bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors); if (typeFound) { return Result(t); @@ -155,7 +155,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name) cons QString typeName = name->toQStringNoThrow(); QQmlImportNamespace *typeNamespace = 0; QList errors; - QQmlType *t = 0; + QQmlType t; bool typeFound = m_imports.resolveType(typeName, &t, 0, 0, &typeNamespace, &errors); if (typeFound) { return Result(t); @@ -191,7 +191,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, cons QString qualifiedTypeName = i->m_qualifier + QLatin1Char('.') + name->toQStringNoThrow(); QQmlImportNamespace *typeNamespace = 0; QList errors; - QQmlType *t = 0; + QQmlType t; bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors); if (typeFound) { return Result(t); diff --git a/src/qml/qml/qqmltypenamecache_p.h b/src/qml/qml/qqmltypenamecache_p.h index 7cdcbe91b6..0705166ec2 100644 --- a/src/qml/qml/qqmltypenamecache_p.h +++ b/src/qml/qml/qqmltypenamecache_p.h @@ -78,13 +78,13 @@ public: struct Result { inline Result(); inline Result(const void *importNamespace); - inline Result(QQmlType *type); + inline Result(const QQmlType &type); inline Result(int scriptIndex); inline Result(const Result &); inline bool isValid() const; - QQmlType *type; + QQmlType type; const void *importNamespace; int scriptIndex; }; @@ -132,9 +132,8 @@ private: { QUrl *url = urls.value(key); if (url) { - QQmlType *type = QQmlMetaType::qmlType(*url); - if (type) - return Result(type); + QQmlType type = QQmlMetaType::qmlType(*url); + return Result(type); } return Result(); @@ -145,7 +144,8 @@ private: { QVector::const_iterator end = modules.constEnd(); for (QVector::const_iterator it = modules.constBegin(); it != end; ++it) { - if (QQmlType *type = it->type(key)) + QQmlType type = it->type(key); + if (type.isValid()) return Result(type); } @@ -160,22 +160,22 @@ private: }; QQmlTypeNameCache::Result::Result() -: type(0), importNamespace(0), scriptIndex(-1) +: importNamespace(0), scriptIndex(-1) { } QQmlTypeNameCache::Result::Result(const void *importNamespace) -: type(0), importNamespace(importNamespace), scriptIndex(-1) +: importNamespace(importNamespace), scriptIndex(-1) { } -QQmlTypeNameCache::Result::Result(QQmlType *type) +QQmlTypeNameCache::Result::Result(const QQmlType &type) : type(type), importNamespace(0), scriptIndex(-1) { } QQmlTypeNameCache::Result::Result(int scriptIndex) -: type(0), importNamespace(0), scriptIndex(scriptIndex) +: importNamespace(0), scriptIndex(scriptIndex) { } @@ -186,7 +186,7 @@ QQmlTypeNameCache::Result::Result(const Result &o) bool QQmlTypeNameCache::Result::isValid() const { - return type || importNamespace || scriptIndex != -1; + return type.isValid() || importNamespace || scriptIndex != -1; } QQmlTypeNameCache::Import::Import() diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 0656bd4c62..6fab7697f8 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -247,8 +247,8 @@ ReturnedValue QmlTypeWrapper::get(const Managed *m, String *name, bool *hasPrope QQmlTypeNameCache::Result r = w->d()->typeNamespace->query(name, w->d()->importNamespace); if (r.isValid()) { - if (r.type) { - return create(scope.engine, object, *r.type, w->d()->mode); + if (r.type.isValid()) { + return create(scope.engine, object, r.type, w->d()->mode); } else if (r.scriptIndex != -1) { QV4::ScopedObject scripts(scope, context->importedScripts.valueRef()); return scripts->getIndexed(r.scriptIndex); @@ -301,7 +301,7 @@ void QmlTypeWrapper::put(Managed *m, String *name, const Value &value) QObject *ao = qmlAttachedPropertiesObjectById(type.attachedPropertiesId(QQmlEnginePrivate::get(e)), object); if (ao) QV4::QObjectWrapper::setQmlProperty(v4, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, value); - } else if (type.isValid() && type.isSingleton()) { + } else if (type.isSingleton()) { QQmlEngine *e = scope.engine->qmlEngine(); QQmlType::SingletonInstanceInfo *siinfo = type.singletonInstanceInfo(); siinfo->init(e); diff --git a/src/quick/designer/qquickdesignersupportitems.cpp b/src/quick/designer/qquickdesignersupportitems.cpp index 874faed0af..38ba46e702 100644 --- a/src/quick/designer/qquickdesignersupportitems.cpp +++ b/src/quick/designer/qquickdesignersupportitems.cpp @@ -175,29 +175,24 @@ static bool isWindow(QObject *object) { return false; } -static QQmlType *getQmlType(const QString &typeName, int majorNumber, int minorNumber) +static bool isCrashingType(const QQmlType &type) { - return QQmlMetaType::qmlType(typeName, majorNumber, minorNumber); -} + QString name = type.qmlTypeName(); -static bool isCrashingType(QQmlType *type) -{ - if (type) { - if (type->qmlTypeName() == QLatin1String("QtMultimedia/MediaPlayer")) - return true; + if (type.qmlTypeName() == QLatin1String("QtMultimedia/MediaPlayer")) + return true; - if (type->qmlTypeName() == QLatin1String("QtMultimedia/Audio")) - return true; + if (type.qmlTypeName() == QLatin1String("QtMultimedia/Audio")) + return true; - if (type->qmlTypeName() == QLatin1String("QtQuick.Controls/MenuItem")) - return true; + if (type.qmlTypeName() == QLatin1String("QtQuick.Controls/MenuItem")) + return true; - if (type->qmlTypeName() == QLatin1String("QtQuick.Controls/Menu")) - return true; + if (type.qmlTypeName() == QLatin1String("QtQuick.Controls/Menu")) + return true; - if (type->qmlTypeName() == QLatin1String("QtQuick/Timer")) - return true; - } + if (type.qmlTypeName() == QLatin1String("QtQuick/Timer")) + return true; return false; } @@ -209,19 +204,19 @@ QObject *QQuickDesignerSupportItems::createPrimitive(const QString &typeName, in Q_UNUSED(disableComponentComplete) QObject *object = 0; - QQmlType *type = getQmlType(typeName, majorNumber, minorNumber); + QQmlType type = QQmlMetaType::qmlType(typeName, majorNumber, minorNumber); if (isCrashingType(type)) { object = new QObject; - } else if (type) { - if ( type->isComposite()) { - object = createComponent(type->sourceUrl(), context); + } else if (type.isValid()) { + if ( type.isComposite()) { + object = createComponent(type.sourceUrl(), context); } else { - if (type->typeName() == "QQmlComponent") { + if (type.typeName() == "QQmlComponent") { object = new QQmlComponent(context->engine(), 0); } else { - object = type->create(); + object = type.create(); } } diff --git a/src/quick/designer/qquickdesignersupportmetainfo.cpp b/src/quick/designer/qquickdesignersupportmetainfo.cpp index 332ae26bd4..b398bae55d 100644 --- a/src/quick/designer/qquickdesignersupportmetainfo.cpp +++ b/src/quick/designer/qquickdesignersupportmetainfo.cpp @@ -53,8 +53,8 @@ bool QQuickDesignerSupportMetaInfo::isSubclassOf(QObject *object, const QByteArr const QMetaObject *metaObject = object->metaObject(); while (metaObject) { - QQmlType *qmlType = QQmlMetaType::qmlType(metaObject); - if (qmlType && qmlType->qmlTypeName() == QLatin1String(superTypeName)) // ignore version numbers + QQmlType qmlType = QQmlMetaType::qmlType(metaObject); + if (qmlType.qmlTypeName() == QLatin1String(superTypeName)) // ignore version numbers return true; if (metaObject->className() == superTypeName) diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 3402aeebc1..6ab84774f2 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -283,9 +283,9 @@ void tst_qmldiskcache::registerImportForImplicitComponent() QCOMPARE(quint32(testUnit->nImports), quint32(2)); QCOMPARE(testUnit->stringAt(testUnit->importAt(0)->uriIndex), QStringLiteral("QtQuick")); - QQmlType *componentType = QQmlMetaType::qmlType(&QQmlComponent::staticMetaObject); + QQmlType componentType = QQmlMetaType::qmlType(&QQmlComponent::staticMetaObject); - QCOMPARE(testUnit->stringAt(testUnit->importAt(1)->uriIndex), QString(componentType->module())); + QCOMPARE(testUnit->stringAt(testUnit->importAt(1)->uriIndex), QString(componentType.module())); QCOMPARE(testUnit->stringAt(testUnit->importAt(1)->qualifierIndex), QStringLiteral("QmlInternals")); QCOMPARE(quint32(testUnit->nObjects), quint32(3)); @@ -295,7 +295,7 @@ void tst_qmldiskcache::registerImportForImplicitComponent() QCOMPARE(quint32(obj->bindingTable()->type), quint32(QV4::CompiledData::Binding::Type_Object)); const QV4::CompiledData::Object *implicitComponent = testUnit->objectAt(obj->bindingTable()->value.objectIndex); - QCOMPARE(testUnit->stringAt(implicitComponent->inheritedTypeNameIndex), QStringLiteral("QmlInternals.") + componentType->elementName()); + QCOMPARE(testUnit->stringAt(implicitComponent->inheritedTypeNameIndex), QStringLiteral("QmlInternals.") + componentType.elementName()); } } diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 30e517c8f9..798e3fd386 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -148,14 +148,14 @@ void tst_qqmlmetatype::initTestCase() void tst_qqmlmetatype::qmlParserStatusCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->parserStatusCast(), -1); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->parserStatusCast(), -1); - - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - int cast = QQmlMetaType::qmlType(qMetaTypeId())->parserStatusCast(); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).parserStatusCast(), -1); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).parserStatusCast(), -1); + + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + int cast = QQmlMetaType::qmlType(qMetaTypeId()).parserStatusCast(); QVERIFY(cast != -1); QVERIFY(cast != 0); @@ -168,14 +168,14 @@ void tst_qqmlmetatype::qmlParserStatusCast() void tst_qqmlmetatype::qmlPropertyValueSourceCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->propertyValueSourceCast(), -1); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->propertyValueSourceCast(), -1); - - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - int cast = QQmlMetaType::qmlType(qMetaTypeId())->propertyValueSourceCast(); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).propertyValueSourceCast(), -1); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).propertyValueSourceCast(), -1); + + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + int cast = QQmlMetaType::qmlType(qMetaTypeId()).propertyValueSourceCast(); QVERIFY(cast != -1); QVERIFY(cast != 0); @@ -188,14 +188,14 @@ void tst_qqmlmetatype::qmlPropertyValueSourceCast() void tst_qqmlmetatype::qmlPropertyValueInterceptorCast() { - QVERIFY(!QQmlMetaType::qmlType(QVariant::Int)); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->propertyValueInterceptorCast(), -1); - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId())->propertyValueInterceptorCast(), -1); - - QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()) != 0); - int cast = QQmlMetaType::qmlType(qMetaTypeId())->propertyValueInterceptorCast(); + QVERIFY(!QQmlMetaType::qmlType(QVariant::Int).isValid()); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).propertyValueInterceptorCast(), -1); + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + QCOMPARE(QQmlMetaType::qmlType(qMetaTypeId()).propertyValueInterceptorCast(), -1); + + QVERIFY(QQmlMetaType::qmlType(qMetaTypeId()).isValid()); + int cast = QQmlMetaType::qmlType(qMetaTypeId()).propertyValueInterceptorCast(); QVERIFY(cast != -1); QVERIFY(cast != 0); @@ -208,17 +208,17 @@ void tst_qqmlmetatype::qmlPropertyValueInterceptorCast() void tst_qqmlmetatype::qmlType() { - QQmlType *type = QQmlMetaType::qmlType(QString("ParserStatusTestType"), QString("Test"), 1, 0); - QVERIFY(type); - QVERIFY(type->module() == QLatin1String("Test")); - QVERIFY(type->elementName() == QLatin1String("ParserStatusTestType")); - QCOMPARE(type->qmlTypeName(), QLatin1String("Test/ParserStatusTestType")); + QQmlType type = QQmlMetaType::qmlType(QString("ParserStatusTestType"), QString("Test"), 1, 0); + QVERIFY(type.isValid()); + QVERIFY(type.module() == QLatin1String("Test")); + QVERIFY(type.elementName() == QLatin1String("ParserStatusTestType")); + QCOMPARE(type.qmlTypeName(), QLatin1String("Test/ParserStatusTestType")); type = QQmlMetaType::qmlType("Test/ParserStatusTestType", 1, 0); - QVERIFY(type); - QVERIFY(type->module() == QLatin1String("Test")); - QVERIFY(type->elementName() == QLatin1String("ParserStatusTestType")); - QCOMPARE(type->qmlTypeName(), QLatin1String("Test/ParserStatusTestType")); + QVERIFY(type.isValid()); + QVERIFY(type.module() == QLatin1String("Test")); + QVERIFY(type.elementName() == QLatin1String("ParserStatusTestType")); + QCOMPARE(type.qmlTypeName(), QLatin1String("Test/ParserStatusTestType")); } void tst_qqmlmetatype::invalidQmlTypeName() @@ -277,23 +277,23 @@ void tst_qqmlmetatype::defaultObject() void tst_qqmlmetatype::registrationType() { - QQmlType *type = QQmlMetaType::qmlType(QString("TestType"), QString("Test"), 1, 0); - QVERIFY(type); - QVERIFY(!type->isInterface()); - QVERIFY(!type->isSingleton()); - QVERIFY(!type->isComposite()); + QQmlType type = QQmlMetaType::qmlType(QString("TestType"), QString("Test"), 1, 0); + QVERIFY(type.isValid()); + QVERIFY(!type.isInterface()); + QVERIFY(!type.isSingleton()); + QVERIFY(!type.isComposite()); type = QQmlMetaType::qmlType(QString("TestTypeSingleton"), QString("Test"), 1, 0); - QVERIFY(type); - QVERIFY(!type->isInterface()); - QVERIFY(type->isSingleton()); - QVERIFY(!type->isComposite()); + QVERIFY(type.isValid()); + QVERIFY(!type.isInterface()); + QVERIFY(type.isSingleton()); + QVERIFY(!type.isComposite()); type = QQmlMetaType::qmlType(QString("TestTypeComposite"), QString("Test"), 1, 0); - QVERIFY(type); - QVERIFY(!type->isInterface()); - QVERIFY(!type->isSingleton()); - QVERIFY(type->isComposite()); + QVERIFY(type.isValid()); + QVERIFY(!type.isInterface()); + QVERIFY(!type.isSingleton()); + QVERIFY(type.isComposite()); } void tst_qqmlmetatype::compositeType() @@ -305,12 +305,12 @@ void tst_qqmlmetatype::compositeType() QObject* obj = c.create(); QVERIFY(obj); - QQmlType *type = QQmlMetaType::qmlType(QString("ImplicitType"), QString(""), 1, 0); - QVERIFY(type); - QVERIFY(type->module().isEmpty()); - QCOMPARE(type->elementName(), QLatin1String("ImplicitType")); - QCOMPARE(type->qmlTypeName(), QLatin1String("ImplicitType")); - QCOMPARE(type->sourceUrl(), testFileUrl("ImplicitType.qml")); + QQmlType type = QQmlMetaType::qmlType(QString("ImplicitType"), QString(""), 1, 0); + QVERIFY(type.isValid()); + QVERIFY(type.module().isEmpty()); + QCOMPARE(type.elementName(), QLatin1String("ImplicitType")); + QCOMPARE(type.qmlTypeName(), QLatin1String("ImplicitType")); + QCOMPARE(type.sourceUrl(), testFileUrl("ImplicitType.qml")); } void tst_qqmlmetatype::externalEnums() diff --git a/tests/benchmarks/qml/creation/tst_creation.cpp b/tests/benchmarks/qml/creation/tst_creation.cpp index 9fc67ada71..30d7ef902e 100644 --- a/tests/benchmarks/qml/creation/tst_creation.cpp +++ b/tests/benchmarks/qml/creation/tst_creation.cpp @@ -196,10 +196,10 @@ void tst_creation::qobject_10tree_cpp() void tst_creation::qobject_qmltype() { - QQmlType *t = QQmlMetaType::qmlType("QtQuick/QtObject", 2, 0); + QQmlType t = QQmlMetaType::qmlType("QtQuick/QtObject", 2, 0); QBENCHMARK { - QObject *obj = t->create(); + QObject *obj = t.create(); delete obj; } } diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index dd7ae36c5d..911ef9e9a4 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -144,11 +144,11 @@ void collectReachableMetaObjects(QObject *object, QSet *met } } -void collectReachableMetaObjects(QQmlEnginePrivate *engine, const QQmlType *ty, QSet *metas) +void collectReachableMetaObjects(QQmlEnginePrivate *engine, const QQmlType &ty, QSet *metas) { - collectReachableMetaObjects(ty->metaObject(), metas, ty->isExtendedType()); - if (ty->attachedPropertiesType(engine)) - collectReachableMetaObjects(ty->attachedPropertiesType(engine), metas); + collectReachableMetaObjects(ty.metaObject(), metas, ty.isExtendedType()); + if (ty.attachedPropertiesType(engine)) + collectReachableMetaObjects(ty.attachedPropertiesType(engine), metas); } /* We want to add the MetaObject for 'Qt' to the list, this is a @@ -216,7 +216,7 @@ void collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate *engine, QSetmetaObject()) ) { if (!ty->isComposite()) { - collectReachableMetaObjects(engine, ty, &metas); + collectReachableMetaObjects(engine, *ty, &metas); } else { qmlTypesByCompositeName[ty->elementName()].insert(ty); } @@ -243,7 +243,7 @@ QSet collectReachableMetaObjects(QQmlEngine *engine, qmlTypesByCppName[ty->metaObject()->className()].insert(ty); if (ty->isExtendedType()) extensions[ty->typeName()].insert(ty->metaObject()->className()); - collectReachableMetaObjects(QQmlEnginePrivate::get(engine), ty, &metas); + collectReachableMetaObjects(QQmlEnginePrivate::get(engine), *ty, &metas); } else { qmlTypesByCompositeName[ty->elementName()].insert(ty); } @@ -1226,16 +1226,16 @@ int main(int argc, char *argv[]) } else { // find a valid QtQuick import QByteArray importCode; - QQmlType *qtObjectType = QQmlMetaType::qmlType(&QObject::staticMetaObject); - if (!qtObjectType) { + QQmlType qtObjectType = QQmlMetaType::qmlType(&QObject::staticMetaObject); + if (!qtObjectType.isValid()) { std::cerr << "Could not find QtObject type" << std::endl; importCode = qtQmlImportString.toUtf8(); } else { - QString module = qtObjectType->qmlTypeName(); + QString module = qtObjectType.qmlTypeName(); module = module.mid(0, module.lastIndexOf(QLatin1Char('/'))); importCode = QString("import %1 %2.%3").arg(module, - QString::number(qtObjectType->majorVersion()), - QString::number(qtObjectType->minorVersion())).toUtf8(); + QString::number(qtObjectType.majorVersion()), + QString::number(qtObjectType.minorVersion())).toUtf8(); } // avoid importing dependencies? for (const QString &moduleToImport : qAsConst(dependencies)) { -- cgit v1.2.3