QGIS API Documentation 3.41.0-Master (cea29feecf2)
|
This class is responsible for keeping cache of rendered images resulting from a map rendering job. More...
#include <qgsmaprenderercache.h>
Public Member Functions | |
QgsMapRendererCache () | |
QImage | cacheImage (const QString &cacheKey) const |
Returns the cached image for the specified cacheKey. | |
void | clear () |
Invalidates the cache contents, clearing all cached images. | |
void | clearCacheImage (const QString &cacheKey) |
Removes an image from the cache with matching cacheKey. | |
QList< QgsMapLayer * > | dependentLayers (const QString &cacheKey) const |
Returns a list of map layers on which an image in the cache depends. | |
bool | hasAnyCacheImage (const QString &cacheKey, double minimumScaleThreshold=0, double maximumScaleThreshold=0) const |
Returns true if the cache contains an image with the specified cacheKey with any cache's parameters (extent and scale) | |
bool | hasCacheImage (const QString &cacheKey) const |
Returns true if the cache contains an image with the specified cacheKey that has the same extent and scale as the cache's global extent and scale. | |
Q_DECL_DEPRECATED bool | init (const QgsRectangle &extent, double scale) |
Initialize cache: sets extent and scale parameters and clears the cache if any parameters have changed since last initialization. | |
void | invalidateCacheForLayer (QgsMapLayer *layer) |
Invalidates cached images which relate to the specified map layer. | |
void | setCacheImage (const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers=QList< QgsMapLayer * >()) |
Set the cached image for a particular cacheKey, using the current cache parameters. | |
void | setCacheImageWithParameters (const QString &cacheKey, const QImage &image, const QgsRectangle &extent, const QgsMapToPixel &mapToPixel, const QList< QgsMapLayer * > &dependentLayers=QList< QgsMapLayer * >()) |
Set the cached image for a particular cacheKey, using a specific extent and mapToPixel (which may differ from the current cache parameters). | |
QImage | transformedCacheImage (const QString &cacheKey, const QgsMapToPixel &mtp) const |
Returns the cached image for the specified cacheKey transformed to the particular extent and scale. | |
bool | updateParameters (const QgsRectangle &extent, const QgsMapToPixel &mtp) |
Sets extent and scale parameters. | |
This class is responsible for keeping cache of rendered images resulting from a map rendering job.
Once a job has a rendered image stored in the cache (using setCacheImage(...)), the cache listens to repaintRequested() signals from dependent layers. If triggered, the cache removes the rendered image (and disconnects from the layers).
When user pans/zooms the canvas, the cache is also used in rendering period for particular layers between the first render update and the moment the layer actually has partially rendered something in the resulting image.
The class is thread-safe (multiple classes can access the same instance safely).
Definition at line 46 of file qgsmaprenderercache.h.
QgsMapRendererCache::QgsMapRendererCache | ( | ) |
Definition at line 26 of file qgsmaprenderercache.cpp.
QImage QgsMapRendererCache::cacheImage | ( | const QString & | cacheKey | ) | const |
Returns the cached image for the specified cacheKey.
The cacheKey usually matches the QgsMapLayer::id() which the image is a render of. Returns a null image if it is not cached.
Definition at line 213 of file qgsmaprenderercache.cpp.
void QgsMapRendererCache::clear | ( | ) |
Invalidates the cache contents, clearing all cached images.
Definition at line 31 of file qgsmaprenderercache.cpp.
void QgsMapRendererCache::clearCacheImage | ( | const QString & | cacheKey | ) |
Removes an image from the cache with matching cacheKey.
Definition at line 310 of file qgsmaprenderercache.cpp.
QList< QgsMapLayer * > QgsMapRendererCache::dependentLayers | ( | const QString & | cacheKey | ) | const |
Returns a list of map layers on which an image in the cache depends.
Definition at line 271 of file qgsmaprenderercache.cpp.
bool QgsMapRendererCache::hasAnyCacheImage | ( | const QString & | cacheKey, |
double | minimumScaleThreshold = 0 , |
||
double | maximumScaleThreshold = 0 |
||
) | const |
Returns true
if the cache contains an image with the specified cacheKey with any cache's parameters (extent and scale)
The optional minimumScaleThreshold and maximumScaleThreshold arguments can be used to specify a range of acceptable cached scales vs current cache scale parameter. E.g. if the minimumScaleThreshold is 0.5 and maximumScaleThreshold is 2.0, then only cached images with a scale between 0.5 * current cache scale and 2.0 * current cache scale will be considered.
Definition at line 192 of file qgsmaprenderercache.cpp.
bool QgsMapRendererCache::hasCacheImage | ( | const QString & | cacheKey | ) | const |
Returns true
if the cache contains an image with the specified cacheKey that has the same extent and scale as the cache's global extent and scale.
Definition at line 175 of file qgsmaprenderercache.cpp.
bool QgsMapRendererCache::init | ( | const QgsRectangle & | extent, |
double | scale | ||
) |
Initialize cache: sets extent and scale parameters and clears the cache if any parameters have changed since last initialization.
Definition at line 87 of file qgsmaprenderercache.cpp.
void QgsMapRendererCache::invalidateCacheForLayer | ( | QgsMapLayer * | layer | ) |
Invalidates cached images which relate to the specified map layer.
Definition at line 288 of file qgsmaprenderercache.cpp.
void QgsMapRendererCache::setCacheImage | ( | const QString & | cacheKey, |
const QImage & | image, | ||
const QList< QgsMapLayer * > & | dependentLayers = QList< QgsMapLayer * >() |
||
) |
Set the cached image for a particular cacheKey, using the current cache parameters.
The cacheKey usually matches the QgsMapLayer::id() which the image is a render of.
A list of dependentLayers should be passed containing all layer on which this cache image is dependent. If any of these layers triggers a repaint then the cache image will be cleared.
Definition at line 124 of file qgsmaprenderercache.cpp.
void QgsMapRendererCache::setCacheImageWithParameters | ( | const QString & | cacheKey, |
const QImage & | image, | ||
const QgsRectangle & | extent, | ||
const QgsMapToPixel & | mapToPixel, | ||
const QList< QgsMapLayer * > & | dependentLayers = QList< QgsMapLayer * >() |
||
) |
Set the cached image for a particular cacheKey, using a specific extent and mapToPixel (which may differ from the current cache parameters).
The cacheKey usually matches the QgsMapLayer::id() which the image is a render of.
A list of dependentLayers should be passed containing all layer on which this cache image is dependent. If any of these layers triggers a repaint then the cache image will be cleared.
Definition at line 135 of file qgsmaprenderercache.cpp.
QImage QgsMapRendererCache::transformedCacheImage | ( | const QString & | cacheKey, |
const QgsMapToPixel & | mtp | ||
) | const |
Returns the cached image for the specified cacheKey transformed to the particular extent and scale.
The cacheKey usually matches the QgsMapLayer::id() which the image is a render of. Returns a null image if it is not cached.
Definition at line 226 of file qgsmaprenderercache.cpp.
bool QgsMapRendererCache::updateParameters | ( | const QgsRectangle & | extent, |
const QgsMapToPixel & | mtp | ||
) |
Sets extent and scale parameters.
Definition at line 106 of file qgsmaprenderercache.cpp.