From 5ed718a0029ed4939e0b31e4fe5b67583d6308d7 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Wed, 31 Mar 2010 15:49:19 +0200 Subject: [PATCH] Fix imported qml component names under Windows Reviewed-by: ckamm --- src/libs/qmljs/qmljsdocument.cpp | 2 ++ src/libs/qmljs/qmljslink.cpp | 19 +++---------------- tests/manual/qml/testfiles/usingbutton.qml | 6 +++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/libs/qmljs/qmljsdocument.cpp b/src/libs/qmljs/qmljsdocument.cpp index 88c8caaa51b..38b9f133cc3 100644 --- a/src/libs/qmljs/qmljsdocument.cpp +++ b/src/libs/qmljs/qmljsdocument.cpp @@ -35,6 +35,7 @@ #include <qmljs/parser/qmljsnodepool_p.h> #include <qmljs/parser/qmljsastfwd_p.h> #include <QtCore/QDir> +#include <QtCore/QDebug> using namespace QmlJS; using namespace QmlJS::AST; @@ -57,6 +58,7 @@ Document::Document(const QString &fileName) || fileInfo.suffix() == QLatin1String("qmlproject")) { _isQmlDocument = true; _componentName = fileInfo.baseName(); + qDebug() << _componentName; if (! _componentName.isEmpty()) { // ### TODO: check the component name. diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 072710bac82..57f3dd99076 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -149,19 +149,6 @@ void Link::linkImports() } } -static QString componentName(const QString &fileName) -{ - QString componentName = fileName; - int sepIndex = componentName.lastIndexOf(QDir::separator()); - if (sepIndex != -1) - componentName.remove(0, sepIndex + 1); - int dotIndex = componentName.indexOf(QLatin1Char('.')); - if (dotIndex != -1) - componentName.truncate(dotIndex); - componentName[0] = componentName[0].toUpper(); - return componentName; -} - void Link::populateImportedTypes(Interpreter::ObjectValue *typeEnv, Document::Ptr doc) { if (! (doc->qmlProgram() && doc->qmlProgram()->imports)) @@ -178,7 +165,7 @@ void Link::populateImportedTypes(Interpreter::ObjectValue *typeEnv, Document::Pt if (otherDoc == doc) continue; - typeEnv->setProperty(componentName(otherDoc->fileName()), + typeEnv->setProperty(otherDoc->componentName(), otherDoc->bind()->rootObjectValue()); } @@ -226,7 +213,7 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, } foreach (Document::Ptr importedDoc, _documentByPath.values(path)) { - const QString targetName = componentName(importedDoc->fileName()); + const QString targetName = importedDoc->componentName(); importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue()); } } @@ -236,7 +223,7 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, if (import->importId) { targetName = import->importId->asString(); } else { - targetName = componentName(importedDoc->fileName()); + targetName = importedDoc->componentName(); } importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue()); diff --git a/tests/manual/qml/testfiles/usingbutton.qml b/tests/manual/qml/testfiles/usingbutton.qml index 27375c89574..de1d033cbd3 100644 --- a/tests/manual/qml/testfiles/usingbutton.qml +++ b/tests/manual/qml/testfiles/usingbutton.qml @@ -1,11 +1,11 @@ import Qt 4.6 -import "components" +import "components" as X Rectangle { width: 640 height: 480 - MyButton { + X.MyButton { } -} \ No newline at end of file +} -- GitLab