forked from qt-creator/qt-creator
QmlDesigner: Cleanups in the content library
Change-Id: I4bbb6f6d89c3e35a265624365eb61664280e9151 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -148,7 +148,7 @@ Item {
|
||||
visible: root.delegateVisible && root.downloadState != "downloading"
|
||||
cache: false
|
||||
|
||||
property string webUrl: modelData.textureWebUrl
|
||||
property string textureUrl: modelData.textureUrl
|
||||
|
||||
IconButton {
|
||||
id: downloadIcon
|
||||
@@ -279,7 +279,7 @@ Item {
|
||||
|
||||
FileDownloader {
|
||||
id: textureDownloader
|
||||
url: image.webUrl
|
||||
url: image.textureUrl
|
||||
probeUrl: false
|
||||
downloadEnabled: true
|
||||
onDownloadStarting: {
|
||||
@@ -333,7 +333,7 @@ Item {
|
||||
|
||||
FileDownloader {
|
||||
id: iconDownloader
|
||||
url: modelData.textureWebIconUrl
|
||||
url: modelData.textureIconUrl
|
||||
probeUrl: false
|
||||
downloadEnabled: true
|
||||
targetFilePath: modelData.textureIconPath
|
||||
|
||||
@@ -275,9 +275,9 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
||||
auto category = new ContentLibraryMaterialsCategory(this, cat);
|
||||
|
||||
const QJsonObject matsObj = catsObj.value(cat).toObject();
|
||||
const QStringList mats = matsObj.keys();
|
||||
for (const QString &mat : mats) {
|
||||
const QJsonObject matObj = matsObj.value(mat).toObject();
|
||||
const QStringList matsNames = matsObj.keys();
|
||||
for (const QString &matName : matsNames) {
|
||||
const QJsonObject matObj = matsObj.value(matName).toObject();
|
||||
|
||||
QStringList files;
|
||||
const QJsonArray assetsArr = matObj.value("files").toArray();
|
||||
@@ -292,7 +292,7 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
||||
bundleId,
|
||||
qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
||||
|
||||
auto bundleMat = new ContentLibraryMaterial(category, mat, qml, type, icon, files,
|
||||
auto bundleMat = new ContentLibraryMaterial(category, matName, qml, type, icon, files,
|
||||
m_downloadPath, m_baseUrl);
|
||||
|
||||
category->addBundleMaterial(bundleMat);
|
||||
|
||||
@@ -12,20 +12,19 @@
|
||||
namespace QmlDesigner {
|
||||
|
||||
ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo,
|
||||
const QString &downloadPath, const QUrl &icon,
|
||||
const QString &key, const QString &webTextureUrl,
|
||||
const QString &webIconUrl, const QString &fileExt,
|
||||
const QSize &dimensions, const qint64 sizeInBytes,
|
||||
bool hasUpdate, bool isNew)
|
||||
const QString &dirPath, const QString &key,
|
||||
const QString &textureUrl, const QString &iconUrl,
|
||||
const QString &suffix, const QSize &dimensions,
|
||||
const qint64 sizeInBytes, bool hasUpdate, bool isNew)
|
||||
: QObject(parent)
|
||||
, m_iconPath(iconFileInfo.filePath())
|
||||
, m_downloadPath(downloadPath)
|
||||
, m_webTextureUrl(webTextureUrl)
|
||||
, m_webIconUrl(webIconUrl)
|
||||
, m_dirPath(dirPath)
|
||||
, m_textureUrl(textureUrl)
|
||||
, m_iconUrl(iconUrl)
|
||||
, m_baseName{iconFileInfo.baseName()}
|
||||
, m_fileExt(fileExt)
|
||||
, m_suffix(suffix)
|
||||
, m_textureKey(key)
|
||||
, m_icon(icon)
|
||||
, m_icon(QUrl::fromLocalFile(iconFileInfo.absoluteFilePath()))
|
||||
, m_dimensions(dimensions)
|
||||
, m_sizeInBytes(sizeInBytes)
|
||||
, m_hasUpdate(hasUpdate)
|
||||
@@ -54,9 +53,9 @@ QString ContentLibraryTexture::iconPath() const
|
||||
return m_iconPath;
|
||||
}
|
||||
|
||||
QString ContentLibraryTexture::resolveFileExt()
|
||||
QString ContentLibraryTexture::resolveSuffix()
|
||||
{
|
||||
const QFileInfoList files = QDir(m_downloadPath).entryInfoList(QDir::Files);
|
||||
const QFileInfoList files = QDir(m_dirPath).entryInfoList(QDir::Files);
|
||||
const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) {
|
||||
return fi.baseName() == m_baseName;
|
||||
});
|
||||
@@ -76,22 +75,20 @@ QString ContentLibraryTexture::resolveFileExt()
|
||||
|
||||
QString ContentLibraryTexture::resolveToolTipText()
|
||||
{
|
||||
if (m_fileExt.isEmpty()) {
|
||||
// No supplied or resolved extension means we have just the icon and no other data
|
||||
return m_baseName;
|
||||
}
|
||||
if (m_suffix.isEmpty())
|
||||
return m_baseName; // empty suffix means we have just the icon and no other data
|
||||
|
||||
QString fileName = m_baseName + m_fileExt;
|
||||
QString fileName = m_baseName + m_suffix;
|
||||
QString imageInfo;
|
||||
|
||||
if (!m_isDownloaded && m_sizeInBytes > 0 && !m_dimensions.isNull()) {
|
||||
imageInfo = ImageUtils::imageInfo(m_dimensions, m_sizeInBytes);
|
||||
} else {
|
||||
QString fullDownloadPath = m_downloadPath + '/' + fileName;
|
||||
QString fullDownloadPath = m_dirPath + '/' + fileName;
|
||||
imageInfo = ImageUtils::imageInfo(fullDownloadPath);
|
||||
}
|
||||
|
||||
return QStringLiteral("%1\n%2").arg(fileName, imageInfo);
|
||||
return QString("%1\n%2").arg(fileName, imageInfo);
|
||||
}
|
||||
|
||||
bool ContentLibraryTexture::isDownloaded() const
|
||||
@@ -99,9 +96,9 @@ bool ContentLibraryTexture::isDownloaded() const
|
||||
return m_isDownloaded;
|
||||
}
|
||||
|
||||
QString ContentLibraryTexture::downloadedTexturePath() const
|
||||
QString ContentLibraryTexture::texturePath() const
|
||||
{
|
||||
return m_downloadPath + '/' + m_baseName + m_fileExt;
|
||||
return m_dirPath + '/' + m_baseName + m_suffix;
|
||||
}
|
||||
|
||||
void ContentLibraryTexture::setDownloaded()
|
||||
@@ -116,16 +113,16 @@ void ContentLibraryTexture::setDownloaded()
|
||||
|
||||
void ContentLibraryTexture::doSetDownloaded()
|
||||
{
|
||||
if (m_fileExt.isEmpty())
|
||||
m_fileExt = resolveFileExt();
|
||||
if (m_suffix.isEmpty())
|
||||
m_suffix = resolveSuffix();
|
||||
|
||||
m_isDownloaded = QFileInfo::exists(downloadedTexturePath());
|
||||
m_isDownloaded = QFileInfo::exists(texturePath());
|
||||
m_toolTip = resolveToolTipText();
|
||||
}
|
||||
|
||||
QString ContentLibraryTexture::parentDirPath() const
|
||||
{
|
||||
return m_downloadPath;
|
||||
return m_dirPath;
|
||||
}
|
||||
|
||||
QString ContentLibraryTexture::textureKey() const
|
||||
|
||||
@@ -19,17 +19,17 @@ class ContentLibraryTexture : public QObject
|
||||
Q_PROPERTY(QString textureToolTip MEMBER m_toolTip NOTIFY textureToolTipChanged)
|
||||
Q_PROPERTY(QUrl textureIcon MEMBER m_icon CONSTANT)
|
||||
Q_PROPERTY(bool textureVisible MEMBER m_visible NOTIFY textureVisibleChanged)
|
||||
Q_PROPERTY(QString textureWebUrl MEMBER m_webTextureUrl CONSTANT)
|
||||
Q_PROPERTY(QString textureWebIconUrl MEMBER m_webIconUrl CONSTANT)
|
||||
Q_PROPERTY(QString textureUrl MEMBER m_textureUrl CONSTANT)
|
||||
Q_PROPERTY(QString textureIconUrl MEMBER m_iconUrl CONSTANT)
|
||||
Q_PROPERTY(bool textureHasUpdate WRITE setHasUpdate READ hasUpdate NOTIFY hasUpdateChanged)
|
||||
Q_PROPERTY(bool textureIsNew MEMBER m_isNew CONSTANT)
|
||||
Q_PROPERTY(QString textureKey MEMBER m_textureKey CONSTANT)
|
||||
|
||||
public:
|
||||
ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, const QString &downloadPath,
|
||||
const QUrl &icon, const QString &key, const QString &webTextureUrl,
|
||||
const QString &webIconUrl, const QString &fileExt, const QSize &dimensions,
|
||||
const qint64 sizeInBytes, bool hasUpdate, bool isNew);
|
||||
ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, const QString &dirPath,
|
||||
const QString &key, const QString &textureUrl, const QString &iconUrl,
|
||||
const QString &suffix, const QSize &dimensions, const qint64 sizeInBytes,
|
||||
bool hasUpdate = false, bool isNew = false);
|
||||
|
||||
Q_INVOKABLE bool isDownloaded() const;
|
||||
Q_INVOKABLE void setDownloaded();
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
QUrl icon() const;
|
||||
QString iconPath() const;
|
||||
QString downloadedTexturePath() const;
|
||||
QString texturePath() const;
|
||||
QString parentDirPath() const;
|
||||
QString textureKey() const;
|
||||
|
||||
@@ -51,17 +51,17 @@ signals:
|
||||
void hasUpdateChanged();
|
||||
|
||||
private:
|
||||
QString resolveFileExt();
|
||||
QString resolveSuffix();
|
||||
QString resolveToolTipText();
|
||||
void doSetDownloaded();
|
||||
|
||||
QString m_iconPath;
|
||||
QString m_downloadPath;
|
||||
QString m_webTextureUrl;
|
||||
QString m_webIconUrl;
|
||||
QString m_dirPath;
|
||||
QString m_textureUrl;
|
||||
QString m_iconUrl;
|
||||
QString m_toolTip;
|
||||
QString m_baseName;
|
||||
QString m_fileExt;
|
||||
QString m_suffix;
|
||||
QString m_textureKey;
|
||||
QUrl m_icon;
|
||||
QSize m_dimensions;
|
||||
|
||||
@@ -14,17 +14,15 @@ namespace QmlDesigner {
|
||||
ContentLibraryTexturesCategory::ContentLibraryTexturesCategory(QObject *parent, const QString &name)
|
||||
: QObject(parent), m_name(name) {}
|
||||
|
||||
void ContentLibraryTexturesCategory::addTexture(const QFileInfo &tex, const QString &downloadPath,
|
||||
void ContentLibraryTexturesCategory::addTexture(const QFileInfo &texIcon, const QString &downloadPath,
|
||||
const QString &key, const QString &webTextureUrl,
|
||||
const QString &webIconUrl, const QString &fileExt,
|
||||
const QString &iconUrl, const QString &suffix,
|
||||
const QSize &dimensions, const qint64 sizeInBytes,
|
||||
bool hasUpdate, bool isNew)
|
||||
{
|
||||
QUrl icon = QUrl::fromLocalFile(tex.absoluteFilePath());
|
||||
|
||||
m_categoryTextures.append(new ContentLibraryTexture(
|
||||
this, tex, downloadPath, icon, key, webTextureUrl, webIconUrl,
|
||||
fileExt, dimensions, sizeInBytes, hasUpdate, isNew));
|
||||
this, texIcon, downloadPath, key, webTextureUrl, iconUrl,
|
||||
suffix, dimensions, sizeInBytes, hasUpdate, isNew));
|
||||
}
|
||||
|
||||
bool ContentLibraryTexturesCategory::filter(const QString &searchText)
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
ContentLibraryTexturesCategory(QObject *parent, const QString &name);
|
||||
|
||||
void addTexture(const QFileInfo &tex, const QString &subPath, const QString &key,
|
||||
const QString &webTextureUrl, const QString &webIconUrl, const QString &fileExt,
|
||||
const QString &webTextureUrl, const QString &iconUrl, const QString &suffix,
|
||||
const QSize &dimensions, const qint64 sizeInBytes, bool hasUpdate, bool isNew);
|
||||
bool filter(const QString &searchText);
|
||||
|
||||
|
||||
@@ -95,37 +95,37 @@ QHash<int, QByteArray> ContentLibraryTexturesModel::roleNames() const
|
||||
/**
|
||||
* @brief Load the bundle categorized icons. Actual textures are downloaded on demand
|
||||
*
|
||||
* @param bundlePath local path to the bundle folder and icons
|
||||
* @param metaData bundle textures metadata
|
||||
* @param textureBundleUrl remote url to the texture bundle
|
||||
* @param bundleIconPath local path to the texture bundle icons folder
|
||||
* @param jsonData bundle textures information from the bundle json
|
||||
*/
|
||||
void ContentLibraryTexturesModel::loadTextureBundle(const QString &remoteUrl, const QString &iconsUrl,
|
||||
void ContentLibraryTexturesModel::loadTextureBundle(const QString &textureBundleUrl,
|
||||
const QString &bundleIconPath,
|
||||
const QVariantMap &metaData)
|
||||
const QVariantMap &jsonData)
|
||||
{
|
||||
if (!m_bundleCategories.isEmpty())
|
||||
return;
|
||||
|
||||
QDir bundleDir = QString("%1/%2").arg(bundleIconPath, m_category);
|
||||
if (!bundleDir.exists()) {
|
||||
qWarning() << __FUNCTION__ << "textures bundle folder doesn't exist." << bundleDir.absolutePath();
|
||||
return;
|
||||
}
|
||||
QTC_ASSERT(bundleDir.exists(), return);
|
||||
|
||||
const QVariantMap imageItems = metaData.value("image_items").toMap();
|
||||
const QVariantMap imageItems = jsonData.value("image_items").toMap();
|
||||
|
||||
const QFileInfoList dirs = bundleDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (const QFileInfo &dir : dirs) {
|
||||
auto category = new ContentLibraryTexturesCategory(this, dir.fileName());
|
||||
const QFileInfoList texFiles = QDir(dir.filePath()).entryInfoList(QDir::Files);
|
||||
for (const QFileInfo &tex : texFiles) {
|
||||
QString textureUrl = QString("%1/%2/%3.zip").arg(remoteUrl, dir.fileName(), tex.baseName());
|
||||
QString iconUrl = QString("%1/%2/%3.png").arg(iconsUrl, dir.fileName(), tex.baseName());
|
||||
const QFileInfoList texIconFiles = QDir(dir.filePath()).entryInfoList(QDir::Files);
|
||||
for (const QFileInfo &texIcon : texIconFiles) {
|
||||
QString textureUrl = QString("%1/%2/%3/%4.zip").arg(textureBundleUrl, m_category,
|
||||
dir.fileName(), texIcon.baseName());
|
||||
QString iconUrl = QString("%1/icons/%2/%3/%4.png").arg(textureBundleUrl, m_category,
|
||||
dir.fileName(), texIcon.baseName());
|
||||
|
||||
QString localDownloadPath = QString("%1/%2/%3")
|
||||
QString texturePath = QString("%1/%2/%3")
|
||||
.arg(Paths::bundlesPathSetting(),
|
||||
m_category,
|
||||
dir.fileName());
|
||||
QString key = QString("%1/%2/%3").arg(m_category, dir.fileName(), tex.baseName());
|
||||
QString key = QString("%1/%2/%3").arg(m_category, dir.fileName(), texIcon.baseName());
|
||||
QString fileExt;
|
||||
QSize dimensions;
|
||||
qint64 sizeInBytes = -1;
|
||||
@@ -141,7 +141,7 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &remoteUrl, co
|
||||
isNew = m_newFiles.contains(key);
|
||||
}
|
||||
|
||||
category->addTexture(tex, localDownloadPath, key, textureUrl, iconUrl, fileExt,
|
||||
category->addTexture(texIcon, texturePath, key, textureUrl, iconUrl, fileExt,
|
||||
dimensions, sizeInBytes, hasUpdate, isNew);
|
||||
}
|
||||
m_bundleCategories.append(category);
|
||||
|
||||
@@ -37,8 +37,8 @@ public:
|
||||
void setHasSceneEnv(bool b);
|
||||
|
||||
void resetModel();
|
||||
void loadTextureBundle(const QString &remoteUrl, const QString &iconsUrl,
|
||||
const QString &bundlePath, const QVariantMap &metaData);
|
||||
void loadTextureBundle(const QString &m_textureBundleUrl, const QString &bundlePath,
|
||||
const QVariantMap &metaData);
|
||||
|
||||
signals:
|
||||
void isEmptyChanged();
|
||||
|
||||
@@ -101,10 +101,10 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
&& m_textureToDrag->isDownloaded()) {
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE,
|
||||
{m_textureToDrag->downloadedTexturePath().toUtf8()});
|
||||
{m_textureToDrag->texturePath().toUtf8()});
|
||||
|
||||
// Allows standard file drag-n-drop. As of now needed to drop on Assets view
|
||||
mimeData->setUrls({QUrl::fromLocalFile(m_textureToDrag->downloadedTexturePath())});
|
||||
mimeData->setUrls({QUrl::fromLocalFile(m_textureToDrag->texturePath())});
|
||||
|
||||
emit bundleTextureDragStarted(m_textureToDrag);
|
||||
model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile());
|
||||
@@ -142,18 +142,12 @@ ContentLibraryWidget::ContentLibraryWidget()
|
||||
m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
|
||||
m_quickWidget->setClearColor(Theme::getColor(Theme::Color::DSpanelBackground));
|
||||
|
||||
m_baseUrl = QmlDesignerPlugin::settings()
|
||||
.value(DesignerSettingsKey::DOWNLOADABLE_BUNDLES_URL).toString()
|
||||
+ "/textures";
|
||||
m_textureBundleUrl = QmlDesignerPlugin::settings()
|
||||
.value(DesignerSettingsKey::DOWNLOADABLE_BUNDLES_URL).toString() + "/textures";
|
||||
|
||||
m_texturesUrl = m_baseUrl + "/Textures";
|
||||
m_textureIconsUrl = m_baseUrl + "/icons/Textures";
|
||||
m_environmentIconsUrl = m_baseUrl + "/icons/Environments";
|
||||
m_environmentsUrl = m_baseUrl + "/Environments";
|
||||
m_bundlePath = Paths::bundlesPathSetting();
|
||||
|
||||
m_downloadPath = Paths::bundlesPathSetting();
|
||||
|
||||
loadTextureBundle();
|
||||
loadTextureBundles();
|
||||
|
||||
Theme::setupTheme(m_quickWidget->engine());
|
||||
m_quickWidget->quickWidget()->installEventFilter(this);
|
||||
@@ -185,33 +179,28 @@ ContentLibraryWidget::ContentLibraryWidget()
|
||||
reloadQmlSource();
|
||||
}
|
||||
|
||||
QVariantMap ContentLibraryWidget::readBundleMetadata()
|
||||
QVariantMap ContentLibraryWidget::readTextureBundleJson()
|
||||
{
|
||||
QVariantMap metaData;
|
||||
QFile jsonFile(m_downloadPath + "/texture_bundle.json");
|
||||
QVariantMap jsonData;
|
||||
QFile jsonFile(m_bundlePath + "/texture_bundle.json");
|
||||
if (jsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
metaData = QJsonDocument::fromJson(jsonFile.readAll()).toVariant().toMap();
|
||||
jsonData = QJsonDocument::fromJson(jsonFile.readAll()).toVariant().toMap();
|
||||
|
||||
int version = metaData["version"].toInt();
|
||||
int version = jsonData["version"].toInt();
|
||||
if (version > TextureBundleMetadataVersion) {
|
||||
qWarning() << "Unrecognized texture metadata file version: " << version;
|
||||
return {};
|
||||
}
|
||||
|
||||
return metaData;
|
||||
return jsonData;
|
||||
}
|
||||
|
||||
void ContentLibraryWidget::loadTextureBundle()
|
||||
void ContentLibraryWidget::loadTextureBundles()
|
||||
{
|
||||
QDir bundleDir{m_downloadPath};
|
||||
QDir bundleDir{m_bundlePath};
|
||||
|
||||
if (fetchTextureBundleMetadata(bundleDir) && fetchTextureBundleIcons(bundleDir)) {
|
||||
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons";
|
||||
QVariantMap metaData = readBundleMetadata();
|
||||
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath, metaData);
|
||||
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
|
||||
bundleIconPath, metaData);
|
||||
}
|
||||
if (fetchTextureBundleJson(bundleDir) && fetchTextureBundleIcons(bundleDir))
|
||||
populateTextureBundleModels();
|
||||
}
|
||||
|
||||
std::tuple<QVariantMap, QVariantMap, QVariantMap> ContentLibraryWidget::compareTextureMetaFiles(
|
||||
@@ -275,9 +264,9 @@ void ContentLibraryWidget::fetchNewTextureIcons(const QVariantMap &existingFiles
|
||||
});
|
||||
|
||||
auto multidownloader = new MultiFileDownloader(this);
|
||||
multidownloader->setBaseUrl(QString(m_baseUrl + "/icons"));
|
||||
multidownloader->setBaseUrl(QString(m_textureBundleUrl + "/icons"));
|
||||
multidownloader->setFiles(fileList);
|
||||
multidownloader->setTargetDirPath(m_downloadPath + "/TextureBundleIcons");
|
||||
multidownloader->setTargetDirPath(m_bundlePath + "/TextureBundleIcons");
|
||||
|
||||
auto downloader = new FileDownloader(this);
|
||||
downloader->setDownloadEnabled(true);
|
||||
@@ -317,15 +306,8 @@ void ContentLibraryWidget::fetchNewTextureIcons(const QVariantMap &existingFiles
|
||||
existingFile.flush();
|
||||
}
|
||||
|
||||
if (fetchTextureBundleIcons(bundleDir)) {
|
||||
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons";
|
||||
QVariantMap metaData = readBundleMetadata();
|
||||
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
|
||||
metaData);
|
||||
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
|
||||
bundleIconPath, metaData);
|
||||
}
|
||||
|
||||
if (fetchTextureBundleIcons(bundleDir))
|
||||
populateTextureBundleModels();
|
||||
});
|
||||
|
||||
multidownloader->start();
|
||||
@@ -436,50 +418,45 @@ QStringList ContentLibraryWidget::saveNewTextures(const QDir &bundleDir, const Q
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentLibraryWidget::fetchTextureBundleMetadata(const QDir &bundleDir)
|
||||
bool ContentLibraryWidget::fetchTextureBundleJson(const QDir &bundleDir)
|
||||
{
|
||||
QString filePath = bundleDir.filePath("texture_bundle.json");
|
||||
|
||||
QFileInfo fi(filePath);
|
||||
bool metaFileExists = fi.exists() && fi.size() > 0;
|
||||
bool jsonFileExists = fi.exists() && fi.size() > 0;
|
||||
|
||||
QString metaFileUrl = m_baseUrl + "/texture_bundle.zip";
|
||||
QString bundleZipUrl = m_textureBundleUrl + "/texture_bundle.zip";
|
||||
FileDownloader *downloader = new FileDownloader(this);
|
||||
downloader->setUrl(metaFileUrl);
|
||||
downloader->setUrl(bundleZipUrl);
|
||||
downloader->setProbeUrl(false);
|
||||
downloader->setDownloadEnabled(true);
|
||||
downloader->start();
|
||||
|
||||
QObject::connect(downloader, &FileDownloader::downloadFailed, this,
|
||||
[this, metaFileExists, bundleDir] {
|
||||
if (metaFileExists) {
|
||||
if (fetchTextureBundleIcons(bundleDir)) {
|
||||
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons";
|
||||
QVariantMap metaData = readBundleMetadata();
|
||||
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
|
||||
metaData);
|
||||
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
|
||||
bundleIconPath, metaData);
|
||||
}
|
||||
[this, jsonFileExists, bundleDir] {
|
||||
if (jsonFileExists) {
|
||||
if (fetchTextureBundleIcons(bundleDir))
|
||||
populateTextureBundleModels();
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(downloader, &FileDownloader::finishedChanged, this,
|
||||
[this, downloader, bundleDir, metaFileExists, filePath] {
|
||||
[this, downloader, bundleDir, jsonFileExists, filePath] {
|
||||
FileExtractor *extractor = new FileExtractor(this);
|
||||
extractor->setArchiveName(downloader->completeBaseName());
|
||||
extractor->setSourceFile(downloader->outputFile());
|
||||
if (!metaFileExists)
|
||||
if (!jsonFileExists)
|
||||
extractor->setTargetPath(bundleDir.absolutePath());
|
||||
|
||||
extractor->setAlwaysCreateDir(false);
|
||||
extractor->setClearTargetPathContents(false);
|
||||
|
||||
QObject::connect(extractor, &FileExtractor::finishedChanged, this,
|
||||
[this, downloader, bundleDir, extractor, metaFileExists, filePath] {
|
||||
[this, downloader, bundleDir, extractor, jsonFileExists, filePath] {
|
||||
downloader->deleteLater();
|
||||
extractor->deleteLater();
|
||||
|
||||
if (metaFileExists) {
|
||||
if (jsonFileExists) {
|
||||
QVariantMap newFiles, existing;
|
||||
QVariantMap modifiedFilesEntries;
|
||||
|
||||
@@ -501,32 +478,35 @@ bool ContentLibraryWidget::fetchTextureBundleMetadata(const QDir &bundleDir)
|
||||
}
|
||||
}
|
||||
|
||||
if (fetchTextureBundleIcons(bundleDir)) {
|
||||
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons";
|
||||
QVariantMap metaData = readBundleMetadata();
|
||||
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
|
||||
metaData);
|
||||
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
|
||||
bundleIconPath, metaData);
|
||||
}
|
||||
if (fetchTextureBundleIcons(bundleDir))
|
||||
populateTextureBundleModels();
|
||||
});
|
||||
|
||||
extractor->extract();
|
||||
});
|
||||
|
||||
downloader->start();
|
||||
return false;
|
||||
}
|
||||
|
||||
void ContentLibraryWidget::populateTextureBundleModels()
|
||||
{
|
||||
QVariantMap jsonData = readTextureBundleJson();
|
||||
|
||||
QString bundleIconPath = m_bundlePath + "/TextureBundleIcons";
|
||||
|
||||
m_texturesModel->loadTextureBundle(m_textureBundleUrl, bundleIconPath, jsonData);
|
||||
m_environmentsModel->loadTextureBundle(m_textureBundleUrl, bundleIconPath, jsonData);
|
||||
}
|
||||
|
||||
bool ContentLibraryWidget::fetchTextureBundleIcons(const QDir &bundleDir)
|
||||
{
|
||||
QString iconsPath = bundleDir.filePath("TextureBundleIcons");
|
||||
|
||||
QDir iconsDir(iconsPath);
|
||||
if (iconsDir.exists() && iconsDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot).length() > 0)
|
||||
if (iconsDir.exists() && !iconsDir.isEmpty())
|
||||
return true;
|
||||
|
||||
QString zipFileUrl = m_baseUrl + "/icons.zip";
|
||||
QString zipFileUrl = m_textureBundleUrl + "/icons.zip";
|
||||
|
||||
FileDownloader *downloader = new FileDownloader(this);
|
||||
downloader->setUrl(zipFileUrl);
|
||||
@@ -546,13 +526,7 @@ bool ContentLibraryWidget::fetchTextureBundleIcons(const QDir &bundleDir)
|
||||
[this, downloader, extractor] {
|
||||
downloader->deleteLater();
|
||||
extractor->deleteLater();
|
||||
|
||||
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons";
|
||||
QVariantMap metaData = readBundleMetadata();
|
||||
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
|
||||
metaData);
|
||||
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
|
||||
bundleIconPath, metaData);
|
||||
populateTextureBundleModels();
|
||||
});
|
||||
|
||||
extractor->extract();
|
||||
@@ -575,7 +549,7 @@ void ContentLibraryWidget::markTextureUpdated(const QString &textureKey)
|
||||
checksumOnServer = m_environmentsModel->removeModifiedFileEntry(textureKey);
|
||||
|
||||
QJsonObject metaDataObj;
|
||||
QFile jsonFile(m_downloadPath + "/texture_bundle.json");
|
||||
QFile jsonFile(m_bundlePath + "/texture_bundle.json");
|
||||
if (jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
metaDataObj = QJsonDocument::fromJson(jsonFile.readAll()).object();
|
||||
jsonFile.close();
|
||||
@@ -592,7 +566,7 @@ void ContentLibraryWidget::markTextureUpdated(const QString &textureKey)
|
||||
QJsonDocument outDoc(metaDataObj);
|
||||
QByteArray data = outDoc.toJson();
|
||||
|
||||
QFile outFile(m_downloadPath + "/texture_bundle.json");
|
||||
QFile outFile(m_bundlePath + "/texture_bundle.json");
|
||||
if (outFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text)) {
|
||||
outFile.write(data);
|
||||
outFile.flush();
|
||||
@@ -787,7 +761,7 @@ void ContentLibraryWidget::addImage(ContentLibraryTexture *tex)
|
||||
if (!tex->isDownloaded())
|
||||
return;
|
||||
|
||||
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::Image);
|
||||
emit addTextureRequested(tex->texturePath(), AddTextureMode::Image);
|
||||
}
|
||||
|
||||
void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex)
|
||||
@@ -795,7 +769,7 @@ void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex)
|
||||
if (!tex->isDownloaded())
|
||||
return;
|
||||
|
||||
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::Texture);
|
||||
emit addTextureRequested(tex->texturePath(), AddTextureMode::Texture);
|
||||
}
|
||||
|
||||
void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex)
|
||||
@@ -803,7 +777,7 @@ void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex)
|
||||
if (!tex->isDownloaded())
|
||||
return;
|
||||
|
||||
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::LightProbe);
|
||||
emit addTextureRequested(tex->texturePath(), AddTextureMode::LightProbe);
|
||||
}
|
||||
|
||||
void ContentLibraryWidget::updateSceneEnvState()
|
||||
|
||||
@@ -100,15 +100,16 @@ private:
|
||||
void updateSearch();
|
||||
void setIsDragging(bool val);
|
||||
QString findTextureBundlePath();
|
||||
void loadTextureBundle();
|
||||
QVariantMap readBundleMetadata();
|
||||
bool fetchTextureBundleMetadata(const QDir &bundleDir);
|
||||
void loadTextureBundles();
|
||||
QVariantMap readTextureBundleJson();
|
||||
bool fetchTextureBundleJson(const QDir &bundleDir);
|
||||
bool fetchTextureBundleIcons(const QDir &bundleDir);
|
||||
void fetchNewTextureIcons(const QVariantMap &existingFiles, const QVariantMap &newFiles,
|
||||
const QString &existingMetaFilePath, const QDir &bundleDir);
|
||||
std::tuple<QVariantMap, QVariantMap, QVariantMap> compareTextureMetaFiles(
|
||||
const QString &existingMetaFile, const QString downloadedMetaFile);
|
||||
QStringList saveNewTextures(const QDir &bundleDir, const QStringList &newFiles);
|
||||
void populateTextureBundleModels();
|
||||
|
||||
QScopedPointer<StudioQuickWidget> m_quickWidget;
|
||||
QPointer<ContentLibraryMaterialsModel> m_materialsModel;
|
||||
@@ -131,12 +132,8 @@ private:
|
||||
bool m_hasQuick3DImport = false;
|
||||
bool m_isDragging = false;
|
||||
bool m_isQt6Project = false;
|
||||
QString m_baseUrl;
|
||||
QString m_texturesUrl;
|
||||
QString m_textureIconsUrl;
|
||||
QString m_environmentIconsUrl;
|
||||
QString m_environmentsUrl;
|
||||
QString m_downloadPath;
|
||||
QString m_textureBundleUrl;
|
||||
QString m_bundlePath;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
Reference in New Issue
Block a user