summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-12-20 04:30:27 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-12-20 04:36:15 (GMT)
commit327169a6a3fb0bac258cb878019734211a707cce (patch)
treec807253dfcbeedb358b059a63c3170f7e56348a8
parent0aeebdc851682d2afd63494ddeafa4e745ad2b72 (diff)
downloadQt-327169a6a3fb0bac258cb878019734211a707cce.zip
Qt-327169a6a3fb0bac258cb878019734211a707cce.tar.gz
Qt-327169a6a3fb0bac258cb878019734211a707cce.tar.bz2
Don't truncate image:// url strings prematurely
Url fragments and queries were being removed from the image ids passed to QDeclarativeImageProvider. Task-number: QTBUG-16195 Reviewed-by: Martin Jones
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp12
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp16
-rw-r--r--tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp46
3 files changed, 62 insertions, 12 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 201e675..cf3ea42 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -760,8 +760,10 @@ QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *s
QImage image;
QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
locker.unlock();
- if (provider)
- image = provider->requestImage(url.path().mid(1), size, req_size);
+ if (provider) {
+ QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
+ image = provider->requestImage(imageId, size, req_size);
+ }
return image;
}
@@ -771,8 +773,10 @@ QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize
QPixmap pixmap;
QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
locker.unlock();
- if (provider)
- pixmap = provider->requestPixmap(url.path().mid(1), size, req_size);
+ if (provider) {
+ QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
+ pixmap = provider->requestPixmap(imageId, size, req_size);
+ }
return pixmap;
}
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index ef31be7..e3da645 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -182,13 +182,17 @@ QDeclarativeImageProvider::ImageType QDeclarativeImageProvider::imageType() cons
Implement this method to return the image with \a id. The default
implementation returns an empty image.
+ The \a id is the requested image source, with the "image:" scheme and
+ provider identifier removed. For example, if the image \l{Image::}{source}
+ was "image://myprovider/icons/home", the given \a id would be "icons/home".
+
The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
an Image element. If \a requestedSize is a valid size, the image
returned should be of that size.
In all cases, \a size must be set to the original size of the image. This
- is used to set the \l {Item::}{width} and \l {Item::}{height} of image
- elements that should be automatically sized to the loaded image.
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of the
+ relevant \l Image if these values have not been set explicitly.
\note this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
@@ -207,13 +211,17 @@ QImage QDeclarativeImageProvider::requestImage(const QString &id, QSize *size, c
Implement this method to return the pixmap with \a id. The default
implementation returns an empty pixmap.
+ The \a id is the requested image source, with the "image:" scheme and
+ provider identifier removed. For example, if the image \l{Image::}{source}
+ was "image://myprovider/icons/home", the given \a id would be "icons/home".
+
The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
an Image element. If \a requestedSize is a valid size, the image
returned should be of that size.
In all cases, \a size must be set to the original size of the image. This
- is used to set the \l {Item::}{width} and \l {Item::}{height} of image
- elements that should be automatically sized to the loaded image.
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of the
+ relevant \l Image if these values have not been set explicitly.
*/
QPixmap QDeclarativeImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
{
diff --git a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp
index cd12e3a..5b214e6 100644
--- a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp
+++ b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp
@@ -100,6 +100,8 @@ public:
QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize)
{
+ lastImageId = id;
+
if (id == QLatin1String("no-such-file.png"))
return QImage();
@@ -114,6 +116,7 @@ public:
}
bool *deleteWatch;
+ QString lastImageId;
};
Q_DECLARE_METATYPE(TestQImageProvider*);
@@ -134,6 +137,8 @@ public:
QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
{
+ lastImageId = id;
+
if (id == QLatin1String("no-such-file.png"))
return QPixmap();
@@ -148,6 +153,7 @@ public:
}
bool *deleteWatch;
+ QString lastImageId;
};
Q_DECLARE_METATYPE(TestQPixmapProvider*);
@@ -164,22 +170,49 @@ QString tst_qdeclarativeimageprovider::newImageFileName() const
void tst_qdeclarativeimageprovider::fillRequestTestsData(const QString &id)
{
QTest::addColumn<QString>("source");
+ QTest::addColumn<QString>("imageId");
QTest::addColumn<QString>("properties");
QTest::addColumn<QSize>("size");
QTest::addColumn<QString>("error");
- QTest::newRow(QTest::toString(id + " exists")) << newImageFileName() << "" << QSize(100,100) << "";
- QTest::newRow(QTest::toString(id + " scaled")) << newImageFileName() << "sourceSize: \"80x30\"" << QSize(80,30) << "";
+ QString fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " simple test"))
+ << "image://test/" + fileName << fileName << "" << QSize(100,100) << "";
+
+ fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " url with no id"))
+ << "image://test/" + fileName << "" + fileName << "" << QSize(100,100) << "";
+
+ fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " url with path"))
+ << "image://test/test/path" + fileName << "test/path" + fileName << "" << QSize(100,100) << "";
+
+ fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " url with fragment"))
+ << "image://test/faq.html?#question13" + fileName << "faq.html?#question13" + fileName << "" << QSize(100,100) << "";
- QTest::newRow(QTest::toString(id + " missing")) << "image://test/no-such-file.png" << "" << QSize()
+ fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " url with query"))
+ << "image://test/cgi-bin/drawgraph.cgi?type=pie&color=green" + fileName << "cgi-bin/drawgraph.cgi?type=pie&color=green" + fileName
+ << "" << QSize(100,100) << "";
+
+ fileName = newImageFileName();
+ QTest::newRow(QTest::toString(id + " scaled image"))
+ << "image://test/" + fileName << fileName << "sourceSize: \"80x30\"" << QSize(80,30) << "";
+
+ QTest::newRow(QTest::toString(id + " missing"))
+ << "image://test/no-such-file.png" << "no-such-file.png" << "" << QSize(100,100)
<< "file::2:1: QML Image: Failed to get image from provider: image://test/no-such-file.png";
- QTest::newRow(QTest::toString(id + " unknown provider")) << "image://bogus/exists.png" << "" << QSize()
+
+ 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";
}
void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvider *provider)
{
QFETCH(QString, source);
+ QFETCH(QString, imageId);
QFETCH(QString, properties);
QFETCH(QSize, size);
QFETCH(QString, error);
@@ -210,6 +243,11 @@ void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvide
QTRY_VERIFY(obj->status() == QDeclarativeImage::Ready);
else
QVERIFY(obj->status() == QDeclarativeImage::Ready);
+ if (QByteArray(QTest::currentDataTag()).startsWith("qimage"))
+ QCOMPARE(static_cast<TestQImageProvider*>(provider)->lastImageId, imageId);
+ else
+ QCOMPARE(static_cast<TestQPixmapProvider*>(provider)->lastImageId, imageId);
+
QCOMPARE(obj->width(), qreal(size.width()));
QCOMPARE(obj->height(), qreal(size.height()));
QCOMPARE(obj->pixmap().width(), size.width());