forked from qt-creator/qt-creator
QmlDesigner: Use complete suffix instead of suffix for download check
This amends patch '5fa1be7dc21721d0667fc1b6dd13f1e1c79a5f0a' using complete suffix instead of doing multiple QFileInfo::exists() checks. Task-number: QDS-15366 Change-Id: Ib377dcb44cbb31a3f54237c1f572d02bd4fd9b29 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
namespace QmlDesigner {
|
||||
|
||||
ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo,
|
||||
const QString &dirPath, const QString &suffix,
|
||||
const QString &dirPath, const QString &completeSuffix,
|
||||
const QSize &dimensions, const qint64 sizeInBytes,
|
||||
const QString &key, const QString &textureUrl,
|
||||
const QString &iconUrl, bool hasUpdate, bool isNew)
|
||||
@@ -22,7 +22,7 @@ ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QFileInfo &i
|
||||
, m_textureUrl(textureUrl)
|
||||
, m_iconUrl(iconUrl)
|
||||
, m_baseName{iconFileInfo.baseName()}
|
||||
, m_suffix(suffix)
|
||||
, m_completeSuffix(completeSuffix)
|
||||
, m_textureKey(key)
|
||||
, m_icon(QUrl::fromLocalFile(iconFileInfo.absoluteFilePath()))
|
||||
, m_dimensions(dimensions)
|
||||
@@ -53,7 +53,7 @@ QString ContentLibraryTexture::iconPath() const
|
||||
return m_iconPath;
|
||||
}
|
||||
|
||||
QString ContentLibraryTexture::resolveSuffix()
|
||||
QString ContentLibraryTexture::resolveCompleteSuffix()
|
||||
{
|
||||
const QFileInfoList files = QDir(m_dirPath).entryInfoList(QDir::Files);
|
||||
const QFileInfoList textureFiles = Utils::filtered(files, [this](const QFileInfo &fi) {
|
||||
@@ -73,7 +73,7 @@ QString ContentLibraryTexture::resolveSuffix()
|
||||
|
||||
QString ContentLibraryTexture::resolveToolTipText()
|
||||
{
|
||||
if (m_suffix.isEmpty())
|
||||
if (m_completeSuffix.isEmpty())
|
||||
return m_baseName; // empty suffix means we have just the icon and no other data
|
||||
|
||||
QString texFileName = fileName();
|
||||
@@ -111,14 +111,10 @@ void ContentLibraryTexture::setDownloaded()
|
||||
|
||||
void ContentLibraryTexture::doSetDownloaded()
|
||||
{
|
||||
if (m_suffix.isEmpty() || !QFileInfo::exists(texturePath())) {
|
||||
m_suffix = resolveSuffix();
|
||||
if (m_completeSuffix.isEmpty())
|
||||
m_completeSuffix = resolveCompleteSuffix();
|
||||
|
||||
// recheck existence as texturePath() might have been reevaluated
|
||||
m_isDownloaded = QFileInfo::exists(texturePath());
|
||||
} else {
|
||||
m_isDownloaded = true;
|
||||
}
|
||||
m_isDownloaded = QFileInfo::exists(texturePath());
|
||||
|
||||
m_toolTip = resolveToolTipText();
|
||||
}
|
||||
@@ -140,7 +136,7 @@ QString ContentLibraryTexture::textureKey() const
|
||||
|
||||
QString ContentLibraryTexture::fileName() const
|
||||
{
|
||||
return m_baseName + m_suffix;
|
||||
return m_baseName + m_completeSuffix;
|
||||
}
|
||||
|
||||
void ContentLibraryTexture::setHasUpdate(bool value)
|
||||
|
@@ -28,7 +28,7 @@ class ContentLibraryTexture : public QObject
|
||||
|
||||
public:
|
||||
ContentLibraryTexture(QObject *parent, const QFileInfo &iconFileInfo, const QString &dirPath,
|
||||
const QString &suffix, const QSize &dimensions, const qint64 sizeInBytes,
|
||||
const QString &completeSuffix, const QSize &dimensions, const qint64 sizeInBytes,
|
||||
const QString &key = {}, const QString &textureUrl = {},
|
||||
const QString &iconUrl = {}, bool hasUpdate = false, bool isNew = false);
|
||||
|
||||
@@ -55,7 +55,7 @@ signals:
|
||||
void hasUpdateChanged();
|
||||
|
||||
private:
|
||||
QString resolveSuffix();
|
||||
QString resolveCompleteSuffix();
|
||||
QString resolveToolTipText();
|
||||
void doSetDownloaded();
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
QString m_iconUrl;
|
||||
QString m_toolTip;
|
||||
QString m_baseName;
|
||||
QString m_suffix;
|
||||
QString m_completeSuffix;
|
||||
QString m_textureKey;
|
||||
QUrl m_icon;
|
||||
QSize m_dimensions;
|
||||
|
@@ -49,7 +49,7 @@ void UserTextureCategory::filter(const QString &searchText)
|
||||
void UserTextureCategory::addItems(const Utils::FilePaths &paths)
|
||||
{
|
||||
for (const Utils::FilePath &filePath : paths) {
|
||||
QString suffix = '.' + filePath.suffix();
|
||||
QString completeSuffix = "." + filePath.completeSuffix();
|
||||
|
||||
QFileInfo iconFileInfo = filePath.parentDir().pathAppended("icons/" + filePath.baseName() + ".png")
|
||||
.toFileInfo();
|
||||
@@ -60,7 +60,7 @@ void UserTextureCategory::addItems(const Utils::FilePaths &paths)
|
||||
qint64 imgFileSize = info.second;
|
||||
|
||||
if (!iconFileInfo.exists()) { // generate an icon if one doesn't exist
|
||||
if (suffix == ".ktx") {
|
||||
if (completeSuffix.endsWith(".ktx")) {
|
||||
QFile::copy(":/contentlibrary/images/texture_ktx.png", iconFileInfo.absoluteFilePath());
|
||||
} else {
|
||||
Asset asset{filePath.toFSPathString()};
|
||||
@@ -71,7 +71,7 @@ void UserTextureCategory::addItems(const Utils::FilePaths &paths)
|
||||
}
|
||||
}
|
||||
|
||||
auto tex = new ContentLibraryTexture(this, iconFileInfo, dirPath, suffix, imgDims, imgFileSize);
|
||||
auto tex = new ContentLibraryTexture(this, iconFileInfo, dirPath, completeSuffix, imgDims, imgFileSize);
|
||||
m_items.append(tex);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user