forked from qt-creator/qt-creator
QmlDesigner: Search for material bundle folder near executable
Fixes: QDS-7717 Change-Id: I33405d0be6d55550d79fc371c6d82760ec6fa5b3 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "bundlematerialcategory.h"
|
#include "bundlematerialcategory.h"
|
||||||
#include "utils/qtcassert.h"
|
#include "utils/qtcassert.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
@@ -82,15 +83,24 @@ QHash<int, QByteArray> MaterialBrowserBundleModel::roleNames() const
|
|||||||
|
|
||||||
void MaterialBrowserBundleModel::loadMaterialBundle()
|
void MaterialBrowserBundleModel::loadMaterialBundle()
|
||||||
{
|
{
|
||||||
if (m_matBundleExists)
|
if (m_matBundleExists || m_probeMatBundleDir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString bundlePath = qEnvironmentVariable("MATERIAL_BUNDLE_PATH");
|
QDir matBundleDir(qEnvironmentVariable("MATERIAL_BUNDLE_PATH"));
|
||||||
|
|
||||||
if (bundlePath.isEmpty())
|
// search for matBundleDir from exec dir and up
|
||||||
return;
|
if (matBundleDir.dirName() == ".") {
|
||||||
|
m_probeMatBundleDir = true; // probe only once
|
||||||
|
|
||||||
QString matBundlePath = bundlePath + "material_bundle.json";
|
matBundleDir.setPath(QCoreApplication::applicationDirPath());
|
||||||
|
while (!matBundleDir.cd("material_bundle") && matBundleDir.cdUp())
|
||||||
|
; // do nothing
|
||||||
|
|
||||||
|
if (matBundleDir.dirName() != "material_bundle") // bundlePathDir not found
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString matBundlePath = matBundleDir.filePath("material_bundle.json");
|
||||||
|
|
||||||
if (m_matBundleObj.isEmpty()) {
|
if (m_matBundleObj.isEmpty()) {
|
||||||
QFile matPropsFile(matBundlePath);
|
QFile matPropsFile(matBundlePath);
|
||||||
@@ -127,7 +137,7 @@ void MaterialBrowserBundleModel::loadMaterialBundle()
|
|||||||
files.append(asset.toString());
|
files.append(asset.toString());
|
||||||
|
|
||||||
auto bundleMat = new BundleMaterial(category, mat, matObj.value("qml").toString(),
|
auto bundleMat = new BundleMaterial(category, mat, matObj.value("qml").toString(),
|
||||||
QUrl::fromLocalFile(bundlePath + matObj.value("icon").toString()), files);
|
QUrl::fromLocalFile(matBundleDir.filePath(matObj.value("icon").toString())), files);
|
||||||
|
|
||||||
category->addBundleMaterial(bundleMat);
|
category->addBundleMaterial(bundleMat);
|
||||||
}
|
}
|
||||||
@@ -139,7 +149,7 @@ void MaterialBrowserBundleModel::loadMaterialBundle()
|
|||||||
for (const QJsonValueRef &file : sharedFilesArr)
|
for (const QJsonValueRef &file : sharedFilesArr)
|
||||||
sharedFiles.append(file.toString());
|
sharedFiles.append(file.toString());
|
||||||
|
|
||||||
m_importer = new Internal::BundleImporter(bundlePath, "MaterialBundle", sharedFiles);
|
m_importer = new Internal::BundleImporter(matBundleDir.path(), "MaterialBundle", sharedFiles);
|
||||||
connect(m_importer, &Internal::BundleImporter::importFinished, this, [&](const QmlDesigner::NodeMetaInfo &metaInfo) {
|
connect(m_importer, &Internal::BundleImporter::importFinished, this, [&](const QmlDesigner::NodeMetaInfo &metaInfo) {
|
||||||
if (metaInfo.isValid())
|
if (metaInfo.isValid())
|
||||||
emit addBundleMaterialToProjectRequested(metaInfo);
|
emit addBundleMaterialToProjectRequested(metaInfo);
|
||||||
|
@@ -92,6 +92,7 @@ private:
|
|||||||
bool m_hasQuick3DImport = false;
|
bool m_hasQuick3DImport = false;
|
||||||
bool m_hasMaterialRoot = false;
|
bool m_hasMaterialRoot = false;
|
||||||
bool m_matBundleExists = false;
|
bool m_matBundleExists = false;
|
||||||
|
bool m_probeMatBundleDir = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user