Skip to content

Commit

Permalink
Improve error message for invalid image provider name.
Browse files Browse the repository at this point in the history
Also fix broken qdeclarativeimageprovider test.
  • Loading branch information
Martin Jones committed May 12, 2011
1 parent 57828fb commit 6fe601e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativeengine.cpp
Expand Up @@ -837,7 +837,7 @@ QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProvider
locker.unlock();
if (provider)
return provider->imageType();
return static_cast<QDeclarativeImageProvider::ImageType>(-1);
return QDeclarativeImageProvider::Invalid;
}

QSGTexture *QDeclarativeEnginePrivate::getTextureFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
Expand Down
3 changes: 2 additions & 1 deletion src/declarative/qml/qdeclarativeimageprovider.h
Expand Up @@ -60,7 +60,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeImageProvider
enum ImageType {
Image,
Pixmap,
Texture
Texture,
Invalid
};

QDeclarativeImageProvider(ImageType type);
Expand Down
20 changes: 17 additions & 3 deletions src/declarative/util/qdeclarativepixmapcache.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
}
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6fe601e

Please sign in to comment.