QGIS API Documentation  2.99.0-Master (5d67572)
Signals | Public Member Functions | Protected Member Functions | List of all members
QgsSvgCache Class Reference

A cache for images / pictures derived from svg files. More...

#include <qgssvgcache.h>

Inheritance diagram for QgsSvgCache:
Inheritance graph
[legend]

Signals

void statusChanged (const QString &statusQString)
 Emit a signal to be caught by qgisapp and display a msg on status bar. More...
 

Public Member Functions

 QgsSvgCache (QObject *parent=0)
 Constructor for QgsSvgCache. More...
 
 ~QgsSvgCache ()
 
void containsParams (const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth) const
 Tests if an svg file contains parameters for fill, stroke color, stroke width. More...
 
void containsParams (const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor, bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity, bool &hasStrokeParam, bool &hasDefaultStrokeColor, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth, bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity) const
 Tests if an svg file contains parameters for fill, stroke color, stroke width. More...
 
QByteArray getImageData (const QString &path) const
 Get image data. More...
 
QImage svgAsImage (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio=0)
 Get SVG as QImage. More...
 
QPicture svgAsPicture (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool forceVectorOutput=false, double fixedAspectRatio=0)
 Get SVG as QPicture&. More...
 
QByteArray svgContent (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0)
 Get SVG content. More...
 
QSizeF svgViewboxSize (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0)
 Calculates the viewbox size of a (possibly cached) SVG file. More...
 

Protected Member Functions

QgsSvgCacheEntrycacheEntry (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0)
 Returns entry from cache or creates a new entry if it does not exist already. More...
 
void cacheImage (QgsSvgCacheEntry *entry)
 
void cachePicture (QgsSvgCacheEntry *entry, bool forceVectorOutput=false)
 
QgsSvgCacheEntryinsertSvg (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0)
 Creates new cache entry and returns pointer to it. More...
 
void replaceParamsAndCacheSvg (QgsSvgCacheEntry *entry)
 
void takeEntryFromList (QgsSvgCacheEntry *entry)
 
void trimToMaximumSize ()
 Removes the least used items until the maximum size is under the limit. More...
 

Detailed Description

A cache for images / pictures derived from svg files.

This class supports parameter replacement in svg files according to the svg params specification (http://www.w3.org/TR/2009/WD-SVGParamPrimer-20090616/). Supported are the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g. <circle fill="param(fill-color red)" stroke="param(pen-color black)" stroke-width="param(outline-width 1)"

QgsSvgCache is not usually directly created, but rather accessed through QgsApplication::svgCache().

Definition at line 113 of file qgssvgcache.h.

Constructor & Destructor Documentation

◆ QgsSvgCache()

QgsSvgCache::QgsSvgCache ( QObject *  parent = 0)

Constructor for QgsSvgCache.

Definition at line 84 of file qgssvgcache.cpp.

◆ ~QgsSvgCache()

QgsSvgCache::~QgsSvgCache ( )

Definition at line 90 of file qgssvgcache.cpp.

Member Function Documentation

◆ cacheEntry()

QgsSvgCacheEntry * QgsSvgCache::cacheEntry ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
double  fixedAspectRatio = 0 
)
protected

Returns entry from cache or creates a new entry if it does not exist already.

Definition at line 573 of file qgssvgcache.cpp.

◆ cacheImage()

void QgsSvgCache::cacheImage ( QgsSvgCacheEntry entry)
protected

Definition at line 472 of file qgssvgcache.cpp.

◆ cachePicture()

void QgsSvgCache::cachePicture ( QgsSvgCacheEntry entry,
bool  forceVectorOutput = false 
)
protected

Definition at line 530 of file qgssvgcache.cpp.

◆ containsParams() [1/2]

void QgsSvgCache::containsParams ( const QString &  path,
bool &  hasFillParam,
QColor &  defaultFillColor,
bool &  hasStrokeParam,
QColor &  defaultStrokeColor,
bool &  hasStrokeWidthParam,
double &  defaultStrokeWidth 
) const

Tests if an svg file contains parameters for fill, stroke color, stroke width.

If yes, possible default values are returned. If there are several default values in the svg file, only the first one is considered

Definition at line 214 of file qgssvgcache.cpp.

◆ containsParams() [2/2]

void QgsSvgCache::containsParams ( const QString &  path,
bool &  hasFillParam,
bool &  hasDefaultFillParam,
QColor &  defaultFillColor,
bool &  hasFillOpacityParam,
bool &  hasDefaultFillOpacity,
double &  defaultFillOpacity,
bool &  hasStrokeParam,
bool &  hasDefaultStrokeColor,
QColor &  defaultStrokeColor,
bool &  hasStrokeWidthParam,
bool &  hasDefaultStrokeWidth,
double &  defaultStrokeWidth,
bool &  hasStrokeOpacityParam,
bool &  hasDefaultStrokeOpacity,
double &  defaultStrokeOpacity 
) const

