QGIS API Documentation  2.99.0-Master (9caa722)
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 
41 class CORE_EXPORT QgsMapRendererCache : public QObject
42 {
43  Q_OBJECT
44  public:
45 
47 
52  void clear();
53 
59  bool init( const QgsRectangle &extent, double scale );
60 
69  void setCacheImage( const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
70 
76  bool hasCacheImage( const QString &cacheKey ) const;
77 
85  QImage cacheImage( const QString &cacheKey ) const;
86 
91  QList< QgsMapLayer * > dependentLayers( const QString &cacheKey ) const;
92 
97  void clearCacheImage( const QString &cacheKey );
98 
99  private slots:
101  void layerRequestedRepaint();
102 
103  private:
104 
105  struct CacheParameters
106  {
107  QImage cachedImage;
108  QgsWeakMapLayerPointerList dependentLayers;
109  };
110 
112  void clearInternal();
113 
115  void dropUnusedConnections();
116 
117  QSet< QgsWeakMapLayerPointer > dependentLayers() const;
118 
119  mutable QMutex mMutex;
120  QgsRectangle mExtent;
121  double mScale = 0;
122 
124  QMap<QString, CacheParameters> mCachedImages;
126  QSet< QgsWeakMapLayerPointer > mConnectedLayers;
127 };
128 
129 
130 #endif // QGSMAPRENDERERCACHE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1101
This class is responsible for keeping cache of rendered images resulting from a map rendering job...