QGIS API Documentation  3.20.0-Odense (decaadbb31)
Classes | Public Member Functions | List of all members
QgsMapRendererCache Class Reference

This class is responsible for keeping cache of rendered images resulting from a map rendering job. More...

#include <qgsmaprenderercache.h>

Inheritance diagram for QgsMapRendererCache:
Inheritance graph
[legend]

Public Member Functions

 QgsMapRendererCache ()
 
QImage cacheImage (const QString &cacheKey) const
 Returns the cached image for the specified cacheKey. More...
 
void clear ()
 Invalidates the cache contents, clearing all cached images. More...
 
void clearCacheImage (const QString &cacheKey)
 Removes an image from the cache with matching cacheKey. More...
 
QList< QgsMapLayer * > dependentLayers (const QString &cacheKey) const
 Returns a list of map layers on which an image in the cache depends. More...
 
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) More...
 
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. More...
 
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. More...
 
void invalidateCacheForLayer (QgsMapLayer *layer)
 Invalidates cached images which relate to the specified map layer. More...
 
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. More...
 
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). More...
 
QImage transformedCacheImage (const QString &cacheKey, const QgsMapToPixel &mtp) const
 Returns the cached image for the specified cacheKey transformed to the particular extent and scale. More...
 
bool updateParameters (const QgsRectangle &extent, const QgsMapToPixel &mtp)
 Sets extent and scale parameters. More...
 

Detailed Description

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).

Since
QGIS 2.4

Definition at line 46 of file qgsmaprenderercache.h.

Constructor & Destructor Documentation

◆ QgsMapRendererCache()

QgsMapRendererCache::QgsMapRendererCache ( )

Definition at line 26 of file qgsmaprenderercache.cpp.

Member Function Documentation

◆ cacheImage()

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.

See also
setCacheImage()
hasCacheImage()

Definition at line 213 of file qgsmaprenderercache.cpp.

◆ clear()

void QgsMapRendererCache::clear ( )

Invalidates the cache contents, clearing all cached images.

See also
clearCacheImage()

Definition at line 31 of file qgsmaprenderercache.cpp.

◆ clearCacheImage()

void QgsMapRendererCache::clearCacheImage ( const QString &  cacheKey)

Removes an image from the cache with matching cacheKey.

See also
clear()

Definition at line 310 of file qgsmaprenderercache.cpp.

◆ dependentLayers()

QList< QgsMapLayer * > QgsMapRendererCache::dependentLayers ( const QString &  cacheKey) const

Returns a list of map layers on which an image in the cache depends.

Since
QGIS 3.0

Definition at line 271 of file qgsmaprenderercache.cpp.

◆ hasAnyCacheImage()

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.

See also
transformedCacheImage()
Since
QGIS 3.18

Definition at line 192 of file qgsmaprenderercache.cpp.

◆ hasCacheImage()

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.

See also
cacheImage()
Since
QGIS 3.0

Definition at line 175 of file qgsmaprenderercache.cpp.

◆ init()

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.

Returns
flag whether the parameters are the same as last time
Deprecated:
since QGIS 3.18 - will be removed in QGIS 4.0. Use the updateParameters() and clear()

Definition at line 87 of file qgsmaprenderercache.cpp.

◆ invalidateCacheForLayer()

void QgsMapRendererCache::invalidateCacheForLayer ( QgsMapLayer layer)

Invalidates cached images which relate to the specified map layer.

Since
QGIS 3.14

Definition at line 288 of file qgsmaprenderercache.cpp.

◆ setCacheImage()

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.

See also
setCacheImageWithParameters()
cacheImage()

Definition at line 124 of file qgsmaprenderercache.cpp.

◆ setCacheImageWithParameters()

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.

See also
cacheImage()
Since
QGIS 3.18

Definition at line 135 of file qgsmaprenderercache.cpp.

◆ transformedCacheImage()

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.

See also
hasAnyCacheImage()
Since
QGIS 3.18

Definition at line 226 of file qgsmaprenderercache.cpp.

◆ updateParameters()

bool QgsMapRendererCache::updateParameters ( const QgsRectangle extent,
const QgsMapToPixel mtp 
)

Sets extent and scale parameters.

Returns
flag whether the parameters are the same as last time
Since
QGIS 3.18

Definition at line 106 of file qgsmaprenderercache.cpp.


The documentation for this class was generated from the following files: