diff --git a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp index 3116eb2f16d..04b5bec128d 100644 --- a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp @@ -1,7 +1,7 @@ #include "qgsfillsymbollayerv2.h" +#include "qgsmarkersymbollayerv2.h" #include "qgssymbollayerv2utils.h" -#include "qgsapplication.h" #include "qgsrendercontext.h" #include "qgsproject.h" @@ -10,7 +10,7 @@ #include QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth ) - : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth ) + : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth ) { mColor = color; } @@ -25,17 +25,17 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH; QPointF offset; - if ( props.contains( "color" ) ) + if( props.contains( "color" ) ) color = QgsSymbolLayerV2Utils::decodeColor( props["color"] ); - if ( props.contains( "style" ) ) + if( props.contains( "style" ) ) style = QgsSymbolLayerV2Utils::decodeBrushStyle( props["style"] ); - if ( props.contains( "color_border" ) ) + if( props.contains( "color_border" ) ) borderColor = QgsSymbolLayerV2Utils::decodeColor( props["color_border"] ); - if ( props.contains( "style_border" ) ) + if( props.contains( "style_border" ) ) borderStyle = QgsSymbolLayerV2Utils::decodePenStyle( props["style_border"] ); - if ( props.contains( "width_border" ) ) + if( props.contains( "width_border" ) ) borderWidth = props["width_border"].toDouble(); - if ( props.contains( "offset" ) ) + if( props.contains( "offset" ) ) offset = QgsSymbolLayerV2Utils::decodePoint( props["offset"] ); QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth ); @@ -56,7 +56,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context // scale brush content for printout double rasterScaleFactor = context.renderContext().rasterScaleFactor(); - if ( rasterScaleFactor != 1.0 ) + if( rasterScaleFactor != 1.0 ) { mBrush.setMatrix( QMatrix().scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ) ); } @@ -64,7 +64,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context QColor selColor = context.selectionColor(); // selColor.setAlphaF( context.alpha() ); mSelBrush = QBrush( selColor ); - if ( selectFillStyle ) mSelBrush.setStyle( mBrushStyle ); + if( selectFillStyle ) mSelBrush.setStyle( mBrushStyle ); mBorderColor.setAlphaF( context.alpha() ); mPen = QPen( mBorderColor ); mPen.setStyle( mBorderStyle ); @@ -78,7 +78,7 @@ void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context ) void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList* rings, QgsSymbolV2RenderContext& context ) { QPainter* p = context.renderContext().painter(); - if ( !p ) + if( !p ) { return; } @@ -86,12 +86,12 @@ void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QListsetBrush( context.selected() ? mSelBrush : mBrush ); p->setPen( mPen ); - if ( !mOffset.isNull() ) + if( !mOffset.isNull() ) p->translate( mOffset ); _renderPolygon( p, points, rings ); - if ( !mOffset.isNull() ) + if( !mOffset.isNull() ) p->translate( -mOffset ); } @@ -138,7 +138,7 @@ QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer() void QgsSVGFillSymbolLayer::setSvgFilePath( const QString& svgPath ) { QFile svgFile( svgPath ); - if ( svgFile.open( QFile::ReadOnly ) ) + if( svgFile.open( QFile::ReadOnly ) ) { mSvgData = svgFile.readAll(); storeViewBox(); @@ -153,22 +153,24 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties QString svgFilePath; - if ( properties.contains( "width" ) ) + if( properties.contains( "width" ) ) { width = properties["width"].toDouble(); } - if ( properties.contains( "svgFile" ) ) + if( properties.contains( "svgFile" ) ) { - svgFilePath = QgsApplication::relativePathToAbsolutePath( properties["svgFile"], QgsApplication::svgPath() ); + QString svgName = properties["svgFile"]; + QString savePath = QgsSvgMarkerSymbolLayerV2::symbolNameToPath( svgName ); + svgFilePath = ( savePath.isEmpty() ? svgName : savePath ); } - if ( !svgFilePath.isEmpty() ) + if( !svgFilePath.isEmpty() ) { return new QgsSVGFillSymbolLayer( svgFilePath, width ); } else { - if ( properties.contains( "data" ) ) + if( properties.contains( "data" ) ) { data = QByteArray::fromHex( properties["data"].toLocal8Bit() ); } @@ -184,7 +186,7 @@ QString QgsSVGFillSymbolLayer::layerType() const void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context ) { - if ( mSvgViewBox.isNull() ) + if( mSvgViewBox.isNull() ) { return; } @@ -199,13 +201,13 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context ) //rasterise byte array to image QPainter p( &textureImage ); QSvgRenderer r( mSvgData ); - if ( !r.isValid() ) + if( !r.isValid() ) { return; } r.render( &p ); - if ( context.alpha() < 1.0 ) + if( context.alpha() < 1.0 ) { QgsSymbolLayerV2Utils::multiplyImageOpacity( &textureImage, context.alpha() ); } @@ -215,7 +217,7 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context ) mBrush.setTextureImage( textureImage ); mBrush.setTransform( brushTransform ); - if ( mOutline ) + if( mOutline ) { mOutline->startRender( context.renderContext() ); } @@ -223,7 +225,7 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context ) void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context ) { - if ( mOutline ) + if( mOutline ) { mOutline->stopRender( context.renderContext() ); } @@ -232,27 +234,27 @@ void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context ) void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList* rings, QgsSymbolV2RenderContext& context ) { QPainter* p = context.renderContext().painter(); - if ( !p ) + if( !p ) { return; } p->setPen( QPen( Qt::NoPen ) ); - if ( context.selected() ) + if( context.selected() ) { QColor selColor = context.selectionColor(); - if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() ); + if( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() ); p->setBrush( QBrush( selColor ) ); _renderPolygon( p, points, rings ); } p->setBrush( mBrush ); _renderPolygon( p, points, rings ); - if ( mOutline ) + if( mOutline ) { mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() ); - if ( rings ) + if( rings ) { QList::const_iterator ringIt = rings->constBegin(); - for ( ; ringIt != rings->constEnd(); ++ringIt ) + for( ; ringIt != rings->constEnd(); ++ringIt ) { mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() ); } @@ -263,9 +265,9 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QListsetSubSymbol( mOutline->clone() ); } @@ -297,10 +299,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const void QgsSVGFillSymbolLayer::storeViewBox() { - if ( !mSvgData.isEmpty() ) + if( !mSvgData.isEmpty() ) { QSvgRenderer r( mSvgData ); - if ( r.isValid() ) + if( r.isValid() ) { mSvgViewBox = r.viewBoxF(); return; @@ -313,14 +315,14 @@ void QgsSVGFillSymbolLayer::storeViewBox() bool QgsSVGFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol ) { - if ( !symbol || symbol->type() != QgsSymbolV2::Line ) + if( !symbol || symbol->type() != QgsSymbolV2::Line ) { delete symbol; return false; } QgsLineSymbolV2* lineSymbol = dynamic_cast( symbol ); - if ( lineSymbol ) + if( lineSymbol ) { delete mOutline; mOutline = lineSymbol;