QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 "qgsmaplayer.h"
21#include "qgsmaptopixel.h"
22#include "qgsrectangle.h"
23
24#include <QImage>
25#include <QMap>
26#include <QMutex>
27
45class CORE_EXPORT QgsMapRendererCache : public QObject
46{
47 Q_OBJECT
48 public:
49
51
56 void clear();
57
65 Q_DECL_DEPRECATED bool init( const QgsRectangle &extent, double scale ) SIP_DEPRECATED;
66
74 bool updateParameters( const QgsRectangle &extent, const QgsMapToPixel &mtp );
75
88 void setCacheImage( const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
89
103 void setCacheImageWithParameters( const QString &cacheKey,
104 const QImage &image,
105 const QgsRectangle &extent,
106 const QgsMapToPixel &mapToPixel,
107 const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
108
115 bool hasCacheImage( const QString &cacheKey ) const;
116
130 bool hasAnyCacheImage( const QString &cacheKey, double minimumScaleThreshold = 0, double maximumScaleThreshold = 0 ) const;
131
139 QImage cacheImage( const QString &cacheKey ) const;
140
153 QImage transformedCacheImage( const QString &cacheKey, const QgsMapToPixel &mtp ) const;
154
158 QList< QgsMapLayer * > dependentLayers( const QString &cacheKey ) const;
159
164 void clearCacheImage( const QString &cacheKey );
165
172
173 private slots:
175 void layerRequestedRepaint();
176
177 private:
178
179 struct CacheParameters
180 {
181 QImage cachedImage;
183 QgsRectangle cachedExtent;
184 QgsMapToPixel cachedMtp;
185 };
186
188 void clearInternal();
189
191 void dropUnusedConnections();
192
193 QSet< QgsWeakMapLayerPointer > dependentLayers() const;
194
195 mutable QMutex mMutex;
196 QgsRectangle mExtent;
197 QgsMapToPixel mMtp;
198
199 double mScale = -1.0; //DEPRECATED
200
202 QMap<QString, CacheParameters> mCachedImages;
204 QSet< QgsWeakMapLayerPointer > mConnectedLayers;
205};
206
207
208#endif // QGSMAPRENDERERCACHE_H
Base class for all map layer types.
Definition qgsmaplayer.h:80
bool updateParameters(const QgsRectangle &extent, const QgsMapToPixel &mtp)
Sets extent and scale parameters.
QList< QgsMapLayer * > dependentLayers(const QString &cacheKey) const
Returns a list of map layers on which an image in the cache depends.
void clear()
Invalidates the cache contents, clearing all cached images.
bool hasCacheImage(const QString &cacheKey) const
Returns true if the cache contains an image with the specified cacheKey that has the same extent and ...
QImage cacheImage(const QString &cacheKey) const
Returns the cached image for the specified cacheKey.
bool hasAnyCacheImage(const QString &cacheKey, double minimumScaleThreshold=0, double maximumScaleThreshold=0) const
Returns true if the cache contains an image with the specified cacheKey with any cache's parameters (...
void setCacheImageWithParameters(const QString &cacheKey, const QImage &image, const QgsRectangle &extent, const QgsMapToPixel &mapToPixel, const QList< QgsMapLayer * > &dependentLayers=QList< QgsMapLayer * >())
Set the cached image for a particular cacheKey, using a specific extent and mapToPixel (which may dif...
void setCacheImage(const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers=QList< QgsMapLayer * >())
Set the cached image for a particular cacheKey, using the current cache parameters.
void invalidateCacheForLayer(QgsMapLayer *layer)
Invalidates cached images which relate to the specified map layer.
void clearCacheImage(const QString &cacheKey)
Removes an image from the cache with matching cacheKey.
QImage transformedCacheImage(const QString &cacheKey, const QgsMapToPixel &mtp) const
Returns the cached image for the specified cacheKey transformed to the particular extent and scale.
Q_DECL_DEPRECATED bool init(const QgsRectangle &extent, double scale)
Initialize cache: sets extent and scale parameters and clears the cache if any parameters have change...
Perform transforms between map coordinates and device coordinates.
A rectangle specified with double values.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.