QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
55 QgsSvgCacheEntry( const QgsSvgCacheEntry &rh ) = delete;
57 QgsSvgCacheEntry &operator=( const QgsSvgCacheEntry &rh ) = delete;
58
59 double size = 0.0; //size in pixels (cast to int for QImage)
60 double strokeWidth = 0;
61 double widthScaleFactor = 1.0;
62
64 double fixedAspectRatio = 0;
65
70 QSizeF viewboxSize;
71
72 QColor fill = Qt::black;
73 QColor stroke = Qt::black;
74 QMap<QString, QString> parameters;
75
76 std::unique_ptr< QImage > image;
77 std::unique_ptr< QPicture > picture;
78 //content (with params replaced)
79 QByteArray svgContent;
80
86 bool isMissingImage = false;
87
88 bool isEqual( const QgsAbstractContentCacheEntry *other ) const override;
89 int dataSize() const override;
90 void dump() const override;
91
92};
93
95#endif
96
118#ifdef SIP_RUN
119class CORE_EXPORT QgsSvgCache : public QgsAbstractContentCacheBase // for sip we skip to the base class and avoid the template difficulty
120{
121#else
122class CORE_EXPORT QgsSvgCache : public QgsAbstractContentCache< QgsSvgCacheEntry >
123{
124#endif
125 Q_OBJECT
126
127 public:
128
132 QgsSvgCache( QObject *parent SIP_TRANSFERTHIS = nullptr );
133
151 QImage svgAsImage( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
152 double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio = 0, bool blocking = false,
153 const QMap<QString, QString> &parameters = QMap<QString, QString>() );
154
177 QPicture svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
178 double widthScaleFactor, bool forceVectorOutput = false, double fixedAspectRatio = 0, bool blocking = false,
179 const QMap<QString, QString> &parameters = QMap<QString, QString>() );
180
199 QSizeF svgViewboxSize( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
200 double widthScaleFactor, double fixedAspectRatio = 0, bool blocking = false, const QMap<QString, QString> &parameters = QMap<QString, QString>() );
201
208 void containsParams( const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam,
209 double &defaultStrokeWidth, bool blocking = false ) const;
210
239 void containsParams( const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor,
240 bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity,
241 bool &hasStrokeParam, bool &hasDefaultStrokeColor, QColor &defaultStrokeColor,
242 bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth,
243 bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity,
244 bool blocking = false ) const SIP_PYNAME( containsParamsV3 );
245
260 QByteArray getImageData( const QString &path, bool blocking = false ) const;
261
277#ifndef SIP_RUN
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>(), bool *isMissingImage = nullptr );
280#else
281 QByteArray svgContent( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
282 double widthScaleFactor, double fixedAspectRatio = 0, bool blocking = false, const QMap<QString, QString> &parameters = QMap<QString, QString>() );
283#endif
284
285 signals:
286
291 Q_DECL_DEPRECATED void statusChanged( const QString &statusQString ) SIP_DEPRECATED;
292
297 void remoteSvgFetched( const QString &url );
298
299 protected:
300
301 bool checkReply( QNetworkReply *reply, const QString &path ) const override;
302
303 private:
304
305 void replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry, bool blocking = false );
306 void cacheImage( QgsSvgCacheEntry *entry );
307 void cachePicture( QgsSvgCacheEntry *entry, bool forceVectorOutput = false );
309 QgsSvgCacheEntry *cacheEntry( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
310 double widthScaleFactor, double fixedAspectRatio = 0, const QMap<QString, QString> &parameters = QMap<QString, QString>(), bool blocking = false, bool *isMissingImage = nullptr );
311
313 void replaceElemParams( QDomElement &elem, const QColor &fill, const QColor &stroke, double strokeWidth, const QMap<QString, QString> &parameters );
314
315 void containsElemParams( const QDomElement &elem,
316 bool &hasFillParam, bool &hasDefaultFill, QColor &defaultFill,
317 bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity,
318 bool &hasStrokeParam, bool &hasDefaultStroke, QColor &defaultStroke,
319 bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth,
320 bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity ) const SIP_PYNAME( containsParamsV3 );
321
323 double calcSizeScaleFactor( QgsSvgCacheEntry *entry, const QDomElement &docElem, QSizeF &viewboxSize ) const;
324
329 QSize sizeForImage( const QgsSvgCacheEntry &entry, QSizeF &viewBoxSize, QSizeF &scaledSize ) const;
330
334 QImage imageFromCachedPicture( const QgsSvgCacheEntry &entry ) const;
335
337 QByteArray mMissingSvg;
338
339 QByteArray mFetchingSvg;
340
341 friend class TestQgsSvgCache;
342};
343
344#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
QgsAbstractContentCacheEntry cannot be copied.
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