From b56de3d8beec853ef09c09ca9cbf8b1549cf0dbe Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 21 Oct 2022 15:18:38 +0200 Subject: [PATCH] QmlDesigner: Reset possible imports explicitly We do not reset/set the possible imports whenever we change the document anymore, since this became really slow. Instead we set those once per project, but we can reset them explicitly when required. The bundleimporter and assetimporter creates new imports, therefore we reset the possible imports. Change-Id: I112bd3c42f1c92f5314407883e86b4dedff45f75 Reviewed-by: Miikka Heikkinen Reviewed-by: Reviewed-by: Thomas Hartmann --- .../components/itemlibrary/itemlibraryassetimporter.cpp | 3 +++ .../components/materialbrowser/bundleimporter.cpp | 3 +++ src/plugins/qmldesigner/designercore/include/rewriterview.h | 3 +++ src/plugins/qmldesigner/designercore/model/rewriterview.cpp | 5 +++++ .../qmldesigner/designercore/model/texttomodelmerger.cpp | 5 +++++ .../qmldesigner/designercore/model/texttomodelmerger.h | 2 ++ 6 files changed, 21 insertions(+) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp index a18e3d43c79..5385c7c2021 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp @@ -692,6 +692,7 @@ void ItemLibraryAssetImporter::finalizeQuick3DImport() QTimer *timer = new QTimer(parent()); static int counter; counter = 0; + timer->callOnTimeout([this, timer, progressTitle, model, result]() { if (!isCancelled()) { notifyProgress(++counter, progressTitle); @@ -699,6 +700,8 @@ void ItemLibraryAssetImporter::finalizeQuick3DImport() if (result.isCanceled() || result.isFinished()) counter = 49; // skip to next step } else if (counter == 50) { + if (model && model->rewriterView()) + model->rewriterView()->resetPossibleImports(); model->rewriterView()->textModifier()->replace(0, 0, {}); } else if (counter < 100) { try { diff --git a/src/plugins/qmldesigner/components/materialbrowser/bundleimporter.cpp b/src/plugins/qmldesigner/components/materialbrowser/bundleimporter.cpp index 2a31fa8885f..22c9df2b918 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/bundleimporter.cpp +++ b/src/plugins/qmldesigner/components/materialbrowser/bundleimporter.cpp @@ -205,6 +205,9 @@ void BundleImporter::handleImportTimer() return; } + if (model && model->rewriterView()) + model->rewriterView()->resetPossibleImports(); + if (m_importAddPending) { try { Import import = Import::createLibraryImport(m_moduleName, "1.0"); diff --git a/src/plugins/qmldesigner/designercore/include/rewriterview.h b/src/plugins/qmldesigner/designercore/include/rewriterview.h index d9da1301768..9671cd23b43 100644 --- a/src/plugins/qmldesigner/designercore/include/rewriterview.h +++ b/src/plugins/qmldesigner/designercore/include/rewriterview.h @@ -162,6 +162,9 @@ public: void setAllowComponentRoot(bool allow); bool allowComponentRoot() const; + + void resetPossibleImports(); + signals: void modelInterfaceProjectUpdated(); diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index 3ed0ec01e7d..1a09a070fd3 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -688,6 +688,11 @@ bool RewriterView::allowComponentRoot() const return m_allowComponentRoot; } +void RewriterView::resetPossibleImports() +{ + m_textToModelMerger->clearPossibleImportKeys(); +} + Internal::ModelNodePositionStorage *RewriterView::positionStorage() const { return m_positionStorage.data(); diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index eaf74c2e125..3c135e103e4 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -2452,6 +2452,11 @@ QList TextToModelMerger::getQMLSingletons() const return list; } +void TextToModelMerger::clearPossibleImportKeys() +{ + m_possibleImportKeys.clear(); +} + QString TextToModelMerger::textAt(const Document::Ptr &doc, const SourceLocation &location) { diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.h b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.h index e9e892ef194..cd3b7affbe2 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.h +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.h @@ -119,6 +119,8 @@ public: QList getQMLSingletons() const; + void clearPossibleImportKeys(); + private: void setupCustomParserNode(const ModelNode &node); void setupComponent(const ModelNode &node);