QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Signals | Public Member Functions | Static 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 &theStatusQString)
 Emit a signal to be caught by qgisapp and display a msg on status bar. More...
 

Public Member Functions

 ~QgsSvgCache ()
 
void containsParams (const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasOutlineParam, QColor &defaultOutlineColor, bool &hasOutlineWidthParam, double &defaultOutlineWidth) const
 Tests if an svg file contains parameters for fill, outline color, outline width. More...
 
Q_DECL_DEPRECATED void containsParams (const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor, bool &hasOutlineParam, bool &hasDefaultOutlineColor, QColor &defaultOutlineColor, bool &hasOutlineWidthParam, bool &hasDefaultOutlineWidth, double &defaultOutlineWidth) const
 Tests if an svg file contains parameters for fill, outline color, outline width. More...
 
void containsParams (const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor, bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity, bool &hasOutlineParam, bool &hasDefaultOutlineColor, QColor &defaultOutlineColor, bool &hasOutlineWidthParam, bool &hasDefaultOutlineWidth, double &defaultOutlineWidth, bool &hasOutlineOpacityParam, bool &hasDefaultOutlineOpacity, double &defaultOutlineOpacity) const
 Tests if an svg file contains parameters for fill, outline color, outline width. More...
 
QByteArray getImageData (const QString &path) const
 Get image data. More...
 
const QImagesvgAsImage (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, bool &fitsInCache)
 Get SVG as QImage. More...
 
const QPicturesvgAsPicture (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput=false)
 Get SVG as QPicture&. More...
 
const QByteArraysvgContent (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor)
 Get SVG content. More...
 
QSizeF svgViewboxSize (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor)
 Calculates the viewbox size of a (possibly cached) SVG file. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Static Public Member Functions

static QgsSvgCacheinstance ()
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

 QgsSvgCache (QObject *parent=nullptr)
 protected constructor More...
 
QgsSvgCacheEntrycacheEntry (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor)
 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 &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor)
 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...
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

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)"

Definition at line 95 of file qgssvgcache.h.

Constructor & Destructor Documentation

◆ ~QgsSvgCache()

QgsSvgCache::~QgsSvgCache ( )

Definition at line 112 of file qgssvgcache.cpp.

◆ QgsSvgCache()

QgsSvgCache::QgsSvgCache ( QObject parent = nullptr)
protected

protected constructor

Definition at line 103 of file qgssvgcache.cpp.

Member Function Documentation

◆ cacheEntry()

QgsSvgCacheEntry * QgsSvgCache::cacheEntry ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor 
)
protected

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

Definition at line 592 of file qgssvgcache.cpp.

◆ cacheImage()

void QgsSvgCache::cacheImage ( QgsSvgCacheEntry entry)
protected

Definition at line 510 of file qgssvgcache.cpp.

◆ cachePicture()

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

Definition at line 559 of file qgssvgcache.cpp.

◆ containsParams() [1/3]

void QgsSvgCache::containsParams ( const QString path,
bool &  hasFillParam,
QColor defaultFillColor,
bool &  hasOutlineParam,
QColor defaultOutlineColor,
bool &  hasOutlineWidthParam,
double &  defaultOutlineWidth 
) const

Tests if an svg file contains parameters for fill, outline color, outline 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 232 of file qgssvgcache.cpp.

◆ containsParams() [2/3]

void QgsSvgCache::containsParams ( const QString path,
bool &  hasFillParam,
bool &  hasDefaultFillParam,
QColor defaultFillColor,
bool &  hasOutlineParam,
bool &  hasDefaultOutlineColor,
QColor defaultOutlineColor,
bool &  hasOutlineWidthParam,
bool &  hasDefaultOutlineWidth,
double &  defaultOutlineWidth 
) const

Tests if an svg file contains parameters for fill, outline color, outline 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
hasOutlineParamwill be true if outline param present in SVG
hasDefaultOutlineColorwill be true if outline param has a default value specified
defaultOutlineColorwill be set to default outline color specified in SVG, if present
hasOutlineWidthParamwill be true if outline width param present in SVG
hasDefaultOutlineWidthwill be true if outline width param has a default value specified
defaultOutlineWidthwill be set to default outline width specified in SVG, if present
Note
available in python bindings as containsParamsV2
added in QGIS 2.12
Deprecated:
use variant with fill and outline opacity

Definition at line 253 of file qgssvgcache.cpp.

◆ containsParams() [3/3]

