QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
50
55 void clear();
56
64 Q_DECL_DEPRECATED bool init( const QgsRectangle &extent, double scale ) SIP_DEPRECATED;
65
73 bool updateParameters( const QgsRectangle &extent, const QgsMapToPixel &mtp );
74
87 void setCacheImage( const QString &cacheKey, const QImage &image, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >() );
88
103 const QString &cacheKey, const QImage &image, const QgsRectangle &extent, const QgsMapToPixel &mapToPixel, const QList< QgsMapLayer * > &dependentLayers = QList< QgsMapLayer * >()
104 );
105
112 bool hasCacheImage( const QString &cacheKey ) const;
113
127 bool hasAnyCacheImage( const QString &cacheKey, double minimumScaleThreshold = 0, double maximumScaleThreshold = 0 ) const;
128
136 QImage cacheImage( const QString &cacheKey ) const;
137
150 QImage transformedCacheImage( const QString &cacheKey, const QgsMapToPixel &mtp ) const;
151
155 QList< QgsMapLayer * > dependentLayers( const QString &cacheKey ) const;
156
161 void clearCacheImage( const QString &cacheKey );
162
169
170 private slots:
172 void layerRequestedRepaint();
173
174 private:
175 struct CacheParameters
176 {
177 QImage cachedImage;
179 QgsRectangle cachedExtent;
180 QgsMapToPixel cachedMtp;
181 };
182
184 void clearInternal();
185
187 void dropUnusedConnections();
188
189 QSet< QgsWeakMapLayerPointer > dependentLayers() const;
190
191 mutable QMutex mMutex;
192 QgsRectangle mExtent;
193 QgsMapToPixel mMtp;
194
195 double mScale = -1.0; //DEPRECATED
196
198 QMap<QString, CacheParameters> mCachedImages;
200 QSet< QgsWeakMapLayerPointer > mConnectedLayers;
201};
202
203
204#endif // QGSMAPRENDERERCACHE_H
Base class for all map layer types.
Definition qgsmaplayer.h:83
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:113
const QString cacheKey(const QString &pathIn)
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.