QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
|
A cache for images / pictures derived from SVG files. More...
#include <qgssvgcache.h>
Signals | |
void | remoteSvgFetched (const QString &url) |
Emitted when the cache has finished retrieving an SVG file from a remote url. | |
Q_DECL_DEPRECATED void | statusChanged (const QString &statusQString) |
Emit a signal to be caught by qgisapp and display a msg on status bar. | |
![]() | |
void | remoteContentFetched (const QString &url) |
Emitted when the cache has finished retrieving content from a remote url. | |
Public Member Functions | |
QgsSvgCache (QObject *parent=nullptr) | |
Constructor for QgsSvgCache. | |
void | containsParams (const QString &path, bool &hasFillParam, bool &hasDefaultFillParam, QColor &defaultFillColor, bool &hasFillOpacityParam, bool &hasDefaultFillOpacity, double &defaultFillOpacity, bool &hasStrokeParam, bool &hasDefaultStrokeColor, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, bool &hasDefaultStrokeWidth, double &defaultStrokeWidth, bool &hasStrokeOpacityParam, bool &hasDefaultStrokeOpacity, double &defaultStrokeOpacity, bool blocking=false) const |
Tests if an SVG file contains parameters for fill, stroke color, stroke width. | |
void | containsParams (const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const |
Tests if an SVG file contains parameters for fill, stroke color, stroke width. | |
QByteArray | getImageData (const QString &path, bool blocking=false) const |
Gets the SVG content corresponding to the given path. | |
QImage | svgAsImage (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >()) |
Returns an SVG drawing as a QImage. | |
QPicture | svgAsPicture (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, bool forceVectorOutput=false, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >()) |
Returns an SVG drawing as a QPicture. | |
QByteArray | svgContent (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >(), bool *isMissingImage=nullptr) |
Gets the SVG content corresponding to the given path. | |
QSizeF | svgViewboxSize (const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >()) |
Calculates the viewbox size of a (possibly cached) SVG file. | |
![]() | |
QgsAbstractContentCache (QObject *parent=nullptr, const QString &typeString=QString(), long maxCacheSize=20000000, int fileModifiedCheckTimeout=30000) | |
Constructor for QgsAbstractContentCache, with the specified parent object. | |
~QgsAbstractContentCache () override | |
![]() | |
QgsAbstractContentCacheBase (QObject *parent) | |
Constructor for QgsAbstractContentCacheBase, with the specified parent object. | |
Protected Member Functions | |
bool | checkReply (QNetworkReply *reply, const QString &path) const override |
Runs additional checks on a network reply to ensure that the reply content is consistent with that required by the cache. | |
![]() | |
QgsSvgCacheEntry * | findExistingEntry (QgsSvgCacheEntry *entryTemplate) |
Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when done), or if no existing entry is found then entryTemplate is transferred to the cache and returned. | |
QByteArray | getContent (const QString &path, const QByteArray &missingContent, const QByteArray &fetchingContent, bool blocking=false) const |
Gets the file content corresponding to the given path. | |
void | onRemoteContentFetched (const QString &url, bool success) override |
Triggered after remote content (i.e. | |
void | trimToMaximumSize () |
Removes the least used cache entries until the maximum cache size is under the predefined size limit. | |
bool | waitForTaskFinished (QgsNetworkContentFetcherTask *task) const |
Blocks the current thread until the task finishes (or user's preset network timeout expires) | |
Friends | |
class | TestQgsSvgCache |
Additional Inherited Members | |
![]() | |
![]() | |
long | mMaxCacheSize |
Maximum cache size. | |
QRecursiveMutex | mMutex |
long | mTotalSize |
Estimated total size of all cached content. | |
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 parameters are:
E.g:
<circle fill="param(fill-color red)" stroke="param(pen-color black)" stroke-width="param(outline-width 1)"
Definition at line 121 of file qgssvgcache.h.
QgsSvgCache::QgsSvgCache | ( | QObject * | parent = nullptr | ) |
Constructor for QgsSvgCache.
Definition at line 102 of file qgssvgcache.cpp.
|
overrideprotectedvirtual |
Runs additional checks on a network reply to ensure that the reply content is consistent with that required by the cache.
Reimplemented from QgsAbstractContentCacheBase.
Definition at line 406 of file qgssvgcache.cpp.
void QgsSvgCache::containsParams | ( | const QString & | path, |
bool & | hasFillParam, | ||
bool & | hasDefaultFillParam, | ||
QColor & | defaultFillColor, | ||
bool & | hasFillOpacityParam, | ||
bool & | hasDefaultFillOpacity, | ||
double & | defaultFillOpacity, | ||
bool & | hasStrokeParam, | ||
bool & | hasDefaultStrokeColor, | ||
QColor & | defaultStrokeColor, | ||
bool & | hasStrokeWidthParam, | ||
bool & | hasDefaultStrokeWidth, | ||
double & | defaultStrokeWidth, | ||
bool & | hasStrokeOpacityParam, | ||
bool & | hasDefaultStrokeOpacity, | ||
double & | defaultStrokeOpacity, | ||
bool | blocking = false |
||
) | const |
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.
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 |
blocking | forces to wait for loading before returning image (optional). |
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 249 of file qgssvgcache.cpp.
void QgsSvgCache::containsParams | ( | const QString & | path, |
bool & | hasFillParam, | ||
QColor & | defaultFillColor, | ||
bool & | hasStrokeParam, | ||
QColor & | defaultStrokeColor, | ||
bool & | hasStrokeWidthParam, | ||
double & | defaultStrokeWidth, | ||
bool | blocking = false |
||
) | const |
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. Blocking forces to wait for loading before returning image (optional). WARNING: the blocking parameter must NEVER be true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.
Definition at line 228 of file qgssvgcache.cpp.
QByteArray QgsSvgCache::getImageData | ( | const QString & | path, |
bool | blocking = false |
||
) | const |
Gets the SVG content corresponding to the given path.
path may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).
The class default missingContent byte array is returned if the path could not be resolved or is broken. If the path corresponds to a remote URL, then class default fetchingContent will be returned while the content is in the process of being fetched. The blocking boolean forces to wait for loading before returning result. The content is loaded in the same thread to ensure provided the remote content.
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 401 of file qgssvgcache.cpp.
|
signal |
Emitted when the cache has finished retrieving an SVG file from a remote url.
|
signal |
Emit a signal to be caught by qgisapp and display a msg on status bar.
QImage QgsSvgCache::svgAsImage | ( | const QString & | path, |
double | size, | ||
const QColor & | fill, | ||
const QColor & | stroke, | ||
double | strokeWidth, | ||
double | widthScaleFactor, | ||
bool & | fitsInCache, | ||
double | fixedAspectRatio = 0 , |
||
bool | blocking = false , |
||
const QMap< QString, QString > & | parameters = QMap<QString, QString>() |
||
) |
Returns an SVG drawing as a QImage.
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) |
blocking | forces to wait for loading before returning image (optional). |
parameters | is a map of parameters to dynamically replace content in SVG. |
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 125 of file qgssvgcache.cpp.
QPicture QgsSvgCache::svgAsPicture | ( | const QString & | path, |
double | size, | ||
const QColor & | fill, | ||
const QColor & | stroke, | ||
double | strokeWidth, | ||
double | widthScaleFactor, | ||
bool | forceVectorOutput = false , |
||
double | fixedAspectRatio = 0 , |
||
bool | blocking = false , |
||
const QMap< QString, QString > & | parameters = QMap<QString, QString>() |
||
) |
Returns an SVG drawing as a QPicture.
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) |
blocking | forces to wait for loading before returning image (optional) |
parameters | is a map of parameters to dynamically replace content in SVG. |
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 185 of file qgssvgcache.cpp.
QByteArray QgsSvgCache::svgContent | ( | const QString & | path, |
double | size, | ||
const QColor & | fill, | ||
const QColor & | stroke, | ||
double | strokeWidth, | ||
double | widthScaleFactor, | ||
double | fixedAspectRatio = 0 , |
||
bool | blocking = false , |
||
const QMap< QString, QString > & | parameters = QMap<QString, QString>() , |
||
bool * | isMissingImage = nullptr |
||
) |
Gets the SVG content corresponding to the given path.
path may be a local file, remote (HTTP) url, or a base 64 encoded string (with a "base64:" prefix).
The parameters size, strokeWidth for width of stroke, widthScaleFactor for width scale factor, fill for color of fill, stroke for color of stroke and fixedAspectRatio for fixed aspect ratio (optional) are needed to get the entry from cache or creates a new entry if it does not exist already.
The blocking boolean forces to wait for loading before returning image. The content is loaded in the same thread to ensure provided the image.
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 209 of file qgssvgcache.cpp.
QSizeF QgsSvgCache::svgViewboxSize | ( | const QString & | path, |
double | size, | ||
const QColor & | fill, | ||
const QColor & | stroke, | ||
double | strokeWidth, | ||
double | widthScaleFactor, | ||
double | fixedAspectRatio = 0 , |
||
bool | blocking = false , |
||
const QMap< QString, QString > & | parameters = QMap<QString, QString>() |
||
) |
Calculates the viewbox size of a (possibly cached) SVG file.
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) |
blocking | forces to wait for loading before returning image (optional). |
parameters | is a map of parameters to dynamically replace content in SVG. |
true
from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server. Definition at line 219 of file qgssvgcache.cpp.
|
friend |
Definition at line 338 of file qgssvgcache.h.