Skip to content

Commit

Permalink
Merge pull request #4912 from dmarteau/svg-marker-size
Browse files Browse the repository at this point in the history
[FEATURE][needs-docs] Svg marker size: change aspect ratio
  • Loading branch information
rldhont committed Oct 4, 2017
2 parents c764d9c + f8152c1 commit 3e45f99
Show file tree
Hide file tree
Showing 25 changed files with 850 additions and 341 deletions.
68 changes: 68 additions & 0 deletions python/core/symbology/qgsmarkersymbollayer.sip
Expand Up @@ -522,9 +522,64 @@ Constructs SVG marker symbol layer with picture from given absolute path to a SV

QString path() const;
%Docstring
Returns the marker SVG path.
.. seealso:: setPath()
:rtype: str
%End

void setPath( const QString &path );
%Docstring
Set the marker SVG path.
\param path SVG path
.. seealso:: path()
%End

double defaultAspectRatio() const;
%Docstring
Returns the default marker aspect ratio between width and height, 0 if not yet calculated.
.. seealso:: updateDefaultAspectRatio()
:rtype: float
%End

double updateDefaultAspectRatio();
%Docstring
Calculates the default marker aspect ratio between width and height.
:return: the default aspect ratio value
.. seealso:: defaultAspectRatio()
:rtype: float
%End

bool preservedAspectRatio() const;
%Docstring
Returns the preserved aspect ratio value, true if fixed aspect ratio has been lower or equal to 0.
.. seealso:: setPreservedAspectRatio()
:rtype: bool
%End

bool setPreservedAspectRatio( bool par );
%Docstring
Set preserved the marker aspect ratio between width and height.
\param par Preserved Aspect Ratio
:return: the preserved aspect ratio value, true if fixed aspect ratio has been lower or equal to 0
.. seealso:: preservedAspectRatio()
:rtype: bool
%End

double fixedAspectRatio() const;
%Docstring
Returns the marker aspect ratio between width and height to be used in rendering,
if the value set is lower or equal to 0 the aspect ratio will be preserved in rendering
.. seealso:: setFixedAspectRatio() QgsSvgCache
:rtype: float
%End

void setFixedAspectRatio( double ratio );
%Docstring
Set the marker aspect ratio between width and height to be used in rendering,
if the value set is lower or equal to 0 the aspect ratio will be preserved in rendering
\param ratio Fixed Aspect Ratio
.. seealso:: fixedAspectRatio() QgsSvgCache
%End

virtual QColor fillColor() const;
virtual void setFillColor( const QColor &color );
Expand Down Expand Up @@ -576,6 +631,19 @@ Constructs SVG marker symbol layer with picture from given absolute path to a SV

protected:

double calculateAspectRatio( QgsSymbolRenderContext &context, double scaledSize, bool &hasDataDefinedAspectRatio ) const;
%Docstring
Calculates the marker aspect ratio between width and height.
\param context symbol render context
\param scaledSize size of symbol to render
\param hasDataDefinedAspectRatio will be set to true if marker has data defined aspectRatio
.. note::

not available in Python bindings
:rtype: float
%End



};

Expand Down
26 changes: 19 additions & 7 deletions python/core/symbology/qgssvgcache.sip
Expand Up @@ -18,9 +18,11 @@ class QgsSvgCacheEntry
#include "qgssvgcache.h"
%End
public:

QgsSvgCacheEntry();

QgsSvgCacheEntry( const QString &path, double size, double strokeWidth, double widthScaleFactor, const QColor &fill, const QColor &stroke );
QgsSvgCacheEntry( const QString &path, double size, double strokeWidth, double widthScaleFactor, const QColor &fill, const QColor &stroke,
double fixedAspectRatio = 0 ) ;
%Docstring
Constructor.
\param path Absolute path to SVG file (relative paths are not resolved).
Expand All @@ -29,6 +31,7 @@ class QgsSvgCacheEntry
\param widthScaleFactor width scale factor
\param fill color of fill
\param stroke color of stroke
\param fixedAspectRatio fixed aspect ratio (optional)
%End
~QgsSvgCacheEntry();

Expand All @@ -41,6 +44,11 @@ Absolute path to SVG file
double strokeWidth;
double widthScaleFactor;

