Quantum GIS API Documentation
1.8
|
A cache for images / pictures derived from svg files. More...
#include <qgssvgcache.h>
Public Member Functions | |
~QgsSvgCache () | |
const QImage & | svgAsImage (const QString &file, int size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor) |
const QPicture & | svgAsPicture (const QString &file, int size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor) |
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. | |
Static Public Member Functions | |
static QgsSvgCache * | instance () |
Protected Member Functions | |
QgsSvgCache () | |
QgsSvgCacheEntry * | insertSVG (const QString &file, int 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) |
QgsSvgCacheEntry * | cacheEntry (const QString &file, int 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 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. | |
QgsSvgCacheEntry * | mLeastRecentEntry |
QgsSvgCacheEntry * | mMostRecentEntry |
Static Private Attributes | |
static QgsSvgCache * | mInstance = 0 |
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 61 of file qgssvgcache.h.
Definition at line 88 of file qgssvgcache.cpp.
References mEntryLookup.
QgsSvgCache::QgsSvgCache | ( | ) | [protected] |
Definition at line 84 of file qgssvgcache.cpp.
Referenced by instance().
QgsSvgCacheEntry * QgsSvgCache::cacheEntry | ( | const QString & | file, |
int | 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 254 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::file, QgsSvgCacheEntry::fill, insertSVG(), mEntryLookup, mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, QgsSvgCacheEntry::outline, QgsSvgCacheEntry::outlineWidth, QgsSvgCacheEntry::previousEntry, QgsSvgCacheEntry::rasterScaleFactor, QgsSvgCacheEntry::size, takeEntryFromList(), and QgsSvgCacheEntry::widthScaleFactor.
Referenced by svgAsImage(), and svgAsPicture().
void QgsSvgCache::cacheImage | ( | QgsSvgCacheEntry * | entry | ) | [protected] |
Definition at line 209 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::image, mTotalSize, QgsSvgCacheEntry::size, and QgsSvgCacheEntry::svgContent.
Referenced by svgAsImage().
void QgsSvgCache::cachePicture | ( | QgsSvgCacheEntry * | entry | ) | [protected] |
Definition at line 231 of file qgssvgcache.cpp.
References mTotalSize, QgsSvgCacheEntry::picture, QgsSvgCacheEntry::rasterScaleFactor, QgsSvgCacheEntry::size, QgsSvgCacheEntry::svgContent, and QgsSvgCacheEntry::widthScaleFactor.
Referenced by svgAsPicture().
void QgsSvgCache::containsElemParams | ( | const QDomElement & | elem, |
bool & | hasFillParam, | ||
QColor & | defaultFill, | ||
bool & | hasOutlineParam, | ||
QColor & | defaultOutline, | ||
bool & | hasOutlineWidthParam, | ||
double & | defaultOutlineWidth | ||
) | const [private] |
Definition at line 380 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 159 of file qgssvgcache.cpp.
References containsElemParams().
Referenced by QgsSvgMarkerSymbolLayerV2::create(), QgsSVGFillSymbolLayer::setDefaultSvgParams(), and QgsSvgMarkerSymbolLayerV2::setPath().
QgsSvgCacheEntry * QgsSvgCache::insertSVG | ( | const QString & | file, |
int | size, | ||
const QColor & | fill, | ||
const QColor & | outline, | ||
double | outlineWidth, | ||
double | widthScaleFactor, | ||
double | rasterScaleFactor | ||
) | [protected] |
Creates new cache entry and returns pointer to it.
Definition at line 130 of file qgssvgcache.cpp.
References mEntryLookup, mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, QgsSvgCacheEntry::previousEntry, replaceParamsAndCacheSvg(), and trimToMaximumSize().
Referenced by cacheEntry().
QgsSvgCache * QgsSvgCache::instance | ( | ) | [static] |
Definition at line 75 of file qgssvgcache.cpp.
References mInstance, and QgsSvgCache().
Referenced by QgsSvgMarkerSymbolLayerV2::create(), QgsSvgMarkerSymbolLayerV2::renderPoint(), QgsSVGFillSymbolLayer::setDefaultSvgParams(), QgsSvgMarkerSymbolLayerV2::setPath(), and QgsSVGFillSymbolLayer::startRender().
void QgsSvgCache::printEntryList | ( | ) | [private] |
For debugging.
Definition at line 490 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::file, mLeastRecentEntry, mTotalSize, QgsSvgCacheEntry::nextEntry, QgsDebugMsg, QgsSvgCacheEntry::rasterScaleFactor, QgsSvgCacheEntry::size, and QgsSvgCacheEntry::widthScaleFactor.
void QgsSvgCache::removeCacheEntry | ( | QString | s, |
QgsSvgCacheEntry * | entry | ||
) | [private] |
Release memory and remove cache entry from mEntryLookup.
Definition at line 484 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 302 of file qgssvgcache.cpp.
Referenced by replaceParamsAndCacheSvg().
void QgsSvgCache::replaceParamsAndCacheSvg | ( | QgsSvgCacheEntry * | entry | ) | [protected] |
Definition at line 182 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::file, QgsSvgCacheEntry::fill, mTotalSize, QgsSvgCacheEntry::outline, QgsSvgCacheEntry::outlineWidth, replaceElemParams(), and QgsSvgCacheEntry::svgContent.
Referenced by insertSVG().
const QImage & QgsSvgCache::svgAsImage | ( | const QString & | file, |
int | size, | ||
const QColor & | fill, | ||
const QColor & | outline, | ||
double | outlineWidth, | ||
double | widthScaleFactor, | ||
double | rasterScaleFactor | ||
) |
Definition at line 98 of file qgssvgcache.cpp.
References cacheEntry(), cacheImage(), QgsSvgCacheEntry::image, and trimToMaximumSize().
Referenced by QgsSvgMarkerSymbolLayerV2::renderPoint(), and QgsSVGFillSymbolLayer::startRender().
const QPicture & QgsSvgCache::svgAsPicture | ( | const QString & | file, |
int | size, | ||
const QColor & | fill, | ||
const QColor & | outline, | ||
double | outlineWidth, | ||
double | widthScaleFactor, | ||
double | rasterScaleFactor | ||
) |
Definition at line 114 of file qgssvgcache.cpp.
References cacheEntry(), cachePicture(), QgsSvgCacheEntry::picture, and trimToMaximumSize().
Referenced by QgsSvgMarkerSymbolLayerV2::renderPoint().
void QgsSvgCache::takeEntryFromList | ( | QgsSvgCacheEntry * | entry | ) | [protected] |
Definition at line 521 of file qgssvgcache.cpp.
References mLeastRecentEntry, mMostRecentEntry, QgsSvgCacheEntry::nextEntry, and QgsSvgCacheEntry::previousEntry.
Referenced by cacheEntry(), and trimToMaximumSize().
void QgsSvgCache::trimToMaximumSize | ( | ) | [protected] |
Removes the least used items until the maximum size is under the limit.
Definition at line 506 of file qgssvgcache.cpp.
References QgsSvgCacheEntry::dataSize(), QgsSvgCacheEntry::file, mEntryLookup, mLeastRecentEntry, mMaximumSize, mTotalSize, QgsSvgCacheEntry::nextEntry, and takeEntryFromList().
Referenced by insertSVG(), svgAsImage(), and svgAsPicture().
QMultiHash< QString, QgsSvgCacheEntry* > QgsSvgCache::mEntryLookup [private] |
Entry pointers accessible by file name.
Definition at line 102 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), removeCacheEntry(), trimToMaximumSize(), and ~QgsSvgCache().
QgsSvgCache * QgsSvgCache::mInstance = 0 [static, private] |
Definition at line 99 of file qgssvgcache.h.
Referenced by instance().
QgsSvgCacheEntry* QgsSvgCache::mLeastRecentEntry [private] |
Definition at line 108 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), printEntryList(), takeEntryFromList(), and trimToMaximumSize().
const long QgsSvgCache::mMaximumSize = 20000000 [static, private] |
Definition at line 112 of file qgssvgcache.h.
Referenced by trimToMaximumSize().
QgsSvgCacheEntry* QgsSvgCache::mMostRecentEntry [private] |
Definition at line 109 of file qgssvgcache.h.
Referenced by cacheEntry(), insertSVG(), and takeEntryFromList().
long QgsSvgCache::mTotalSize [private] |
Estimated total size of all images, pictures and svgContent.
Definition at line 104 of file qgssvgcache.h.
Referenced by cacheImage(), cachePicture(), printEntryList(), replaceParamsAndCacheSvg(), and trimToMaximumSize().