Subgroup: Svg

Class: QgsSvgCache

class qgis.core.QgsSvgCache

Bases: PyQt5.QtCore.QObject

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

Methods

blockSignals
childEvent
children
connectNotify
containsParams Tests if an svg file contains parameters for fill, stroke color, stroke width.
containsParamsV3 Tests if an svg file contains parameters for fill, stroke color, stroke width.
customEvent
deleteLater
disconnect
disconnectNotify
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
event
eventFilter
findChild findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject
findChildren findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject]
getImageData Get image data
inherits
installEventFilter
isSignalConnected
isWidgetType
isWindowType
killTimer
metaObject
moveToThread
objectName
parent
property
pyqtConfigure Each keyword argument is either the name of a Qt property or a Qt signal.
receivers
removeEventFilter
sender
senderSignalIndex
setObjectName
setParent
setProperty
signalsBlocked
startTimer
svgAsImage Get SVG as QImage.
svgAsPicture Get SVG as QPicture&.
svgContent Get SVG content
svgViewboxSize Calculates the viewbox size of a (possibly cached) SVG file.
thread
timerEvent
tr

Attributes

destroyed destroyed(self, QObject = None) [signal]
objectNameChanged objectNameChanged(self, str) [signal]
staticMetaObject
statusChanged Emit a signal to be caught by qgisapp and display a msg on status bar [signal]
childEvent()
connectNotify()
containsParams(self, path: str, defaultFillColor: Union[QColor, Qt.GlobalColor], defaultStrokeColor: Union[QColor, Qt.GlobalColor]) → Tuple[bool, bool, bool, float]

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*

containsParamsV3(self, path: str, defaultFillColor: Union[QColor, Qt.GlobalColor], defaultStrokeColor: Union[QColor, Qt.GlobalColor]) → Tuple[bool, bool, bool, bool, float, bool, bool, bool, bool, float, bool, bool, float]

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:
  • path – path to SVG file
  • hasFillParam – will be true if fill param present in SVG
  • hasDefaultFillParam – will be true if fill param has a default value specified
  • defaultFillColor – will be set to default fill color specified in SVG, if present
  • hasFillOpacityParam – will be true if fill opacity param present in SVG
  • hasDefaultFillOpacity – will be true if fill opacity param has a default value specified
  • defaultFillOpacity – will be set to default fill opacity specified in SVG, if present
  • hasStrokeParam – will be true if stroke param present in SVG
  • hasDefaultStrokeColor – will be true if stroke param has a default value specified
  • defaultStrokeColor – will be set to default stroke color specified in SVG, if present
  • hasStrokeWidthParam – will be true if stroke width param present in SVG
  • hasDefaultStrokeWidth – will be true if stroke width param has a default value specified
  • defaultStrokeWidth – will be set to default stroke width specified in SVG, if present
  • hasStrokeOpacityParam – will be true if stroke opacity param present in SVG
  • hasDefaultStrokeOpacity – will be true if stroke opacity param has a default value specified
  • defaultStrokeOpacity – will be set to default stroke opacity specified in SVG, if present

Note

available in Python bindings as containsParamsV3

New in version 2.14.

customEvent()
disconnectNotify()
getImageData(self, path: str) → QByteArray

Get image data

isSignalConnected()
receivers()
sender()
senderSignalIndex()
statusChanged

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

svgAsImage(self, path: str, size: float, fill: Union[QColor, Qt.GlobalColor], stroke: Union[QColor, Qt.GlobalColor], strokeWidth: float, widthScaleFactor: float, fixedAspectRatio: float = 0) → Tuple[QImage, bool]

Get SVG as QImage.

Parameters:
  • path – Absolute path to SVG file.
  • size – size of cached image
  • fill – color of fill
  • stroke – color of stroke
  • strokeWidth – width of stroke
  • widthScaleFactor – width scale factor
  • fitsInCache
  • fixedAspectRatio – fixed aspect ratio (optional)
svgAsPicture(self, path: str, size: float, fill: Union[QColor, Qt.GlobalColor], stroke: Union[QColor, Qt.GlobalColor], strokeWidth: float, widthScaleFactor: float, forceVectorOutput: bool = False, fixedAspectRatio: float = 0) → QPicture

Get SVG as QPicture&.

Parameters:
  • path – Absolute path to SVG file.
  • size – size of cached image
  • fill – color of fill
  • stroke – color of stroke
  • strokeWidth – width of stroke
  • widthScaleFactor – width scale factor
  • forceVectorOutput
  • fixedAspectRatio – fixed aspect ratio (optional)
svgContent(self, path: str, size: float, fill: Union[QColor, Qt.GlobalColor], stroke: Union[QColor, Qt.GlobalColor], strokeWidth: float, widthScaleFactor: float, fixedAspectRatio: float = 0) → QByteArray

Get SVG content

svgViewboxSize(self, path: str, size: float, fill: Union[QColor, Qt.GlobalColor], stroke: Union[QColor, Qt.GlobalColor], strokeWidth: float, widthScaleFactor: float, fixedAspectRatio: float = 0) → QSizeF

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

Parameters:
  • path – Absolute path to SVG file.
  • size – size of cached image
  • fill – color of fill
  • stroke – color of stroke
  • strokeWidth – width of stroke
  • widthScaleFactor – width scale factor
  • fixedAspectRatio – fixed aspect ratio (optional)
Returns:

viewbox size set in SVG file

New in version 2.14.

timerEvent()