summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2017-02-06 09:37:13 +0100
committerAlbert Astals Cid <albert.astals@canonical.com>2017-02-08 10:07:41 +0000
commitade0ed7fa9ad06a1dc1312e7abad8baf20f7b756 (patch)
treec0d32c4ba0191e17eb6729c9104cc644b799f0a0
parent6cfeabe92db25a10812a657f7f4fdadfb505204d (diff)
Improve QQuickAsyncImageProvider example
Also link it from more places Change-Id: Ib5fbf89f4a039f885e918d57ee477e9788049d8d Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
-rw-r--r--examples/quick/imageresponseprovider/imageresponseprovider.cpp16
-rw-r--r--src/quick/util/qquickimageprovider.cpp4
2 files changed, 12 insertions, 8 deletions
diff --git a/examples/quick/imageresponseprovider/imageresponseprovider.cpp b/examples/quick/imageresponseprovider/imageresponseprovider.cpp
index a888c823a6..d4633b779a 100644
--- a/examples/quick/imageresponseprovider/imageresponseprovider.cpp
+++ b/examples/quick/imageresponseprovider/imageresponseprovider.cpp
@@ -51,37 +51,37 @@ class AsyncImageResponse : public QQuickImageResponse, public QRunnable
{
public:
AsyncImageResponse(const QString &id, const QSize &requestedSize)
- : m_id(id), m_requestedSize(requestedSize), m_texture(0)
+ : m_id(id), m_requestedSize(requestedSize)
{
setAutoDelete(false);
}
QQuickTextureFactory *textureFactory() const
{
- return m_texture;
+ return QQuickTextureFactory::textureFactoryForImage(m_image);
}
void run()
{
- QImage image(50, 50, QImage::Format_RGB32);
+ m_image = QImage(50, 50, QImage::Format_RGB32);
if (m_id == "slow") {
qDebug() << "Slow, red, sleeping for 5 seconds";
QThread::sleep(5);
- image.fill(Qt::red);
+ m_image.fill(Qt::red);
} else {
qDebug() << "Fast, blue, sleeping for 1 second";
QThread::sleep(1);
- image.fill(Qt::blue);
+ m_image.fill(Qt::blue);
}
if (m_requestedSize.isValid())
- image = image.scaled(m_requestedSize);
- m_texture = QQuickTextureFactory::textureFactoryForImage(image);
+ m_image = m_image.scaled(m_requestedSize);
+
emit finished();
}
QString m_id;
QSize m_requestedSize;
- QQuickTextureFactory *m_texture;
+ QImage m_image;
};
class AsyncImageProvider : public QQuickAsyncImageProvider
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp
index 0c245d2b23..d2a8a5097c 100644
--- a/src/quick/util/qquickimageprovider.cpp
+++ b/src/quick/util/qquickimageprovider.cpp
@@ -158,6 +158,8 @@ QQuickTextureFactory *QQuickTextureFactory::textureFactoryForImage(const QImage
If you are using QRunnable as base for your QQuickImageResponse
ensure automatic deletion is disabled.
+ See the \l {imageresponseprovider}{Image Response Provider Example} for a complete implementation.
+
\sa QQuickImageProvider
*/
@@ -472,6 +474,8 @@ QQuickTextureFactory *QQuickImageProvider::requestTexture(const QString &id, QSi
\inmodule QtQuick
\brief The QQuickAsyncImageProvider class provides an interface for for asynchronous control of QML image requests.
+ See the \l {imageresponseprovider}{Image Response Provider Example} for a complete implementation.
+
\sa QQuickImageProvider
*/
QQuickAsyncImageProvider::QQuickAsyncImageProvider()