Commit 4dcc0c2a authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.qmlModelView: fixes adding imports

We use requiredImport() and only add an import if it does
not exists before (even with alias).
parent 9f9bdd72
...@@ -173,22 +173,26 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE ...@@ -173,22 +173,26 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
try { try {
RewriterTransaction transaction = beginRewriterTransaction(); RewriterTransaction transaction = beginRewriterTransaction();
if (itemLibraryEntry.typeName().contains('.')) { if (itemLibraryEntry.typeName().contains('.')) {
const QString newImportUrl = itemLibraryEntry.typeName().split('.').first();
const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion())); const QString newImportUrl = itemLibraryEntry.requiredImport();
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
if (!itemLibraryEntry.requiredImport().isEmpty()) {
foreach (const Import &import, model()->imports()) { const QString newImportVersion = QString("%1.%2").arg(QString::number(itemLibraryEntry.majorVersion()), QString::number(itemLibraryEntry.minorVersion()));
if (import.isLibraryImport() Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
&& import.url() == newImport.url()
&& import.version() == newImport.version()) { foreach (const Import &import, model()->imports()) {
// reuse this import if (import.isLibraryImport()
newImport = import; && import.url() == newImport.url()
break; && import.version() == newImport.version()) {
// reuse this import
newImport = import;
break;
}
} }
}
if (!model()->imports().contains(newImport)) { if (!model()->hasImport(newImport, true)) {
model()->changeImports(QList<Import>() << newImport, QList<Import>()); model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment