mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-11 00:04:27 -04:00
Better handling of relative / absolute pathes for fill symbol layer. Fixes bug #3154
git-svn-id: http://svn.osgeo.org/qgis/trunk@14515 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9c34d64fcb
commit
7c5445f5a5
@ -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 @@ 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<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
|
||||
{
|
||||
QPainter* p = context.renderContext().painter();
|
||||
if ( !p )
|
||||
if( !p )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -86,12 +86,12 @@ void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<Q
|
||||
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 @@ 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<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 @@ 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
|
||||
{
|
||||
@ -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 );
|
||||
}
|
||||
@ -288,7 +290,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
|
||||
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
|
||||
}
|
||||
|
||||
if ( mOutline )
|
||||
if( mOutline )
|
||||
{
|
||||
clonedLayer->setSubSymbol( 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<QgsLineSymbolV2*>( symbol );
|
||||
if ( lineSymbol )
|
||||
if( lineSymbol )
|
||||
{
|
||||
delete mOutline;
|
||||
mOutline = lineSymbol;
|
||||
|
Loading…
x
Reference in New Issue
Block a user