Skip to content

Commit

Permalink
Merge pull request #1449 from edigonzales/master
Browse files Browse the repository at this point in the history
fixes #10520 (scale method for SVG) and #10509 (dash pattern)
  • Loading branch information
wonder-sk committed Jun 13, 2014
2 parents ea0e1b1 + b3cbefc commit c49e38c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion python/core/symbology-ng/qgsmarkersymbollayerv2.sip
Expand Up @@ -95,7 +95,8 @@ class QgsSvgMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
public:
QgsSvgMarkerSymbolLayerV2( QString name = DEFAULT_SVGMARKER_NAME,
double size = DEFAULT_SVGMARKER_SIZE,
double angle = DEFAULT_SVGMARKER_ANGLE );
double angle = DEFAULT_SVGMARKER_ANGLE,
QgsSymbolV2::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD );

// static stuff

Expand Down
16 changes: 15 additions & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -443,12 +443,26 @@ void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
QgsExpression* dashPatternExpression = expression( "customdash" );
if ( dashPatternExpression )
{

double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale );

double dashWidthDiv = mPen.widthF();
//fix dash pattern width in Qt 4.8
QStringList versionSplit = QString( qVersion() ).split( "." );
if ( versionSplit.size() > 1
&& versionSplit.at( 1 ).toInt() >= 8
&& ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 )
{
dashWidthDiv = 1.0;
}


QVector<qreal> dashVector;
QStringList dashList = dashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" );
QStringList::const_iterator dashIt = dashList.constBegin();
for ( ; dashIt != dashList.constEnd(); ++dashIt )
{
dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / mPen.widthF() );
dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv );
}
pen.setDashPattern( dashVector );
}
Expand Down
14 changes: 10 additions & 4 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -976,12 +976,13 @@ QgsMapUnitScale QgsSimpleMarkerSymbolLayerV2::mapUnitScale() const
//////////


QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2( QString name, double size, double angle )
QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2( QString name, double size, double angle, QgsSymbolV2::ScaleMethod scaleMethod )
{
mPath = QgsSymbolLayerV2Utils::symbolNameToPath( name );
mSize = size;
mAngle = angle;
mOffset = QPointF( 0, 0 );
mScaleMethod = scaleMethod;
mOutlineWidth = 1.0;
mOutlineWidthUnit = QgsSymbolV2::MM;
mFillColor = QColor( Qt::black );
Expand All @@ -994,15 +995,18 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
QString name = DEFAULT_SVGMARKER_NAME;
double size = DEFAULT_SVGMARKER_SIZE;
double angle = DEFAULT_SVGMARKER_ANGLE;

QgsSymbolV2::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD;

if ( props.contains( "name" ) )
name = props["name"];
if ( props.contains( "size" ) )
size = props["size"].toDouble();
if ( props.contains( "angle" ) )
angle = props["angle"].toDouble();

QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( name, size, angle );
if ( props.contains( "scale_method" ) )
scaleMethod = QgsSymbolLayerV2Utils::decodeScaleMethod( props["scale_method"] );

QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( name, size, angle, scaleMethod );

//we only check the svg default parameters if necessary, since it could be expensive
if ( !props.contains( "fill" ) && !props.contains( "outline" ) && !props.contains( "outline-width" ) )
Expand Down Expand Up @@ -1143,6 +1147,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re

double scaledSize = mSize;
QgsExpression* sizeExpression = expression( "size" );

bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;

if ( sizeExpression )
Expand Down Expand Up @@ -1297,6 +1302,7 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["offset_map_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( mOffsetMapUnitScale );
map["scale_method"] = QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod );
map["fill"] = mFillColor.name();
map["outline"] = mOutlineColor.name();
map["outline-width"] = QString::number( mOutlineWidth );
Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -149,7 +149,8 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
public:
QgsSvgMarkerSymbolLayerV2( QString name = DEFAULT_SVGMARKER_NAME,
double size = DEFAULT_SVGMARKER_SIZE,
double angle = DEFAULT_SVGMARKER_ANGLE );
double angle = DEFAULT_SVGMARKER_ANGLE,
QgsSymbolV2::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD );

// static stuff

Expand Down

0 comments on commit c49e38c

Please sign in to comment.