From 8f17625ef5df4b1782355a8304f65164a7074903 Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Mon, 20 Feb 2023 21:32:53 +0200 Subject: [PATCH] QmlDesigner: Fix downloading textures no longer working after some clicks A "locking" mechanism was implemented to prevent multiple textures from being downloaded at the same time. However, there was a mistake made, which made it so that when a texture that had already been downloaded was clicked again, this locking would be enforced and not released. Also, fixed minor issues: * The download button now has a black outline, so as to better distinguish it inside black-and-white textures * Canceling the download of a texture no longer marks the download as failed -- it should show it as if the download was never attempted. * Fixed tooltips not showing the texture size for downloaded textures - and now we also update the tooltip text after the real texture has been downloaded. * Always creating the "target path" in the FileExtractor, if it does not exist -- this is different from the "target folder" name, which is an folder that can optionally be created inside this "target path" (cherry picked from commit 87f76d9bfa9e13b12105725ee0b528f6ecd40161) Task-number: QDS-8664 Change-Id: Ieac0e81a5595a8bff3d1aa7ff6252e16c2509c2e Reviewed-by: Thomas Hartmann Reviewed-by: Samuel Ghinet --- .../ContentLibraryTexture.qml | 8 ++-- .../contentlibrary/contentlibrarytexture.cpp | 43 ++++++++++++------- .../contentlibrary/contentlibrarytexture.h | 6 ++- .../qmldesigner/utils/fileextractor.cpp | 8 ++++ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml index a749d8d52db..ac98bb40faa 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml @@ -121,6 +121,8 @@ Item { anchors.right: parent.right anchors.bottom: parent.bottom + style: Text.Outline + styleColor: "black" visible: root.downloadState !== "downloaded" } @@ -164,10 +166,10 @@ Item { } onClicked: { - if (!rootView.markTextureDownloading()) + if (root.downloadState !== "" && root.downloadState !== "failed") return - if (root.downloadState !== "" && root.downloadState !== "failed") + if (!rootView.markTextureDownloading()) return progressBar.visible = true @@ -205,7 +207,7 @@ Item { root.progressText = "" root.progressValue = 0 - root.downloadState = "failed" + root.downloadState = "" root.downloadStateChanged() mouseArea.enabled = true diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp index 600d84368ea..e0227203ba8 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp @@ -20,20 +20,8 @@ ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &i , m_baseName{iconFileInfo.baseName()} , m_icon(icon) { - m_fileExt = computeFileExt(); - - QString fileName; - QString imageInfo; - if (m_fileExt.isEmpty()) { - imageInfo = ImageUtils::imageInfo(m_iconPath, false); - fileName = m_baseName + m_defaultExt; - } else { - fileName = m_baseName + m_fileExt; - QString fullDownloadPath = m_downloadPath + "/" + fileName; - imageInfo = ImageUtils::imageInfo(fullDownloadPath, false); - } - - m_toolTip = QLatin1String("%1\n%2").arg(fileName, imageInfo); + m_fileExt = resolveFileExt(); + m_toolTip = resolveToolTipText(); } bool ContentLibraryTexture::filter(const QString &searchText) @@ -56,7 +44,7 @@ QString ContentLibraryTexture::path() const return m_iconPath; } -QString ContentLibraryTexture::computeFileExt() +QString ContentLibraryTexture::resolveFileExt() { const QFileInfoList files = QDir(m_downloadPath).entryInfoList(QDir::Files); const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) { @@ -76,6 +64,23 @@ QString ContentLibraryTexture::computeFileExt() return QString{"."} + textureFiles.at(0).completeSuffix(); } +QString ContentLibraryTexture::resolveToolTipText() +{ + QString fileName; + QString imageInfo; + + if (m_fileExt.isEmpty()) { + imageInfo = ImageUtils::imageInfo(m_iconPath, false); + fileName = m_baseName + m_defaultExt; + } else { + fileName = m_baseName + m_fileExt; + QString fullDownloadPath = m_downloadPath + "/" + fileName; + imageInfo = ImageUtils::imageInfo(fullDownloadPath, true); + } + + return QLatin1String("%1\n%2").arg(fileName, imageInfo); +} + bool ContentLibraryTexture::isDownloaded() const { if (m_fileExt.isEmpty()) @@ -87,7 +92,13 @@ bool ContentLibraryTexture::isDownloaded() const void ContentLibraryTexture::setDownloaded() { - m_fileExt = computeFileExt(); + m_fileExt = resolveFileExt(); + QString toolTip = resolveToolTipText(); + + if (toolTip != m_toolTip) { + m_toolTip = toolTip; + emit textureToolTipChanged(); + } } QString ContentLibraryTexture::parentDirPath() const diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h index 5921bb27965..54b90ba6d88 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h @@ -15,7 +15,7 @@ class ContentLibraryTexture : public QObject Q_PROPERTY(QString textureIconPath MEMBER m_iconPath CONSTANT) Q_PROPERTY(QString textureParentPath READ parentDirPath CONSTANT) - Q_PROPERTY(QString textureToolTip MEMBER m_toolTip CONSTANT) + 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_webUrl CONSTANT) @@ -35,10 +35,12 @@ public: signals: void textureVisibleChanged(); + void textureToolTipChanged(); private: inline static const QString m_defaultExt = ".png"; - QString computeFileExt(); + QString resolveFileExt(); + QString resolveToolTipText(); QString m_iconPath; QString m_downloadPath; diff --git a/src/plugins/qmldesigner/utils/fileextractor.cpp b/src/plugins/qmldesigner/utils/fileextractor.cpp index 79aa4974e5c..a7e32b6bc1d 100644 --- a/src/plugins/qmldesigner/utils/fileextractor.cpp +++ b/src/plugins/qmldesigner/utils/fileextractor.cpp @@ -82,6 +82,14 @@ QString FileExtractor::targetPath() const void FileExtractor::setTargetPath(const QString &path) { m_targetPath = Utils::FilePath::fromString(path); + + QDir dir(m_targetPath.toString()); + + if (!path.isEmpty() && !dir.exists()) { + // Even though m_targetPath will be created eventually, we need to make sure the path exists + // before m_bytesBefore is being calculated. + dir.mkpath(m_targetPath.toString()); + } } void FileExtractor::browse()