Skip to content

Commit f202c03

Browse files
committedJul 2, 2015
dxf export:
* add missing marker types (fixes #13062) * add missing support for data-defined marker names (fixes #13063) (backported from b28c484)
1 parent a4e629b commit f202c03

File tree

3 files changed

+52
-88
lines changed

3 files changed

+52
-88
lines changed
 

‎python/core/symbology-ng/qgsmarkersymbollayerv2.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
7979
void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
8080

8181
bool prepareShape( QString name = QString() );
82+
bool prepareShape( QString name, QPolygonF &polygon ) const;
8283
bool preparePath( QString name = QString() );
8384

8485
/**Prepares cache image

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

Lines changed: 49 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,27 @@ void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context
365365

366366
bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
367367
{
368-
mPolygon.clear();
368+
return prepareShape( name.isNull() ? mName : name, mPolygon );
369+
}
369370

370-
if ( name.isNull() )
371-
{
372-
name = mName;
373-
}
371+
bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name, QPolygonF &polygon ) const
372+
{
373+
polygon.clear();
374374

375375
if ( name == "square" || name == "rectangle" )
376376
{
377-
mPolygon = QPolygonF( QRectF( QPointF( -1, -1 ), QPointF( 1, 1 ) ) );
377+
polygon = QPolygonF( QRectF( QPointF( -1, -1 ), QPointF( 1, 1 ) ) );
378378
return true;
379379
}
380380
else if ( name == "diamond" )
381381
{
382-
mPolygon << QPointF( -1, 0 ) << QPointF( 0, 1 )
382+
polygon << QPointF( -1, 0 ) << QPointF( 0, 1 )
383383
<< QPointF( 1, 0 ) << QPointF( 0, -1 );
384384
return true;
385385
}
386386
else if ( name == "pentagon" )
387387
{
388-
mPolygon << QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288.0 ) ) )
388+
polygon << QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288.0 ) ) )
389389
<< QPointF( sin( DEG2RAD( 216.0 ) ), - cos( DEG2RAD( 216.0 ) ) )
390390
<< QPointF( sin( DEG2RAD( 144.0 ) ), - cos( DEG2RAD( 144.0 ) ) )
391391
<< QPointF( sin( DEG2RAD( 72.0 ) ), - cos( DEG2RAD( 72.0 ) ) )
@@ -394,12 +394,12 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
394394
}
395395
else if ( name == "triangle" )
396396
{
397-
mPolygon << QPointF( -1, 1 ) << QPointF( 1, 1 ) << QPointF( 0, -1 );
397+
polygon << QPointF( -1, 1 ) << QPointF( 1, 1 ) << QPointF( 0, -1 );
398398
return true;
399399
}
400400
else if ( name == "equilateral_triangle" )
401401
{
402-
mPolygon << QPointF( sin( DEG2RAD( 240.0 ) ), - cos( DEG2RAD( 240.0 ) ) )
402+
polygon << QPointF( sin( DEG2RAD( 240.0 ) ), - cos( DEG2RAD( 240.0 ) ) )
403403
<< QPointF( sin( DEG2RAD( 120.0 ) ), - cos( DEG2RAD( 120.0 ) ) )
404404
<< QPointF( 0, -1 );
405405
return true;
@@ -408,7 +408,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
408408
{
409409
double sixth = 1.0 / 3;
410410

411-
mPolygon << QPointF( 0, -1 )
411+
polygon << QPointF( 0, -1 )
412412
<< QPointF( -sixth, -sixth )
413413
<< QPointF( -1, -sixth )
414414
<< QPointF( -sixth, 0 )
@@ -424,7 +424,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
424424
{
425425
double inner_r = cos( DEG2RAD( 72.0 ) ) / cos( DEG2RAD( 36.0 ) );
426426

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
428428
<< QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288 ) ) ) // 288
429429
<< QPointF( inner_r * sin( DEG2RAD( 252.0 ) ), - inner_r * cos( DEG2RAD( 252.0 ) ) ) // 252
430430
<< QPointF( sin( DEG2RAD( 216.0 ) ), - cos( DEG2RAD( 216.0 ) ) ) // 216
@@ -438,8 +438,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
438438
}
439439
else if ( name == "arrow" )
440440
{
441-
mPolygon
442-
<< QPointF( 0, -1 )
441+
polygon << QPointF( 0, -1 )
443442
<< QPointF( 0.5, -0.5 )
444443
<< QPointF( 0.25, -0.5 )
445444
<< QPointF( 0.25, 1 )
@@ -450,7 +449,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
450449
}
451450
else if ( name == "filled_arrowhead" )
452451
{
453-
mPolygon << QPointF( 0, 0 ) << QPointF( -1, 1 ) << QPointF( -1, -1 );
452+
polygon << QPointF( 0, 0 ) << QPointF( -1, 1 ) << QPointF( -1, -1 );
454453
return true;
455454
}
456455

@@ -842,7 +841,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
842841
{
843842
if ( sizeExpression )
844843
{
845-
size = sizeExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
844+
size = sizeExpression->evaluate( *f ).toDouble();
846845
}
847846

848847
switch ( mScaleMethod )
@@ -867,7 +866,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
867866
QgsExpression* outlineWidthExpression = expression( "outline_width" );
868867
if ( context && outlineWidthExpression )
869868
{
870-
outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
869+
outlineWidth = outlineWidthExpression->evaluate( *f ).toDouble();
871870
}
872871
if ( mSizeUnit == QgsSymbolV2::MM )
873872
{
@@ -904,8 +903,16 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
904903
QgsExpression* angleExpression = expression( "angle" );
905904
if ( context && angleExpression )
906905
{
907-
angle = angleExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
906+
angle = angleExpression->evaluate( *f ).toDouble();
908907
}
908+
909+
QString name( mName );
910+
QgsExpression* nameExpression = expression( "name" );
911+
if ( context && nameExpression )
912+
{
913+
name = nameExpression->evaluate( *f ).toString();
914+
}
915+
909916
angle = -angle; //rotation in Qt is counterclockwise
910917
if ( angle )
911918
off = _rotatedOffset( off, angle );
@@ -921,75 +928,42 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
921928
if ( angle != 0 )
922929
t.rotate( angle );
923930

924-
//data defined symbol name
925-
926-
if ( mName == "circle" )
931+
QPolygonF polygon;
932+
if ( prepareShape( name, polygon ) )
927933
{
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 );
942937

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-
{
950938
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];
957945

958946
if ( mBrush.style() != Qt::NoBrush )
959947
e.writePolygon( p, layerName, "SOLID", bc );
960948
if ( mPen.style() != Qt::NoPen )
961949
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
962950
}
963-
else if ( mName == "triangle" )
951+
else if ( name == "circle" )
964952
{
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-
972953
if ( mBrush.style() != Qt::NoBrush )
973-
e.writePolygon( p, layerName, "SOLID", bc );
974-
954+
e.writeFilledCircle( layerName, bc, shift, halfSize );
975955
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 );
982957
}
983-
#endif
984-
else if ( mName == "line" )
958+
else if ( name == "line" )
985959
{
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 ) );
988962

989963
if ( mPen.style() != Qt::NoPen )
990964
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
991965
}
992-
else if ( mName == "cross" )
966+
else if ( name == "cross" )
993967
{
994968
if ( mPen.style() != Qt::NoPen )
995969
{
@@ -1002,20 +976,20 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
1002976
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
1003977
}
1004978
}
1005-
else if ( mName == "x" || mName == "cross2" )
979+
else if ( name == "x" || name == "cross2" )
1006980
{
1007981
if ( mPen.style() != Qt::NoPen )
1008982
{
1009983
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
1010984
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 ) );
1013987

1014988
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
1015989
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
1016990
}
1017991
}
1018-
else if ( mName == "arrowhead" )
992+
else if ( name == "arrowhead" )
1019993
{
1020994
if ( mPen.style() != Qt::NoPen )
1021995
{
@@ -1027,21 +1001,9 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
10271001
e.writeLine( pt3, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
10281002
}
10291003
}
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-
}
10431004
else
10441005
{
1006+
QgsDebugMsg( QString( "Unsupported dxf marker name %1" ).arg( name ) );
10451007
return false;
10461008
}
10471009

@@ -1635,7 +1597,7 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
16351597
QgsExpression* offsetExpression = expression( "offset" );
16361598
if ( offsetExpression )
16371599
{
1638-
QString offsetString = offsetExpression->evaluate( *f ).toString();
1600+
QString offsetString = offsetExpression->evaluate( *f ).toString();
16391601
offset = QgsSymbolLayerV2Utils::decodePoint( offsetString );
16401602
}
16411603
double offsetX = offset.x();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
108108
void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
109109

110110
bool prepareShape( QString name = QString() );
111+
bool prepareShape( QString name, QPolygonF &polygon ) const;
111112
bool preparePath( QString name = QString() );
112113

113-
/**Prepares cache image
114+
/** Prepares cache image
114115
@return true in case of success, false if cache image size too large*/
115116
bool prepareCache( QgsSymbolV2RenderContext& context );
116117

0 commit comments

Comments
 (0)
Please sign in to comment.