1
1
#include " qgsfillsymbollayerv2.h"
2
+ #include " qgsmarkersymbollayerv2.h"
2
3
#include " qgssymbollayerv2utils.h"
3
4
4
- #include " qgsapplication.h"
5
5
#include " qgsrendercontext.h"
6
6
#include " qgsproject.h"
7
7
10
10
#include < QSvgRenderer>
11
11
12
12
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2 ( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
13
- : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
13
+ : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
14
14
{
15
15
mColor = color;
16
16
}
@@ -25,17 +25,17 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
25
25
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;
26
26
QPointF offset;
27
27
28
- if ( props.contains ( " color" ) )
28
+ if ( props.contains ( " color" ) )
29
29
color = QgsSymbolLayerV2Utils::decodeColor ( props[" color" ] );
30
- if ( props.contains ( " style" ) )
30
+ if ( props.contains ( " style" ) )
31
31
style = QgsSymbolLayerV2Utils::decodeBrushStyle ( props[" style" ] );
32
- if ( props.contains ( " color_border" ) )
32
+ if ( props.contains ( " color_border" ) )
33
33
borderColor = QgsSymbolLayerV2Utils::decodeColor ( props[" color_border" ] );
34
- if ( props.contains ( " style_border" ) )
34
+ if ( props.contains ( " style_border" ) )
35
35
borderStyle = QgsSymbolLayerV2Utils::decodePenStyle ( props[" style_border" ] );
36
- if ( props.contains ( " width_border" ) )
36
+ if ( props.contains ( " width_border" ) )
37
37
borderWidth = props[" width_border" ].toDouble ();
38
- if ( props.contains ( " offset" ) )
38
+ if ( props.contains ( " offset" ) )
39
39
offset = QgsSymbolLayerV2Utils::decodePoint ( props[" offset" ] );
40
40
41
41
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2 ( color, style, borderColor, borderStyle, borderWidth );
@@ -56,15 +56,15 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
56
56
57
57
// scale brush content for printout
58
58
double rasterScaleFactor = context.renderContext ().rasterScaleFactor ();
59
- if ( rasterScaleFactor != 1.0 )
59
+ if ( rasterScaleFactor != 1.0 )
60
60
{
61
61
mBrush .setMatrix ( QMatrix ().scale ( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ) );
62
62
}
63
63
64
64
QColor selColor = context.selectionColor ();
65
65
// selColor.setAlphaF( context.alpha() );
66
66
mSelBrush = QBrush ( selColor );
67
- if ( selectFillStyle ) mSelBrush .setStyle ( mBrushStyle );
67
+ if ( selectFillStyle ) mSelBrush .setStyle ( mBrushStyle );
68
68
mBorderColor .setAlphaF ( context.alpha () );
69
69
mPen = QPen ( mBorderColor );
70
70
mPen .setStyle ( mBorderStyle );
@@ -78,20 +78,20 @@ void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
78
78
void QgsSimpleFillSymbolLayerV2::renderPolygon ( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
79
79
{
80
80
QPainter* p = context.renderContext ().painter ();
81
- if ( !p )
81
+ if ( !p )
82
82
{
83
83
return ;
84
84
}
85
85
86
86
p->setBrush ( context.selected () ? mSelBrush : mBrush );
87
87
p->setPen ( mPen );
88
88
89
- if ( !mOffset .isNull () )
89
+ if ( !mOffset .isNull () )
90
90
p->translate ( mOffset );
91
91
92
92
_renderPolygon ( p, points, rings );
93
93
94
- if ( !mOffset .isNull () )
94
+ if ( !mOffset .isNull () )
95
95
p->translate ( -mOffset );
96
96
}
97
97
@@ -138,7 +138,7 @@ QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer()
138
138
void QgsSVGFillSymbolLayer::setSvgFilePath ( const QString& svgPath )
139
139
{
140
140
QFile svgFile ( svgPath );
141
- if ( svgFile.open ( QFile::ReadOnly ) )
141
+ if ( svgFile.open ( QFile::ReadOnly ) )
142
142
{
143
143
mSvgData = svgFile.readAll ();
144
144
storeViewBox ();
@@ -153,22 +153,24 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
153
153
QString svgFilePath;
154
154
155
155
156
- if ( properties.contains ( " width" ) )
156
+ if ( properties.contains ( " width" ) )
157
157
{
158
158
width = properties[" width" ].toDouble ();
159
159
}
160
- if ( properties.contains ( " svgFile" ) )
160
+ if ( properties.contains ( " svgFile" ) )
161
161
{
162
- svgFilePath = QgsApplication::relativePathToAbsolutePath ( properties[" svgFile" ], QgsApplication::svgPath () );
162
+ QString svgName = properties[" svgFile" ];
163
+ QString savePath = QgsSvgMarkerSymbolLayerV2::symbolNameToPath ( svgName );
164
+ svgFilePath = ( savePath.isEmpty () ? svgName : savePath );
163
165
}
164
166
165
- if ( !svgFilePath.isEmpty () )
167
+ if ( !svgFilePath.isEmpty () )
166
168
{
167
169
return new QgsSVGFillSymbolLayer ( svgFilePath, width );
168
170
}
169
171
else
170
172
{
171
- if ( properties.contains ( " data" ) )
173
+ if ( properties.contains ( " data" ) )
172
174
{
173
175
data = QByteArray::fromHex ( properties[" data" ].toLocal8Bit () );
174
176
}
@@ -184,7 +186,7 @@ QString QgsSVGFillSymbolLayer::layerType() const
184
186
185
187
void QgsSVGFillSymbolLayer::startRender ( QgsSymbolV2RenderContext& context )
186
188
{
187
- if ( mSvgViewBox .isNull () )
189
+ if ( mSvgViewBox .isNull () )
188
190
{
189
191
return ;
190
192
}
@@ -199,13 +201,13 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
199
201
// rasterise byte array to image
200
202
QPainter p ( &textureImage );
201
203
QSvgRenderer r ( mSvgData );
202
- if ( !r.isValid () )
204
+ if ( !r.isValid () )
203
205
{
204
206
return ;
205
207
}
206
208
r.render ( &p );
207
209
208
- if ( context.alpha () < 1.0 )
210
+ if ( context.alpha () < 1.0 )
209
211
{
210
212
QgsSymbolLayerV2Utils::multiplyImageOpacity ( &textureImage, context.alpha () );
211
213
}
@@ -215,15 +217,15 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
215
217
mBrush .setTextureImage ( textureImage );
216
218
mBrush .setTransform ( brushTransform );
217
219
218
- if ( mOutline )
220
+ if ( mOutline )
219
221
{
220
222
mOutline ->startRender ( context.renderContext () );
221
223
}
222
224
}
223
225
224
226
void QgsSVGFillSymbolLayer::stopRender ( QgsSymbolV2RenderContext& context )
225
227
{
226
- if ( mOutline )
228
+ if ( mOutline )
227
229
{
228
230
mOutline ->stopRender ( context.renderContext () );
229
231
}
@@ -232,27 +234,27 @@ void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
232
234
void QgsSVGFillSymbolLayer::renderPolygon ( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
233
235
{
234
236
QPainter* p = context.renderContext ().painter ();
235
- if ( !p )
237
+ if ( !p )
236
238
{
237
239
return ;
238
240
}
239
241
p->setPen ( QPen ( Qt::NoPen ) );
240
- if ( context.selected () )
242
+ if ( context.selected () )
241
243
{
242
244
QColor selColor = context.selectionColor ();
243
- if ( ! selectionIsOpaque ) selColor.setAlphaF ( context.alpha () );
245
+ if ( ! selectionIsOpaque ) selColor.setAlphaF ( context.alpha () );
244
246
p->setBrush ( QBrush ( selColor ) );
245
247
_renderPolygon ( p, points, rings );
246
248
}
247
249
p->setBrush ( mBrush );
248
250
_renderPolygon ( p, points, rings );
249
- if ( mOutline )
251
+ if ( mOutline )
250
252
{
251
253
mOutline ->renderPolyline ( points, context.renderContext (), -1 , selectFillBorder && context.selected () );
252
- if ( rings )
254
+ if ( rings )
253
255
{
254
256
QList<QPolygonF>::const_iterator ringIt = rings->constBegin ();
255
- for ( ; ringIt != rings->constEnd (); ++ringIt )
257
+ for ( ; ringIt != rings->constEnd (); ++ringIt )
256
258
{
257
259
mOutline ->renderPolyline ( *ringIt, context.renderContext (), -1 , selectFillBorder && context.selected () );
258
260
}
@@ -263,9 +265,9 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
263
265
QgsStringMap QgsSVGFillSymbolLayer::properties () const
264
266
{
265
267
QgsStringMap map;
266
- if ( !mSvgFilePath .isEmpty () )
268
+ if ( !mSvgFilePath .isEmpty () )
267
269
{
268
- map.insert ( " svgFile" , QgsApplication::absolutePathToRelativePath ( mSvgFilePath , QgsApplication::svgPath () ) );
270
+ map.insert ( " svgFile" , QgsSvgMarkerSymbolLayerV2::symbolPathToName ( mSvgFilePath ) );
269
271
}
270
272
else
271
273
{
@@ -279,7 +281,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
279
281
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone () const
280
282
{
281
283
QgsSymbolLayerV2* clonedLayer = 0 ;
282
- if ( !mSvgFilePath .isEmpty () )
284
+ if ( !mSvgFilePath .isEmpty () )
283
285
{
284
286
clonedLayer = new QgsSVGFillSymbolLayer ( mSvgFilePath , mPatternWidth );
285
287
}
@@ -288,7 +290,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
288
290
clonedLayer = new QgsSVGFillSymbolLayer ( mSvgData , mPatternWidth );
289
291
}
290
292
291
- if ( mOutline )
293
+ if ( mOutline )
292
294
{
293
295
clonedLayer->setSubSymbol ( mOutline ->clone () );
294
296
}
@@ -297,10 +299,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
297
299
298
300
void QgsSVGFillSymbolLayer::storeViewBox ()
299
301
{
300
- if ( !mSvgData .isEmpty () )
302
+ if ( !mSvgData .isEmpty () )
301
303
{
302
304
QSvgRenderer r ( mSvgData );
303
- if ( r.isValid () )
305
+ if ( r.isValid () )
304
306
{
305
307
mSvgViewBox = r.viewBoxF ();
306
308
return ;
@@ -313,14 +315,14 @@ void QgsSVGFillSymbolLayer::storeViewBox()
313
315
314
316
bool QgsSVGFillSymbolLayer::setSubSymbol ( QgsSymbolV2* symbol )
315
317
{
316
- if ( !symbol || symbol->type () != QgsSymbolV2::Line )
318
+ if ( !symbol || symbol->type () != QgsSymbolV2::Line )
317
319
{
318
320
delete symbol;
319
321
return false ;
320
322
}
321
323
322
324
QgsLineSymbolV2* lineSymbol = dynamic_cast <QgsLineSymbolV2*>( symbol );
323
- if ( lineSymbol )
325
+ if ( lineSymbol )
324
326
{
325
327
delete mOutline ;
326
328
mOutline = lineSymbol;
0 commit comments