QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
63  int dataSize() const override;
64  void dump() const override;
65  bool isEqual( const QgsAbstractContentCacheEntry *other ) const override;
66 
67 };
68 
70 #endif
71 
85 #ifdef SIP_RUN
86 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCacheBase // for sip we skip to the base class and avoid the template difficulty
87 {
88 #else
89 class CORE_EXPORT QgsImageCache : public QgsAbstractContentCache< QgsImageCacheEntry >
90 {
91 #endif
92  Q_OBJECT
93 
94  public:
95 
99  QgsImageCache( QObject *parent SIP_TRANSFERTHIS = nullptr );
100 
125  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT, bool blocking = false );
126 
142  QSize originalSize( const QString &path, bool blocking = false ) const;
143 
144  signals:
145 
149  void remoteImageFetched( const QString &url );
150 
151  private:
152 
153  QImage renderImage( const QString &path, QSize size, const bool keepAspectRatio, const double opacity, bool blocking = false ) const;
154 
156  QByteArray mMissingSvg;
157 
158  QByteArray mFetchingSvg;
159 
160  friend class TestQgsImageCache;
161 };
162 
163 #endif // QGSIMAGECACHE_H
Abstract base class for file content caches, such as SVG or raster image caches.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Base class for entries in a QgsAbstractContentCache.
virtual int dataSize() const =0
Returns the memory usage in bytes for the entry.
virtual bool isEqual(const QgsAbstractContentCacheEntry *other) const =0
Tests whether this entry matches another entry.
virtual void dump() const =0
Dumps debugging strings containing the item&#39;s properties.
#define SIP_OUT
Definition: qgis_sip.h:58
A cache for images derived from raster files.
Definition: qgsimagecache.h:89
A QObject derived base class for QgsAbstractContentCache.