Skip to content

Commit b28c484

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

File tree

3 files changed

+46
-85
lines changed

3 files changed

+46
-85
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: 43 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -320,27 +320,27 @@ void QgsSimpleMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context
320320

321321
bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
322322
{
323-
mPolygon.clear();
323+
return prepareShape( name.isNull() ? mName : name, mPolygon );
324+
}
324325

325-
if ( name.isNull() )
326-
{
327-
name = mName;
328-
}
326+
bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name, QPolygonF &polygon ) const
327+
{
328+
polygon.clear();
329329

330330
if ( name == "square" || name == "rectangle" )
331331
{
332-
mPolygon = QPolygonF( QRectF( QPointF( -1, -1 ), QPointF( 1, 1 ) ) );
332+
polygon = QPolygonF( QRectF( QPointF( -1, -1 ), QPointF( 1, 1 ) ) );
333333
return true;
334334
}
335335
else if ( name == "diamond" )
336336
{
337-
mPolygon << QPointF( -1, 0 ) << QPointF( 0, 1 )
337+
polygon << QPointF( -1, 0 ) << QPointF( 0, 1 )
338338
<< QPointF( 1, 0 ) << QPointF( 0, -1 );
339339
return true;
340340
}
341341
else if ( name == "pentagon" )
342342
{
343-
mPolygon << QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288.0 ) ) )
343+
polygon << QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288.0 ) ) )
344344
<< QPointF( sin( DEG2RAD( 216.0 ) ), - cos( DEG2RAD( 216.0 ) ) )
345345
<< QPointF( sin( DEG2RAD( 144.0 ) ), - cos( DEG2RAD( 144.0 ) ) )
346346
<< QPointF( sin( DEG2RAD( 72.0 ) ), - cos( DEG2RAD( 72.0 ) ) )
@@ -349,12 +349,12 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
349349
}
350350
else if ( name == "triangle" )
351351
{
352-
mPolygon << QPointF( -1, 1 ) << QPointF( 1, 1 ) << QPointF( 0, -1 );
352+
polygon << QPointF( -1, 1 ) << QPointF( 1, 1 ) << QPointF( 0, -1 );
353353
return true;
354354
}
355355
else if ( name == "equilateral_triangle" )
356356
{
357-
mPolygon << QPointF( sin( DEG2RAD( 240.0 ) ), - cos( DEG2RAD( 240.0 ) ) )
357+
polygon << QPointF( sin( DEG2RAD( 240.0 ) ), - cos( DEG2RAD( 240.0 ) ) )
358358
<< QPointF( sin( DEG2RAD( 120.0 ) ), - cos( DEG2RAD( 120.0 ) ) )
359359
<< QPointF( 0, -1 );
360360
return true;
@@ -363,7 +363,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
363363
{
364364
double sixth = 1.0 / 3;
365365

366-
mPolygon << QPointF( 0, -1 )
366+
polygon << QPointF( 0, -1 )
367367
<< QPointF( -sixth, -sixth )
368368
<< QPointF( -1, -sixth )
369369
<< QPointF( -sixth, 0 )
@@ -379,7 +379,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
379379
{
380380
double inner_r = cos( DEG2RAD( 72.0 ) ) / cos( DEG2RAD( 36.0 ) );
381381

382-
mPolygon << QPointF( inner_r * sin( DEG2RAD( 324.0 ) ), - inner_r * cos( DEG2RAD( 324.0 ) ) ) // 324
382+
polygon << QPointF( inner_r * sin( DEG2RAD( 324.0 ) ), - inner_r * cos( DEG2RAD( 324.0 ) ) ) // 324
383383
<< QPointF( sin( DEG2RAD( 288.0 ) ), - cos( DEG2RAD( 288 ) ) ) // 288
384384
<< QPointF( inner_r * sin( DEG2RAD( 252.0 ) ), - inner_r * cos( DEG2RAD( 252.0 ) ) ) // 252
385385
<< QPointF( sin( DEG2RAD( 216.0 ) ), - cos( DEG2RAD( 216.0 ) ) ) // 216
@@ -393,8 +393,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
393393
}
394394
else if ( name == "arrow" )
395395
{
396-
mPolygon
397-
<< QPointF( 0, -1 )
396+
polygon << QPointF( 0, -1 )
398397
<< QPointF( 0.5, -0.5 )
399398
<< QPointF( 0.25, -0.5 )
400399
<< QPointF( 0.25, 1 )
@@ -405,7 +404,7 @@ bool QgsSimpleMarkerSymbolLayerV2::prepareShape( QString name )
405404
}
406405
else if ( name == "filled_arrowhead" )
407406
{
408-
mPolygon << QPointF( 0, 0 ) << QPointF( -1, 1 ) << QPointF( -1, -1 );
407+
polygon << QPointF( 0, 0 ) << QPointF( -1, 1 ) << QPointF( -1, -1 );
409408
return true;
410409
}
411410

@@ -883,6 +882,12 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
883882
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, f, mAngle ).toDouble() + mLineAngle;
884883
}
885884

885+
QString name( mName );
886+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
887+
{
888+
name = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME, f, QVariant(), &ok ).toString();
889+
}
890+
886891
angle = -angle; //rotation in Qt is counterclockwise
887892
if ( angle )
888893
off = _rotatedOffset( off, angle );
@@ -898,75 +903,42 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
898903
if ( angle != 0 )
899904
t.rotate( angle );
900905

