From 6fe601e4bcff790a335de949a20e223380ce9408 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 12 May 2011 14:34:48 +1000 Subject: [PATCH] Improve error message for invalid image provider name. Also fix broken qdeclarativeimageprovider test. --- src/declarative/qml/qdeclarativeengine.cpp | 2 +- src/declarative/qml/qdeclarativeimageprovider.h | 3 ++- src/declarative/util/qdeclarativepixmapcache.cpp | 20 +++++++++++++++++--- .../tst_qdeclarativeimageprovider.cpp | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 2ed1080..eb2974f 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -837,7 +837,7 @@ QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProvider locker.unlock(); if (provider) return provider->imageType(); - return static_cast(-1); + return QDeclarativeImageProvider::Invalid; } QSGTexture *QDeclarativeEnginePrivate::getTextureFromProvider(const QUrl &url, QSize *size, const QSize& req_size) diff --git a/src/declarative/qml/qdeclarativeimageprovider.h b/src/declarative/qml/qdeclarativeimageprovider.h index e5e80f2..512724b 100644 --- a/src/declarative/qml/qdeclarativeimageprovider.h +++ b/src/declarative/qml/qdeclarativeimageprovider.h @@ -60,7 +60,8 @@ public: enum ImageType { Image, Pixmap, - Texture + Texture, + Invalid }; QDeclarativeImageProvider(ImageType type); diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index f0e999b..ef0c422 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -507,8 +507,19 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c QSize readSize; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); QDeclarativeImageProvider::ImageType imageType = ep->getImageProviderType(url); - - if (imageType == QDeclarativeImageProvider::Image) { + if (imageType == QDeclarativeImageProvider::Invalid) { + QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::Loading; + QString errorStr = QDeclarativePixmap::tr("Invalid image provider: %1").arg(url.toString()); + QImage image; + mutex.lock(); + if (!cancelled.contains(runningJob)) { + if (sgContext) + runningJob->postReply(errorCode, errorStr, readSize, sgContext->createTexture(image), sgContext); + else + runningJob->postReply(errorCode, errorStr, readSize, image); + } + mutex.unlock(); + } else if (imageType == QDeclarativeImageProvider::Image) { QImage image = ep->getImageFromProvider(url, &readSize, requestSize); QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError; QString errorStr; @@ -877,6 +888,9 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, QDeclarativeImageProvider::ImageType imageType = ep->getImageProviderType(url); switch (imageType) { + case QDeclarativeImageProvider::Invalid: + return new QDeclarativePixmapData(url, requestSize, + QDeclarativePixmap::tr("Invalid image provider: %1").arg(url.toString())); case QDeclarativeImageProvider::Texture: { QSGTexture *texture = ep->getTextureFromProvider(url, &readSize, requestSize); @@ -912,7 +926,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, } } - // no matching provider, or provider has bad image type, or provider returned null image + // provider has bad image type, or provider returned null image return new QDeclarativePixmapData(url, requestSize, QDeclarativePixmap::tr("Failed to get image from provider: %1").arg(url.toString())); } diff --git a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp index 6d35332..b7d826f 100644 --- a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp +++ b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp @@ -210,7 +210,7 @@ void tst_qdeclarativeimageprovider::fillRequestTestsData(const QString &id) QTest::newRow(QTest::toString(id + " unknown provider")) << "image://bogus/exists.png" << "" << "" << QSize() - << "file::2:1: QML Image: Failed to get image from provider: image://bogus/exists.png"; + << "file::2:1: QML Image: Invalid image provider: image://bogus/exists.png"; } void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvider *provider) @@ -350,7 +350,7 @@ void tst_qdeclarativeimageprovider::removeProvider() // remove the provider and confirm QString fileName = newImageFileName(); - QString error("file::2:1: QML Image: Failed to get image from provider: " + fileName); + QString error("file::2:1: QML Image: Invalid image provider: " + fileName); QTest::ignoreMessage(QtWarningMsg, error.toUtf8()); engine.removeImageProvider("test"); -- 1.7.2.5