forked from qt-creator/qt-creator
QmlDesigner: Fix old and new project structures discrepancies
Force reload bundles when generated folder changes between projects launches. Fixes: QDS-12899 Fixes: QDS-12902 Change-Id: I61b2729309cf2b853441358379ac5a569a3af886 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -93,11 +93,9 @@ QHash<int, QByteArray> 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();
|
||||
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
void loadBundle();
|
||||
void loadBundle(bool force = false);
|
||||
void setSearchText(const QString &searchText);
|
||||
void updateImportedState(const QStringList &importedItems);
|
||||
|
||||
|
@@ -234,10 +234,10 @@ QJsonObject &ContentLibraryUserModel::bundleObjectRef(const QString &bundleId)
|
||||
return qobject_cast<UserItemCategory *>(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();
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -101,6 +101,7 @@ private:
|
||||
qint32 m_sceneId = -1;
|
||||
CreateTexture m_createTexture;
|
||||
Utils::FilePath m_iconSavePath;
|
||||
QString m_generatedFolderName;
|
||||
std::unique_ptr<ZipWriter> m_zipWriter;
|
||||
std::unique_ptr<QTemporaryDir> m_tempDir;
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user