QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
120  QImage pathAsImage( const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache SIP_OUT );
121 
132  QSize originalSize( const QString &path ) const;
133 
134  signals:
135 
139  void remoteImageFetched( const QString &url );
140 
141  private:
142 
143  QImage renderImage( const QString &path, QSize size, const bool keepAspectRatio, const double opacity ) const;
144 
146  QByteArray mMissingSvg;
147 
148  QByteArray mFetchingSvg;
149 
150  friend class TestQgsImageCache;
151 };
152 
153 #endif // QGSIMAGECACHE_H
Abstract base class for file content caches, such as SVG or raster image caches.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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:51
A cache for images derived from raster files.
Definition: qgsimagecache.h:89
A QObject derived base class for QgsAbstractContentCache.