Skip to content

Commit

Permalink
Support SVG relative paths in SVG cache to enable relative data defin…
Browse files Browse the repository at this point in the history
…ed paths. Fixes #8883
  • Loading branch information
blazek committed Jan 26, 2014
1 parent 667e067 commit 55727f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/core/symbology-ng/qgssvgcache.cpp
Expand Up @@ -20,6 +20,8 @@
#include "qgslogger.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsmessagelog.h"
#include "qgssymbollayerv2utils.h"

#include <QApplication>
#include <QCoreApplication>
#include <QCursor>
Expand Down Expand Up @@ -165,7 +167,10 @@ const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, con
QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor )
{
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( file, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
// The file may be relative path (e.g. if path is data defined)
QString path = QgsSymbolLayerV2Utils::symbolNameToPath( file );

QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );

replaceParamsAndCacheSvg( entry );

Expand Down
14 changes: 13 additions & 1 deletion src/core/symbology-ng/qgssvgcache.h
Expand Up @@ -32,6 +32,9 @@ class CORE_EXPORT QgsSvgCacheEntry
{
public:
QgsSvgCacheEntry();
/** Constructor.
* @param file Absolute path to SVG file (relative paths are not resolved).
*/
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFctor, const QColor& fill, const QColor& outline );
~QgsSvgCacheEntry();

Expand Down Expand Up @@ -69,8 +72,14 @@ class CORE_EXPORT QgsSvgCache : public QObject
static QgsSvgCache* instance();
~QgsSvgCache();

/** Get SVG as QImage.
* @param file Absolute or relative path to SVG file.
*/
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 QPicture&.
* @param file Absolute or relative path to SVG file.
*/
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput = false );

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

/**Creates new cache entry and returns pointer to it*/
/**Creates new cache entry and returns pointer to it
* @param 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
*/
QgsSvgCacheEntry* insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor );

Expand Down
5 changes: 4 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -249,7 +249,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
//! Return a list of svg files at the specified directory
static QStringList listSvgFilesAt( QString directory );

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

//! Get symbols's name from its path
Expand Down

1 comment on commit 55727f7

@pcav
Copy link
Member

@pcav pcav commented on 55727f7 Mar 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work done for Regione Toscana - SITA (CIG ZB10C90E5A)

Please sign in to comment.