forked from qt-creator/qt-creator
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 <Thomas.Hartmann@digia.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
9cc88836f7
commit
605e869335
@@ -80,14 +80,13 @@
|
|||||||
#include "dummycontextobject.h"
|
#include "dummycontextobject.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool testImportStatements(const QStringList &importStatementList, bool enableErrorOutput = false) {
|
bool testImportStatements(const QStringList &importStatementList, const QUrl &url, bool enableErrorOutput = false) {
|
||||||
static const QUrl localEmptyUrl(QUrl::fromLocalFile(""));
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent testImportComponent(&engine);
|
QQmlComponent testImportComponent(&engine);
|
||||||
|
|
||||||
QByteArray testComponentCode = QStringList(importStatementList).join("\n").toUtf8();
|
QByteArray testComponentCode = QStringList(importStatementList).join("\n").toUtf8();
|
||||||
|
|
||||||
testImportComponent.setData(testComponentCode.append("\nItem {}\n"), localEmptyUrl);
|
testImportComponent.setData(testComponentCode.append("\nItem {}\n"), url);
|
||||||
testImportComponent.create();
|
testImportComponent.create();
|
||||||
|
|
||||||
if (testImportComponent.errors().isEmpty()) {
|
if (testImportComponent.errors().isEmpty()) {
|
||||||
@@ -399,13 +398,13 @@ void NodeInstanceServer::setupImports(const QVector<AddImportContainer> &contain
|
|||||||
bool enableErrorOutput(true);
|
bool enableErrorOutput(true);
|
||||||
|
|
||||||
// maybe it just works
|
// maybe it just works
|
||||||
if (testImportStatements(importStatementList)) {
|
if (testImportStatements(importStatementList, fileUrl())) {
|
||||||
workingImportStatementList = importStatementList;
|
workingImportStatementList = importStatementList;
|
||||||
} else {
|
} else {
|
||||||
QString firstWorkingImportStatement; //usually this will be "import QtQuick x.x"
|
QString firstWorkingImportStatement; //usually this will be "import QtQuick x.x"
|
||||||
QStringList otherImportStatements;
|
QStringList otherImportStatements;
|
||||||
foreach (const QString &importStatement, importStatementList) {
|
foreach (const QString &importStatement, importStatementList) {
|
||||||
if (testImportStatements(QStringList(importStatement)))
|
if (testImportStatements(QStringList(importStatement), fileUrl()))
|
||||||
firstWorkingImportStatement = importStatement;
|
firstWorkingImportStatement = importStatement;
|
||||||
else
|
else
|
||||||
otherImportStatements.append(importStatement);
|
otherImportStatements.append(importStatement);
|
||||||
@@ -413,9 +412,11 @@ void NodeInstanceServer::setupImports(const QVector<AddImportContainer> &contain
|
|||||||
|
|
||||||
// find the bad imports from otherImportStatements
|
// find the bad imports from otherImportStatements
|
||||||
foreach (const QString &importStatement, otherImportStatements) {
|
foreach (const QString &importStatement, otherImportStatements) {
|
||||||
if (testImportStatements(QStringList(firstWorkingImportStatement) << importStatement, enableErrorOutput))
|
if (testImportStatements(QStringList(firstWorkingImportStatement) <<
|
||||||
|
importStatement, fileUrl(), enableErrorOutput)) {
|
||||||
workingImportStatementList.append(importStatement);
|
workingImportStatementList.append(importStatement);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
workingImportStatementList.prepend(firstWorkingImportStatement);
|
workingImportStatementList.prepend(firstWorkingImportStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +425,7 @@ void NodeInstanceServer::setupImports(const QVector<AddImportContainer> &contain
|
|||||||
|
|
||||||
void NodeInstanceServer::setupOnlyWorkingImports(const QStringList &workingImportStatementList)
|
void NodeInstanceServer::setupOnlyWorkingImports(const QStringList &workingImportStatementList)
|
||||||
{
|
{
|
||||||
QByteArray componentCode = workingImportStatementList.join("\n").toUtf8();
|
QByteArray componentCode = workingImportStatementList.join("\n").toUtf8().append("\n");
|
||||||
m_importCode = componentCode;
|
m_importCode = componentCode;
|
||||||
|
|
||||||
m_importComponent = new QQmlComponent(engine(), quickView());
|
m_importComponent = new QQmlComponent(engine(), quickView());
|
||||||
@@ -461,7 +462,8 @@ void NodeInstanceServer::setupDummyData(const QUrl &fileUrl)
|
|||||||
void NodeInstanceServer::setupDefaultDummyData()
|
void NodeInstanceServer::setupDefaultDummyData()
|
||||||
{
|
{
|
||||||
QQmlComponent component(engine());
|
QQmlComponent component(engine());
|
||||||
QByteArray defaultContextObjectArray("import QmlDesigner 1.0\n"
|
QByteArray defaultContextObjectArray("import QtQml 2.0\n"
|
||||||
|
"import QmlDesigner 1.0\n"
|
||||||
"DummyContextObject {\n"
|
"DummyContextObject {\n"
|
||||||
" parent: QtObject {\n"
|
" parent: QtObject {\n"
|
||||||
" property real width: 360\n"
|
" property real width: 360\n"
|
||||||
|
Reference in New Issue
Block a user