src/declarative/qml/qdeclarativeimageprovider.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    57     QDeclarativeImageProvider is used to provide advanced image loading features
    57     QDeclarativeImageProvider is used to provide advanced image loading features
    58     in QML applications. It allows images in QML to be:
    58     in QML applications. It allows images in QML to be:
    59 
    59 
    60     \list
    60     \list
    61     \o Loaded using QPixmaps rather than actual image files
    61     \o Loaded using QPixmaps rather than actual image files
    62     \o Loaded asynchronously in a separate thread, if imageType() is \l ImageType::Image
    62     \o Loaded asynchronously in a separate thread, if imageType() is \l{QDeclarativeImageProvider::ImageType}{ImageType::Image}
    63     \endlist
    63     \endlist
    64 
    64 
    65     To specify that an image should be loaded by an image provider, use the
    65     To specify that an image should be loaded by an image provider, use the
    66     \bold {"image:"} scheme for the URL source of the image, followed by the 
    66     \bold {"image:"} scheme for the URL source of the image, followed by the 
    67     identifiers of the image provider and the requested image. For example:
    67     identifiers of the image provider and the requested image. For example:
    68    
    68 
    69     \qml
    69     \qml
    70     Image { source: "image://myimageprovider/image.png" }
    70     Image { source: "image://myimageprovider/image.png" }
    71     \endqml
    71     \endqml
    72 
    72 
    73     This specifies that the image should be loaded by the image provider named 
    73     This specifies that the image should be loaded by the image provider named 
    81     Here are two images. Their \c source values indicate they should be loaded by
    81     Here are two images. Their \c source values indicate they should be loaded by
    82     an image provider named "colors", and the images to be loaded are "yellow"
    82     an image provider named "colors", and the images to be loaded are "yellow"
    83     and "red", respectively:
    83     and "red", respectively:
    84 
    84 
    85     \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
    85     \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
    86  
    86 
    87     When these images are loaded by QML, it looks for a matching image provider
    87     When these images are loaded by QML, it looks for a matching image provider
    88     and calls its requestImage() or requestPixmap() method (depending on its
    88     and calls its requestImage() or requestPixmap() method (depending on its
    89     imageType()) to load the image. The method is called with the \c id 
    89     imageType()) to load the image. The method is called with the \c id 
    90     parameter set to "yellow" for the first image, and "red" for the second.
    90     parameter set to "yellow" for the first image, and "red" for the second.
    91 
    91 
   110 
   110 
   111         ...
   111         ...
   112     }
   112     }
   113     \endcode
   113     \endcode
   114 
   114 
   115     Now the images can be succesfully loaded in QML:
   115     Now the images can be successfully loaded in QML:
   116 
   116 
   117     \image imageprovider.png
   117     \image imageprovider.png
   118 
   118 
   119     A complete example is available in Qt's 
   119     A complete example is available in Qt's 
   120     \l {declarative/cppextensions/imageprovider}{examples/declarative/cppextensions/imageprovider}
   120     \l {declarative/cppextensions/imageprovider}{examples/declarative/cppextensions/imageprovider}
   134     Asynchronous loading is not supported for image providers that provide
   134     Asynchronous loading is not supported for image providers that provide
   135     QPixmap rather than QImage values, as pixmaps can only be created in the
   135     QPixmap rather than QImage values, as pixmaps can only be created in the
   136     main thread. In this case, if \l {Image::}{asynchronous} is set to 
   136     main thread. In this case, if \l {Image::}{asynchronous} is set to 
   137     \c true, the value is ignored and the image is loaded
   137     \c true, the value is ignored and the image is loaded
   138     synchronously.
   138     synchronously.
   139    
   139 
   140     \sa QDeclarativeEngine::addImageProvider()
   140     \sa QDeclarativeEngine::addImageProvider()
   141 */
   141 */
   142 
   142 
   143 /*!
   143 /*!
   144     \enum QDeclarativeImageProvider::ImageType
   144     \enum QDeclarativeImageProvider::ImageType
   159 {
   159 {
   160     d->type = type;
   160     d->type = type;
   161 }
   161 }
   162 
   162 
   163 /*!
   163 /*!
   164    \internal
   164     Destroys the QDeclarativeImageProvider
       
   165 
       
   166     \note The destructor of your derived class need to be thread safe.
   165 */
   167 */
   166 QDeclarativeImageProvider::~QDeclarativeImageProvider()
   168 QDeclarativeImageProvider::~QDeclarativeImageProvider()
   167 {
   169 {
   168     delete d;
   170     delete d;
   169 }
   171 }
   210     returned should be of that size.
   212     returned should be of that size.
   211 
   213 
   212     In all cases, \a size must be set to the original size of the image. This
   214     In all cases, \a size must be set to the original size of the image. This
   213     is used to set the \l {Item::}{width} and \l {Item::}{height} of image
   215     is used to set the \l {Item::}{width} and \l {Item::}{height} of image
   214     elements that should be automatically sized to the loaded image.
   216     elements that should be automatically sized to the loaded image.
   215 
       
   216     \note this method may be called by multiple threads, so ensure the
       
   217     implementation of this method is reentrant.
       
   218 */
   217 */
   219 QPixmap QDeclarativeImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
   218 QPixmap QDeclarativeImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
   220 {
   219 {
   221     Q_UNUSED(id);
   220     Q_UNUSED(id);
   222     Q_UNUSED(size);
   221     Q_UNUSED(size);