@@ -271,22 +271,27 @@ void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context
271
271
Q_UNUSED ( context );
272
272
}
273
273
274
- bool QgsSimpleMarkerSymbolLayerV2::prepareShape ()
274
+ bool QgsSimpleMarkerSymbolLayerV2::prepareShape ( QString name )
275
275
{
276
276
mPolygon .clear ();
277
277
278
- if ( mName == " square" || mName == " rectangle" )
278
+ if ( name.isNull () )
279
+ {
280
+ name = mName ;
281
+ }
282
+
283
+ if ( name == " square" || name == " rectangle" )
279
284
{
280
285
mPolygon = QPolygonF ( QRectF ( QPointF ( -1 , -1 ), QPointF ( 1 , 1 ) ) );
281
286
return true ;
282
287
}
283
- else if ( mName == " diamond" )
288
+ else if ( name == " diamond" )
284
289
{
285
290
mPolygon << QPointF ( -1 , 0 ) << QPointF ( 0 , 1 )
286
291
<< QPointF ( 1 , 0 ) << QPointF ( 0 , -1 );
287
292
return true ;
288
293
}
289
- else if ( mName == " pentagon" )
294
+ else if ( name == " pentagon" )
290
295
{
291
296
mPolygon << QPointF ( sin ( DEG2RAD ( 288.0 ) ), - cos ( DEG2RAD ( 288.0 ) ) )
292
297
<< QPointF ( sin ( DEG2RAD ( 216.0 ) ), - cos ( DEG2RAD ( 216.0 ) ) )
@@ -295,19 +300,19 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
295
300
<< QPointF ( 0 , -1 );
296
301
return true ;
297
302
}
298
- else if ( mName == " triangle" )
303
+ else if ( name == " triangle" )
299
304
{
300
305
mPolygon << QPointF ( -1 , 1 ) << QPointF ( 1 , 1 ) << QPointF ( 0 , -1 );
301
306
return true ;
302
307
}
303
- else if ( mName == " equilateral_triangle" )
308
+ else if ( name == " equilateral_triangle" )
304
309
{
305
310
mPolygon << QPointF ( sin ( DEG2RAD ( 240.0 ) ), - cos ( DEG2RAD ( 240.0 ) ) )
306
311
<< QPointF ( sin ( DEG2RAD ( 120.0 ) ), - cos ( DEG2RAD ( 120.0 ) ) )
307
312
<< QPointF ( 0 , -1 );
308
313
return true ;
309
314
}
310
- else if ( mName == " star" )
315
+ else if ( name == " star" )
311
316
{
312
317
double sixth = 1.0 / 3 ;
313
318
@@ -323,7 +328,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
323
328
<< QPointF ( + sixth, -sixth );
324
329
return true ;
325
330
}
326
- else if ( mName == " regular_star" )
331
+ else if ( name == " regular_star" )
327
332
{
328
333
double inner_r = cos ( DEG2RAD ( 72.0 ) ) / cos ( DEG2RAD ( 36.0 ) );
329
334
@@ -339,7 +344,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
339
344
<< QPointF ( 0 , -1 ); // 0
340
345
return true ;
341
346
}
342
- else if ( mName == " arrow" )
347
+ else if ( name == " arrow" )
343
348
{
344
349
mPolygon
345
350
<< QPointF ( 0 , -1 )
@@ -351,7 +356,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
351
356
<< QPointF ( -0.5 , -0.5 );
352
357
return true ;
353
358
}
354
- else if ( mName == " filled_arrowhead" )
359
+ else if ( name == " filled_arrowhead" )
355
360
{
356
361
mPolygon << QPointF ( 0 , 0 ) << QPointF ( -1 , 1 ) << QPointF ( -1 , -1 );
357
362
return true ;
@@ -360,38 +365,42 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
360
365
return false ;
361
366
}
362
367
363
- bool QgsSimpleMarkerSymbolLayerV2::preparePath ()
368
+ bool QgsSimpleMarkerSymbolLayerV2::preparePath ( QString name )
364
369
{
365
370
mPath = QPainterPath ();
371
+ if ( name.isNull () )
372
+ {
373
+ name = mName ;
374
+ }
366
375
367
- if ( mName == " circle" )
376
+ if ( name == " circle" )
368
377
{
369
378
mPath .addEllipse ( QRectF ( -1 , -1 , 2 , 2 ) ); // x,y,w,h
370
379
return true ;
371
380
}
372
- else if ( mName == " cross" )
381
+ else if ( name == " cross" )
373
382
{
374
383
mPath .moveTo ( -1 , 0 );
375
384
mPath .lineTo ( 1 , 0 ); // horizontal
376
385
mPath .moveTo ( 0 , -1 );
377
386
mPath .lineTo ( 0 , 1 ); // vertical
378
387
return true ;
379
388
}
380
- else if ( mName == " x" || mName == " cross2" )
389
+ else if ( name == " x" || name == " cross2" )
381
390
{
382
391
mPath .moveTo ( -1 , -1 );
383
392
mPath .lineTo ( 1 , 1 );
384
393
mPath .moveTo ( 1 , -1 );
385
394
mPath .lineTo ( -1 , 1 );
386
395
return true ;
387
396
}
388
- else if ( mName == " line" )
397
+ else if ( name == " line" )
389
398
{
390
399
mPath .moveTo ( 0 , -1 );
391
400
mPath .lineTo ( 0 , 1 ); // vertical line
392
401
return true ;
393
402
}
394
- else if ( mName == " arrowhead" )
403
+ else if ( name == " arrowhead" )
395
404
{
396
405
mPath .moveTo ( 0 , 0 );
397
406
mPath .lineTo ( -1 , -1 );
@@ -443,6 +452,16 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
443
452
if ( angle )
444
453
off = _rotatedOffset ( off, angle );
445
454
455
+ // data defined shape?
456
+ if ( mNameExpression )
457
+ {
458
+ QString name = mNameExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toString ();
459
+ if ( !prepareShape ( name ) ) // drawing as a polygon
460
+ {
461
+ preparePath ( name ); // drawing as a painter path
462
+ }
463
+ }
464
+
446
465
if ( mUsingCache )
447
466
{
448
467
// we will use cached image
0 commit comments