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:
Mahmoud Badri
2024-04-11 18:27:02 +03:00
parent 00bbf37cff
commit 247d2dbf6d
10 changed files with 123 additions and 157 deletions

View File

@@ -148,7 +148,7 @@ Item {
visible: root.delegateVisible && root.downloadState != "downloading" visible: root.delegateVisible && root.downloadState != "downloading"
cache: false cache: false
property string webUrl: modelData.textureWebUrl property string textureUrl: modelData.textureUrl
IconButton { IconButton {
id: downloadIcon id: downloadIcon
@@ -279,7 +279,7 @@ Item {
FileDownloader { FileDownloader {
id: textureDownloader id: textureDownloader
url: image.webUrl url: image.textureUrl
probeUrl: false probeUrl: false
downloadEnabled: true downloadEnabled: true
onDownloadStarting: { onDownloadStarting: {
@@ -333,7 +333,7 @@ Item {
FileDownloader { FileDownloader {
id: iconDownloader id: iconDownloader
url: modelData.textureWebIconUrl url: modelData.textureIconUrl
probeUrl: false probeUrl: false
downloadEnabled: true downloadEnabled: true
targetFilePath: modelData.textureIconPath targetFilePath: modelData.textureIconPath

View File

@@ -275,9 +275,9 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
auto category = new ContentLibraryMaterialsCategory(this, cat); auto category = new ContentLibraryMaterialsCategory(this, cat);
const QJsonObject matsObj = catsObj.value(cat).toObject(); const QJsonObject matsObj = catsObj.value(cat).toObject();
const QStringList mats = matsObj.keys(); const QStringList matsNames = matsObj.keys();
for (const QString &mat : mats) { for (const QString &matName : matsNames) {
const QJsonObject matObj = matsObj.value(mat).toObject(); const QJsonObject matObj = matsObj.value(matName).toObject();
QStringList files; QStringList files;
const QJsonArray assetsArr = matObj.value("files").toArray(); const QJsonArray assetsArr = matObj.value("files").toArray();
@@ -292,7 +292,7 @@ void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
bundleId, bundleId,
qml.chopped(4)).toLatin1(); // chopped(4): remove .qml 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); m_downloadPath, m_baseUrl);
category->addBundleMaterial(bundleMat); category->addBundleMaterial(bundleMat);

View File

@@ -12,20 +12,19 @@
namespace QmlDesigner { namespace QmlDesigner {
ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo,
const QString &downloadPath, const QUrl &icon, const QString &dirPath, const QString &key,
const QString &key, const QString &webTextureUrl, const QString &textureUrl, const QString &iconUrl,
const QString &webIconUrl, const QString &fileExt, const QString &suffix, const QSize &dimensions,
const QSize &dimensions, const qint64 sizeInBytes, const qint64 sizeInBytes, bool hasUpdate, bool isNew)
bool hasUpdate, bool isNew)
: QObject(parent) : QObject(parent)
, m_iconPath(iconFileInfo.filePath()) , m_iconPath(iconFileInfo.filePath())
, m_downloadPath(downloadPath) , m_dirPath(dirPath)
, m_webTextureUrl(webTextureUrl) , m_textureUrl(textureUrl)
, m_webIconUrl(webIconUrl) , m_iconUrl(iconUrl)
, m_baseName{iconFileInfo.baseName()} , m_baseName{iconFileInfo.baseName()}
, m_fileExt(fileExt) , m_suffix(suffix)
, m_textureKey(key) , m_textureKey(key)
, m_icon(icon) , m_icon(QUrl::fromLocalFile(iconFileInfo.absoluteFilePath()))
, m_dimensions(dimensions) , m_dimensions(dimensions)
, m_sizeInBytes(sizeInBytes) , m_sizeInBytes(sizeInBytes)
, m_hasUpdate(hasUpdate) , m_hasUpdate(hasUpdate)
@@ -54,9 +53,9 @@ QString ContentLibraryTexture::iconPath() const
return m_iconPath; 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) { const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) {
return fi.baseName() == m_baseName; return fi.baseName() == m_baseName;
}); });
@@ -76,22 +75,20 @@ QString ContentLibraryTexture::resolveFileExt()
QString ContentLibraryTexture::resolveToolTipText() QString ContentLibraryTexture::resolveToolTipText()
{ {
if (m_fileExt.isEmpty()) { if (m_suffix.isEmpty())
// No supplied or resolved extension means we have just the icon and no other data return m_baseName; // empty suffix means we have just the icon and no other data
return m_baseName;
}
QString fileName = m_baseName + m_fileExt; QString fileName = m_baseName + m_suffix;
QString imageInfo; QString imageInfo;
if (!m_isDownloaded && m_sizeInBytes > 0 && !m_dimensions.isNull()) { if (!m_isDownloaded && m_sizeInBytes > 0 && !m_dimensions.isNull()) {
imageInfo = ImageUtils::imageInfo(m_dimensions, m_sizeInBytes); imageInfo = ImageUtils::imageInfo(m_dimensions, m_sizeInBytes);
} else { } else {
QString fullDownloadPath = m_downloadPath + '/' + fileName; QString fullDownloadPath = m_dirPath + '/' + fileName;
imageInfo = ImageUtils::imageInfo(fullDownloadPath); imageInfo = ImageUtils::imageInfo(fullDownloadPath);
} }
return QStringLiteral("%1\n%2").arg(fileName, imageInfo); return QString("%1\n%2").arg(fileName, imageInfo);
} }
bool ContentLibraryTexture::isDownloaded() const bool ContentLibraryTexture::isDownloaded() const
@@ -99,9 +96,9 @@ bool ContentLibraryTexture::isDownloaded() const
return m_isDownloaded; 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() void ContentLibraryTexture::setDownloaded()
@@ -116,16 +113,16 @@ void ContentLibraryTexture::setDownloaded()
void ContentLibraryTexture::doSetDownloaded() void ContentLibraryTexture::doSetDownloaded()
{ {
if (m_fileExt.isEmpty()) if (m_suffix.isEmpty())
m_fileExt = resolveFileExt(); m_suffix = resolveSuffix();
m_isDownloaded = QFileInfo::exists(downloadedTexturePath()); m_isDownloaded = QFileInfo::exists(texturePath());
m_toolTip = resolveToolTipText(); m_toolTip = resolveToolTipText();
} }
QString ContentLibraryTexture::parentDirPath() const QString ContentLibraryTexture::parentDirPath() const
{ {
return m_downloadPath; return m_dirPath;
} }
QString ContentLibraryTexture::textureKey() const QString ContentLibraryTexture::textureKey() const

View File

@@ -19,17 +19,17 @@ class ContentLibraryTexture : public QObject
Q_PROPERTY(QString textureToolTip MEMBER m_toolTip NOTIFY textureToolTipChanged) Q_PROPERTY(QString textureToolTip MEMBER m_toolTip NOTIFY textureToolTipChanged)
Q_PROPERTY(QUrl textureIcon MEMBER m_icon CONSTANT) Q_PROPERTY(QUrl textureIcon MEMBER m_icon CONSTANT)
Q_PROPERTY(bool textureVisible MEMBER m_visible NOTIFY textureVisibleChanged) Q_PROPERTY(bool textureVisible MEMBER m_visible NOTIFY textureVisibleChanged)
Q_PROPERTY(QString textureWebUrl MEMBER m_webTextureUrl CONSTANT) Q_PROPERTY(QString textureUrl MEMBER m_textureUrl CONSTANT)
Q_PROPERTY(QString textureWebIconUrl MEMBER m_webIconUrl CONSTANT) Q_PROPERTY(QString textureIconUrl MEMBER m_iconUrl CONSTANT)
Q_PROPERTY(bool textureHasUpdate WRITE setHasUpdate READ hasUpdate NOTIFY hasUpdateChanged) Q_PROPERTY(bool textureHasUpdate WRITE setHasUpdate READ hasUpdate NOTIFY hasUpdateChanged)
Q_PROPERTY(bool textureIsNew MEMBER m_isNew CONSTANT) Q_PROPERTY(bool textureIsNew MEMBER m_isNew CONSTANT)
Q_PROPERTY(QString textureKey MEMBER m_textureKey CONSTANT) Q_PROPERTY(QString textureKey MEMBER m_textureKey CONSTANT)
public: public:
ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, const QString &downloadPath, ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, const QString &dirPath,
const QUrl &icon, const QString &key, const QString &webTextureUrl, const QString &key, const QString &textureUrl, const QString &iconUrl,
const QString &webIconUrl, const QString &fileExt, const QSize &dimensions, const QString &suffix, const QSize &dimensions, const qint64 sizeInBytes,
const qint64 sizeInBytes, bool hasUpdate, bool isNew); bool hasUpdate = false, bool isNew = false);
Q_INVOKABLE bool isDownloaded() const; Q_INVOKABLE bool isDownloaded() const;
Q_INVOKABLE void setDownloaded(); Q_INVOKABLE void setDownloaded();
@@ -38,7 +38,7 @@ public:
QUrl icon() const; QUrl icon() const;
QString iconPath() const; QString iconPath() const;
QString downloadedTexturePath() const; QString texturePath() const;
QString parentDirPath() const; QString parentDirPath() const;
QString textureKey() const; QString textureKey() const;
@@ -51,17 +51,17 @@ signals:
void hasUpdateChanged(); void hasUpdateChanged();
private: private:
QString resolveFileExt(); QString resolveSuffix();
QString resolveToolTipText(); QString resolveToolTipText();
void doSetDownloaded(); void doSetDownloaded();
QString m_iconPath; QString m_iconPath;
QString m_downloadPath; QString m_dirPath;
QString m_webTextureUrl; QString m_textureUrl;
QString m_webIconUrl; QString m_iconUrl;
QString m_toolTip; QString m_toolTip;
QString m_baseName; QString m_baseName;
QString m_fileExt; QString m_suffix;
QString m_textureKey; QString m_textureKey;
QUrl m_icon; QUrl m_icon;
QSize m_dimensions; QSize m_dimensions;

View File

@@ -14,17 +14,15 @@ namespace QmlDesigner {
ContentLibraryTexturesCategory::ContentLibraryTexturesCategory(QObject *parent, const QString &name) ContentLibraryTexturesCategory::ContentLibraryTexturesCategory(QObject *parent, const QString &name)
: QObject(parent), m_name(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 &key, const QString &webTextureUrl,
const QString &webIconUrl, const QString &fileExt, const QString &iconUrl, const QString &suffix,
const QSize &dimensions, const qint64 sizeInBytes, const QSize &dimensions, const qint64 sizeInBytes,
bool hasUpdate, bool isNew) bool hasUpdate, bool isNew)
{ {
QUrl icon = QUrl::fromLocalFile(tex.absoluteFilePath());
m_categoryTextures.append(new ContentLibraryTexture( m_categoryTextures.append(new ContentLibraryTexture(
this, tex, downloadPath, icon, key, webTextureUrl, webIconUrl, this, texIcon, downloadPath, key, webTextureUrl, iconUrl,
fileExt, dimensions, sizeInBytes, hasUpdate, isNew)); suffix, dimensions, sizeInBytes, hasUpdate, isNew));
} }
bool ContentLibraryTexturesCategory::filter(const QString &searchText) bool ContentLibraryTexturesCategory::filter(const QString &searchText)

View File

@@ -28,7 +28,7 @@ public:
ContentLibraryTexturesCategory(QObject *parent, const QString &name); ContentLibraryTexturesCategory(QObject *parent, const QString &name);
void addTexture(const QFileInfo &tex, const QString &subPath, const QString &key, 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); const QSize &dimensions, const qint64 sizeInBytes, bool hasUpdate, bool isNew);
bool filter(const QString &searchText); bool filter(const QString &searchText);

View File

@@ -95,37 +95,37 @@ QHash<int, QByteArray> ContentLibraryTexturesModel::roleNames() const
/** /**
* @brief Load the bundle categorized icons. Actual textures are downloaded on demand * @brief Load the bundle categorized icons. Actual textures are downloaded on demand
* *
* @param bundlePath local path to the bundle folder and icons * @param textureBundleUrl remote url to the texture bundle
* @param metaData bundle textures metadata * @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 QString &bundleIconPath,
const QVariantMap &metaData) const QVariantMap &jsonData)
{ {
if (!m_bundleCategories.isEmpty()) if (!m_bundleCategories.isEmpty())
return; return;
QDir bundleDir = QString("%1/%2").arg(bundleIconPath, m_category); QDir bundleDir = QString("%1/%2").arg(bundleIconPath, m_category);
if (!bundleDir.exists()) { QTC_ASSERT(bundleDir.exists(), return);
qWarning() << __FUNCTION__ << "textures bundle folder doesn't exist." << bundleDir.absolutePath();
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); const QFileInfoList dirs = bundleDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
for (const QFileInfo &dir : dirs) { for (const QFileInfo &dir : dirs) {
auto category = new ContentLibraryTexturesCategory(this, dir.fileName()); auto category = new ContentLibraryTexturesCategory(this, dir.fileName());
const QFileInfoList texFiles = QDir(dir.filePath()).entryInfoList(QDir::Files); const QFileInfoList texIconFiles = QDir(dir.filePath()).entryInfoList(QDir::Files);
for (const QFileInfo &tex : texFiles) { for (const QFileInfo &texIcon : texIconFiles) {
QString textureUrl = QString("%1/%2/%3.zip").arg(remoteUrl, dir.fileName(), tex.baseName()); QString textureUrl = QString("%1/%2/%3/%4.zip").arg(textureBundleUrl, m_category,
QString iconUrl = QString("%1/%2/%3.png").arg(iconsUrl, dir.fileName(), tex.baseName()); 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(), .arg(Paths::bundlesPathSetting(),
m_category, m_category,
dir.fileName()); 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; QString fileExt;
QSize dimensions; QSize dimensions;
qint64 sizeInBytes = -1; qint64 sizeInBytes = -1;
@@ -141,7 +141,7 @@ void ContentLibraryTexturesModel::loadTextureBundle(const QString &remoteUrl, co
isNew = m_newFiles.contains(key); 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); dimensions, sizeInBytes, hasUpdate, isNew);
} }
m_bundleCategories.append(category); m_bundleCategories.append(category);

View File

@@ -37,8 +37,8 @@ public:
void setHasSceneEnv(bool b); void setHasSceneEnv(bool b);
void resetModel(); void resetModel();
void loadTextureBundle(const QString &remoteUrl, const QString &iconsUrl, void loadTextureBundle(const QString &m_textureBundleUrl, const QString &bundlePath,
const QString &bundlePath, const QVariantMap &metaData); const QVariantMap &metaData);
signals: signals:
void isEmptyChanged(); void isEmptyChanged();

View File

@@ -101,10 +101,10 @@ bool ContentLibraryWidget::eventFilter(QObject *obj, QEvent *event)
&& m_textureToDrag->isDownloaded()) { && m_textureToDrag->isDownloaded()) {
QMimeData *mimeData = new QMimeData; QMimeData *mimeData = new QMimeData;
mimeData->setData(Constants::MIME_TYPE_BUNDLE_TEXTURE, 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 // 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); emit bundleTextureDragStarted(m_textureToDrag);
model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile()); model->startDrag(mimeData, m_textureToDrag->icon().toLocalFile());
@@ -142,18 +142,12 @@ ContentLibraryWidget::ContentLibraryWidget()
m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports"); m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
m_quickWidget->setClearColor(Theme::getColor(Theme::Color::DSpanelBackground)); m_quickWidget->setClearColor(Theme::getColor(Theme::Color::DSpanelBackground));
m_baseUrl = QmlDesignerPlugin::settings() m_textureBundleUrl = QmlDesignerPlugin::settings()
.value(DesignerSettingsKey::DOWNLOADABLE_BUNDLES_URL).toString() .value(DesignerSettingsKey::DOWNLOADABLE_BUNDLES_URL).toString() + "/textures";
+ "/textures";
m_texturesUrl = m_baseUrl + "/Textures"; m_bundlePath = Paths::bundlesPathSetting();
m_textureIconsUrl = m_baseUrl + "/icons/Textures";
m_environmentIconsUrl = m_baseUrl + "/icons/Environments";
m_environmentsUrl = m_baseUrl + "/Environments";
m_downloadPath = Paths::bundlesPathSetting(); loadTextureBundles();
loadTextureBundle();
Theme::setupTheme(m_quickWidget->engine()); Theme::setupTheme(m_quickWidget->engine());
m_quickWidget->quickWidget()->installEventFilter(this); m_quickWidget->quickWidget()->installEventFilter(this);
@@ -185,33 +179,28 @@ ContentLibraryWidget::ContentLibraryWidget()
reloadQmlSource(); reloadQmlSource();
} }
QVariantMap ContentLibraryWidget::readBundleMetadata() QVariantMap ContentLibraryWidget::readTextureBundleJson()
{ {
QVariantMap metaData; QVariantMap jsonData;
QFile jsonFile(m_downloadPath + "/texture_bundle.json"); QFile jsonFile(m_bundlePath + "/texture_bundle.json");
if (jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) 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) { if (version > TextureBundleMetadataVersion) {
qWarning() << "Unrecognized texture metadata file version: " << version; qWarning() << "Unrecognized texture metadata file version: " << version;
return {}; return {};
} }
return metaData; return jsonData;
} }
void ContentLibraryWidget::loadTextureBundle() void ContentLibraryWidget::loadTextureBundles()
{ {
QDir bundleDir{m_downloadPath}; QDir bundleDir{m_bundlePath};
if (fetchTextureBundleMetadata(bundleDir) && fetchTextureBundleIcons(bundleDir)) { if (fetchTextureBundleJson(bundleDir) && fetchTextureBundleIcons(bundleDir))
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons"; populateTextureBundleModels();
QVariantMap metaData = readBundleMetadata();
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath, metaData);
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
bundleIconPath, metaData);
}
} }
std::tuple<QVariantMap, QVariantMap, QVariantMap> ContentLibraryWidget::compareTextureMetaFiles( std::tuple<QVariantMap, QVariantMap, QVariantMap> ContentLibraryWidget::compareTextureMetaFiles(
@@ -275,9 +264,9 @@ void ContentLibraryWidget::fetchNewTextureIcons(const QVariantMap &existingFiles
}); });
auto multidownloader = new MultiFileDownloader(this); auto multidownloader = new MultiFileDownloader(this);
multidownloader->setBaseUrl(QString(m_baseUrl + "/icons")); multidownloader->setBaseUrl(QString(m_textureBundleUrl + "/icons"));
multidownloader->setFiles(fileList); multidownloader->setFiles(fileList);
multidownloader->setTargetDirPath(m_downloadPath + "/TextureBundleIcons"); multidownloader->setTargetDirPath(m_bundlePath + "/TextureBundleIcons");
auto downloader = new FileDownloader(this); auto downloader = new FileDownloader(this);
downloader->setDownloadEnabled(true); downloader->setDownloadEnabled(true);
@@ -317,15 +306,8 @@ void ContentLibraryWidget::fetchNewTextureIcons(const QVariantMap &existingFiles
existingFile.flush(); existingFile.flush();
} }
if (fetchTextureBundleIcons(bundleDir)) { if (fetchTextureBundleIcons(bundleDir))
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons"; populateTextureBundleModels();
QVariantMap metaData = readBundleMetadata();
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
metaData);
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
bundleIconPath, metaData);
}
}); });
multidownloader->start(); 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"); QString filePath = bundleDir.filePath("texture_bundle.json");
QFileInfo fi(filePath); 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); FileDownloader *downloader = new FileDownloader(this);
downloader->setUrl(metaFileUrl); downloader->setUrl(bundleZipUrl);
downloader->setProbeUrl(false); downloader->setProbeUrl(false);
downloader->setDownloadEnabled(true); downloader->setDownloadEnabled(true);
downloader->start();
QObject::connect(downloader, &FileDownloader::downloadFailed, this, QObject::connect(downloader, &FileDownloader::downloadFailed, this,
[this, metaFileExists, bundleDir] { [this, jsonFileExists, bundleDir] {
if (metaFileExists) { if (jsonFileExists) {
if (fetchTextureBundleIcons(bundleDir)) { if (fetchTextureBundleIcons(bundleDir))
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons"; populateTextureBundleModels();
QVariantMap metaData = readBundleMetadata();
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
metaData);
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
bundleIconPath, metaData);
}
} }
}); });
QObject::connect(downloader, &FileDownloader::finishedChanged, this, QObject::connect(downloader, &FileDownloader::finishedChanged, this,
[this, downloader, bundleDir, metaFileExists, filePath] { [this, downloader, bundleDir, jsonFileExists, filePath] {
FileExtractor *extractor = new FileExtractor(this); FileExtractor *extractor = new FileExtractor(this);
extractor->setArchiveName(downloader->completeBaseName()); extractor->setArchiveName(downloader->completeBaseName());
extractor->setSourceFile(downloader->outputFile()); extractor->setSourceFile(downloader->outputFile());
if (!metaFileExists) if (!jsonFileExists)
extractor->setTargetPath(bundleDir.absolutePath()); extractor->setTargetPath(bundleDir.absolutePath());
extractor->setAlwaysCreateDir(false); extractor->setAlwaysCreateDir(false);
extractor->setClearTargetPathContents(false); extractor->setClearTargetPathContents(false);
QObject::connect(extractor, &FileExtractor::finishedChanged, this, QObject::connect(extractor, &FileExtractor::finishedChanged, this,
[this, downloader, bundleDir, extractor, metaFileExists, filePath] { [this, downloader, bundleDir, extractor, jsonFileExists, filePath] {
downloader->deleteLater(); downloader->deleteLater();
extractor->deleteLater(); extractor->deleteLater();
if (metaFileExists) { if (jsonFileExists) {
QVariantMap newFiles, existing; QVariantMap newFiles, existing;
QVariantMap modifiedFilesEntries; QVariantMap modifiedFilesEntries;
@@ -501,32 +478,35 @@ bool ContentLibraryWidget::fetchTextureBundleMetadata(const QDir &bundleDir)
} }
} }
if (fetchTextureBundleIcons(bundleDir)) { if (fetchTextureBundleIcons(bundleDir))
QString bundleIconPath = m_downloadPath + "/TextureBundleIcons"; populateTextureBundleModels();
QVariantMap metaData = readBundleMetadata();
m_texturesModel->loadTextureBundle(m_texturesUrl, m_textureIconsUrl, bundleIconPath,
metaData);
m_environmentsModel->loadTextureBundle(m_environmentsUrl, m_environmentIconsUrl,
bundleIconPath, metaData);
}
}); });
extractor->extract(); extractor->extract();
}); });
downloader->start();
return false; 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) bool ContentLibraryWidget::fetchTextureBundleIcons(const QDir &bundleDir)
{ {
QString iconsPath = bundleDir.filePath("TextureBundleIcons"); QString iconsPath = bundleDir.filePath("TextureBundleIcons");
QDir iconsDir(iconsPath); QDir iconsDir(iconsPath);
if (iconsDir.exists() && iconsDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot).length() > 0) if (iconsDir.exists() && !iconsDir.isEmpty())
return true; return true;
QString zipFileUrl = m_baseUrl + "/icons.zip"; QString zipFileUrl = m_textureBundleUrl + "/icons.zip";
FileDownloader *downloader = new FileDownloader(this); FileDownloader *downloader = new FileDownloader(this);
downloader->setUrl(zipFileUrl); downloader->setUrl(zipFileUrl);
@@ -546,13 +526,7 @@ bool ContentLibraryWidget::fetchTextureBundleIcons(const QDir &bundleDir)
[this, downloader, extractor] { [this, downloader, extractor] {
downloader->deleteLater(); downloader->deleteLater();
extractor->deleteLater(); extractor->deleteLater();
populateTextureBundleModels();
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);
}); });
extractor->extract(); extractor->extract();
@@ -575,7 +549,7 @@ void ContentLibraryWidget::markTextureUpdated(const QString &textureKey)
checksumOnServer = m_environmentsModel->removeModifiedFileEntry(textureKey); checksumOnServer = m_environmentsModel->removeModifiedFileEntry(textureKey);
QJsonObject metaDataObj; QJsonObject metaDataObj;
QFile jsonFile(m_downloadPath + "/texture_bundle.json"); QFile jsonFile(m_bundlePath + "/texture_bundle.json");
if (jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { if (jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
metaDataObj = QJsonDocument::fromJson(jsonFile.readAll()).object(); metaDataObj = QJsonDocument::fromJson(jsonFile.readAll()).object();
jsonFile.close(); jsonFile.close();
@@ -592,7 +566,7 @@ void ContentLibraryWidget::markTextureUpdated(const QString &textureKey)
QJsonDocument outDoc(metaDataObj); QJsonDocument outDoc(metaDataObj);
QByteArray data = outDoc.toJson(); 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)) { if (outFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Text)) {
outFile.write(data); outFile.write(data);
outFile.flush(); outFile.flush();
@@ -787,7 +761,7 @@ void ContentLibraryWidget::addImage(ContentLibraryTexture *tex)
if (!tex->isDownloaded()) if (!tex->isDownloaded())
return; return;
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::Image); emit addTextureRequested(tex->texturePath(), AddTextureMode::Image);
} }
void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex) void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex)
@@ -795,7 +769,7 @@ void ContentLibraryWidget::addTexture(ContentLibraryTexture *tex)
if (!tex->isDownloaded()) if (!tex->isDownloaded())
return; return;
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::Texture); emit addTextureRequested(tex->texturePath(), AddTextureMode::Texture);
} }
void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex) void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex)
@@ -803,7 +777,7 @@ void ContentLibraryWidget::addLightProbe(ContentLibraryTexture *tex)
if (!tex->isDownloaded()) if (!tex->isDownloaded())
return; return;
emit addTextureRequested(tex->downloadedTexturePath(), AddTextureMode::LightProbe); emit addTextureRequested(tex->texturePath(), AddTextureMode::LightProbe);
} }
void ContentLibraryWidget::updateSceneEnvState() void ContentLibraryWidget::updateSceneEnvState()

View File

@@ -100,15 +100,16 @@ private:
void updateSearch(); void updateSearch();
void setIsDragging(bool val); void setIsDragging(bool val);
QString findTextureBundlePath(); QString findTextureBundlePath();
void loadTextureBundle(); void loadTextureBundles();
QVariantMap readBundleMetadata(); QVariantMap readTextureBundleJson();
bool fetchTextureBundleMetadata(const QDir &bundleDir); bool fetchTextureBundleJson(const QDir &bundleDir);
bool fetchTextureBundleIcons(const QDir &bundleDir); bool fetchTextureBundleIcons(const QDir &bundleDir);
void fetchNewTextureIcons(const QVariantMap &existingFiles, const QVariantMap &newFiles, void fetchNewTextureIcons(const QVariantMap &existingFiles, const QVariantMap &newFiles,
const QString &existingMetaFilePath, const QDir &bundleDir); const QString &existingMetaFilePath, const QDir &bundleDir);
std::tuple<QVariantMap, QVariantMap, QVariantMap> compareTextureMetaFiles( std::tuple<QVariantMap, QVariantMap, QVariantMap> compareTextureMetaFiles(
const QString &existingMetaFile, const QString downloadedMetaFile); const QString &existingMetaFile, const QString downloadedMetaFile);
QStringList saveNewTextures(const QDir &bundleDir, const QStringList &newFiles); QStringList saveNewTextures(const QDir &bundleDir, const QStringList &newFiles);
void populateTextureBundleModels();
QScopedPointer<StudioQuickWidget> m_quickWidget; QScopedPointer<StudioQuickWidget> m_quickWidget;
QPointer<ContentLibraryMaterialsModel> m_materialsModel; QPointer<ContentLibraryMaterialsModel> m_materialsModel;
@@ -131,12 +132,8 @@ private:
bool m_hasQuick3DImport = false; bool m_hasQuick3DImport = false;
bool m_isDragging = false; bool m_isDragging = false;
bool m_isQt6Project = false; bool m_isQt6Project = false;
QString m_baseUrl; QString m_textureBundleUrl;
QString m_texturesUrl; QString m_bundlePath;
QString m_textureIconsUrl;
QString m_environmentIconsUrl;
QString m_environmentsUrl;
QString m_downloadPath;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner