QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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.
 
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.
 

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

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.

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

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:
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: