QmlDesigner: Fix used imports not working correctly

The existing logic (in qmljsinterpreter.cpp) for updating used imports doesn't work correctly. It takes into consideration items that are not
part of the currently open document. Fixed by checking current model
items in the document and updating used imports based on it.

Fixes: QDS-3785
Change-Id: Ia50c3c7e7ca41b9bca0d69e7c2e253f29892933e
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2021-03-31 18:47:14 +03:00
parent 719dc7ed89
commit 392c466b20
2 changed files with 15 additions and 5 deletions

View File

@@ -212,6 +212,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
QString projectName = project ? project->displayName() : "";
// create import sections
const QList<Import> usedImports = model->usedImports();
QHash<QString, ItemLibraryImport *> importHash;
for (const Import &import : model->imports()) {
if (import.url() != projectName) {
@@ -239,6 +240,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
auto sectionType = isQuick3DAsset ? ItemLibraryImport::SectionType::Quick3DAssets
: ItemLibraryImport::SectionType::Default;
ItemLibraryImport *itemLibImport = new ItemLibraryImport(import, this, sectionType);
itemLibImport->setImportUsed(usedImports.contains(import));
importHash.insert(importUrl, itemLibImport);
}
}