[QGIS Commit] r14515 - trunk/qgis/src/core/symbology-ng
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Nov 5 12:20:11 EDT 2010
Author: mhugent
Date: 2010-11-05 09:20:11 -0700 (Fri, 05 Nov 2010)
New Revision: 14515
Modified:
trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Log:
Better handling of relative / absolute pathes for fill symbol layer. Fixes bug #3154
Modified: trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-11-05 14:33:13 UTC (rev 14514)
+++ trunk/qgis/src/core/symbology-ng/qgsfillsymbollayerv2.cpp 2010-11-05 16:20:11 UTC (rev 14515)
@@ -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 <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;
}
@@ -25,17 +25,17 @@
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 @@
// 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 @@
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::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
- if ( !p )
+ if( !p )
{
return;
}
@@ -86,12 +86,12 @@
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 );
}
@@ -138,7 +138,7 @@
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 @@
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 @@
void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
- if ( mSvgViewBox.isNull() )
+ if( mSvgViewBox.isNull() )
{
return;
}
@@ -199,13 +201,13 @@
//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 @@
mBrush.setTextureImage( textureImage );
mBrush.setTransform( brushTransform );
- if ( mOutline )
+ if( mOutline )
{
mOutline->startRender( context.renderContext() );
}
@@ -223,7 +225,7 @@
void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
{
- if ( mOutline )
+ if( mOutline )
{
mOutline->stopRender( context.renderContext() );
}
@@ -232,27 +234,27 @@
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() );
}
@@ -263,9 +265,9 @@
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
{
@@ -279,7 +281,7 @@
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
{
QgsSymbolLayerV2* clonedLayer = 0;
- if ( !mSvgFilePath.isEmpty() )
+ if( !mSvgFilePath.isEmpty() )
{
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
}
@@ -288,7 +290,7 @@
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
}
- if ( mOutline )
+ if( mOutline )
{
clonedLayer->setSubSymbol( mOutline->clone() );
}
@@ -297,10 +299,10 @@
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 @@
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;
More information about the QGIS-commit
mailing list