28 QMutexLocker lock( &mMutex );
32 void QgsMapRendererCache::clearInternal()
38 const auto constMConnectedLayers = mConnectedLayers;
47 mCachedImages.clear();
48 mConnectedLayers.clear();
51 void QgsMapRendererCache::dropUnusedConnections()
54 QSet< QgsWeakMapLayerPointer > disconnects = mConnectedLayers.subtract( stillDepends );
55 const auto constDisconnects = disconnects;
65 mConnectedLayers = stillDepends;
70 QSet< QgsWeakMapLayerPointer > result;
71 QMap<QString, CacheParameters>::const_iterator it = mCachedImages.constBegin();
72 for ( ; it != mCachedImages.constEnd(); ++it )
86 QMutexLocker lock( &mMutex );
89 if ( extent == mExtent &&
104 QMutexLocker lock( &mMutex );
106 CacheParameters params;
107 params.cachedImage = image;
110 const auto constDependentLayers = dependentLayers;
115 params.dependentLayers << layer;
120 mConnectedLayers << layer;
125 mCachedImages[cacheKey] = params;
130 return mCachedImages.contains( cacheKey );
135 QMutexLocker lock( &mMutex );
136 return mCachedImages.value( cacheKey ).cachedImage;
141 if ( mCachedImages.contains( cacheKey ) )
143 return _qgis_listQPointerToRaw( mCachedImages.value( cacheKey ).dependentLayers );
145 return QList< QgsMapLayer * >();
148 void QgsMapRendererCache::layerRequestedRepaint()
154 QMutexLocker lock( &mMutex );
157 QMap<QString, CacheParameters>::iterator it = mCachedImages.begin();
158 for ( ; it != mCachedImages.end(); )
160 if ( !it.value().dependentLayers.contains( layer ) )
166 it = mCachedImages.erase( it );
168 dropUnusedConnections();
173 QMutexLocker lock( &mMutex );
175 mCachedImages.remove( cacheKey );
176 dropUnusedConnections();
QList< QgsMapLayer *> dependentLayers(const QString &cacheKey) const
Returns a list of map layers on which an image in the cache depends.
A rectangle specified with double values.
Base class for all map layer types.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setCacheImage(const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers=QList< QgsMapLayer * >())
Set the cached image for a particular cacheKey.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
bool init(const QgsRectangle &extent, double scale)
Initialize cache: set new parameters and clears the cache if any parameters have changed since last i...
QImage cacheImage(const QString &cacheKey) const
Returns the cached image for the specified cacheKey.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
bool hasCacheImage(const QString &cacheKey) const
Returns true if the cache contains an image with 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.