33 QMutexLocker lock( &mMutex );
37 void QgsMapRendererCache::clearInternal()
51 mCachedImages.clear();
52 mConnectedLayers.clear();
55 void QgsMapRendererCache::dropUnusedConnections()
58 const QSet< QgsWeakMapLayerPointer > disconnects = mConnectedLayers.subtract( stillDepends );
68 mConnectedLayers = stillDepends;
73 QSet< QgsWeakMapLayerPointer > result;
74 QMap<QString, CacheParameters>::const_iterator it = mCachedImages.constBegin();
75 for ( ; it != mCachedImages.constEnd(); ++it )
89 QMutexLocker lock( &mMutex );
92 if ( extent == mExtent &&
108 QMutexLocker lock( &mMutex );
111 if ( extent == mExtent &&
126 QMutexLocker lock( &mMutex );
137 QMutexLocker lock( &mMutex );
139 if ( extent != mExtent || mapToPixel != mMtp )
141 auto it = mCachedImages.constFind( cacheKey );
142 if ( it != mCachedImages.constEnd() )
147 if ( it->cachedExtent == mExtent && it->cachedMtp == mMtp )
152 CacheParameters params;
153 params.cachedImage = image;
154 params.cachedExtent = extent;
155 params.cachedMtp = mapToPixel;
162 params.dependentLayers << layer;
167 mConnectedLayers << layer;
172 mCachedImages[cacheKey] = params;
177 QMutexLocker lock( &mMutex );
179 auto it = mCachedImages.constFind( cacheKey );
180 if ( it != mCachedImages.constEnd() )
182 const CacheParameters ¶ms = it.value();
183 return ( params.cachedExtent == mExtent &&
184 params.cachedMtp.transform() == mMtp.
transform() );
194 auto it = mCachedImages.constFind( cacheKey );
195 if ( it != mCachedImages.constEnd() )
197 const CacheParameters ¶ms = it.value();
200 if ( minimumScaleThreshold != 0 && mMtp.
mapUnitsPerPixel() < params.cachedMtp.mapUnitsPerPixel() * minimumScaleThreshold )
202 if ( maximumScaleThreshold != 0 && mMtp.
mapUnitsPerPixel() > params.cachedMtp.mapUnitsPerPixel() * maximumScaleThreshold )
215 QMutexLocker lock( &mMutex );
216 return mCachedImages.value( cacheKey ).cachedImage;
221 qreal x = point.
x(), y = point.
y();
223 return QPointF( x, y ) * scale;
228 QMutexLocker lock( &mMutex );
229 const CacheParameters params = mCachedImages.value( cacheKey );
231 if ( params.cachedExtent == mExtent &&
234 return params.cachedImage;
244 if ( intersection.
isNull() )
250 const QRectF targetRect( ulT.x(), ulT.y(), lrT.x() - ulT.x(), lrT.y() - ulT.y() );
253 const QPointF ulS = _transform( params.cachedMtp,
QgsPointXY( intersection.
xMinimum(), intersection.
yMaximum() ), params.cachedImage.devicePixelRatio() );
254 const QPointF lrS = _transform( params.cachedMtp,
QgsPointXY( intersection.
xMaximum(), intersection.
yMinimum() ), params.cachedImage.devicePixelRatio() );
255 const QRectF sourceRect( ulS.x(), ulS.y(), lrS.x() - ulS.x(), lrS.y() - ulS.y() );
258 QImage ret( params.cachedImage.size(), params.cachedImage.format() );
259 ret.setDevicePixelRatio( params.cachedImage.devicePixelRatio() );
260 ret.setDotsPerMeterX( params.cachedImage.dotsPerMeterX() );
261 ret.setDotsPerMeterY( params.cachedImage.dotsPerMeterY() );
262 ret.fill( Qt::transparent );
264 painter.begin( &ret );
265 painter.drawImage( targetRect, params.cachedImage, sourceRect );
273 auto it = mCachedImages.constFind( cacheKey );
274 if ( it != mCachedImages.constEnd() )
276 return _qgis_listQPointerToRaw( ( *it ).dependentLayers );
278 return QList< QgsMapLayer * >();
282 void QgsMapRendererCache::layerRequestedRepaint()
284 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
293 QMutexLocker lock( &mMutex );
296 QMap<QString, CacheParameters>::iterator it = mCachedImages.begin();
297 for ( ; it != mCachedImages.end(); )
299 if ( !it.value().dependentLayers.contains( layer ) )
305 it = mCachedImages.erase( it );
307 dropUnusedConnections();
312 QMutexLocker lock( &mMutex );
314 mCachedImages.remove( cacheKey );
315 dropUnusedConnections();