Skip to content

Commit cb193d9

Browse files
committedMar 28, 2013
Data defined shape for simple marker does not work yet
1 parent e7a4574 commit cb193d9

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed
 

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,27 @@ void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context
271271
Q_UNUSED( context );
272272
}
273273

274-
bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
274+
bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
275275
{
276276
mPolygon.clear();
277277

278-
if ( mName == "square" || mName == "rectangle" )
278+
if ( name.isNull() )
279+
{
280+
name = mName;
281+
}
282+
283+
if ( name == "square" || name == "rectangle" )
279284
{
280285
mPolygon = QPolygonF( QRectF( QPointF( -1, -1 ), QPointF( 1, 1 ) ) );
281286
return true;
282287
}
283-
else if ( mName == "diamond" )
288+
else if ( name == "diamond" )
284289
{
285290
mPolygon << QPointF( -1, 0 ) << QPointF( 0, 1 )
286291
<< QPointF( 1, 0 ) << QPointF( 0, -1 );
287292
return true;
288293
}
289-
else if ( mName == "pentagon" )
294+
else if ( name == "pentagon" )
290295
{
291296
mPolygon << QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288.0 ) ) )
292297
<< QPointF( sin( DEG2RAD( 216.0 ) ), - cos( DEG2RAD( 216.0 ) ) )
@@ -295,19 +300,19 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
295300
<< QPointF( 0, -1 );
296301
return true;
297302
}
298-
else if ( mName == "triangle" )
303+
else if ( name == "triangle" )
299304
{
300305
mPolygon << QPointF( -1, 1 ) << QPointF( 1, 1 ) << QPointF( 0, -1 );
301306
return true;
302307
}
303-
else if ( mName == "equilateral_triangle" )
308+
else if ( name == "equilateral_triangle" )
304309
{
305310
mPolygon << QPointF( sin( DEG2RAD( 240.0 ) ), - cos( DEG2RAD( 240.0 ) ) )
306311
<< QPointF( sin( DEG2RAD( 120.0 ) ), - cos( DEG2RAD( 120.0 ) ) )
307312
<< QPointF( 0, -1 );
308313
return true;
309314
}
310-
else if ( mName == "star" )
315+
else if ( name == "star" )
311316
{
312317
double sixth = 1.0 / 3;
313318

@@ -323,7 +328,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
323328
<< QPointF( + sixth, -sixth );
324329
return true;
325330
}
326-
else if ( mName == "regular_star" )
331+
else if ( name == "regular_star" )
327332
{
328333
double inner_r = cos( DEG2RAD( 72.0 ) ) / cos( DEG2RAD( 36.0 ) );
329334

@@ -339,7 +344,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
339344
<< QPointF( 0, -1 ); // 0
340345
return true;
341346
}
342-
else if ( mName == "arrow" )
347+
else if ( name == "arrow" )
343348
{
344349
mPolygon
345350
<< QPointF( 0, -1 )
@@ -351,7 +356,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
351356
<< QPointF( -0.5, -0.5 );
352357
return true;
353358
}
354-
else if ( mName == "filled_arrowhead" )
359+
else if ( name == "filled_arrowhead" )
355360
{
356361
mPolygon << QPointF( 0, 0 ) << QPointF( -1, 1 ) << QPointF( -1, -1 );
357362
return true;
@@ -360,38 +365,42 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape()
360365
return false;
361366
}
362367

363-
bool QgsSimpleMarkerSymbolLayerV2::preparePath()
368+
bool QgsSimpleMarkerSymbolLayerV2::preparePath( QString name )
364369
{
365370
mPath = QPainterPath();
371+
if ( name.isNull() )
372+
{
373+
name = mName;
374+
}
366375

367-
if ( mName == "circle" )
376+
if ( name == "circle" )
368377
{
369378
mPath.addEllipse( QRectF( -1, -1, 2, 2 ) ); // x,y,w,h
370379
return true;
371380
}
372-
else if ( mName == "cross" )
381+
else if ( name == "cross" )
373382
{
374383
mPath.moveTo( -1, 0 );
375384
mPath.lineTo( 1, 0 ); // horizontal
376385
mPath.moveTo( 0, -1 );
377386
mPath.lineTo( 0, 1 ); // vertical
378387
return true;
379388
}
380-
else if ( mName == "x" || mName == "cross2" )
389+
else if ( name == "x" || name == "cross2" )
381390
{
382391
mPath.moveTo( -1, -1 );
383392
mPath.lineTo( 1, 1 );
384393
mPath.moveTo( 1, -1 );
385394
mPath.lineTo( -1, 1 );
386395
return true;
387396
}
388-
else if ( mName == "line" )
397+
else if ( name == "line" )
389398
{
390399
mPath.moveTo( 0, -1 );
391400
mPath.lineTo( 0, 1 ); // vertical line
392401
return true;
393402
}
394-
else if ( mName == "arrowhead" )
403+
else if ( name == "arrowhead" )
395404
{
396405
mPath.moveTo( 0, 0 );
397406
mPath.lineTo( -1, -1 );
@@ -443,6 +452,16 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
443452
if ( angle )
444453
off = _rotatedOffset( off, angle );
445454

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+
446465
if ( mUsingCache )
447466
{
448467
// we will use cached image

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
8383

8484
void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
8585

86-
bool prepareShape();
87-
bool preparePath();
86+
bool prepareShape( QString name = QString() );
87+
bool preparePath( QString name = QString() );
8888

8989
void prepareCache( QgsSymbolV2RenderContext& context );
9090

0 commit comments

Comments
 (0)
Please sign in to comment.