QGIS API Documentation
2.4.0-Chugiak
|
A cache for images / pictures derived from svg files. More...
#include <qgssvgcache.h>
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 () | |
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. More... | |
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&. More... | |
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... | |
QByteArray | getImageData (const QString &path) const |
Get image data. More... | |
Static Public Member Functions | |
static QgsSvgCache * | instance () |
Protected Member Functions | |
QgsSvgCache (QObject *parent=0) | |
protected constructor More... | |
QgsSvgCacheEntry * | insertSVG (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 | cacheImage (QgsSvgCacheEntry *entry) |
void | cachePicture (QgsSvgCacheEntry *entry, bool forceVectorOutput=false) |
QgsSvgCacheEntry * | cacheEntry (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 | trimToMaximumSize () |
Removes the least used items until the maximum size is under the limit. More... | |
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. More... | |
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. More... | |
void | printEntryList () |
For debugging. More... | |
Private Attributes | |
QMultiHash< QString, QgsSvgCacheEntry * > | mEntryLookup |
Entry pointers accessible by file name. More... | |
long | mTotalSize |
Estimated total size of all images, pictures and svgContent. More... | |
QgsSvgCacheEntry * | mLeastRecentEntry |
QgsSvgCacheEntry * | mMostRecentEntry |
QByteArray | mMissingSvg |
SVG content to be rendered if SVG file was not found. More... | |
QMutex | mMutex |
Mutex to prevent concurrent access to the class from multiple threads at once (may corrupt the entries otherwise). More... | |
Static Private Attributes | |
static const long | mMaximumSize = 20000000 |
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 73 of file qgssvgcache.h.
QgsSvgCache::~QgsSvgCache | ( | ) |
Definition at line 99 of file qgssvgcache.cpp.
References mEntryLookup.
|
protected |
|
protected |
Returns entry from cache or creates a new entry if it does not exist already.
Definition at line 439 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::fill, insertSVG(), mEntryLookup, mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, QgsSvgCacheEntry::outline, QgsSvgCacheEntry::outlineWidth, QgsSvgCacheEntry::previousEntry, qgsDoubleNear(), QgsSvgCacheEntry::rasterScaleFactor, rasterScaleFactor, QgsSvgCacheEntry::size, takeEntryFromList(), and QgsSvgCacheEntry::widthScaleFactor.
Referenced by svgAsImage(), and svgAsPicture().
|
protected |
Definition at line 357 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::image, mTotalSize, QgsSvgCacheEntry::size, and QgsSvgCacheEntry::svgContent.
Referenced by svgAsImage().
|
protected |
Definition at line 406 of file qgssvgcache.cpp.
References mTotalSize, QgsSvgCacheEntry::picture, QgsSvgCacheEntry::size, and QgsSvgCacheEntry::svgContent.
Referenced by svgAsImage(), and svgAsPicture().
|
private |
Definition at line 565 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 204 of file qgssvgcache.cpp.
References containsElemParams(), and getImageData().
Referenced by QgsSvgMarkerSymbolLayerV2::create(), QgsSVGFillSymbolLayer::setDefaultSvgParams(), and QgsSvgMarkerSymbolLayerV2::setPath().
|
privateslot |
Definition at line 736 of file qgssvgcache.cpp.
References QgsDebugMsg, statusChanged(), and tr.
Referenced by getImageData().
QByteArray QgsSvgCache::getImageData | ( | const QString & | path | ) | const |
Get image data.
Definition at line 242 of file qgssvgcache.cpp.
References downloadProgress(), QgsNetworkAccessManager::instance(), QgsMessageLog::logMessage(), mMissingSvg, QgsDebugMsg, and tr.
Referenced by containsParams(), replaceParamsAndCacheSvg(), and QgsSVGFillSymbolLayer::setSvgFilePath().
|
protected |
Creates new cache entry and returns pointer to it.
file | Absolute 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 |
size | size of cached image |
fill | color of fill |
outline | color of outline |
outlineWidth | width of outline |
widthScaleFactor | width scale factor |
rasterScaleFactor | raster scale factor |
Definition at line 172 of file qgssvgcache.cpp.
References mEntryLookup, mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, QgsSvgCacheEntry::previousEntry, replaceParamsAndCacheSvg(), QgsSymbolLayerV2Utils::symbolNameToPath(), and trimToMaximumSize().
Referenced by cacheEntry().
|
static |
Definition at line 84 of file qgssvgcache.cpp.
Referenced by QgsSVGFillSymbolLayer::applyPattern(), QgsSvgMarkerSymbolLayerV2::create(), QgsSvgMarkerSymbolLayerV2::renderPoint(), QgsSVGFillSymbolLayer::setDefaultSvgParams(), QgsSvgMarkerSymbolLayerV2::setPath(), and QgsSVGFillSymbolLayer::setSvgFilePath().
|
private |
For debugging.
Definition at line 675 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::file, mLeastRecentEntry, mTotalSize, QgsSvgCacheEntry::nextEntry, QgsDebugMsg, QgsSvgCacheEntry::rasterScaleFactor, QgsSvgCacheEntry::size, and QgsSvgCacheEntry::widthScaleFactor.
|
private |
Release memory and remove cache entry from mEntryLookup.
Definition at line 669 of file qgssvgcache.cpp.
References mEntryLookup.
|
private |
Replaces parameters in elements of a dom node and calls method for all child nodes.
Definition at line 487 of file qgssvgcache.cpp.
Referenced by replaceParamsAndCacheSvg().
|
protected |
Definition at line 221 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::file, QgsSvgCacheEntry::fill, getImageData(), mTotalSize, QgsSvgCacheEntry::outline, QgsSvgCacheEntry::outlineWidth, replaceElemParams(), and QgsSvgCacheEntry::svgContent.
Referenced by insertSVG().
|
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.
file | Absolute or relative path to SVG file. |
size | size of cached image |
fill | color of fill |
outline | color of outline |
outlineWidth | width of outline |
widthScaleFactor | width scale factor |
rasterScaleFactor | raster scale factor |
fitsInCache |
Definition at line 109 of file qgssvgcache.cpp.
References cacheEntry(), cacheImage(), cachePicture(), QgsSvgCacheEntry::image, mMaximumSize, mMutex, 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&.
file | Absolute or relative path to SVG file. |
size | size of cached image |
fill | color of fill |
outline | color of outline |
outlineWidth | width of outline |
widthScaleFactor | width scale factor |
rasterScaleFactor | raster scale factor |
forceVectorOutput |
Definition at line 154 of file qgssvgcache.cpp.
References cacheEntry(), cachePicture(), mMutex, QgsSvgCacheEntry::picture, and trimToMaximumSize().
Referenced by QgsSVGFillSymbolLayer::applyPattern(), and QgsSvgMarkerSymbolLayerV2::renderPoint().
|
protected |
Definition at line 711 of file qgssvgcache.cpp.
References mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, and QgsSvgCacheEntry::previousEntry.
Referenced by cacheEntry(), and trimToMaximumSize().
|
protected |
Removes the least used items until the maximum size is under the limit.
Definition at line 691 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::dataSize(), QgsSvgCacheEntry::file, mEntryLookup, mLeastRecentEntry, mMaximumSize, mMostRecentEntry, mTotalSize, QgsSvgCacheEntry::nextEntry, and takeEntryFromList().
Referenced by insertSVG(), svgAsImage(), and svgAsPicture().
|
private |
Entry pointers accessible by file name.
Definition at line 154 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), removeCacheEntry(), trimToMaximumSize(), and ~QgsSvgCache().
|
private |
Definition at line 160 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), printEntryList(), takeEntryFromList(), and trimToMaximumSize().
|
staticprivate |
Definition at line 164 of file qgssvgcache.h.
Referenced by svgAsImage(), and trimToMaximumSize().
|
private |
SVG content to be rendered if SVG file was not found.
Definition at line 179 of file qgssvgcache.h.
Referenced by getImageData(), and QgsSvgCache().
|
private |
Definition at line 161 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), takeEntryFromList(), and trimToMaximumSize().
|
private |
Mutex to prevent concurrent access to the class from multiple threads at once (may corrupt the entries otherwise).
Definition at line 182 of file qgssvgcache.h.
Referenced by svgAsImage(), and svgAsPicture().
|
private |
Estimated total size of all images, pictures and svgContent.
Definition at line 156 of file qgssvgcache.h.
Referenced by cacheImage(), cachePicture(), printEntryList(), replaceParamsAndCacheSvg(), and trimToMaximumSize().