@@ -117,18 +117,92 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
117
117
return sl;
118
118
}
119
119
120
+ // QgsImageFillSymbolLayer
121
+
122
+ QgsImageFillSymbolLayer::QgsImageFillSymbolLayer (): mOutlineWidth( 0.0 ), mOutline( 0 )
123
+ {
124
+ setSubSymbol ( new QgsLineSymbolV2 () );
125
+ }
126
+
127
+ QgsImageFillSymbolLayer::~QgsImageFillSymbolLayer ()
128
+ {
129
+ }
130
+
131
+ void QgsImageFillSymbolLayer::renderPolygon ( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
132
+ {
133
+ QPainter* p = context.renderContext ().painter ();
134
+ if ( !p )
135
+ {
136
+ return ;
137
+ }
138
+ p->setPen ( QPen ( Qt::NoPen ) );
139
+ if ( context.selected () )
140
+ {
141
+ QColor selColor = context.selectionColor ();
142
+ if ( ! selectionIsOpaque )
143
+ selColor.setAlphaF ( context.alpha () );
144
+ p->setBrush ( QBrush ( selColor ) );
145
+ _renderPolygon ( p, points, rings );
146
+ }
147
+
148
+ if ( doubleNear ( mAngle , 0.0 ) )
149
+ {
150
+ p->setBrush ( mBrush );
151
+ }
152
+ else
153
+ {
154
+ QTransform t = mBrush .transform ();
155
+ t.rotate ( mAngle );
156
+ QBrush rotatedBrush = mBrush ;
157
+ rotatedBrush.setTransform ( t );
158
+ p->setBrush ( rotatedBrush );
159
+ }
160
+ _renderPolygon ( p, points, rings );
161
+ if ( mOutline )
162
+ {
163
+ mOutline ->renderPolyline ( points, context.renderContext (), -1 , selectFillBorder && context.selected () );
164
+ if ( rings )
165
+ {
166
+ QList<QPolygonF>::const_iterator ringIt = rings->constBegin ();
167
+ for ( ; ringIt != rings->constEnd (); ++ringIt )
168
+ {
169
+ mOutline ->renderPolyline ( *ringIt, context.renderContext (), -1 , selectFillBorder && context.selected () );
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ bool QgsImageFillSymbolLayer::setSubSymbol ( QgsSymbolV2* symbol )
176
+ {
177
+ if ( !symbol || symbol->type () != QgsSymbolV2::Line )
178
+ {
179
+ delete symbol;
180
+ return false ;
181
+ }
182
+
183
+ QgsLineSymbolV2* lineSymbol = dynamic_cast <QgsLineSymbolV2*>( symbol );
184
+ if ( lineSymbol )
185
+ {
186
+ delete mOutline ;
187
+ mOutline = lineSymbol;
188
+ return true ;
189
+ }
190
+
191
+ delete symbol;
192
+ return false ;
193
+ }
194
+
120
195
// QgsSVGFillSymbolLayer
121
196
122
- QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QString& svgFilePath, double width, double angle ): mPatternWidth( width ), mOutline( 0 )
197
+ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QString& svgFilePath, double width, double angle ): QgsImageFillSymbolLayer( ), mPatternWidth( width )
123
198
{
124
199
setSvgFilePath ( svgFilePath );
125
200
mOutlineWidth = 0.3 ;
126
201
mAngle = angle;
127
- setSubSymbol ( new QgsLineSymbolV2 () );
128
202
}
129
203
130
- QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QByteArray& svgData, double width, double angle ): mPatternWidth( width ),
131
- mSvgData( svgData ), mOutline( 0 )
204
+ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QByteArray& svgData, double width, double angle ): QgsImageFillSymbolLayer(), mPatternWidth( width ),
205
+ mSvgData( svgData )
132
206
{
133
207
storeViewBox ();
134
208
mOutlineWidth = 0.3 ;
@@ -236,50 +310,6 @@ void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
236
310
}
237
311
}
238
312
239
- void QgsSVGFillSymbolLayer::renderPolygon ( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
240
- {
241
- QPainter* p = context.renderContext ().painter ();
242
- if ( !p )
243
- {
244
- return ;
245
- }
246
- p->setPen ( QPen ( Qt::NoPen ) );
247
- if ( context.selected () )
248
- {
249
- QColor selColor = context.selectionColor ();
250
- if ( ! selectionIsOpaque )
251
- selColor.setAlphaF ( context.alpha () );
252
- p->setBrush ( QBrush ( selColor ) );
253
- _renderPolygon ( p, points, rings );
254
- }
255
-
256
- if ( doubleNear ( mAngle , 0.0 ) )
257
- {
258
- p->setBrush ( mBrush );
259
- }
260
- else
261
- {
262
- QTransform t = mBrush .transform ();
263
- t.rotate ( mAngle );
264
- QBrush rotatedBrush = mBrush ;
265
- rotatedBrush.setTransform ( t );
266
- p->setBrush ( rotatedBrush );
267
- }
268
- _renderPolygon ( p, points, rings );
269
- if ( mOutline )
270
- {
271
- mOutline ->renderPolyline ( points, context.renderContext (), -1 , selectFillBorder && context.selected () );
272
- if ( rings )
273
- {
274
- QList<QPolygonF>::const_iterator ringIt = rings->constBegin ();
275
- for ( ; ringIt != rings->constEnd (); ++ringIt )
276
- {
277
- mOutline ->renderPolyline ( *ringIt, context.renderContext (), -1 , selectFillBorder && context.selected () );
278
- }
279
- }
280
- }
281
- }
282
-
283
313
QgsStringMap QgsSVGFillSymbolLayer::properties () const
284
314
{
285
315
QgsStringMap map;
@@ -332,27 +362,7 @@ void QgsSVGFillSymbolLayer::storeViewBox()
332
362
return ;
333
363
}
334
364
335
- bool QgsSVGFillSymbolLayer::setSubSymbol ( QgsSymbolV2* symbol )
336
- {
337
- if ( !symbol || symbol->type () != QgsSymbolV2::Line )
338
- {
339
- delete symbol;
340
- return false ;
341
- }
342
-
343
- QgsLineSymbolV2* lineSymbol = dynamic_cast <QgsLineSymbolV2*>( symbol );
344
- if ( lineSymbol )
345
- {
346
- delete mOutline ;
347
- mOutline = lineSymbol;
348
- return true ;
349
- }
350
-
351
- delete symbol;
352
- return false ;
353
- }
354
-
355
- QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer ()
365
+ QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer (): QgsImageFillSymbolLayer()
356
366
{
357
367
}
358
368
@@ -451,24 +461,16 @@ void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& conte
451
461
// set image to mBrush
452
462
mBrush .setTextureImage ( patternImage );
453
463
464
+ if ( mOutline )
465
+ {
466
+ mOutline ->startRender ( context.renderContext () );
467
+ }
454
468
}
455
469
456
470
void QgsLinePatternFillSymbolLayer::stopRender ( QgsSymbolV2RenderContext& context )
457
471
{
458
472
}
459
473
460
- void QgsLinePatternFillSymbolLayer::renderPolygon ( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
461
- {
462
- QPainter* p = context.renderContext ().painter ();
463
- if ( !p )
464
- {
465
- return ;
466
- }
467
-
468
- p->setBrush ( mBrush );
469
- _renderPolygon ( p, points, rings );
470
- }
471
-
472
474
QgsStringMap QgsLinePatternFillSymbolLayer::properties () const
473
475
{
474
476
QgsStringMap map;
@@ -481,7 +483,12 @@ QgsStringMap QgsLinePatternFillSymbolLayer::properties() const
481
483
482
484
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone () const
483
485
{
484
- return QgsLinePatternFillSymbolLayer::create ( properties () );
486
+ QgsSymbolLayerV2* clonedLayer = QgsLinePatternFillSymbolLayer::create ( properties () );
487
+ if ( mOutline )
488
+ {
489
+ clonedLayer->setSubSymbol ( mOutline ->clone () );
490
+ }
491
+ return clonedLayer;
485
492
}
486
493
487
494
0 commit comments