QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgssvgcache.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssvgcache.h
3 ------------------------------
4 begin : 2011
5 copyright : (C) 2011 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
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 QGSSVGCACHE_H
19#define QGSSVGCACHE_H
20
22#include "qgis.h"
23
24#include <QPicture>
25
26class QDomElement;
27
28#ifndef SIP_RUN
29
31
36class CORE_EXPORT QgsSvgCacheEntry : public QgsAbstractContentCacheEntry
37{
38 public:
39
51 QgsSvgCacheEntry( const QString &path, double size, double strokeWidth, double widthScaleFactor, const QColor &fill, const QColor &stroke,
52 double fixedAspectRatio = 0, const QMap<QString, QString> &parameters = QMap<QString, QString>() ) ;
53
54 QgsSvgCacheEntry( const QgsSvgCacheEntry &rh ) = delete;
55 QgsSvgCacheEntry &operator=( const QgsSvgCacheEntry &rh ) = delete;
56
57 double size = 0.0; //size in pixels (cast to int for QImage)
58 double strokeWidth = 0;
59 double widthScaleFactor = 1.0;
60
62 double fixedAspectRatio = 0;
63
67 QSizeF viewboxSize;
68
69 QColor fill = Qt::black;
70 QColor stroke = Qt::black;
71 QMap<QString, QString> parameters;
72
73 std::unique_ptr< QImage > image;
74 std::unique_ptr< QPicture > picture;
75 //content (with params replaced)
76 QByteArray svgContent;
77
83 bool isMissingImage = false;
84
85 bool isEqual( const QgsAbstractContentCacheEntry *other ) const override;
86 int dataSize() const override;
87 void dump() const override;
88
89};
90
92#endif
93
117#ifdef SIP_RUN
118class CORE_EXPORT QgsSvgCache : public QgsAbstractContentCacheBase // for sip we skip to the base class and avoid the template difficulty
119{
120#else
121class CORE_EXPORT QgsSvgCache : public QgsAbstractContentCache< QgsSvgCacheEntry >
122{
123#endif
124 Q_OBJECT
125
126 public:
127
131 QgsSvgCache( QObject *parent SIP_TRANSFERTHIS = nullptr );
132
150 QImage svgAsImage( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
151 double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio = 0, bool blocking = false,
152 const QMap<QString, QString> &parameters = QMap<QString, QString>() );
153
176 QPicture svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
177 double widthScaleFactor, bool forceVectorOutput = false, double fixedAspectRatio = 0, bool blocking = false,
178 const QMap<QString, QString> &parameters = QMap<QString, QString>() );
179
197 QSizeF svgViewboxSize( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
198 double widthScaleFactor, double fixedAspectRatio = 0, bool blocking = false, const QMap<QString, QString> &parameters = QMap<QString, QString>() );
199
206 void containsParams( const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam,
207 double &defaultStrokeWidth, bool blocking = false ) const;
208
236 void containsParams( const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor,
237 bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity,
238 bool &hasStrokeParam, bool &hasDefaultStrokeColor, QColor &defaultStrokeColor,
239 bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth,
240 bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity,
241 bool blocking = false ) const SIP_PYNAME( containsParamsV3 );
242
257 QByteArray getImageData( const QString &path, bool blocking = false ) const;
258
274#ifndef SIP_RUN
275 QByteArray svgContent( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
276 double widthScaleFactor, double fixedAspectRatio = 0, bool blocking = false, const QMap<QString, QString> &parameters = QMap<QString, QString>(), bool *isMissingImage = nullptr );
277#else
278 QByteArray svgContent( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
279 double widthScaleFactor, double fixedAspectRatio = 0, bool blocking = false, const QMap<QString, QString> &parameters = QMap<QString, QString>() );
280#endif
281
282 signals:
283
288 Q_DECL_DEPRECATED void statusChanged( const QString &statusQString ) SIP_DEPRECATED;
289
294 void remoteSvgFetched( const QString &url );
295
296 protected:
297
298 bool checkReply( QNetworkReply *reply, const QString &path ) const override;
299
300 private:
301
302 void replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry, bool blocking = false );
303 void cacheImage( QgsSvgCacheEntry *entry );
304 void cachePicture( QgsSvgCacheEntry *entry, bool forceVectorOutput = false );
306 QgsSvgCacheEntry *cacheEntry( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
307 double widthScaleFactor, double fixedAspectRatio = 0, const QMap<QString, QString> &parameters = QMap<QString, QString>(), bool blocking = false, bool *isMissingImage = nullptr );
308
310 void replaceElemParams( QDomElement &elem, const QColor &fill, const QColor &stroke, double strokeWidth, const QMap<QString, QString> &parameters );
311
312 void containsElemParams( const QDomElement &elem,
313 bool &hasFillParam, bool &hasDefaultFill, QColor &defaultFill,
314 bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity,
315 bool &hasStrokeParam, bool &hasDefaultStroke, QColor &defaultStroke,
316 bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth,
317 bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity ) const SIP_PYNAME( containsParamsV3 );
318
320 double calcSizeScaleFactor( QgsSvgCacheEntry *entry, const QDomElement &docElem, QSizeF &viewboxSize ) const;
321
326 QSize sizeForImage( const QgsSvgCacheEntry &entry, QSizeF &viewBoxSize, QSizeF &scaledSize ) const;
327
331 QImage imageFromCachedPicture( const QgsSvgCacheEntry &entry ) const;
332
334 QByteArray mMissingSvg;
335
336 QByteArray mFetchingSvg;
337
338 friend class TestQgsSvgCache;
339};
340
341#endif // QGSSVGCACHE_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.
QgsAbstractContentCacheEntry & operator=(const QgsAbstractContentCacheEntry &rh)=delete
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 / pictures derived from SVG files.
Q_DECL_DEPRECATED void statusChanged(const QString &statusQString)
Emit a signal to be caught by qgisapp and display a msg on status bar.
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_PYNAME(name)
Definition qgis_sip.h:81