diff options
author | Tim Jenssen <tim.jenssen@digia.com> | 2016-03-23 12:34:03 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@theqtcompany.com> | 2016-03-23 11:57:42 +0000 |
commit | 61411f9415ef6f5bfa408ef5547af33cf76c1be0 (patch) | |
tree | 9de537b692e42f66cfa9538898109c4248983207 /src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp | |
parent | d27d51050c57f1b03a2e43e220b37d49c99f2f0e (diff) |
Keep QT_RESTRICTED_CAST_FROM_ASCII in the designer
There is no reason to undefine QT_RESTRICTED_CAST_FROM_ASCII (anymore).
Change-Id: Iabeacc8a89d662e78986e2dc275c2096a9c9e519
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp')
-rw-r--r-- | src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp | 155 |
1 files changed, 78 insertions, 77 deletions
diff --git a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp index efb8ab9bec..8dbbfedc5c 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp @@ -46,7 +46,7 @@ namespace Internal { struct TypeDescription { - TypeName className; + QString className; int minorVersion; int majorVersion; }; @@ -330,9 +330,9 @@ private: const ContextPtr m_context; }; -static inline bool isValueType(const QString &type) +static inline bool isValueType(const TypeName &type) { - QStringList objectValuesList; + PropertyTypeList objectValuesList; objectValuesList << "QFont" << "QPoint" << "QPointF" << "QSize" << "QSizeF" << "QVector3D" << "QVector2D"; return objectValuesList.contains(type); } @@ -367,7 +367,7 @@ QStringList prototypes(const ObjectValue *ov, const ContextPtr &context, bool ve } } else { if (versions) - list << ov->className() + " -1.-1"; + list << ov->className() + QLatin1String(" -1.-1"); else list << ov->className(); } @@ -394,10 +394,11 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *objectValue, const Cont QList<PropertyInfo> newList = processor.properties(); foreach (PropertyInfo property, newList) { - PropertyName name = property.first; - if (!objectValue->isWritable(name) && objectValue->isPointer(name)) { + const PropertyName name = property.first; + const QString nameAsString = QString::fromUtf8(name); + if (!objectValue->isWritable(nameAsString) && objectValue->isPointer(nameAsString)) { //dot property - const CppComponentValue * qmlValue = value_cast<CppComponentValue>(objectValue->lookupMember(name, context)); + const CppComponentValue * qmlValue = value_cast<CppComponentValue>(objectValue->lookupMember(nameAsString, context)); if (qmlValue) { QList<PropertyInfo> dotProperties = getQmlTypes(qmlValue, context, false, rec + 1); foreach (const PropertyInfo &propertyInfo, dotProperties) { @@ -408,8 +409,8 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *objectValue, const Cont } } } - if (isValueType(objectValue->propertyType(name))) { - const ObjectValue *dotObjectValue = value_cast<ObjectValue>(objectValue->lookupMember(name, context)); + if (isValueType(objectValue->propertyType(nameAsString).toUtf8())) { + const ObjectValue *dotObjectValue = value_cast<ObjectValue>(objectValue->lookupMember(nameAsString, context)); if (dotObjectValue) { QList<PropertyInfo> dotProperties = getObjectTypes(dotObjectValue, context, false, rec + 1); foreach (const PropertyInfo &propertyInfo, dotProperties) { @@ -421,8 +422,8 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *objectValue, const Cont } } TypeName type = property.second; - if (!objectValue->isPointer(name) && !objectValue->isListProperty(name)) - type = objectValue->propertyType(name).toUtf8(); + if (!objectValue->isPointer(nameAsString) && !objectValue->isListProperty(nameAsString)) + type = objectValue->propertyType(nameAsString).toUtf8(); propertyList.append(qMakePair(name, type)); } @@ -444,7 +445,7 @@ PropertyNameList getSignals(const ObjectValue *objectValue, const ContextPtr &co { PropertyNameList signalList; - if (!objectValue) + if (!objectValue) return signalList; if (objectValue->className().isEmpty()) return signalList; @@ -537,7 +538,7 @@ public: bool isPropertyEnum(const PropertyName &propertyName) const; QString propertyEnumScope(const PropertyName &propertyName) const; QStringList keysForEnum(const QString &enumName) const; - bool cleverCheckType(const QString &otherType) const; + bool cleverCheckType(const TypeName &otherType) const; QVariant::Type variantTypeId(const PropertyName &properyName) const; int majorVersion() const; @@ -545,7 +546,7 @@ public: TypeName qualfiedTypeName() const; Model *model() const; - QString cppPackageName() const; + QByteArray cppPackageName() const; QString componentSource() const; QString componentFileName() const; @@ -553,8 +554,8 @@ public: static Pointer create(Model *model, const TypeName &type, int maj = -1, int min = -1); - QSet<QString> &prototypeCachePositives(); - QSet<QString> &prototypeCacheNegatives(); + QSet<QByteArray> &prototypeCachePositives(); + QSet<QByteArray> &prototypeCacheNegatives(); static void clearCache(); @@ -582,18 +583,18 @@ private: PropertyNameList m_localProperties; PropertyName m_defaultPropertyName; QList<TypeDescription> m_prototypes; - QSet<QString> m_prototypeCachePositives; - QSet<QString> m_prototypeCacheNegatives; + QSet<QByteArray> m_prototypeCachePositives; + QSet<QByteArray> m_prototypeCacheNegatives; //storing the pointer would not be save ContextPtr context() const; const Document *document() const; QPointer<Model> m_model; - static QHash<QString, Pointer> m_nodeMetaInfoCache; + static QHash<TypeName, Pointer> m_nodeMetaInfoCache; }; -QHash<QString, NodeMetaInfoPrivate::Pointer> NodeMetaInfoPrivate::m_nodeMetaInfoCache; +QHash<TypeName, NodeMetaInfoPrivate::Pointer> NodeMetaInfoPrivate::m_nodeMetaInfoCache; bool NodeMetaInfoPrivate::isFileComponent() const { @@ -615,12 +616,12 @@ PropertyNameList NodeMetaInfoPrivate::signalNames() const return m_signals; } -QSet<QString> &NodeMetaInfoPrivate::prototypeCachePositives() +QSet<QByteArray> &NodeMetaInfoPrivate::prototypeCachePositives() { return m_prototypeCachePositives; } -QSet<QString> &NodeMetaInfoPrivate::prototypeCacheNegatives() +QSet<QByteArray> &NodeMetaInfoPrivate::prototypeCacheNegatives() { return m_prototypeCacheNegatives; } @@ -637,9 +638,9 @@ PropertyName NodeMetaInfoPrivate::defaultPropertyName() const return PropertyName("data"); } -static inline QString stringIdentifier( const QString &type, int maj, int min) +static inline TypeName stringIdentifier( const TypeName &type, int maj, int min) { - return type + QString::number(maj) + '_' + QString::number(min); + return type + QString::number(maj).toLatin1() + '_' + QString::number(min).toLatin1(); } NodeMetaInfoPrivate::Pointer NodeMetaInfoPrivate::create(Model *model, const TypeName &type, int major, int minor) @@ -748,7 +749,7 @@ const CppComponentValue *NodeMetaInfoPrivate::getCppComponentValue() const return value; // maybe 'type' is a cpp name - const CppComponentValue *cppValue = context()->valueOwner()->cppQmlTypes().objectByCppName(type); + const CppComponentValue *cppValue = context()->valueOwner()->cppQmlTypes().objectByCppName(QString::fromUtf8(type)); if (cppValue) { foreach (const LanguageUtils::FakeMetaObject::Export &exportValue, cppValue->metaObject()->exports()) { @@ -813,12 +814,12 @@ bool NodeMetaInfoPrivate::isPropertyWritable(const PropertyName &propertyName) c const PropertyNameList parts = propertyName.split('.'); const PropertyName objectName = parts.first(); const PropertyName rawPropertyName = parts.last(); - const QString objectType = propertyType(objectName); + const TypeName objectType = propertyType(objectName); if (isValueType(objectType)) return true; - QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType.toUtf8())); + QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType)); if (objectInfo->isValid()) return objectInfo->isPropertyWritable(rawPropertyName); else @@ -828,8 +829,8 @@ bool NodeMetaInfoPrivate::isPropertyWritable(const PropertyName &propertyName) c const CppComponentValue *qmlObjectValue = getNearestCppComponentValue(); if (!qmlObjectValue) return true; - if (qmlObjectValue->hasProperty(propertyName)) - return qmlObjectValue->isWritable(propertyName); + if (qmlObjectValue->hasProperty(QString::fromUtf8(propertyName))) + return qmlObjectValue->isWritable(QString::fromUtf8(propertyName)); else return true; //all properties of components are writable } @@ -844,12 +845,12 @@ bool NodeMetaInfoPrivate::isPropertyList(const PropertyName &propertyName) const const PropertyNameList parts = propertyName.split('.'); const PropertyName objectName = parts.first(); const PropertyName rawPropertyName = parts.last(); - const QString objectType = propertyType(objectName); + const TypeName objectType = propertyType(objectName); if (isValueType(objectType)) return false; - QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType.toUtf8())); + QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType)); if (objectInfo->isValid()) return objectInfo->isPropertyList(rawPropertyName); else @@ -859,7 +860,7 @@ bool NodeMetaInfoPrivate::isPropertyList(const PropertyName &propertyName) const const CppComponentValue *qmlObjectValue = getNearestCppComponentValue(); if (!qmlObjectValue) return false; - return qmlObjectValue->isListProperty(propertyName); + return qmlObjectValue->isListProperty(QString::fromUtf8(propertyName)); } bool NodeMetaInfoPrivate::isPropertyPointer(const PropertyName &propertyName) const @@ -871,12 +872,12 @@ bool NodeMetaInfoPrivate::isPropertyPointer(const PropertyName &propertyName) co const PropertyNameList parts = propertyName.split('.'); const PropertyName objectName = parts.first(); const PropertyName rawPropertyName = parts.last(); - const QString objectType = propertyType(objectName); + const TypeName objectType = propertyType(objectName); if (isValueType(objectType)) return false; - QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType.toUtf8())); + QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType)); if (objectInfo->isValid()) return objectInfo->isPropertyPointer(rawPropertyName); else @@ -886,7 +887,7 @@ bool NodeMetaInfoPrivate::isPropertyPointer(const PropertyName &propertyName) co const CppComponentValue *qmlObjectValue = getNearestCppComponentValue(); if (!qmlObjectValue) return false; - return qmlObjectValue->isPointer(propertyName); + return qmlObjectValue->isPointer(QString::fromUtf8(propertyName)); } bool NodeMetaInfoPrivate::isPropertyEnum(const PropertyName &propertyName) const @@ -901,12 +902,12 @@ bool NodeMetaInfoPrivate::isPropertyEnum(const PropertyName &propertyName) const const PropertyNameList parts = propertyName.split('.'); const PropertyName objectName = parts.first(); const PropertyName rawPropertyName = parts.last(); - const QString objectType = propertyType(objectName); + const TypeName objectType = propertyType(objectName); if (isValueType(objectType)) return false; - QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType.toUtf8())); + QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType)); if (objectInfo->isValid()) return objectInfo->isPropertyEnum(rawPropertyName); else @@ -916,7 +917,7 @@ bool NodeMetaInfoPrivate::isPropertyEnum(const PropertyName &propertyName) const const CppComponentValue *qmlObjectValue = getNearestCppComponentValue(); if (!qmlObjectValue) return false; - return qmlObjectValue->getEnum(propertyType(propertyName)).isValid(); + return qmlObjectValue->getEnum(QString::fromUtf8(propertyType(propertyName))).isValid(); } QString NodeMetaInfoPrivate::propertyEnumScope(const PropertyName &propertyName) const @@ -931,12 +932,12 @@ QString NodeMetaInfoPrivate::propertyEnumScope(const PropertyName &propertyName) const PropertyNameList parts = propertyName.split('.'); const PropertyName objectName = parts.first(); const PropertyName rawPropertyName = parts.last(); - const QString objectType = propertyType(objectName); + const TypeName objectType = propertyType(objectName); if (isValueType(objectType)) return QString(); - QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType.toUtf8())); + QSharedPointer<NodeMetaInfoPrivate> objectInfo(create(m_model, objectType)); if (objectInfo->isValid()) return objectInfo->propertyEnumScope(rawPropertyName); else @@ -947,7 +948,7 @@ QString NodeMetaInfoPrivate::propertyEnumScope(const PropertyName &propertyName) if (!qmlObjectValue) return QString(); const CppComponentValue *definedIn = 0; - qmlObjectValue->getEnum(propertyType(propertyName), &definedIn); + qmlObjectValue->getEnum(QString::fromUtf8(propertyType(propertyName)), &definedIn); if (definedIn) { QString nonCppPackage; foreach (const LanguageUtils::FakeMetaObject::Export &qmlExport, definedIn->metaObject()->exports()) { @@ -966,25 +967,25 @@ QString NodeMetaInfoPrivate::propertyEnumScope(const PropertyName &propertyName) return QString(); } -static QString getUnqualifiedName(const QString &name) +static QByteArray getUnqualifiedName(const QByteArray &name) { - const QStringList nameComponents = name.split('.'); + const QList<QByteArray> nameComponents = name.split('.'); if (nameComponents.size() < 2) return name; return nameComponents.last(); } -static QString getPackage(const QString &name) +static QByteArray getPackage(const QByteArray &name) { - QStringList nameComponents = name.split('.'); + QList<QByteArray> nameComponents = name.split('.'); if (nameComponents.size() < 2) - return QString(); + return QByteArray(); nameComponents.removeLast(); - return nameComponents.join(QLatin1Char('.')); + return nameComponents.join('.'); } -bool NodeMetaInfoPrivate::cleverCheckType(const QString &otherType) const +bool NodeMetaInfoPrivate::cleverCheckType(const TypeName &otherType) const { if (otherType == qualfiedTypeName()) return true; @@ -992,18 +993,18 @@ bool NodeMetaInfoPrivate::cleverCheckType(const QString &otherType) const if (isFileComponent()) return false; - const QString typeName = getUnqualifiedName(otherType); - const QString package = getPackage(otherType); + const QByteArray typeName = getUnqualifiedName(otherType); + const QByteArray package = getPackage(otherType); if (cppPackageName() == package) - return QString(package + '.' + typeName) == cppPackageName() + '.' + getUnqualifiedName(qualfiedTypeName()); + return QByteArray(package + '.' + typeName) == (cppPackageName() + '.' + getUnqualifiedName(qualfiedTypeName())); const CppComponentValue *qmlObjectValue = getCppComponentValue(); if (!qmlObjectValue) return false; const LanguageUtils::FakeMetaObject::Export exp = - qmlObjectValue->metaObject()->exportInPackage(package); + qmlObjectValue->metaObject()->exportInPackage(QString::fromUtf8(package)); QString convertedName = exp.type; if (convertedName.isEmpty()) convertedName = qmlObjectValue->className(); @@ -1013,7 +1014,7 @@ bool NodeMetaInfoPrivate::cleverCheckType(const QString &otherType) const QVariant::Type NodeMetaInfoPrivate::variantTypeId(const PropertyName &properyName) const { - QString typeName = propertyType(properyName); + TypeName typeName = propertyType(properyName); if (typeName == "string") return QVariant::String; @@ -1044,7 +1045,7 @@ QVariant::Type NodeMetaInfoPrivate::variantTypeId(const PropertyName &properyNam if (typeName == "var") return QVariant::UserType; - return QVariant::nameToType(typeName.toUtf8().data()); + return QVariant::nameToType(typeName.data()); } int NodeMetaInfoPrivate::majorVersion() const @@ -1079,13 +1080,13 @@ QStringList NodeMetaInfoPrivate::keysForEnum(const QString &enumName) const return qmlObjectValue->getEnum(enumName).keys(); } -QString NodeMetaInfoPrivate::cppPackageName() const +QByteArray NodeMetaInfoPrivate::cppPackageName() const { if (!isFileComponent()) { if (const CppComponentValue *qmlObject = getCppComponentValue()) - return qmlObject->moduleName(); + return qmlObject->moduleName().toUtf8(); } - return QString(); + return QByteArray(); } QString NodeMetaInfoPrivate::componentSource() const @@ -1131,7 +1132,7 @@ QString NodeMetaInfoPrivate::importDirectoryPath() const if (QDir(targetPath).exists()) return targetPath; const QString targetPathVersion = QDir(importPath).filePath(importInfo.path() - + QLatin1Char('.') + + '.' + QString::number(importInfo.version().majorVersion())); if (QDir(targetPathVersion).exists()) return targetPathVersion; @@ -1147,10 +1148,10 @@ QString NodeMetaInfoPrivate::lookupName() const QString className = QString::fromUtf8(m_qualfiedTypeName); QString packageName; - QStringList packageClassName = className.split(QLatin1Char('.')); + QStringList packageClassName = className.split('.'); if (packageClassName.size() > 1) { className = packageClassName.takeLast(); - packageName = packageClassName.join(QLatin1Char('.')); + packageName = packageClassName.join('.'); } return CppQmlTypes::qualifiedName( @@ -1200,30 +1201,30 @@ void NodeMetaInfoPrivate::setupPrototypes() foreach (const ObjectValue *ov, objects) { TypeDescription description; - description.className = ov->className().toUtf8(); + description.className = ov->className(); description.minorVersion = -1; description.majorVersion = -1; if (const CppComponentValue * qmlValue = value_cast<CppComponentValue>(ov)) { description.minorVersion = qmlValue->componentVersion().minorVersion(); description.majorVersion = qmlValue->componentVersion().majorVersion(); - LanguageUtils::FakeMetaObject::Export qtquickExport = qmlValue->metaObject()->exportInPackage("QtQuick"); - LanguageUtils::FakeMetaObject::Export cppExport = qmlValue->metaObject()->exportInPackage("<cpp>"); + LanguageUtils::FakeMetaObject::Export qtquickExport = qmlValue->metaObject()->exportInPackage(QLatin1String("QtQuick")); + LanguageUtils::FakeMetaObject::Export cppExport = qmlValue->metaObject()->exportInPackage(QLatin1String("<cpp>")); if (qtquickExport.isValid()) { - description.className = qtquickExport.package.toUtf8() + '.' + qtquickExport.type.toUtf8(); + description.className = qtquickExport.package + '.' + qtquickExport.type; } else { bool found = false; if (cppExport.isValid()) { foreach (const LanguageUtils::FakeMetaObject::Export &exportValue, qmlValue->metaObject()->exports()) { if (exportValue.package.toUtf8() != "<cpp>") { found = true; - description.className = exportValue.package.toUtf8() + '.' + exportValue.type.toUtf8(); + description.className = exportValue.package + '.' + exportValue.type; } } } if (!found) { if (qmlValue->moduleName().isEmpty() && cppExport.isValid()) { - description.className = cppExport.package.toUtf8() + '.' + cppExport.type.toUtf8(); + description.className = cppExport.package + '.' + cppExport.type; } else if (!qmlValue->moduleName().isEmpty()) { description.className = qmlValue->moduleName().toUtf8() + '.' + description.className; } @@ -1239,7 +1240,7 @@ void NodeMetaInfoPrivate::setupPrototypes() QString uri = importInfo.name(); uri.replace(QStringLiteral(","), QStringLiteral(".")); if (!uri.isEmpty()) - description.className = QString(uri + QString::fromLatin1(".") + QString::fromUtf8(description.className)).toUtf8(); + description.className = QString(uri + "." + description.className); } m_prototypes.append(description); @@ -1264,8 +1265,8 @@ const CppComponentValue *NodeMetaInfoPrivate::getNearestCppComponentValue() cons QString NodeMetaInfoPrivate::fullQualifiedImportAliasType() const { if (m_model && m_model->rewriterView()) - return model()->rewriterView()->convertTypeToImportAlias(m_qualfiedTypeName); - return m_qualfiedTypeName; + return model()->rewriterView()->convertTypeToImportAlias(QString::fromUtf8(m_qualfiedTypeName)); + return QString::fromUtf8(m_qualfiedTypeName); } } //namespace Internal @@ -1369,7 +1370,7 @@ QString NodeMetaInfo::propertyEnumScope(const PropertyName &propertyName) const QStringList NodeMetaInfo::propertyKeysForEnum(const PropertyName &propertyName) const { - return m_privateData->keysForEnum(propertyTypeName(propertyName)); + return m_privateData->keysForEnum(QString::fromUtf8(propertyTypeName(propertyName))); } QVariant NodeMetaInfo::propertyCastedValue(const PropertyName &propertyName, const QVariant &value) const @@ -1381,17 +1382,17 @@ QVariant NodeMetaInfo::propertyCastedValue(const PropertyName &propertyName, con || variant.canConvert<Enumeration>()) return variant; - const QString typeName = propertyTypeName(propertyName); + const TypeName typeName = propertyTypeName(propertyName); QVariant::Type typeId = m_privateData->variantTypeId(propertyName); if (variant.type() == QVariant::UserType && variant.userType() == ModelNode::variantUserType()) { return variant; - } else if (typeId == QVariant::UserType && typeName == QStringLiteral("QVariant")) { + } else if (typeId == QVariant::UserType && typeName == "QVariant") { return variant; - } else if (typeId == QVariant::UserType && typeName == QStringLiteral("variant")) { + } else if (typeId == QVariant::UserType && typeName == "variant") { return variant; - } else if (typeId == QVariant::UserType && typeName == QStringLiteral("var")) { + } else if (typeId == QVariant::UserType && typeName == "var") { return variant; } else if (variant.type() == QVariant::List) { // TODO: check the contents of the list @@ -1413,7 +1414,7 @@ QList<NodeMetaInfo> NodeMetaInfo::superClasses() const QList<NodeMetaInfo> list; foreach (const Internal::TypeDescription &type, m_privateData->prototypes()) { - list.append(NodeMetaInfo(m_privateData->model(), type.className, type.majorVersion, type.minorVersion)); + list.append(NodeMetaInfo(m_privateData->model(), type.className.toUtf8(), type.majorVersion, type.minorVersion)); } return list; } @@ -1426,9 +1427,9 @@ NodeMetaInfo NodeMetaInfo::directSuperClass() const return NodeMetaInfo(); } -QList<TypeName> NodeMetaInfo::superClassNames() const +QStringList NodeMetaInfo::superClassNames() const { - QList<TypeName> list; + QStringList list; foreach (const Internal::TypeDescription &type, m_privateData->prototypes()) { list.append(type.className); |