QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
42 class CORE_EXPORT QgsMapRendererCache : public QObject
43 {
44  Q_OBJECT
45  public:
46 
48 
53  void clear();
54 
60  bool init( const QgsRectangle &extent, double scale );
61 
70  void setCacheImage( const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
71 
77  bool hasCacheImage( const QString &cacheKey ) const;
78 
86  QImage cacheImage( const QString &cacheKey ) const;
87 
92  QList< QgsMapLayer * > dependentLayers( const QString &cacheKey ) const;
93 
98  void clearCacheImage( const QString &cacheKey );
99 
100  private slots:
102  void layerRequestedRepaint();
103 
104  private:
105 
106  struct CacheParameters
107  {
108  QImage cachedImage;
109  QgsWeakMapLayerPointerList dependentLayers;
110  };
111 
113  void clearInternal();
114 
116  void dropUnusedConnections();
117 
118  QSet< QgsWeakMapLayerPointer > dependentLayers() const;
119 
120  mutable QMutex mMutex;
121  QgsRectangle mExtent;
122  double mScale = 0;
123 
125  QMap<QString, CacheParameters> mCachedImages;
127  QSet< QgsWeakMapLayerPointer > mConnectedLayers;
128 };
129 
130 
131 #endif // QGSMAPRENDERERCACHE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:1489
This class is responsible for keeping cache of rendered images resulting from a map rendering job...