QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
51  QgsImageCacheEntry( const QString &path, QSize size, bool keepAspectRatio, double opacity, double targetDpi ) ;
52 
54  QSize size;
55 
57  bool keepAspectRatio = true;
58 
60  double opacity = 1.0;
61 
63  QImage image;
64 
70  bool isMissingImage = false;
71 
77  double targetDpi = 96;
78 
79  int dataSize() const override;
80  void dump() const override;
81  bool isEqual( const QgsAbstractContentCacheEntry *other ) const override;
82 
83 };
84 
86 #endif
87 
101 #ifdef SIP_RUN
102 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCacheBase // for sip we skip to the base class and avoid the template difficulty
103 {
104 #else
105 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCache< QgsImageCacheEntry >
106 {
107 #endif
108  Q_OBJECT
109 
110  public:
111 
115  QgsImageCache( QObject *parent SIP_TRANSFERTHIS = nullptr );
116 
146 #ifndef SIP_RUN
147  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT, bool blocking = false, double targetDpi = 96, bool *isMissing = nullptr );
148 #else
149  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT, bool blocking = false, double targetDpi = 96 );
150 #endif
151 
167  QSize originalSize( const QString &path, bool blocking = false ) const;
168 
169  signals:
170 
174  void remoteImageFetched( const QString &url );
175 
176  private:
177 
178  QImage renderImage( const QString &path, QSize size, const bool keepAspectRatio, const double opacity, double targetDpi, bool &isBroken, bool blocking = false ) const;
179 
181  QByteArray mMissingSvg;
182 
183  QByteArray mFetchingSvg;
184 
185  friend class TestQgsImageCache;
186 };
187 
188 #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.
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