QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
QgsSvgCache Class Reference

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

#include <qgssvgcache.h>

Collaboration diagram for QgsSvgCache:
Collaboration graph
[legend]

Signals

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

Public Member Functions

 ~QgsSvgCache ()
const QImage & svgAsImage (const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, bool &fitsInCache)
 Get SVG as QImage.
const QPicture & 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&.
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.
QByteArray getImageData (const QString &path) const
 Get image data.

Static Public Member Functions

static QgsSvgCacheinstance ()

Protected Member Functions

 QgsSvgCache (QObject *parent=0)
 protected constructor
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.
void replaceParamsAndCacheSvg (QgsSvgCacheEntry *entry)
void cacheImage (QgsSvgCacheEntry *entry)
void cachePicture (QgsSvgCacheEntry *entry, bool forceVectorOutput=false)
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.
void trimToMaximumSize ()
 Removes the least used items until the maximum size is under the limit.
void takeEntryFromList (QgsSvgCacheEntry *entry)

Private Slots

void downloadProgress (qint64, qint64)

Private Member Functions

void replaceElemParams (QDomElement &elem, const QColor &fill, const QColor &outline, double outlineWidth)
 Replaces parameters in elements of a dom node and calls method for all child nodes.
void containsElemParams (const QDomElement &elem, bool &hasFillParam, QColor &defaultFill, bool &hasOutlineParam, QColor &defaultOutline, bool &hasOutlineWidthParam, double &defaultOutlineWidth) const
void removeCacheEntry (QString s, QgsSvgCacheEntry *entry)
 Release memory and remove cache entry from mEntryLookup.
void printEntryList ()
 For debugging.

Private Attributes

QMultiHash< QString,
QgsSvgCacheEntry * > 
mEntryLookup
 Entry pointers accessible by file name.
long mTotalSize
 Estimated total size of all images, pictures and svgContent.
QgsSvgCacheEntrymLeastRecentEntry
QgsSvgCacheEntrymMostRecentEntry
QByteArray mMissingSvg
 SVG content to be rendered if SVG file was not found.

Static Private Attributes

static const long mMaximumSize = 20000000

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 72 of file qgssvgcache.h.

Constructor & Destructor Documentation

QgsSvgCache::~QgsSvgCache ( )

Definition at line 99 of file qgssvgcache.cpp.

References mEntryLookup.

QgsSvgCache::QgsSvgCache ( QObject *  parent = 0)
protected

protected constructor

Definition at line 90 of file qgssvgcache.cpp.

References mMissingSvg.

Member Function Documentation

QgsSvgCacheEntry * QgsSvgCache::cacheEntry ( const QString &  file,
double  size,
const QColor &  fill,
const QColor &  outline,
double  outlineWidth,
double  widthScaleFactor,
double  rasterScaleFactor 
)
protected
void QgsSvgCache::cacheImage ( QgsSvgCacheEntry entry)
protected
void QgsSvgCache::cachePicture ( QgsSvgCacheEntry entry,
bool  forceVectorOutput = false 
)
protected
void QgsSvgCache::containsElemParams ( const QDomElement &  elem,
bool &  hasFillParam,
QColor &  defaultFill,
bool &  hasOutlineParam,
QColor &  defaultOutline,
bool &  hasOutlineWidthParam,
double &  defaultOutlineWidth 
) const
private

Definition at line 572 of file qgssvgcache.cpp.

Referenced by containsParams().

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 200 of file qgssvgcache.cpp.

References containsElemParams(), and getImageData().

Referenced by QgsSvgMarkerSymbolLayerV2::create(), QgsSVGFillSymbolLayer::setDefaultSvgParams(), and QgsSvgMarkerSymbolLayerV2::setPath().

void QgsSvgCache::downloadProgress ( qint64  bytesReceived,
qint64  bytesTotal 
)
privateslot

Definition at line 743 of file qgssvgcache.cpp.

References QgsDebugMsg, statusChanged(), and tr.

Referenced by getImageData().