901-
//data defined symbol name
902-
903-
if ( mName == "circle" )
906+
QPolygonF polygon;
907+
if ( prepareShape( name, polygon ) )
904908
{
905-
if ( mBrush.style() != Qt::NoBrush )
906-
e.writeFilledCircle( layerName, bc, shift, halfSize );
907-
if ( mPen.style() != Qt::NoPen )
908-
e.writeCircle( layerName, pc, shift, halfSize, "CONTINUOUS", outlineWidth );
909-
}
910-
else if ( mName == "square" || mName == "rectangle" )
911-
{
912-
QgsPolygon p( 1 );
913-
p[0].resize( 5 );
914-
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
915-
p[0][1] = t.map( QPointF( -halfSize, halfSize ) );
916-
p[0][2] = t.map( QPointF( halfSize, halfSize ) );
917-
p[0][3] = t.map( QPointF( halfSize, -halfSize ) );
918-
p[0][4] = p[0][0];
909+
t.scale( halfSize, -halfSize );
910+
911+
polygon = t.map( polygon );
919912

920-
if ( mBrush.style() != Qt::NoBrush )
921-
e.writePolygon( p, layerName, "SOLID", bc );
922-
if ( mPen.style() != Qt::NoPen )
923-
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
924-
}
925-
else if ( mName == "diamond" )
926-
{
927913
QgsPolygon p( 1 );
928-
p[0].resize( 5 );
929-
p[0][0] = t.map( QPointF( -halfSize, 0 ) );
930-
p[0][1] = t.map( QPointF( 0, halfSize ) );
931-
p[0][3] = t.map( QPointF( halfSize, 0 ) );
932-
p[0][1] = t.map( QPointF( 0, -halfSize ) );
933-
p[0][4] = p[0][0];
914+
p.resize( 1 );
915+
p[0].resize( polygon.size() + 1 );
916+
int i = 0;
917+
for ( i = 0; i < polygon.size(); i++ )
918+
p[0][i] = polygon[i];
919+
p[0][i] = p[0][0];
934920

935921
if ( mBrush.style() != Qt::NoBrush )
936922
e.writePolygon( p, layerName, "SOLID", bc );
937923
if ( mPen.style() != Qt::NoPen )
938924
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
939925
}
940-
else if ( mName == "triangle" )
926+
else if ( name == "circle" )
941927
{
942-
QgsPolygon p( 1 );
943-
p[0].resize( 4 );
944-
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
945-
p[0][1] = t.map( QPointF( halfSize, -halfSize ) );
946-
p[0][1] = t.map( QPointF( 0, halfSize ) );
947-
p[0][2] = p[0][0];
948-
949928
if ( mBrush.style() != Qt::NoBrush )
950-
e.writePolygon( p, layerName, "SOLID", bc );
951-
929+
e.writeFilledCircle( layerName, bc, shift, halfSize );
952930
if ( mPen.style() != Qt::NoPen )
953-
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
954-
}
955-
#if 0
956-
else if ( mName == "equilateral_triangle" )
957-
{
958-
931+
e.writeCircle( layerName, pc, shift, halfSize, "CONTINUOUS", outlineWidth );
959932
}
960-
#endif
961-
else if ( mName == "line" )
933+
else if ( name == "line" )
962934
{
963-
QPointF pt1 = t.map( QPointF( 0, halfSize ) );
964-
QPointF pt2 = t.map( QPointF( 0, -halfSize ) );
935+
QPointF pt1 = t.map( QPointF( 0, -halfSize ) );
936+
QPointF pt2 = t.map( QPointF( 0, halfSize ) );
965937

966938
if ( mPen.style() != Qt::NoPen )
967939
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
968940
}
969-
else if ( mName == "cross" )
941+
else if ( name == "cross" )
970942
{
971943
if ( mPen.style() != Qt::NoPen )
972944
{
@@ -979,20 +951,20 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
979951
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
980952
}
981953
}
982-
else if ( mName == "x" || mName == "cross2" )
954+
else if ( name == "x" || name == "cross2" )
983955
{
984956
if ( mPen.style() != Qt::NoPen )
985957
{
986958
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
987959
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
988-
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
989-
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );
960+
QPointF pt3 = t.map( QPointF( halfSize, -halfSize ) );
961+
QPointF pt4 = t.map( QPointF( -halfSize, halfSize ) );
990962

991963
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
992964
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
993965
}
994966
}
995-
else if ( mName == "arrowhead" )
967+
else if ( name == "arrowhead" )
996968
{
997969
if ( mPen.style() != Qt::NoPen )
998970
{
@@ -1004,21 +976,9 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
1004976
e.writeLine( pt3, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
1005977
}
1006978
}
1007-
else if ( mName == "filled_arrowhead" )
1008-
{
1009-
if ( mBrush.style() != Qt::NoBrush )
1010-
{
1011-
QgsPolygon p( 1 );
1012-
p[0].resize( 4 );
1013-
p[0][0] = t.map( QPointF( -halfSize, halfSize ) );
1014-
p[0][1] = t.map( QPointF( 0, 0 ) );
1015-
p[0][2] = t.map( QPointF( -halfSize, -halfSize ) );
1016-
p[0][3] = p[0][0];
1017-
e.writePolygon( p, layerName, "SOLID", bc );
1018-
}
1019-
}
1020979
else
1021980
{
981+
QgsDebugMsg( QString( "Unsupported dxf marker name %1" ).arg( name ) );
1022982
return false;
1023983
}
1024984

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

Lines changed: 2 additions & 2 deletions
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

@@ -132,7 +133,6 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
132133

133134
//Maximum width/height of cache image
134135
static const int mMaximumCacheWidth = 3000;
135-
136136
};
137137

138138
//////////

0 commit comments

Comments
 (0)
Please sign in to comment.