@@ -28,7 +28,7 @@ QgsSymbolV2::QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers )
28
28
{
29
29
mLayers .removeAt ( i-- );
30
30
}
31
- else if ( mLayers [i]->type () != mType )
31
+ else if ( ! isSymbolLayerCompatible ( mLayers [i]->type () ) )
32
32
{
33
33
delete mLayers [i];
34
34
mLayers .removeAt ( i-- );
@@ -69,12 +69,21 @@ QgsSymbolLayerV2* QgsSymbolV2::symbolLayer( int layer )
69
69
}
70
70
71
71
72
+ bool QgsSymbolV2::isSymbolLayerCompatible ( SymbolType t )
73
+ {
74
+ // fill symbol can contain also line symbol layers for drawing of outlines
75
+ if ( mType == Fill && t == Line )
76
+ return true ;
77
+
78
+ return mType == t;
79
+ }
80
+
72
81
73
82
bool QgsSymbolV2::insertSymbolLayer ( int index, QgsSymbolLayerV2* layer )
74
83
{
75
84
if ( index < 0 || index > mLayers .count () ) // can be added also after the last index
76
85
return false ;
77
- if ( layer == NULL || layer->type () != mType )
86
+ if ( layer == NULL || ! isSymbolLayerCompatible ( layer->type () ) )
78
87
return false ;
79
88
80
89
mLayers .insert ( index , layer );
@@ -84,7 +93,7 @@ bool QgsSymbolV2::insertSymbolLayer( int index, QgsSymbolLayerV2* layer )
84
93
85
94
bool QgsSymbolV2::appendSymbolLayer ( QgsSymbolLayerV2* layer )
86
95
{
87
- if ( layer == NULL || layer->type () != mType )
96
+ if ( layer == NULL || ! isSymbolLayerCompatible ( layer->type () ) )
88
97
return false ;
89
98
90
99
mLayers .append ( layer );
@@ -116,7 +125,7 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )
116
125
{
117
126
if ( index < 0 || index >= mLayers .count () )
118
127
return false ;
119
- if ( layer == NULL || layer->type () != mType )
128
+ if ( layer == NULL || ! isSymbolLayerCompatible ( layer->type () ) )
120
129
return false ;
121
130
122
131
delete mLayers [index ]; // first delete the original layer
@@ -165,7 +174,20 @@ void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
165
174
QgsSymbolV2RenderContext symbolContext ( context, mOutputUnit , mAlpha , false , mRenderHints );
166
175
for ( QgsSymbolLayerV2List::iterator it = mLayers .begin (); it != mLayers .end (); ++it )
167
176
{
168
- ( *it )->drawPreviewIcon ( symbolContext, size );
177
+ if ( mType == Fill && ( *it )->type () == Line )
178
+ {
179
+ // line symbol layer would normally draw just a line
180
+ // so we override this case to force it to draw a polygon outline
181
+ QgsLineSymbolLayerV2* lsl = ( QgsLineSymbolLayerV2* ) * it;
182
+
183
+ // from QgsFillSymbolLayerV2::drawPreviewIcon()
184
+ QPolygonF poly = QRectF ( QPointF ( 0 , 0 ), QPointF ( size.width () - 1 , size.height () - 1 ) );
185
+ lsl->startRender ( symbolContext );
186
+ lsl->renderPolygonOutline ( poly, NULL , symbolContext );
187
+ lsl->stopRender ( symbolContext );
188
+ }
189
+ else
190
+ ( *it )->drawPreviewIcon ( symbolContext, size );
169
191
}
170
192
}
171
193
@@ -456,14 +478,29 @@ void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>*
456
478
if ( layer != -1 )
457
479
{
458
480
if ( layer >= 0 && layer < mLayers .count () )
459
- (( QgsFillSymbolLayerV2* ) mLayers [layer] )->renderPolygon ( points, rings, symbolContext );
481
+ {
482
+ QgsSymbolV2::SymbolType layertype = mLayers .at ( layer )->type ();
483
+ if ( layertype == QgsSymbolV2::Fill )
484
+ (( QgsFillSymbolLayerV2* ) mLayers [layer] )->renderPolygon ( points, rings, symbolContext );
485
+ else if ( layertype == QgsSymbolV2::Line )
486
+ (( QgsLineSymbolLayerV2* ) mLayers [layer] )->renderPolygonOutline ( points, rings, symbolContext );
487
+ }
460
488
return ;
461
489
}
462
490
463
491
for ( QgsSymbolLayerV2List::iterator it = mLayers .begin (); it != mLayers .end (); ++it )
464
492
{
465
- QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
466
- layer->renderPolygon ( points, rings, symbolContext );
493
+ QgsSymbolV2::SymbolType layertype = ( *it )->type ();
494
+ if ( layertype == QgsSymbolV2::Fill )
495
+ {
496
+ QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
497
+ layer->renderPolygon ( points, rings, symbolContext );
498
+ }
499
+ else if ( layertype == QgsSymbolV2::Line )
500
+ {
501
+ QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
502
+ layer->renderPolygonOutline ( points, rings, symbolContext );
503
+ }
467
504
}
468
505
}
469
506
0 commit comments