QByteArray QgsSvgCache::getImageData ( const QString &  path) const
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 168 of file qgssvgcache.cpp.

References mEntryLookup, mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, QgsSvgCacheEntry::previousEntry, replaceParamsAndCacheSvg(), QgsSymbolLayerV2Utils::symbolNameToPath(), and trimToMaximumSize().

Referenced by cacheEntry().

QgsSvgCache * QgsSvgCache::instance ( )
static
void QgsSvgCache::printEntryList ( )
private
void QgsSvgCache::removeCacheEntry ( QString  s,
QgsSvgCacheEntry entry 
)
private

Release memory and remove cache entry from mEntryLookup.

Definition at line 676 of file qgssvgcache.cpp.

References mEntryLookup.

void QgsSvgCache::replaceElemParams ( QDomElement &  elem,
const QColor &  fill,
const QColor &  outline,
double  outlineWidth 
)
private

Replaces parameters in elements of a dom node and calls method for all child nodes.

Definition at line 494 of file qgssvgcache.cpp.

Referenced by replaceParamsAndCacheSvg().

void QgsSvgCache::replaceParamsAndCacheSvg ( QgsSvgCacheEntry entry)
protected
void QgsSvgCache::statusChanged ( const QString &  theStatusQString)
signal

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

Referenced by downloadProgress().

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 109 of file qgssvgcache.cpp.

References cacheEntry(), cacheImage(), cachePicture(), QgsSvgCacheEntry::image, mMaximumSize, QgsSvgCacheEntry::picture, QgsSvgCacheEntry::size, QgsSvgCacheEntry::svgContent, and trimToMaximumSize().

Referenced by QgsSVGFillSymbolLayer::applyPattern(), and QgsSvgMarkerSymbolLayerV2::renderPoint().

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 152 of file qgssvgcache.cpp.

References cacheEntry(), cachePicture(), QgsSvgCacheEntry::picture, and trimToMaximumSize().

Referenced by QgsSVGFillSymbolLayer::applyPattern(), and QgsSvgMarkerSymbolLayerV2::renderPoint().

void QgsSvgCache::takeEntryFromList ( QgsSvgCacheEntry entry)
protected
void QgsSvgCache::trimToMaximumSize ( )
protected

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

Definition at line 698 of file qgssvgcache.cpp.

References QgsSvgCacheEntry::dataSize(), QgsSvgCacheEntry::file, mEntryLookup, mLeastRecentEntry, mMaximumSize, mMostRecentEntry, mTotalSize, QgsSvgCacheEntry::nextEntry, and takeEntryFromList().

Referenced by insertSVG(), svgAsImage(), and svgAsPicture().

Member Data Documentation

QMultiHash< QString, QgsSvgCacheEntry* > QgsSvgCache::mEntryLookup
private

Entry pointers accessible by file name.

Definition at line 153 of file qgssvgcache.h.

Referenced by cacheEntry(), insertSVG(), removeCacheEntry(), trimToMaximumSize(), and ~QgsSvgCache().

QgsSvgCacheEntry* QgsSvgCache::mLeastRecentEntry
private
const long QgsSvgCache::mMaximumSize = 20000000
staticprivate

Definition at line 163 of file qgssvgcache.h.

Referenced by svgAsImage(), and trimToMaximumSize().

QByteArray QgsSvgCache::mMissingSvg
private

SVG content to be rendered if SVG file was not found.

Definition at line 178 of file qgssvgcache.h.

Referenced by getImageData(), and QgsSvgCache().

QgsSvgCacheEntry* QgsSvgCache::mMostRecentEntry
private

Definition at line 160 of file qgssvgcache.h.

Referenced by cacheEntry(), insertSVG(), takeEntryFromList(), and trimToMaximumSize().

long QgsSvgCache::mTotalSize
private

Estimated total size of all images, pictures and svgContent.

Definition at line 155 of file qgssvgcache.h.

Referenced by cacheImage(), cachePicture(), printEntryList(), replaceParamsAndCacheSvg(), and trimToMaximumSize().


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