double fixedAspectRatio;
%Docstring
Fixed aspect ratio
%End

QSizeF viewboxSize;
%Docstring
SVG viewbox size.
Expand Down Expand Up @@ -91,7 +99,7 @@ the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g.
~QgsSvgCache();

QImage svgAsImage( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor, bool &fitsInCache );
double widthScaleFactor, bool &fitsInCache, double fixedAspectRatio = 0 );
%Docstring
Get SVG as QImage.
\param path Absolute path to SVG file.
Expand All @@ -101,11 +109,12 @@ the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g.
\param strokeWidth width of stroke
\param widthScaleFactor width scale factor
\param fitsInCache
\param fixedAspectRatio fixed aspect ratio (optional)
:rtype: QImage
%End

QPicture svgAsPicture( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor, bool forceVectorOutput = false );
double widthScaleFactor, bool forceVectorOutput = false, double fixedAspectRatio = 0 );
%Docstring
Get SVG as QPicture&.
\param path Absolute path to SVG file.
Expand All @@ -115,11 +124,12 @@ the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g.
\param strokeWidth width of stroke
\param widthScaleFactor width scale factor
\param forceVectorOutput
\param fixedAspectRatio fixed aspect ratio (optional)
:rtype: QPicture
%End

QSizeF svgViewboxSize( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor );
double widthScaleFactor, double fixedAspectRatio = 0 );
%Docstring
Calculates the viewbox size of a (possibly cached) SVG file.
\param path Absolute path to SVG file.
Expand All @@ -128,6 +138,7 @@ the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g.
\param stroke color of stroke
\param strokeWidth width of stroke
\param widthScaleFactor width scale factor
\param fixedAspectRatio fixed aspect ratio (optional)
:return: viewbox size set in SVG file
.. versionadded:: 2.14
:rtype: QSizeF
Expand Down Expand Up @@ -177,7 +188,7 @@ Get image data
%End

QByteArray svgContent( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor );
double widthScaleFactor, double fixedAspectRatio = 0 );
%Docstring
Get SVG content
:rtype: QByteArray
Expand All @@ -192,7 +203,7 @@ Emit a signal to be caught by qgisapp and display a msg on status bar
protected:

QgsSvgCacheEntry *insertSvg( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor );
double widthScaleFactor, double fixedAspectRatio = 0 );
%Docstring
Creates new cache entry and returns pointer to it
\param path Absolute path to SVG file
Expand All @@ -201,14 +212,15 @@ Emit a signal to be caught by qgisapp and display a msg on status bar
\param stroke color of stroke
\param strokeWidth width of stroke
\param widthScaleFactor width scale factor
\param fixedAspectRatio fixed aspect ratio (optional)
:rtype: QgsSvgCacheEntry
%End

void replaceParamsAndCacheSvg( QgsSvgCacheEntry *entry );
void cacheImage( QgsSvgCacheEntry *entry );
void cachePicture( QgsSvgCacheEntry *entry, bool forceVectorOutput = false );
QgsSvgCacheEntry *cacheEntry( const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth,
double widthScaleFactor );
double widthScaleFactor, double fixedAspectRatio = 0 );
%Docstring
Returns entry from cache or creates a new entry if it does not exist already
:rtype: QgsSvgCacheEntry
Expand Down
1 change: 1 addition & 0 deletions python/core/symbology/qgssymbollayer.sip
Expand Up @@ -92,6 +92,7 @@ class QgsSymbolLayer
PropertyCharacter,
PropertyWidth,
PropertyHeight,
PropertyPreserveAspectRatio,
PropertyFillStyle,
PropertyJoinStyle,
PropertySecondaryColor,
Expand Down
3 changes: 0 additions & 3 deletions python/gui/symbology/qgssymbollayerwidget.sip
Expand Up @@ -364,9 +364,6 @@ class QgsSvgMarkerSymbolLayerWidget : QgsSymbolLayerWidget
public slots:
void setName( const QModelIndex &idx );
void populateIcons( const QModelIndex &idx );
void setSize();
void setAngle();
void setOffset();
void on_mFileToolButton_clicked();
void on_mFileLineEdit_textEdited( const QString &text );
void on_mFileLineEdit_editingFinished();
Expand Down

0 comments on commit 3e45f99

Please sign in to comment.