Skip to content

Commit

Permalink
Better handling of relative / absolute pathes for fill symbol layer. …
Browse files Browse the repository at this point in the history
…Fixes bug #3154

git-svn-id: http://svn.osgeo.org/qgis/trunk@14515 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 5, 2010
1 parent 9c34d64 commit 7c5445f
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions 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"

Expand All @@ -10,7 +10,7 @@
#include <QSvgRenderer>

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;
}
Expand All @@ -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 );
Expand All @@ -56,15 +56,15 @@ 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 ) );
}

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 );
Expand All @@ -78,20 +78,20 @@ void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
if ( !p )
if( !p )
{
return;
}

p->setBrush( 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 );
}

Expand Down Expand Up @@ -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();
Expand All @@ -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() );
}
Expand All @@ -184,7 +186,7 @@ QString QgsSVGFillSymbolLayer::layerType() const

void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
if ( mSvgViewBox.isNull() )
if( mSvgViewBox.isNull() )
{
return;
}
Expand All @@ -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() );
}
Expand All @@ -215,15 +217,15 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
mBrush.setTextureImage( textureImage );
mBrush.setTransform( brushTransform );

if ( mOutline )
if( mOutline )
{
mOutline->startRender( context.renderContext() );
}
}

void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
{
if ( mOutline )
if( mOutline )
{
mOutline->stopRender( context.renderContext() );
}
Expand All @@ -232,27 +234,27 @@ void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolygonF>* 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<QPolygonF>::const_iterator ringIt = rings->constBegin();
for ( ; ringIt != rings->constEnd(); ++ringIt )
for( ; ringIt != rings->constEnd(); ++ringIt )
{
mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() );
}
Expand All @@ -263,9 +265,9 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
QgsStringMap QgsSVGFillSymbolLayer::properties() const
{
QgsStringMap map;
if ( !mSvgFilePath.isEmpty() )
if( !mSvgFilePath.isEmpty() )
{
map.insert( "svgFile", QgsApplication::absolutePathToRelativePath( mSvgFilePath, QgsApplication::svgPath() ) );
map.insert( "svgFile", QgsSvgMarkerSymbolLayerV2::symbolPathToName( mSvgFilePath ) );
}
else
{
Expand All @@ -279,7 +281,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
{
QgsSymbolLayerV2* clonedLayer = 0;
if ( !mSvgFilePath.isEmpty() )
if( !mSvgFilePath.isEmpty() )
{
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
}
Expand All @@ -288,7 +290,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
}

if ( mOutline )
if( mOutline )
{
clonedLayer->setSubSymbol( mOutline->clone() );
}
Expand All @@ -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;
Expand All @@ -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<QgsLineSymbolV2*>( symbol );
if ( lineSymbol )
if( lineSymbol )
{
delete mOutline;
mOutline = lineSymbol;
Expand Down

0 comments on commit 7c5445f

Please sign in to comment.