QGIS API Documentation  3.21.0-Master (56b4176581)
qgsmaprenderercache.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaprenderercache.h
3  --------------------------------------
4  Date : December 2013
5  Copyright : (C) 2013 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPRENDERERCACHE_H
17 #define QGSMAPRENDERERCACHE_H
18 
19 #include "qgis_core.h"
20 #include <QMap>
21 #include <QImage>
22 #include <QMutex>
23 
24 #include "qgsrectangle.h"
25 #include "qgsmaplayer.h"
26 
27 
46 class CORE_EXPORT QgsMapRendererCache : public QObject
47 {
48  Q_OBJECT
49  public:
50 
52 
57  void clear();
58 
66  Q_DECL_DEPRECATED bool init( const QgsRectangle &extent, double scale ) SIP_DEPRECATED;
67 
75  bool updateParameters( const QgsRectangle &extent, const QgsMapToPixel &mtp );
76 
89  void setCacheImage( const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
90 
104  void setCacheImageWithParameters( const QString &cacheKey,
105  const QImage &image,
106  const QgsRectangle &extent,
107  const QgsMapToPixel &mapToPixel,
108  const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
109 
117  bool hasCacheImage( const QString &cacheKey ) const;
118 
132  bool hasAnyCacheImage( const QString &cacheKey, double minimumScaleThreshold = 0, double maximumScaleThreshold = 0 ) const;
133 
141  QImage cacheImage( const QString &cacheKey ) const;
142 
155  QImage transformedCacheImage( const QString &cacheKey, const QgsMapToPixel &mtp ) const;
156 
161  QList< QgsMapLayer * > dependentLayers( const QString &cacheKey ) const;
162 
167  void clearCacheImage( const QString &cacheKey );
168 
174  void invalidateCacheForLayer( QgsMapLayer *layer );
175 
176  private slots:
178  void layerRequestedRepaint();
179 
180  private:
181 
182  struct CacheParameters
183  {
184  QImage cachedImage;
185  QgsWeakMapLayerPointerList dependentLayers;
186  QgsRectangle cachedExtent;
187  QgsMapToPixel cachedMtp;
188  };
189 
191  void clearInternal();
192 
194  void dropUnusedConnections();
195 
196  QSet< QgsWeakMapLayerPointer > dependentLayers() const;
197 
198  mutable QMutex mMutex;
199  QgsRectangle mExtent;
200  QgsMapToPixel mMtp;
201 
202  double mScale = -1.0; //DEPRECATED
203 
205  QMap<QString, CacheParameters> mCachedImages;
207  QSet< QgsWeakMapLayerPointer > mConnectedLayers;
208 };
209 
210 
211 #endif // QGSMAPRENDERERCACHE_H
Base class for all map layer types.
Definition: qgsmaplayer.h:72
This class is responsible for keeping cache of rendered images resulting from a map rendering job.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2135