void QgsSvgCache::containsParams ( const QString path,
bool &  hasFillParam,
bool &  hasDefaultFillParam,
QColor defaultFillColor,
bool &  hasFillOpacityParam,
bool &  hasDefaultFillOpacity,
double &  defaultFillOpacity,
bool &  hasOutlineParam,
bool &  hasDefaultOutlineColor,
QColor defaultOutlineColor,
bool &  hasOutlineWidthParam,
bool &  hasDefaultOutlineWidth,
double &  defaultOutlineWidth,
bool &  hasOutlineOpacityParam,
bool &  hasDefaultOutlineOpacity,
double &  defaultOutlineOpacity 
) const

Tests if an svg file contains parameters for fill, outline color, outline 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
hasOutlineParamwill be true if outline param present in SVG
hasDefaultOutlineColorwill be true if outline param has a default value specified
defaultOutlineColorwill be set to default outline color specified in SVG, if present
hasOutlineWidthParamwill be true if outline width param present in SVG
hasDefaultOutlineWidthwill be true if outline width param has a default value specified
defaultOutlineWidthwill be set to default outline width specified in SVG, if present
hasOutlineOpacityParamwill be true if outline opacity param present in SVG
hasDefaultOutlineOpacitywill be true if outline opacity param has a default value specified
defaultOutlineOpacitywill be set to default outline opacity specified in SVG, if present
Note
available in python bindings as containsParamsV3
added in QGIS 2.14

Definition at line 272 of file qgssvgcache.cpp.

◆ getImageData()

QByteArray QgsSvgCache::getImageData ( const QString path) const

Get image data.

Definition at line 395 of file qgssvgcache.cpp.

◆ insertSVG()

QgsSvgCacheEntry * QgsSvgCache::insertSVG ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor 
)
protected

Creates new cache entry and returns pointer to it.

Parameters
fileAbsolute or relative path to SVG file. If the path is relative the file is searched by QgsSymbolLayerV2Utils::symbolNameToPath() in SVG paths. in settings svg/searchPathsForSVG
sizesize of cached image
fillcolor of fill
outlinecolor of outline
outlineWidthwidth of outline
widthScaleFactorwidth scale factor
rasterScaleFactorraster scale factor

Definition at line 200 of file qgssvgcache.cpp.

◆ instance()

QgsSvgCache * QgsSvgCache::instance ( )
static

Definition at line 97 of file qgssvgcache.cpp.

◆ replaceParamsAndCacheSvg()

void QgsSvgCache::replaceParamsAndCacheSvg ( QgsSvgCacheEntry entry)
protected

Definition at line 310 of file qgssvgcache.cpp.

◆ statusChanged

void QgsSvgCache::statusChanged ( const QString theStatusQString)
signal

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

◆ svgAsImage()

const QImage & QgsSvgCache::svgAsImage ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor,
bool &  fitsInCache 
)

Get SVG as QImage.

Parameters
fileAbsolute or relative path to SVG file.
sizesize of cached image
fillcolor of fill
outlinecolor of outline
outlineWidthwidth of outline
widthScaleFactorwidth scale factor
rasterScaleFactorraster scale factor
fitsInCache

Definition at line 118 of file qgssvgcache.cpp.

◆ svgAsPicture()

const QPicture & QgsSvgCache::svgAsPicture ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor,
bool  forceVectorOutput = false 
)

Get SVG as QPicture&.

Parameters
fileAbsolute or relative path to SVG file.
sizesize of cached image
fillcolor of fill
outlinecolor of outline
outlineWidthwidth of outline
widthScaleFactorwidth scale factor
rasterScaleFactorraster scale factor
forceVectorOutput

Definition at line 163 of file qgssvgcache.cpp.

◆ svgContent()

const QByteArray & QgsSvgCache::svgContent ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor 
)

Get SVG content.

Definition at line 181 of file qgssvgcache.cpp.

◆ svgViewboxSize()

QSizeF QgsSvgCache::svgViewboxSize ( const QString file,
double  size,
const QColor fill,
const QColor outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor 
)

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

Parameters
fileAbsolute or relative path to SVG file.
sizesize of cached image
fillcolor of fill
outlinecolor of outline
outlineWidthwidth of outline
widthScaleFactorwidth scale factor
rasterScaleFactorraster scale factor
Returns
viewbox size set in SVG file
Note
added in QGIS 2.14

Definition at line 191 of file qgssvgcache.cpp.

◆ takeEntryFromList()

void QgsSvgCache::takeEntryFromList ( QgsSvgCacheEntry entry)
protected

Definition at line 949 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 929 of file qgssvgcache.cpp.


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