forked from qt-creator/qt-creator
QmlDesigner: Reload bundles when id change
i.e. when opening a project that has a different import folder style from the currently open project. Fixes: QDS-12639 Change-Id: I8d341c38ec771dc5e28c4436cd9ad191e27c38a8 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -95,9 +95,21 @@ QHash<int, QByteArray> ContentLibraryEffectsModel::roleNames() const
|
|||||||
|
|
||||||
void ContentLibraryEffectsModel::loadBundle()
|
void ContentLibraryEffectsModel::loadBundle()
|
||||||
{
|
{
|
||||||
if (m_bundleExists || m_probeBundleDir)
|
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
||||||
|
|
||||||
|
if (m_probeBundleDir || (m_bundleExists && m_bundleId == compUtils.effectsBundleId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
qDeleteAll(m_bundleCategories);
|
||||||
|
m_bundleCategories.clear();
|
||||||
|
m_bundleExists = false;
|
||||||
|
m_isEmpty = true;
|
||||||
|
m_probeBundleDir = false;
|
||||||
|
m_bundleObj = {};
|
||||||
|
m_bundleId.clear();
|
||||||
|
m_bundlePath.clear();
|
||||||
|
|
||||||
QDir bundleDir;
|
QDir bundleDir;
|
||||||
|
|
||||||
if (!qEnvironmentVariable("EFFECT_BUNDLE_PATH").isEmpty())
|
if (!qEnvironmentVariable("EFFECT_BUNDLE_PATH").isEmpty())
|
||||||
@@ -112,30 +124,30 @@ void ContentLibraryEffectsModel::loadBundle()
|
|||||||
while (!bundleDir.cd("effect_bundle") && bundleDir.cdUp())
|
while (!bundleDir.cd("effect_bundle") && bundleDir.cdUp())
|
||||||
; // do nothing
|
; // do nothing
|
||||||
|
|
||||||
if (bundleDir.dirName() != "effect_bundle") // bundlePathDir not found
|
if (bundleDir.dirName() != "effect_bundle") { // bundlePathDir not found
|
||||||
|
resetModel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString bundlePath = bundleDir.filePath("effect_bundle.json");
|
QString bundlePath = bundleDir.filePath("effect_bundle.json");
|
||||||
|
|
||||||
if (m_bundleObj.isEmpty()) {
|
QFile bundleFile(bundlePath);
|
||||||
QFile propsFile(bundlePath);
|
if (!bundleFile.open(QIODevice::ReadOnly)) {
|
||||||
|
|
||||||
if (!propsFile.open(QIODevice::ReadOnly)) {
|
|
||||||
qWarning("Couldn't open effect_bundle.json");
|
qWarning("Couldn't open effect_bundle.json");
|
||||||
|
resetModel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(propsFile.readAll());
|
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(bundleFile.readAll());
|
||||||
if (bundleJsonDoc.isNull()) {
|
if (bundleJsonDoc.isNull()) {
|
||||||
qWarning("Invalid effect_bundle.json file");
|
qWarning("Invalid effect_bundle.json file");
|
||||||
|
resetModel();
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
m_bundleObj = bundleJsonDoc.object();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
m_bundleObj = bundleJsonDoc.object();
|
||||||
|
|
||||||
QString bundleType = compUtils.effectsBundleType();
|
QString bundleType = compUtils.effectsBundleType();
|
||||||
m_bundleId = compUtils.effectsBundleId();
|
m_bundleId = compUtils.effectsBundleId();
|
||||||
|
|
||||||
@@ -145,9 +157,9 @@ void ContentLibraryEffectsModel::loadBundle()
|
|||||||
auto category = new ContentLibraryEffectsCategory(this, cat);
|
auto category = new ContentLibraryEffectsCategory(this, cat);
|
||||||
|
|
||||||
const QJsonObject itemsObj = catsObj.value(cat).toObject();
|
const QJsonObject itemsObj = catsObj.value(cat).toObject();
|
||||||
const QStringList items = itemsObj.keys();
|
const QStringList itemsNames = itemsObj.keys();
|
||||||
for (const QString &item : items) {
|
for (const QString &itemName : itemsNames) {
|
||||||
const QJsonObject itemObj = itemsObj.value(item).toObject();
|
const QJsonObject itemObj = itemsObj.value(itemName).toObject();
|
||||||
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
const QJsonArray assetsArr = itemObj.value("files").toArray();
|
const QJsonArray assetsArr = itemObj.value("files").toArray();
|
||||||
@@ -159,7 +171,7 @@ void ContentLibraryEffectsModel::loadBundle()
|
|||||||
TypeName type = QLatin1String("%1.%2")
|
TypeName type = QLatin1String("%1.%2")
|
||||||
.arg(bundleType, qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
.arg(bundleType, qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
||||||
|
|
||||||
auto bundleItem = new ContentLibraryEffect(category, item, qml, type, icon, files);
|
auto bundleItem = new ContentLibraryEffect(category, itemName, qml, type, icon, files);
|
||||||
|
|
||||||
category->addBundleItem(bundleItem);
|
category->addBundleItem(bundleItem);
|
||||||
}
|
}
|
||||||
@@ -171,11 +183,10 @@ void ContentLibraryEffectsModel::loadBundle()
|
|||||||
for (const QJsonValueConstRef &file : sharedFilesArr)
|
for (const QJsonValueConstRef &file : sharedFilesArr)
|
||||||
m_bundleSharedFiles.append(file.toString());
|
m_bundleSharedFiles.append(file.toString());
|
||||||
|
|
||||||
resetModel();
|
|
||||||
updateIsEmpty();
|
|
||||||
m_bundlePath = bundleDir.path();
|
m_bundlePath = bundleDir.path();
|
||||||
m_bundleExists = true;
|
m_bundleExists = true;
|
||||||
emit bundleExistsChanged();
|
updateIsEmpty();
|
||||||
|
resetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentLibraryEffectsModel::hasRequiredQuick3DImport() const
|
bool ContentLibraryEffectsModel::hasRequiredQuick3DImport() const
|
||||||
|
|||||||
@@ -212,35 +212,43 @@ QString ContentLibraryMaterialsModel::bundleId() const
|
|||||||
return m_bundleId;
|
return m_bundleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &bundleDir)
|
||||||
{
|
{
|
||||||
if (m_matBundleExists)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString matBundlePath = matBundleDir.filePath("material_bundle.json");
|
|
||||||
|
|
||||||
if (m_matBundleObj.isEmpty()) {
|
|
||||||
QFile matPropsFile(matBundlePath);
|
|
||||||
|
|
||||||
if (!matPropsFile.open(QIODevice::ReadOnly)) {
|
|
||||||
qWarning("Couldn't open material_bundle.json");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonDocument matBundleJsonDoc = QJsonDocument::fromJson(matPropsFile.readAll());
|
|
||||||
if (matBundleJsonDoc.isNull()) {
|
|
||||||
qWarning("Invalid material_bundle.json file");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
m_matBundleObj = matBundleJsonDoc.object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
||||||
|
|
||||||
|
if (m_bundleExists && m_bundleId == compUtils.materialsBundleId())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
qDeleteAll(m_bundleCategories);
|
||||||
|
m_bundleCategories.clear();
|
||||||
|
m_bundleExists = false;
|
||||||
|
m_isEmpty = true;
|
||||||
|
m_bundleObj = {};
|
||||||
|
m_bundleId.clear();
|
||||||
|
|
||||||
|
QString bundlePath = bundleDir.filePath("material_bundle.json");
|
||||||
|
|
||||||
|
QFile bundleFile(bundlePath);
|
||||||
|
if (!bundleFile.open(QIODevice::ReadOnly)) {
|
||||||
|
qWarning("Couldn't open material_bundle.json");
|
||||||
|
resetModel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument bundleJsonDoc = QJsonDocument::fromJson(bundleFile.readAll());
|
||||||
|
if (bundleJsonDoc.isNull()) {
|
||||||
|
qWarning("Invalid material_bundle.json file");
|
||||||
|
resetModel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_bundleObj = bundleJsonDoc.object();
|
||||||
|
|
||||||
QString bundleType = compUtils.materialsBundleType();
|
QString bundleType = compUtils.materialsBundleType();
|
||||||
m_bundleId = compUtils.materialsBundleId();
|
m_bundleId = compUtils.materialsBundleId();
|
||||||
|
|
||||||
const QJsonObject catsObj = m_matBundleObj.value("categories").toObject();
|
const QJsonObject catsObj = m_bundleObj.value("categories").toObject();
|
||||||
const QStringList categories = catsObj.keys();
|
const QStringList categories = catsObj.keys();
|
||||||
for (const QString &cat : categories) {
|
for (const QString &cat : categories) {
|
||||||
auto category = new ContentLibraryMaterialsCategory(this, cat);
|
auto category = new ContentLibraryMaterialsCategory(this, cat);
|
||||||
@@ -255,7 +263,7 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
|||||||
for (const QJsonValueConstRef &asset : assetsArr)
|
for (const QJsonValueConstRef &asset : assetsArr)
|
||||||
files.append(asset.toString());
|
files.append(asset.toString());
|
||||||
|
|
||||||
QUrl icon = QUrl::fromLocalFile(matBundleDir.filePath(matObj.value("icon").toString()));
|
QUrl icon = QUrl::fromLocalFile(bundleDir.filePath(matObj.value("icon").toString()));
|
||||||
QString qml = matObj.value("qml").toString();
|
QString qml = matObj.value("qml").toString();
|
||||||
TypeName type = QLatin1String("%1.%2")
|
TypeName type = QLatin1String("%1.%2")
|
||||||
.arg(bundleType, qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
.arg(bundleType, qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
||||||
@@ -269,23 +277,22 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_bundleSharedFiles.clear();
|
m_bundleSharedFiles.clear();
|
||||||
const QJsonArray sharedFilesArr = m_matBundleObj.value("sharedFiles").toArray();
|
const QJsonArray sharedFilesArr = m_bundleObj.value("sharedFiles").toArray();
|
||||||
for (const QJsonValueConstRef &file : sharedFilesArr)
|
for (const QJsonValueConstRef &file : sharedFilesArr)
|
||||||
m_bundleSharedFiles.append(file.toString());
|
m_bundleSharedFiles.append(file.toString());
|
||||||
|
|
||||||
QStringList missingSharedFiles;
|
QStringList missingSharedFiles;
|
||||||
for (const QString &s : std::as_const(m_bundleSharedFiles)) {
|
for (const QString &s : std::as_const(m_bundleSharedFiles)) {
|
||||||
if (!QFileInfo::exists(matBundleDir.filePath(s)))
|
if (!QFileInfo::exists(bundleDir.filePath(s)))
|
||||||
missingSharedFiles.push_back(s);
|
missingSharedFiles.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missingSharedFiles.length() > 0)
|
if (missingSharedFiles.length() > 0)
|
||||||
downloadSharedFiles(matBundleDir, missingSharedFiles);
|
downloadSharedFiles(bundleDir, missingSharedFiles);
|
||||||
|
|
||||||
resetModel();
|
m_bundleExists = true;
|
||||||
updateIsEmpty();
|
updateIsEmpty();
|
||||||
m_matBundleExists = true;
|
resetModel();
|
||||||
emit matBundleExistsChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
|
bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
|
||||||
@@ -295,7 +302,7 @@ bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
|
|||||||
|
|
||||||
bool ContentLibraryMaterialsModel::matBundleExists() const
|
bool ContentLibraryMaterialsModel::matBundleExists() const
|
||||||
{
|
{
|
||||||
return m_matBundleExists;
|
return m_bundleExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryMaterialsModel::setSearchText(const QString &searchText)
|
void ContentLibraryMaterialsModel::setSearchText(const QString &searchText)
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ private:
|
|||||||
QString m_bundleId;
|
QString m_bundleId;
|
||||||
QStringList m_bundleSharedFiles;
|
QStringList m_bundleSharedFiles;
|
||||||
QList<ContentLibraryMaterialsCategory *> m_bundleCategories;
|
QList<ContentLibraryMaterialsCategory *> m_bundleCategories;
|
||||||
QJsonObject m_matBundleObj;
|
QJsonObject m_bundleObj;
|
||||||
|
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
bool m_matBundleExists = false;
|
bool m_bundleExists = false;
|
||||||
bool m_hasModelSelection = false;
|
bool m_hasModelSelection = false;
|
||||||
|
|
||||||
int m_quick3dMajorVersion = -1;
|
int m_quick3dMajorVersion = -1;
|
||||||
|
|||||||
@@ -226,13 +226,24 @@ QJsonObject &ContentLibraryUserModel::bundleJsonObjectRef()
|
|||||||
|
|
||||||
void ContentLibraryUserModel::loadMaterialBundle()
|
void ContentLibraryUserModel::loadMaterialBundle()
|
||||||
{
|
{
|
||||||
if (m_matBundleExists)
|
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
||||||
|
|
||||||
|
if (m_matBundleExists && m_bundleIdMaterial == compUtils.userMaterialsBundleId())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
qDeleteAll(m_userMaterials);
|
||||||
|
m_userMaterials.clear();
|
||||||
|
m_matBundleExists = false;
|
||||||
|
m_isEmpty = true;
|
||||||
|
m_bundleObj = {};
|
||||||
|
m_bundleIdMaterial.clear();
|
||||||
|
|
||||||
|
int matSectionIdx = 0;
|
||||||
|
|
||||||
QDir bundleDir{Paths::bundlesPathSetting() + "/User/materials"};
|
QDir bundleDir{Paths::bundlesPathSetting() + "/User/materials"};
|
||||||
bundleDir.mkpath(".");
|
bundleDir.mkpath(".");
|
||||||
|
|
||||||
if (m_bundleObj.isEmpty()) {
|
|
||||||
auto jsonFilePath = Utils::FilePath::fromString(bundleDir.filePath("user_materials_bundle.json"));
|
auto jsonFilePath = Utils::FilePath::fromString(bundleDir.filePath("user_materials_bundle.json"));
|
||||||
if (!jsonFilePath.exists()) {
|
if (!jsonFilePath.exists()) {
|
||||||
QString jsonContent = "{\n";
|
QString jsonContent = "{\n";
|
||||||
@@ -246,19 +257,18 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
QFile jsonFile(jsonFilePath.path());
|
QFile jsonFile(jsonFilePath.path());
|
||||||
if (!jsonFile.open(QIODevice::ReadOnly)) {
|
if (!jsonFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning("Couldn't open user_materials_bundle.json");
|
qWarning("Couldn't open user_materials_bundle.json");
|
||||||
|
emit dataChanged(index(matSectionIdx), index(matSectionIdx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument matBundleJsonDoc = QJsonDocument::fromJson(jsonFile.readAll());
|
QJsonDocument matBundleJsonDoc = QJsonDocument::fromJson(jsonFile.readAll());
|
||||||
if (matBundleJsonDoc.isNull()) {
|
if (matBundleJsonDoc.isNull()) {
|
||||||
qWarning("Invalid user_materials_bundle.json file");
|
qWarning("Invalid user_materials_bundle.json file");
|
||||||
|
emit dataChanged(index(matSectionIdx), index(matSectionIdx));
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
m_bundleObj = matBundleJsonDoc.object();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto compUtils = QmlDesignerPlugin::instance()->documentManager().generatedComponentUtils();
|
m_bundleObj = matBundleJsonDoc.object();
|
||||||
m_bundleObj["id"] = compUtils.userMaterialsBundleId();
|
m_bundleObj["id"] = compUtils.userMaterialsBundleId();
|
||||||
|
|
||||||
// parse materials
|
// parse materials
|
||||||
@@ -290,6 +300,7 @@ void ContentLibraryUserModel::loadMaterialBundle()
|
|||||||
|
|
||||||
m_matBundleExists = true;
|
m_matBundleExists = true;
|
||||||
emit matBundleExistsChanged();
|
emit matBundleExistsChanged();
|
||||||
|
emit dataChanged(index(matSectionIdx), index(matSectionIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLibraryUserModel::loadTextureBundle()
|
void ContentLibraryUserModel::loadTextureBundle()
|
||||||
|
|||||||
Reference in New Issue
Block a user