forked from qt-creator/qt-creator
Fix imported qml component names under Windows
Reviewed-by: ckamm
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Qt 4.6
|
||||
import "components"
|
||||
import "components" as X
|
||||
|
||||
Rectangle {
|
||||
width: 640
|
||||
height: 480
|
||||
|
||||
MyButton {
|
||||
X.MyButton {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user