Skip to content

Commit 55727f7

Browse files
committed
Support SVG relative paths in SVG cache to enable relative data defined paths. Fixes #8883
1 parent 667e067 commit 55727f7

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "qgslogger.h"
2121
#include "qgsnetworkaccessmanager.h"
2222
#include "qgsmessagelog.h"
23+
#include "qgssymbollayerv2utils.h"
24+
2325
#include <QApplication>
2426
#include <QCoreApplication>
2527
#include <QCursor>
@@ -165,7 +167,10 @@ const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, con
165167
QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
166168
double widthScaleFactor, double rasterScaleFactor )
167169
{
168-
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( file, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
170+
// The file may be relative path (e.g. if path is data defined)
171+
QString path = QgsSymbolLayerV2Utils::symbolNameToPath( file );
172+
173+
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
169174

170175
replaceParamsAndCacheSvg( entry );
171176

src/core/symbology-ng/qgssvgcache.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class CORE_EXPORT QgsSvgCacheEntry
3232
{
3333
public:
3434
QgsSvgCacheEntry();
35+
/** Constructor.
36+
* @param file Absolute path to SVG file (relative paths are not resolved).
37+
*/
3538
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFctor, const QColor& fill, const QColor& outline );
3639
~QgsSvgCacheEntry();
3740

@@ -69,8 +72,14 @@ class CORE_EXPORT QgsSvgCache : public QObject
6972
static QgsSvgCache* instance();
7073
~QgsSvgCache();
7174

75+
/** Get SVG as QImage.
76+
* @param file Absolute or relative path to SVG file.
77+
*/
7278
const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
7379
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache );
80+
/** Get SVG as QPicture&.
81+
* @param file Absolute or relative path to SVG file.
82+
*/
7483
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
7584
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );
7685

@@ -90,7 +99,10 @@ class CORE_EXPORT QgsSvgCache : public QObject
9099
//! protected constructor
91100
QgsSvgCache( QObject * parent = 0 );
92101

93-
/**Creates new cache entry and returns pointer to it*/
102+
/**Creates new cache entry and returns pointer to it
103+
* @param file Absolute or relative path to SVG file. If the path is relative the file is searched by QgsSymbolLayerV2Utils::symbolNameToPath() in SVG paths.
104+
in settings svg/searchPathsForSVG
105+
*/
94106
QgsSvgCacheEntry* insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
95107
double widthScaleFactor, double rasterScaleFactor );
96108

src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
249249
//! Return a list of svg files at the specified directory
250250
static QStringList listSvgFilesAt( QString directory );
251251

252-
//! Get symbol's path from its name
252+
/** Get symbol's path from its name.
253+
* If the name is not absolute path the file is searched in SVG paths specified
254+
* in settings svg/searchPathsForSVG.
255+
*/
253256
static QString symbolNameToPath( QString name );
254257

255258
//! Get symbols's name from its path

0 commit comments

Comments
 (0)