diff options
Diffstat (limited to 'src/quick/util/qquickpixmapcache.cpp')
-rw-r--r-- | src/quick/util/qquickpixmapcache.cpp | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index e218b84fff..7097bcc156 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -414,6 +414,34 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e } } +static QStringList fromLatin1List(const QList<QByteArray> &list) +{ + QStringList res; + res.reserve(list.size()); + for (const QByteArray &item : list) + res.append(QString::fromLatin1(item)); + return res; +} + +static QString existingImageFileForPath(const QString &localFile) +{ + // Do nothing if given filepath exists or already has a suffix + QFileInfo fi(localFile); + if (!fi.suffix().isEmpty() || fi.exists()) + return localFile; + + static const QStringList suffixes = fromLatin1List(QSGTextureReader::supportedFileFormats() + + QImageReader::supportedImageFormats()); + QString tryFile = localFile + QStringLiteral(".xxxx"); + const int suffixIdx = localFile.length() + 1; + for (const QString &suffix : suffixes) { + tryFile.replace(suffixIdx, 10, suffix); + if (QFileInfo::exists(tryFile)) + return tryFile; + } + return localFile; +} + QQuickPixmapReader::QQuickPixmapReader(QQmlEngine *eng) : QThread(eng), engine(eng), threadObject(0) #if QT_CONFIG(qml_network) @@ -769,18 +797,18 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u QImage image; QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError; QString errorStr; - QFile f(localFile); + QFile f(existingImageFileForPath(localFile)); QSize readSize; if (f.open(QIODevice::ReadOnly)) { - - // for now, purely use suffix information to determine whether we are working with a compressed texture - QByteArray suffix = QFileInfo(f).suffix().toLower().toLatin1(); - if (QSGTextureReader::isTexture(&f, suffix)) { - QQuickTextureFactory *factory = QSGTextureReader::read(&f, suffix); + QSGTextureReader texReader(&f, localFile); + if (texReader.isTexture()) { + QQuickTextureFactory *factory = texReader.read(); if (factory) { readSize = factory->textureSize(); } else { errorStr = QQuickPixmap::tr("Error decoding: %1").arg(url.toString()); + if (f.fileName() != localFile) + errorStr += QString::fromLatin1(" (%1)").arg(f.fileName()); errorCode = QQuickPixmapReply::Decoding; } mutex.lock(); @@ -789,8 +817,11 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u mutex.unlock(); return; } else { - if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, runningJob->providerOptions)) + if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, runningJob->providerOptions)) { errorCode = QQuickPixmapReply::Loading; + if (f.fileName() != localFile) + errorStr += QString::fromLatin1(" (%1)").arg(f.fileName()); + } } } else { errorStr = QQuickPixmap::tr("Cannot open: %1").arg(url.toString()); @@ -1247,20 +1278,21 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q if (localFile.isEmpty()) return 0; - QFile f(localFile); + QFile f(existingImageFileForPath(localFile)); QSize readSize; QString errorString; if (f.open(QIODevice::ReadOnly)) { - // for now, purely use suffix information to determine whether we are working with a compressed texture - QByteArray suffix = QFileInfo(f).suffix().toLower().toLatin1(); - if (QSGTextureReader::isTexture(&f, suffix)) { - QQuickTextureFactory *factory = QSGTextureReader::read(&f, suffix); + QSGTextureReader texReader(&f, localFile); + if (texReader.isTexture()) { + QQuickTextureFactory *factory = texReader.read(); if (factory) { *ok = true; - return new QQuickPixmapData(declarativePixmap, factory); + return new QQuickPixmapData(declarativePixmap, url, factory, factory->textureSize(), requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform); } else { errorString = QQuickPixmap::tr("Error decoding: %1").arg(url.toString()); + if (f.fileName() != localFile) + errorString += QString::fromLatin1(" (%1)").arg(f.fileName()); } } else { QImage image; @@ -1268,6 +1300,8 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q if (readImage(url, &f, &image, &errorString, &readSize, requestSize, providerOptions, &appliedTransform)) { *ok = true; return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, appliedTransform); + } else if (f.fileName() != localFile) { + errorString += QString::fromLatin1(" (%1)").arg(f.fileName()); } } } else { |