Tests if an svg file contains parameters for fill, stroke color, stroke width.

If yes, possible default values are returned. If there are several default values in the svg file, only the first one is considered.

Parameters
pathpath to SVG file
hasFillParamwill be true if fill param present in SVG
hasDefaultFillParamwill be true if fill param has a default value specified
defaultFillColorwill be set to default fill color specified in SVG, if present
hasFillOpacityParamwill be true if fill opacity param present in SVG
hasDefaultFillOpacitywill be true if fill opacity param has a default value specified
defaultFillOpacitywill be set to default fill opacity specified in SVG, if present
hasStrokeParamwill be true if stroke param present in SVG
hasDefaultStrokeColorwill be true if stroke param has a default value specified
defaultStrokeColorwill be set to default stroke color specified in SVG, if present
hasStrokeWidthParamwill be true if stroke width param present in SVG
hasDefaultStrokeWidthwill be true if stroke width param has a default value specified
defaultStrokeWidthwill be set to default stroke width specified in SVG, if present
hasStrokeOpacityParamwill be true if stroke opacity param present in SVG
hasDefaultStrokeOpacitywill be true if stroke opacity param has a default value specified
defaultStrokeOpacitywill be set to default stroke opacity specified in SVG, if present
Note
available in Python bindings as containsParamsV3
Since
QGIS 2.14

Definition at line 234 of file qgssvgcache.cpp.

◆ getImageData()

QByteArray QgsSvgCache::getImageData ( const QString &  path) const

Get image data.

Definition at line 357 of file qgssvgcache.cpp.

◆ insertSvg()

QgsSvgCacheEntry * QgsSvgCache::insertSvg ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
double  fixedAspectRatio = 0 
)
protected

Creates new cache entry and returns pointer to it.

Parameters
pathAbsolute path to SVG file
sizesize of cached image
fillcolor of fill
strokecolor of stroke
strokeWidthwidth of stroke
widthScaleFactorwidth scale factor
fixedAspectRatiofixed aspect ratio (optional)

Definition at line 185 of file qgssvgcache.cpp.

◆ replaceParamsAndCacheSvg()

void QgsSvgCache::replaceParamsAndCacheSvg ( QgsSvgCacheEntry entry)
protected

Definition at line 272 of file qgssvgcache.cpp.

◆ statusChanged

void QgsSvgCache::statusChanged ( const QString &  statusQString)
signal

Emit a signal to be caught by qgisapp and display a msg on status bar.

◆ svgAsImage()

QImage QgsSvgCache::svgAsImage ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
bool &  fitsInCache,
double  fixedAspectRatio = 0 
)

Get SVG as QImage.

Parameters
pathAbsolute path to SVG file.
sizesize of cached image
fillcolor of fill
strokecolor of stroke
strokeWidthwidth of stroke
widthScaleFactorwidth scale factor
fitsInCache
fixedAspectRatiofixed aspect ratio (optional)

Definition at line 96 of file qgssvgcache.cpp.

◆ svgAsPicture()

QPicture QgsSvgCache::svgAsPicture ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
bool  forceVectorOutput = false,
double  fixedAspectRatio = 0 
)

Get SVG as QPicture&.

Parameters
pathAbsolute path to SVG file.
sizesize of cached image
fillcolor of fill
strokecolor of stroke
strokeWidthwidth of stroke
widthScaleFactorwidth scale factor
forceVectorOutput
fixedAspectRatiofixed aspect ratio (optional)

Definition at line 148 of file qgssvgcache.cpp.

◆ svgContent()

QByteArray QgsSvgCache::svgContent ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
double  fixedAspectRatio = 0 
)

Get SVG content.

Definition at line 166 of file qgssvgcache.cpp.

◆ svgViewboxSize()

QSizeF QgsSvgCache::svgViewboxSize ( const QString &  path,
double  size,
const QColor &  fill,
const QColor &  stroke,
double  strokeWidth,
double  widthScaleFactor,
double  fixedAspectRatio = 0 
)

Calculates the viewbox size of a (possibly cached) SVG file.

Parameters
pathAbsolute path to SVG file.
sizesize of cached image
fillcolor of fill
strokecolor of stroke
strokeWidthwidth of stroke
widthScaleFactorwidth scale factor
fixedAspectRatiofixed aspect ratio (optional)
Returns
viewbox size set in SVG file
Since
QGIS 2.14

Definition at line 176 of file qgssvgcache.cpp.

◆ takeEntryFromList()

void QgsSvgCache::takeEntryFromList ( QgsSvgCacheEntry entry)
protected

Definition at line 929 of file qgssvgcache.cpp.

◆ trimToMaximumSize()

void QgsSvgCache::trimToMaximumSize ( )
protected

Removes the least used items until the maximum size is under the limit.

Definition at line 909 of file qgssvgcache.cpp.


The documentation for this class was generated from the following files: