diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp index ac4a75a293d..d9f8bd4950d 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.cpp @@ -93,11 +93,9 @@ QHash ContentLibraryEffectsModel::roleNames() const return roles; } -void ContentLibraryEffectsModel::loadBundle() +void ContentLibraryEffectsModel::loadBundle(bool force) { - auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); - - if (m_probeBundleDir || (m_bundleExists && m_bundleId == compUtils.effectsBundleId())) + if (m_probeBundleDir && !force) return; // clean up @@ -148,6 +146,7 @@ void ContentLibraryEffectsModel::loadBundle() m_bundleObj = bundleJsonDoc.object(); + auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); QString bundleType = compUtils.effectsBundleType(); m_bundleId = compUtils.effectsBundleId(); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h index 5bcb857fca5..2063668ba99 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryeffectsmodel.h @@ -28,7 +28,7 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role) override; QHash roleNames() const override; - void loadBundle(); + void loadBundle(bool force = false); void setSearchText(const QString &searchText); void updateImportedState(const QStringList &importedItems); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp index 996429dc00f..6a888bec3d4 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.cpp @@ -234,10 +234,10 @@ QJsonObject &ContentLibraryUserModel::bundleObjectRef(const QString &bundleId) return qobject_cast(m_userCategories[secIdx])->bundleObjRef(); } -void ContentLibraryUserModel::loadBundles() +void ContentLibraryUserModel::loadBundles(bool force) { for (UserCategory *cat : std::as_const(m_userCategories)) - cat->loadBundle(); + cat->loadBundle(force); resetModel(); updateIsEmpty(); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h index 2c85a735820..ca42f8233b6 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryusermodel.h @@ -57,7 +57,7 @@ public: void setBundleObj(const QJsonObject &newBundleObj); QJsonObject &bundleObjectRef(const QString &bundleId); - void loadBundles(); + void loadBundles(bool force = false); Q_INVOKABLE void applyToSelected(QmlDesigner::ContentLibraryItem *mat, bool add = false); Q_INVOKABLE void addToProject(ContentLibraryItem *item); diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp index 6c90a565c12..ddfdaaab241 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp @@ -266,15 +266,20 @@ void ContentLibraryView::modelAttached(Model *model) // bundles loading has to happen here, otherwise project path is not ready which will // cause bundle items types to resolve incorrectly - m_widget->materialsModel()->loadBundle(); - m_widget->effectsModel()->loadBundle(); - m_widget->userModel()->loadBundles(); - auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); + QString genFolderName = compUtils.generatedComponentsPath().fileName(); + bool forceReload = m_generatedFolderName != genFolderName; + + m_widget->materialsModel()->loadBundle(); + m_widget->effectsModel()->loadBundle(forceReload); + m_widget->userModel()->loadBundles(forceReload); + m_widget->updateImportedState(compUtils.materialsBundleId()); m_widget->updateImportedState(compUtils.effectsBundleId()); m_widget->updateImportedState(compUtils.userMaterialsBundleId()); m_widget->updateImportedState(compUtils.user3DBundleId()); + + m_generatedFolderName = genFolderName; } void ContentLibraryView::modelAboutToBeDetached(Model *model) diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h index b2418836d21..1b09d979959 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.h @@ -101,6 +101,7 @@ private: qint32 m_sceneId = -1; CreateTexture m_createTexture; Utils::FilePath m_iconSavePath; + QString m_generatedFolderName; std::unique_ptr m_zipWriter; std::unique_ptr m_tempDir; diff --git a/src/plugins/qmldesigner/components/contentlibrary/usercategory.h b/src/plugins/qmldesigner/components/contentlibrary/usercategory.h index 38421c293cb..40b5c6d76ea 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/usercategory.h +++ b/src/plugins/qmldesigner/components/contentlibrary/usercategory.h @@ -25,7 +25,7 @@ public: bool noMatch() const; void setNoMatch(bool val); - virtual void loadBundle() = 0; + virtual void loadBundle(bool force = false) = 0; virtual void filter(const QString &searchText) = 0; void addItem(QObject *item); diff --git a/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.cpp b/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.cpp index 40a467b8dd9..c6983a92525 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.cpp @@ -20,9 +20,9 @@ UserItemCategory::UserItemCategory(const QString &title, const Utils::FilePath & { } -void UserItemCategory::loadBundle() +void UserItemCategory::loadBundle(bool force) { - if (m_bundleLoaded) + if (m_bundleLoaded && !force) return; // clean up @@ -66,12 +66,11 @@ void UserItemCategory::loadBundle() return; } - auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); - m_bundleObj = bundleJsonDoc.object(); m_bundleObj["id"] = m_bundleId; // parse items + auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils(); QString typePrefix = compUtils.userBundleType(m_bundleId); const QJsonArray itemsArr = m_bundleObj.value("items").toArray(); for (const QJsonValueConstRef &itemRef : itemsArr) { diff --git a/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.h b/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.h index 1d55fc077a9..dceaee50810 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.h +++ b/src/plugins/qmldesigner/components/contentlibrary/useritemcategory.h @@ -18,7 +18,7 @@ class UserItemCategory : public UserCategory public: UserItemCategory(const QString &title, const Utils::FilePath &bundlePath, const QString &bundleId); - void loadBundle() override; + void loadBundle(bool force) override; void filter(const QString &searchText) override; QStringList sharedFiles() const; diff --git a/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.cpp b/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.cpp index 5c3e99069fc..22b9cf20aa3 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.cpp @@ -15,9 +15,9 @@ UserTextureCategory::UserTextureCategory(const QString &title, const Utils::File { } -void UserTextureCategory::loadBundle() +void UserTextureCategory::loadBundle(bool force) { - if (m_bundleLoaded) + if (m_bundleLoaded && !force) return; // clean up diff --git a/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.h b/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.h index 5e58f8f0059..511e2ea3f83 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.h +++ b/src/plugins/qmldesigner/components/contentlibrary/usertexturecategory.h @@ -16,7 +16,7 @@ class UserTextureCategory : public UserCategory public: UserTextureCategory(const QString &title, const Utils::FilePath &bundlePath); - void loadBundle() override; + void loadBundle(bool force) override; void filter(const QString &searchText) override; void addItems(const Utils::FilePaths &paths);