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 87f76d9bfa)
Task-number: QDS-8664
Change-Id: Ieac0e81a5595a8bff3d1aa7ff6252e16c2509c2e
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io>
This commit is contained in:
Samuel Ghinet
2023-02-20 21:32:53 +02:00
committed by Thomas Hartmann
parent ed503f3db5
commit 8f17625ef5
4 changed files with 44 additions and 21 deletions

View File

@@ -121,6 +121,8 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
style: Text.Outline
styleColor: "black"
visible: root.downloadState !== "downloaded" visible: root.downloadState !== "downloaded"
} }
@@ -164,10 +166,10 @@ Item {
} }
onClicked: { onClicked: {
if (!rootView.markTextureDownloading()) if (root.downloadState !== "" && root.downloadState !== "failed")
return return
if (root.downloadState !== "" && root.downloadState !== "failed") if (!rootView.markTextureDownloading())
return return
progressBar.visible = true progressBar.visible = true
@@ -205,7 +207,7 @@ Item {
root.progressText = "" root.progressText = ""
root.progressValue = 0 root.progressValue = 0
root.downloadState = "failed" root.downloadState = ""
root.downloadStateChanged() root.downloadStateChanged()
mouseArea.enabled = true mouseArea.enabled = true

View File

@@ -20,20 +20,8 @@ ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &i
, m_baseName{iconFileInfo.baseName()} , m_baseName{iconFileInfo.baseName()}
, m_icon(icon) , m_icon(icon)
{ {
m_fileExt = computeFileExt(); m_fileExt = resolveFileExt();
m_toolTip = 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, false);
}
m_toolTip = QLatin1String("%1\n%2").arg(fileName, imageInfo);
} }
bool ContentLibraryTexture::filter(const QString &searchText) bool ContentLibraryTexture::filter(const QString &searchText)
@@ -56,7 +44,7 @@ QString ContentLibraryTexture::path() const
return m_iconPath; return m_iconPath;
} }
QString ContentLibraryTexture::computeFileExt() QString ContentLibraryTexture::resolveFileExt()
{ {
const QFileInfoList files = QDir(m_downloadPath).entryInfoList(QDir::Files); const QFileInfoList files = QDir(m_downloadPath).entryInfoList(QDir::Files);
const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) { const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) {
@@ -76,6 +64,23 @@ QString ContentLibraryTexture::computeFileExt()
return QString{"."} + textureFiles.at(0).completeSuffix(); 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 bool ContentLibraryTexture::isDownloaded() const
{ {
if (m_fileExt.isEmpty()) if (m_fileExt.isEmpty())
@@ -87,7 +92,13 @@ bool ContentLibraryTexture::isDownloaded() const
void ContentLibraryTexture::setDownloaded() 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 QString ContentLibraryTexture::parentDirPath() const

View File

@@ -15,7 +15,7 @@ class ContentLibraryTexture : public QObject
Q_PROPERTY(QString textureIconPath MEMBER m_iconPath CONSTANT) Q_PROPERTY(QString textureIconPath MEMBER m_iconPath CONSTANT)
Q_PROPERTY(QString textureParentPath READ parentDirPath 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(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_webUrl CONSTANT) Q_PROPERTY(QString textureWebUrl MEMBER m_webUrl CONSTANT)
@@ -35,10 +35,12 @@ public:
signals: signals:
void textureVisibleChanged(); void textureVisibleChanged();
void textureToolTipChanged();
private: private:
inline static const QString m_defaultExt = ".png"; inline static const QString m_defaultExt = ".png";
QString computeFileExt(); QString resolveFileExt();
QString resolveToolTipText();
QString m_iconPath; QString m_iconPath;
QString m_downloadPath; QString m_downloadPath;

View File

@@ -82,6 +82,14 @@ QString FileExtractor::targetPath() const
void FileExtractor::setTargetPath(const QString &path) void FileExtractor::setTargetPath(const QString &path)
{ {
m_targetPath = Utils::FilePath::fromString(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() void FileExtractor::browse()