Skip to content
Permalink
Browse files

Merge pull request #4912 from dmarteau/svg-marker-size

[FEATURE][needs-docs] Svg marker size: change aspect ratio
  • Loading branch information
rldhont committed Oct 4, 2017
2 parents c764d9c + f8152c1 commit 3e45f997a6f2339b3fb20383066ebb4d19b485ed
Showing with 850 additions and 341 deletions.
  1. +68 −0 python/core/symbology/qgsmarkersymbollayer.sip
  2. +19 −7 python/core/symbology/qgssvgcache.sip
  3. +1 −0 python/core/symbology/qgssymbollayer.sip
  4. +0 −3 python/gui/symbology/qgssymbollayerwidget.sip
  5. +95 −4 src/core/symbology/qgsmarkersymbollayer.cpp
  6. +57 −0 src/core/symbology/qgsmarkersymbollayer.h
  7. +46 −18 src/core/symbology/qgssvgcache.cpp
  8. +17 −7 src/core/symbology/qgssvgcache.h
  9. +1 −0 src/core/symbology/qgssymbollayer.cpp
  10. +1 −0 src/core/symbology/qgssymbollayer.h
  11. +89 −8 src/gui/symbology/qgssymbollayerwidget.cpp
  12. +5 −4 src/gui/symbology/qgssymbollayerwidget.h
  13. +352 −288 src/ui/symbollayer/widget_svgmarker.ui
  14. +2 −2 tests/code_layout/acceptable_missing_doc.py
  15. +97 −0 tests/src/core/testqgssvgmarker.cpp
  16. BIN ...control_images/symbol_svgmarker/expected_svgmarker_aspectratio/expected_svgmarker_aspectratio.png
  17. BIN ...ol_images/symbol_svgmarker/expected_svgmarker_aspectratio/expected_svgmarker_aspectratio_mask.png
  18. BIN tests/testdata/control_images/symbol_svgmarker/expected_svgmarker_bench/expected_svgmarker_bench.png
  19. BIN ...stdata/control_images/symbol_svgmarker/expected_svgmarker_bench/expected_svgmarker_bench_mask.png
  20. BIN ...ymbol_svgmarker/expected_svgmarker_dynamic_aspectratio/expected_svgmarker_dynamic_aspectratio.png
  21. BIN ..._svgmarker/expected_svgmarker_dynamic_aspectratio/expected_svgmarker_dynamic_aspectratio_mask.png
  22. BIN ...gmarker/expected_svgmarker_dynamicsize_aspectratio/expected_svgmarker_dynamicsize_aspectratio.png
  23. BIN ...er/expected_svgmarker_dynamicsize_aspectratio/expected_svgmarker_dynamicsize_aspectratio_mask.png
  24. BIN ...arker/expected_svgmarker_dynamicwidth_aspectratio/expected_svgmarker_dynamicwidth_aspectratio.png
  25. BIN .../expected_svgmarker_dynamicwidth_aspectratio/expected_svgmarker_dynamicwidth_aspectratio_mask.png
@@ -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 );
@@ -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



};

@@ -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).
@@ -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();

@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -92,6 +92,7 @@ class QgsSymbolLayer
PropertyCharacter,
PropertyWidth,
PropertyHeight,
PropertyPreserveAspectRatio,
PropertyFillStyle,
PropertyJoinStyle,
PropertySecondaryColor,
@@ -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();

0 comments on commit 3e45f99

Please sign in to comment.
You can’t perform that action at this time.