@@ -365,27 +365,27 @@ void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context
365
365
366
366
bool QgsSimpleMarkerSymbolLayerV2::prepareShape ( QString name )
367
367
{
368
- mPolygon .clear ();
368
+ return prepareShape ( name.isNull () ? mName : name, mPolygon );
369
+ }
369
370
370
- if ( name.isNull () )
371
- {
372
- name = mName ;
373
- }
371
+ bool QgsSimpleMarkerSymbolLayerV2::prepareShape ( QString name, QPolygonF &polygon ) const
372
+ {
373
+ polygon.clear ();
374
374
375
375
if ( name == " square" || name == " rectangle" )
376
376
{
377
- mPolygon = QPolygonF ( QRectF ( QPointF ( -1 , -1 ), QPointF ( 1 , 1 ) ) );
377
+ polygon = QPolygonF ( QRectF ( QPointF ( -1 , -1 ), QPointF ( 1 , 1 ) ) );
378
378
return true ;
379
379
}
380
380
else if ( name == " diamond" )
381
381
{
382
- mPolygon << QPointF ( -1 , 0 ) << QPointF ( 0 , 1 )
382
+ polygon << QPointF ( -1 , 0 ) << QPointF ( 0 , 1 )
383
383
<< QPointF ( 1 , 0 ) << QPointF ( 0 , -1 );
384
384
return true ;
385
385
}
386
386
else if ( name == " pentagon" )
387
387
{
388
- mPolygon << QPointF ( sin ( DEG2RAD ( 288.0 ) ), - cos ( DEG2RAD ( 288.0 ) ) )
388
+ polygon << QPointF ( sin ( DEG2RAD ( 288.0 ) ), - cos ( DEG2RAD ( 288.0 ) ) )
389
389
<< QPointF ( sin ( DEG2RAD ( 216.0 ) ), - cos ( DEG2RAD ( 216.0 ) ) )
390
390
<< QPointF ( sin ( DEG2RAD ( 144.0 ) ), - cos ( DEG2RAD ( 144.0 ) ) )
391
391
<< QPointF ( sin ( DEG2RAD ( 72.0 ) ), - cos ( DEG2RAD ( 72.0 ) ) )
@@ -394,12 +394,12 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
394
394
}
395
395
else if ( name == " triangle" )
396
396
{
397
- mPolygon << QPointF ( -1 , 1 ) << QPointF ( 1 , 1 ) << QPointF ( 0 , -1 );
397
+ polygon << QPointF ( -1 , 1 ) << QPointF ( 1 , 1 ) << QPointF ( 0 , -1 );
398
398
return true ;
399
399
}
400
400
else if ( name == " equilateral_triangle" )
401
401
{
402
- mPolygon << QPointF ( sin ( DEG2RAD ( 240.0 ) ), - cos ( DEG2RAD ( 240.0 ) ) )
402
+ polygon << QPointF ( sin ( DEG2RAD ( 240.0 ) ), - cos ( DEG2RAD ( 240.0 ) ) )
403
403
<< QPointF ( sin ( DEG2RAD ( 120.0 ) ), - cos ( DEG2RAD ( 120.0 ) ) )
404
404
<< QPointF ( 0 , -1 );
405
405
return true ;
@@ -408,7 +408,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
408
408
{
409
409
double sixth = 1.0 / 3 ;
410
410
411
- mPolygon << QPointF ( 0 , -1 )
411
+ polygon << QPointF ( 0 , -1 )
412
412
<< QPointF ( -sixth, -sixth )
413
413
<< QPointF ( -1 , -sixth )
414
414
<< QPointF ( -sixth, 0 )
@@ -424,7 +424,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
424
424
{
425
425
double inner_r = cos ( DEG2RAD ( 72.0 ) ) / cos ( DEG2RAD ( 36.0 ) );
426
426
427
- mPolygon << QPointF ( inner_r * sin ( DEG2RAD ( 324.0 ) ), - inner_r * cos ( DEG2RAD ( 324.0 ) ) ) // 324
427
+ polygon << QPointF ( inner_r * sin ( DEG2RAD ( 324.0 ) ), - inner_r * cos ( DEG2RAD ( 324.0 ) ) ) // 324
428
428
<< QPointF ( sin ( DEG2RAD ( 288.0 ) ), - cos ( DEG2RAD ( 288 ) ) ) // 288
429
429
<< QPointF ( inner_r * sin ( DEG2RAD ( 252.0 ) ), - inner_r * cos ( DEG2RAD ( 252.0 ) ) ) // 252
430
430
<< QPointF ( sin ( DEG2RAD ( 216.0 ) ), - cos ( DEG2RAD ( 216.0 ) ) ) // 216
@@ -438,8 +438,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
438
438
}
439
439
else if ( name == " arrow" )
440
440
{
441
- mPolygon
442
- << QPointF ( 0 , -1 )
441
+ polygon << QPointF ( 0 , -1 )
443
442
<< QPointF ( 0.5 , -0.5 )
444
443
<< QPointF ( 0.25 , -0.5 )
445
444
<< QPointF ( 0.25 , 1 )
@@ -450,7 +449,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
450
449
}
451
450
else if ( name == " filled_arrowhead" )
452
451
{
453
- mPolygon << QPointF ( 0 , 0 ) << QPointF ( -1 , 1 ) << QPointF ( -1 , -1 );
452
+ polygon << QPointF ( 0 , 0 ) << QPointF ( -1 , 1 ) << QPointF ( -1 , -1 );
454
453
return true ;
455
454
}
456
455
@@ -842,7 +841,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
842
841
{
843
842
if ( sizeExpression )
844
843
{
845
- size = sizeExpression->evaluate ( const_cast <QgsFeature*>( context-> feature () ) ).toDouble ();
844
+ size = sizeExpression->evaluate ( *f ).toDouble ();
846
845
}
847
846
848
847
switch ( mScaleMethod )
@@ -867,7 +866,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
867
866
QgsExpression* outlineWidthExpression = expression ( " outline_width" );
868
867
if ( context && outlineWidthExpression )
869
868
{
870
- outlineWidth = outlineWidthExpression->evaluate ( const_cast <QgsFeature*>( context-> feature () ) ).toDouble ();
869
+ outlineWidth = outlineWidthExpression->evaluate ( *f ).toDouble ();
871
870
}
872
871
if ( mSizeUnit == QgsSymbolV2::MM )
873
872
{
@@ -904,8 +903,16 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
904
903
QgsExpression* angleExpression = expression ( " angle" );
905
904
if ( context && angleExpression )
906
905
{
907
- angle = angleExpression->evaluate ( const_cast <QgsFeature*>( context-> feature () ) ).toDouble ();
906
+ angle = angleExpression->evaluate ( *f ).toDouble ();
908
907
}
908
+
909
+ QString name ( mName );
910
+ QgsExpression* nameExpression = expression ( " name" );
911
+ if ( context && nameExpression )
912
+ {
913
+ name = nameExpression->evaluate ( *f ).toString ();
914
+ }
915
+
909
916
angle = -angle; // rotation in Qt is counterclockwise
910
917
if ( angle )
911
918
off = _rotatedOffset ( off, angle );
@@ -921,75 +928,42 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
921
928
if ( angle != 0 )
922
929
t.rotate ( angle );
923
930
924
- // data defined symbol name
925
-
926
- if ( mName == " circle" )
931
+ QPolygonF polygon;
932
+ if ( prepareShape ( name, polygon ) )
927
933
{
928
- if ( mBrush .style () != Qt::NoBrush )
929
- e.writeFilledCircle ( layerName, bc, shift, halfSize );
930
- if ( mPen .style () != Qt::NoPen )
931
- e.writeCircle ( layerName, pc, shift, halfSize, " CONTINUOUS" , outlineWidth );
932
- }
933
- else if ( mName == " square" || mName == " rectangle" )
934
- {
935
- QgsPolygon p ( 1 );
936
- p[0 ].resize ( 5 );
937
- p[0 ][0 ] = t.map ( QPointF ( -halfSize, -halfSize ) );
938
- p[0 ][1 ] = t.map ( QPointF ( -halfSize, halfSize ) );
939
- p[0 ][2 ] = t.map ( QPointF ( halfSize, halfSize ) );
940
- p[0 ][3 ] = t.map ( QPointF ( halfSize, -halfSize ) );
941
- p[0 ][4 ] = p[0 ][0 ];
934
+ t.scale ( halfSize, -halfSize );
935
+
936
+ polygon = t.map ( polygon );
942
937
943
- if ( mBrush .style () != Qt::NoBrush )
944
- e.writePolygon ( p, layerName, " SOLID" , bc );
945
- if ( mPen .style () != Qt::NoPen )
946
- e.writePolyline ( p[0 ], layerName, " CONTINUOUS" , pc, outlineWidth );
947
- }
948
- else if ( mName == " diamond" )
949
- {
950
938
QgsPolygon p ( 1 );
951
- p[ 0 ] .resize ( 5 );
952
- p[0 ][ 0 ] = t. map ( QPointF ( -halfSize, 0 ) );
953
- p[ 0 ][ 1 ] = t. map ( QPointF ( 0 , halfSize ) ) ;
954
- p[ 0 ][ 3 ] = t. map ( QPointF ( halfSize, 0 ) );
955
- p[0 ][1 ] = t. map ( QPointF ( 0 , -halfSize ) ) ;
956
- p[0 ][4 ] = p[0 ][0 ];
939
+ p.resize ( 1 );
940
+ p[0 ]. resize ( polygon. size () + 1 );
941
+ int i = 0 ;
942
+ for ( i = 0 ; i < polygon. size (); i++ )
943
+ p[0 ][i ] = polygon[i] ;
944
+ p[0 ][i ] = p[0 ][0 ];
957
945
958
946
if ( mBrush .style () != Qt::NoBrush )
959
947
e.writePolygon ( p, layerName, " SOLID" , bc );
960
948
if ( mPen .style () != Qt::NoPen )
961
949
e.writePolyline ( p[0 ], layerName, " CONTINUOUS" , pc, outlineWidth );
962
950
}
963
- else if ( mName == " triangle " )
951
+ else if ( name == " circle " )
964
952
{
965
- QgsPolygon p ( 1 );
966
- p[0 ].resize ( 4 );
967
- p[0 ][0 ] = t.map ( QPointF ( -halfSize, -halfSize ) );
968
- p[0 ][1 ] = t.map ( QPointF ( halfSize, -halfSize ) );
969
- p[0 ][1 ] = t.map ( QPointF ( 0 , halfSize ) );
970
- p[0 ][2 ] = p[0 ][0 ];
971
-
972
953
if ( mBrush .style () != Qt::NoBrush )
973
- e.writePolygon ( p, layerName, " SOLID" , bc );
974
-
954
+ e.writeFilledCircle ( layerName, bc, shift, halfSize );
975
955
if ( mPen .style () != Qt::NoPen )
976
- e.writePolyline ( p[0 ], layerName, " CONTINUOUS" , pc, outlineWidth );
977
- }
978
- #if 0
979
- else if ( mName == "equilateral_triangle" )
980
- {
981
-
956
+ e.writeCircle ( layerName, pc, shift, halfSize, " CONTINUOUS" , outlineWidth );
982
957
}
983
- #endif
984
- else if ( mName == " line" )
958
+ else if ( name == " line" )
985
959
{
986
- QPointF pt1 = t.map ( QPointF ( 0 , halfSize ) );
987
- QPointF pt2 = t.map ( QPointF ( 0 , - halfSize ) );
960
+ QPointF pt1 = t.map ( QPointF ( 0 , - halfSize ) );
961
+ QPointF pt2 = t.map ( QPointF ( 0 , halfSize ) );
988
962
989
963
if ( mPen .style () != Qt::NoPen )
990
964
e.writeLine ( pt1, pt2, layerName, " CONTINUOUS" , pc, outlineWidth );
991
965
}
992
- else if ( mName == " cross" )
966
+ else if ( name == " cross" )
993
967
{
994
968
if ( mPen .style () != Qt::NoPen )
995
969
{
@@ -1002,20 +976,20 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
1002
976
e.writeLine ( pt3, pt4, layerName, " CONTINUOUS" , pc, outlineWidth );
1003
977
}
1004
978
}
1005
- else if ( mName == " x" || mName == " cross2" )
979
+ else if ( name == " x" || name == " cross2" )
1006
980
{
1007
981
if ( mPen .style () != Qt::NoPen )
1008
982
{
1009
983
QPointF pt1 = t.map ( QPointF ( -halfSize, -halfSize ) );
1010
984
QPointF pt2 = t.map ( QPointF ( halfSize, halfSize ) );
1011
- QPointF pt3 = t.map ( QPointF ( - halfSize, halfSize ) );
1012
- QPointF pt4 = t.map ( QPointF ( halfSize, - halfSize ) );
985
+ QPointF pt3 = t.map ( QPointF ( halfSize, - halfSize ) );
986
+ QPointF pt4 = t.map ( QPointF ( - halfSize, halfSize ) );
1013
987
1014
988
e.writeLine ( pt1, pt2, layerName, " CONTINUOUS" , pc, outlineWidth );
1015
989
e.writeLine ( pt3, pt4, layerName, " CONTINUOUS" , pc, outlineWidth );
1016
990
}
1017
991
}
1018
- else if ( mName == " arrowhead" )
992
+ else if ( name == " arrowhead" )
1019
993
{
1020
994
if ( mPen .style () != Qt::NoPen )
1021
995
{
@@ -1027,21 +1001,9 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
1027
1001
e.writeLine ( pt3, pt2, layerName, " CONTINUOUS" , pc, outlineWidth );
1028
1002
}
1029
1003
}
1030
- else if ( mName == " filled_arrowhead" )
1031
- {
1032
- if ( mBrush .style () != Qt::NoBrush )
1033
- {
1034
- QgsPolygon p ( 1 );
1035
- p[0 ].resize ( 4 );
1036
- p[0 ][0 ] = t.map ( QPointF ( -halfSize, halfSize ) );
1037
- p[0 ][1 ] = t.map ( QPointF ( 0 , 0 ) );
1038
- p[0 ][2 ] = t.map ( QPointF ( -halfSize, -halfSize ) );
1039
- p[0 ][3 ] = p[0 ][0 ];
1040
- e.writePolygon ( p, layerName, " SOLID" , bc );
1041
- }
1042
- }
1043
1004
else
1044
1005
{
1006
+ QgsDebugMsg ( QString ( " Unsupported dxf marker name %1" ).arg ( name ) );
1045
1007
return false ;
1046
1008
}
1047
1009
@@ -1635,7 +1597,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
1635
1597
QgsExpression* offsetExpression = expression ( " offset" );
1636
1598
if ( offsetExpression )
1637
1599
{
1638
- QString offsetString = offsetExpression->evaluate ( *f ).toString ();
1600
+ QString offsetString = offsetExpression->evaluate ( *f ).toString ();
1639
1601
offset = QgsSymbolLayerV2Utils::decodePoint ( offsetString );
1640
1602
}
1641
1603
double offsetX = offset.x ();
0 commit comments