QGIS API Documentation  3.21.0-Master (909859188c)
qgsimagecache.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsimagecache.h
3  ---------------
4  begin : December 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSIMAGECACHE_H
19 #define QGSIMAGECACHE_H
20 
22 #include "qgis_sip.h"
23 #include "qgis_core.h"
24 
25 #include <QElapsedTimer>
26 #include <QSize>
27 #include <QImage>
28 
29 #ifndef SIP_RUN
30 
32 
39 class CORE_EXPORT QgsImageCacheEntry : public QgsAbstractContentCacheEntry
40 {
41  public:
42 
49  QgsImageCacheEntry( const QString &path, QSize size, bool keepAspectRatio, double opacity ) ;
50 
52  QSize size;
53 
55  bool keepAspectRatio = true;
56 
58  double opacity = 1.0;
59 
61  QImage image;
62 
68  bool isMissingImage = false;
69 
70  int dataSize() const override;
71  void dump() const override;
72  bool isEqual( const QgsAbstractContentCacheEntry *other ) const override;
73 
74 };
75 
77 #endif
78 
92 #ifdef SIP_RUN
93 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCacheBase // for sip we skip to the base class and avoid the template difficulty
94 {
95 #else
96 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCache< QgsImageCacheEntry >
97 {
98 #endif
99  Q_OBJECT
100 
101  public:
102 
106  QgsImageCache( QObject *parent SIP_TRANSFERTHIS = nullptr );
107 
132 #ifndef SIP_RUN
133  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT, bool blocking = false, bool *isMissing = nullptr );
134 #else
135  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT, bool blocking = false );
136 #endif
137 
153  QSize originalSize( const QString &path, bool blocking = false ) const;
154 
155  signals:
156 
160  void remoteImageFetched( const QString &url );
161 
162  private:
163 
164  QImage renderImage( const QString &path, QSize size, const bool keepAspectRatio, const double opacity, bool &isBroken, bool blocking = false ) const;
165 
167  QByteArray mMissingSvg;
168 
169  QByteArray mFetchingSvg;
170 
171  friend class TestQgsImageCache;
172 };
173 
174 #endif // QGSIMAGECACHE_H
A QObject derived base class for QgsAbstractContentCache.
Base class for entries in a QgsAbstractContentCache.
virtual int dataSize() const =0
Returns the memory usage in bytes for the entry.
virtual void dump() const =0
Dumps debugging strings containing the item's properties.
virtual bool isEqual(const QgsAbstractContentCacheEntry *other) const =0
Tests whether this entry matches another entry.
Abstract base class for file content caches, such as SVG or raster image caches.
A cache for images derived from raster files.
Definition: qgsimagecache.h:97
void remoteImageFetched(const QString &url)
Emitted when the cache has finished retrieving an image file from a remote url.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_OUT
Definition: qgis_sip.h:58