diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-09-16 13:55:10 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-09-19 13:52:26 +0200 |
commit | 6c925cf0fc4f0c6494e5e5639e84970d67ea248b (patch) | |
tree | 81d2e75cd1567bf08f8cd0eadbeea8bb91e63739 /src/plugins/qmldesigner | |
parent | 793031c7ba64ca7ba67c6a555bbab49ae2ec0b85 (diff) | |
download | qt-creator-6c925cf0fc4f0c6494e5e5639e84970d67ea248b.tar.gz |
QmlJS: Rework exported C++ type registry.
The problem was that if you exported
A 1.0, A 1.1 and B 1.0 where A is the prototype of B
the code model had not enough information to know that, depending
on the import, B 1.0's prototype should be A 1.1 or A 1.0.
To solve this problem QmlObjectValues now store the import's version
as well as the local component version. In the example above B 1.0
would have import version 1.1 if the 1.1 module was imported and thus
be able to choose the right prototype.
Change-Id: I7ef33f12ca5a528c62b2a8240f4b5720b0ebd4c3
Reviewed-on: http://codereview.qt-project.org/5129
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Diffstat (limited to 'src/plugins/qmldesigner')
-rw-r--r-- | src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp | 106 | ||||
-rw-r--r-- | src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp | 6 |
2 files changed, 37 insertions, 75 deletions
diff --git a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp index 5afb1a343e..d7db630154 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp @@ -104,7 +104,7 @@ public: m_properties.append(qMakePair(name, type)); } else { if (const QmlObjectValue * ov = dynamic_cast<const QmlObjectValue *>(value)) { - QString qualifiedTypeName = ov->packageName().isEmpty() ? ov->className() : ov->packageName() + '.' + ov->className(); + QString qualifiedTypeName = ov->moduleName().isEmpty() ? ov->className() : ov->moduleName() + '.' + ov->className(); m_properties.append(qMakePair(name, qualifiedTypeName)); } else { TypeId typeId; @@ -157,11 +157,11 @@ QStringList prototypes(const ObjectValue *ov, const ContextPtr &context, bool ve const QmlObjectValue * qmlValue = dynamic_cast<const QmlObjectValue *>(ov); if (qmlValue) { if (versions) { - list << qmlValue->packageName() + '.' + qmlValue->className() + - ' ' + QString::number(qmlValue->version().majorVersion()) + - '.' + QString::number(qmlValue->version().minorVersion()); + list << qmlValue->moduleName() + '.' + qmlValue->className() + + ' ' + QString::number(qmlValue->componentVersion().majorVersion()) + + '.' + QString::number(qmlValue->componentVersion().minorVersion()); } else { - list << qmlValue->packageName() + QLatin1Char('.') + qmlValue->className(); + list << qmlValue->moduleName() + QLatin1Char('.') + qmlValue->className(); } } else { if (versions) { @@ -436,9 +436,9 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in if (objectValue) { const QmlObjectValue *qmlValue = dynamic_cast<const QmlObjectValue *>(objectValue); if (qmlValue) { - m_majorVersion = qmlValue->version().majorVersion(); - m_minorVersion = qmlValue->version().minorVersion(); - m_qualfiedTypeName = qmlValue->packageName() + '.' + qmlValue->className(); + m_majorVersion = qmlValue->componentVersion().majorVersion(); + m_minorVersion = qmlValue->componentVersion().minorVersion(); + m_qualfiedTypeName = qmlValue->moduleName() + '.' + qmlValue->className(); } else { m_isComponent = true; } @@ -452,73 +452,35 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in } } -static inline QString getUrlFromType(const QString& typeName) -{ - QStringList nameComponents = typeName.split('.'); - QString result; - - for (int i = 0; i < (nameComponents.count() - 1); i++) { - result += nameComponents.at(i); - } - - return result; -} - const QmlJS::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue() const { - QmlJS::QmlObjectValue * value = context()->valueOwner()->cppQmlTypes().typeByQualifiedName(lookupName()); - if (value) - return value; - - //If no version was specified (-1,-1) the approach above does not work. - //But we can look up the value "manually" - //This is usefull to make something like QtQuick.Item -1 -1 work in all cases - //and fix ambiguities with Qt 4.7. - - if (m_majorVersion != -1 || m_minorVersion != -1) - return 0; - - const QString old_qualfiedTypeName = m_qualfiedTypeName; - - //This makes only sense if a package was specified. - if (m_qualfiedTypeName.split(".").count() < 2) + const QStringList nameComponents = m_qualfiedTypeName.split('.'); + if (nameComponents.size() < 2) return 0; + const QString type = nameComponents.last(); - const QString package = getUrlFromType(m_qualfiedTypeName); - const QString type = m_qualfiedTypeName.split('.').last(); - - - LanguageUtils::ComponentVersion version(9999, 9999); - //get the correct version - ImportInfo importInfo = context()->imports(document())->info(fullQualifiedImportAliasType(), context().data()); - - if (importInfo.isValid()) - version = importInfo.version(); + // maybe 'type' is a cpp name + const QmlJS::QmlObjectValue *value = context()->valueOwner()->cppQmlTypes().objectByCppName(type); + if (value) + return value; - QList<QmlObjectValue *> qmlObjectValues = context()->valueOwner()->cppQmlTypes().typesForImport(package, version); - const QmlObjectValue *qmlValue = 0; - foreach (QmlObjectValue *value, qmlObjectValues) { - if (value->className() == type) - qmlValue = value; + QString module; + for (int i = 0; i < nameComponents.size() - 1; ++i) { + if (i != 0) + module += QLatin1Char('/'); + module += nameComponents.at(i); } - if (!qmlValue) - return 0; - - //Now we have to check the different packages. - const LanguageUtils::FakeMetaObject::Export exp = - qmlValue->metaObject()->exportInPackage(package); - const QString convertedName = exp.type; - - //Not available in the requested package - if (convertedName.isNull()) - return 0; - - //Different name for requested package - if (type != convertedName) - return 0; + // otherwise get the qml object value that's available in the document + foreach (const QmlJS::Import &import, context()->imports(document())->all()) { + if (import.info.name() != module) + continue; + const Value *lookupResult = import.object->lookupMember(type, context()); + if ((value = dynamic_cast<const QmlObjectValue *>(lookupResult))) + return value; + } - return qmlValue; + return 0; } const QmlJS::ObjectValue *NodeMetaInfoPrivate::getObjectValue() const @@ -775,7 +737,7 @@ QStringList NodeMetaInfoPrivate::keysForEnum(const QString &enumName) const QString NodeMetaInfoPrivate::packageName() const { if (!isComponent()) - return getQmlObjectValue()->packageName(); + return getQmlObjectValue()->moduleName(); return QString(); } @@ -855,10 +817,10 @@ void NodeMetaInfoPrivate::setupPrototypes() description.minorVersion = -1; description.majorVersion = -1; if (const QmlObjectValue * qmlValue = dynamic_cast<const QmlObjectValue *>(ov)) { - description.minorVersion = qmlValue->version().minorVersion(); - description.majorVersion = qmlValue->version().majorVersion(); - if (!qmlValue->packageName().isEmpty()) - description.className = qmlValue->packageName() + '.' + description.className; + description.minorVersion = qmlValue->componentVersion().minorVersion(); + description.majorVersion = qmlValue->componentVersion().majorVersion(); + if (!qmlValue->moduleName().isEmpty()) + description.className = qmlValue->moduleName() + '.' + description.className; m_prototypes.append(description); } else { if (context()->lookupType(document(), QStringList() << ov->className())) diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index b636fd83ce..bab7cf2acf 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -362,11 +362,11 @@ public: const QmlObjectValue * qmlValue = dynamic_cast<const QmlObjectValue *>(value); if (qmlValue) { - typeName = fixUpPackeNameForQt(qmlValue->packageName()) + QLatin1String(".") + qmlValue->className(); + typeName = fixUpPackeNameForQt(qmlValue->moduleName()) + QLatin1String(".") + qmlValue->className(); //### todo this is just a hack to support QtQuick 1.0 - majorVersion = fixUpMajorVersionForQt(qmlValue->packageName(), qmlValue->version().majorVersion()); - minorVersion = fixUpMinorVersionForQt(qmlValue->packageName(), qmlValue->version().minorVersion()); + majorVersion = fixUpMajorVersionForQt(qmlValue->moduleName(), qmlValue->componentVersion().majorVersion()); + minorVersion = fixUpMinorVersionForQt(qmlValue->moduleName(), qmlValue->componentVersion().minorVersion()); } else { for (UiQualifiedId *iter = astTypeNode; iter; iter = iter->next) if (!iter->next && !iter->name.isEmpty()) |