From 605e869335df3ee9f439bab4bc2e3c67520784e1 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Fri, 10 Oct 2014 10:08:24 +0200 Subject: [PATCH] QmlDesigner: fix regression from last filter import fix - adding line ending to the import code - set correct fileUrl to resolve local directory imports Task-number: QTCREATORBUG-12625 Change-Id: I2861fc5674ff0fa4f6cc9e308a22cd2853ffa85c Reviewed-by: Thomas Hartmann --- .../instances/nodeinstanceserver.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp index 56cd70694b3..884f5ef392d 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserver.cpp @@ -80,14 +80,13 @@ #include "dummycontextobject.h" namespace { - bool testImportStatements(const QStringList &importStatementList, bool enableErrorOutput = false) { - static const QUrl localEmptyUrl(QUrl::fromLocalFile("")); + bool testImportStatements(const QStringList &importStatementList, const QUrl &url, bool enableErrorOutput = false) { QQmlEngine engine; QQmlComponent testImportComponent(&engine); QByteArray testComponentCode = QStringList(importStatementList).join("\n").toUtf8(); - testImportComponent.setData(testComponentCode.append("\nItem {}\n"), localEmptyUrl); + testImportComponent.setData(testComponentCode.append("\nItem {}\n"), url); testImportComponent.create(); if (testImportComponent.errors().isEmpty()) { @@ -399,13 +398,13 @@ void NodeInstanceServer::setupImports(const QVector &contain bool enableErrorOutput(true); // maybe it just works - if (testImportStatements(importStatementList)) { + if (testImportStatements(importStatementList, fileUrl())) { workingImportStatementList = importStatementList; } else { QString firstWorkingImportStatement; //usually this will be "import QtQuick x.x" QStringList otherImportStatements; foreach (const QString &importStatement, importStatementList) { - if (testImportStatements(QStringList(importStatement))) + if (testImportStatements(QStringList(importStatement), fileUrl())) firstWorkingImportStatement = importStatement; else otherImportStatements.append(importStatement); @@ -413,8 +412,10 @@ void NodeInstanceServer::setupImports(const QVector &contain // find the bad imports from otherImportStatements foreach (const QString &importStatement, otherImportStatements) { - if (testImportStatements(QStringList(firstWorkingImportStatement) << importStatement, enableErrorOutput)) + if (testImportStatements(QStringList(firstWorkingImportStatement) << + importStatement, fileUrl(), enableErrorOutput)) { workingImportStatementList.append(importStatement); + } } workingImportStatementList.prepend(firstWorkingImportStatement); } @@ -424,7 +425,7 @@ void NodeInstanceServer::setupImports(const QVector &contain void NodeInstanceServer::setupOnlyWorkingImports(const QStringList &workingImportStatementList) { - QByteArray componentCode = workingImportStatementList.join("\n").toUtf8(); + QByteArray componentCode = workingImportStatementList.join("\n").toUtf8().append("\n"); m_importCode = componentCode; m_importComponent = new QQmlComponent(engine(), quickView()); @@ -461,7 +462,8 @@ void NodeInstanceServer::setupDummyData(const QUrl &fileUrl) void NodeInstanceServer::setupDefaultDummyData() { QQmlComponent component(engine()); - QByteArray defaultContextObjectArray("import QmlDesigner 1.0\n" + QByteArray defaultContextObjectArray("import QtQml 2.0\n" + "import QmlDesigner 1.0\n" "DummyContextObject {\n" " parent: QtObject {\n" " property real width: 360\n"