16 #include "qgsdxfexport.h"
25 #include <QDomDocument>
26 #include <QDomElement>
29 mSymbolHeightUnit(
QgsSymbolV2::MM ), mFillColor( Qt::white ), mOutlineColor( Qt::black ), mOutlineStyle( Qt::SolidLine ), mOutlineWidth( 0 ), mOutlineWidthUnit(
QgsSymbolV2::MM )
34 mPen.setJoinStyle( Qt::MiterJoin );
36 mBrush.setStyle( Qt::SolidPattern );
49 if ( properties.contains(
"symbol_name" ) )
53 if ( properties.contains(
"symbol_width" ) )
57 if ( properties.contains(
"symbol_width_unit" ) )
61 if ( properties.contains(
"symbol_height" ) )
65 if ( properties.contains(
"symbol_height_unit" ) )
69 if ( properties.contains(
"angle" ) )
71 layer->
setAngle( properties[
"angle"].toDouble() );
73 if ( properties.contains(
"outline_style" ) )
77 if ( properties.contains(
"outline_width" ) )
81 if ( properties.contains(
"outline_width_unit" ) )
85 if ( properties.contains(
"fill_color" ) )
89 if ( properties.contains(
"outline_color" ) )
93 if ( properties.contains(
"offset" ) )
97 if ( properties.contains(
"offset_unit" ) )
101 if ( properties.contains(
"horizontal_anchor_point" ) )
105 if ( properties.contains(
"vertical_anchor_point" ) )
111 if ( properties.contains(
"width_expression" ) )
115 if ( properties.contains(
"height_expression" ) )
119 if ( properties.contains(
"rotation_expression" ) )
123 if ( properties.contains(
"outline_width_expression" ) )
127 if ( properties.contains(
"fill_color_expression" ) )
131 if ( properties.contains(
"outline_color_expression" ) )
135 if ( properties.contains(
"symbol_name_expression" ) )
139 if ( properties.contains(
"offset_expression" ) )
143 if ( properties.contains(
"horizontal_anchor_point_expression" ) )
145 layer->
setDataDefinedProperty(
"horizontal_anchor_point", properties[
"horizontal_anchor_point_expression" ] );
147 if ( properties.contains(
"vertical_anchor_point_expression" ) )
149 layer->
setDataDefinedProperty(
"vertical_anchor_point", properties[
"vertical_anchor_point_expression" ] );
153 if ( !properties[
"width_field"].isEmpty() )
157 if ( !properties[
"height_field"].isEmpty() )
161 if ( !properties[
"rotation_field"].isEmpty() )
165 if ( !properties[
"outline_width_field"].isEmpty() )
169 if ( !properties[
"fill_color_field"].isEmpty() )
173 if ( !properties[
"outline_color_field"].isEmpty() )
177 if ( !properties[
"symbol_name_field"].isEmpty() )
195 if ( outlineWidthExpression )
197 double width = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
199 mPen.setWidthF( width );
201 if ( fillColorExpression )
203 QString colorString = fillColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
206 if ( outlineColorExpression )
208 QString colorString = outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
211 if ( widthExpression || heightExpression || symbolNameExpression )
214 if ( symbolNameExpression )
216 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
225 QPointF off( offsetX, offsetY );
234 double rotation = 0.0;
235 if ( rotationExpression )
237 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
247 transform.translate( point.x() + off.x(), point.y() + off.y() );
250 transform.rotate( rotation );
260 return "EllipseMarker";
287 QDomElement symbolizerElem = doc.createElement(
"se:PointSymbolizer" );
288 if ( !props.value(
"uom",
"" ).isEmpty() )
289 symbolizerElem.setAttribute(
"uom", props.value(
"uom",
"" ) );
290 element.appendChild( symbolizerElem );
301 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
302 element.appendChild( graphicElem );
309 graphicElem.appendChild( factorElem );
313 QString angleFunc = props.value(
"angle",
"" );
314 if ( angleFunc.isEmpty() )
317 if ( rotationExpression )
320 angleFunc = QString::number(
mAngle );
322 else if ( rotationExpression )
326 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg( rotationExpression->
expression() );
332 double angle = angleFunc.toDouble( &ok );
336 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg(
mAngle );
341 angleFunc = QString::number( angle +
mAngle );
351 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
352 if ( graphicElem.isNull() )
355 QString name =
"circle";
357 double borderWidth,
size;
358 double widthHeightFactor = 1.0;
359 Qt::PenStyle borderStyle;
362 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
364 if ( it.key() ==
"widthHeightFactor" )
367 double v = it.value().toDouble( &ok );
369 widthHeightFactor = v;
381 double d = angleFunc.toDouble( &ok );
406 map[
"angle"] = QString::number(
mAngle );
435 if ( widthExpression )
437 width = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
451 if ( heightExpression )
453 height = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
465 if ( symbolName ==
"circle" )
467 mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
469 else if ( symbolName ==
"rectangle" )
471 mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
473 else if ( symbolName ==
"cross" )
480 else if ( symbolName ==
"triangle" )
511 if ( widthExpression )
513 symbolWidth = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
521 symbolWidth *= mmMapUnitScaleFactor;
527 if ( heightExpression )
529 symbolHeight = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
533 symbolHeight =
mSize;
537 symbolHeight *= mmMapUnitScaleFactor;
543 if ( outlineWidthExpression )
545 outlineWidth = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
555 if ( fillColorExpression )
557 c = QColor( fillColorExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString() );
559 int colorIndex = e.closestColorMatch( c.rgb() );
564 if ( symbolNameExpression )
567 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString();
574 QPointF off( offsetX, offsetY );
577 double rotation = 0.0;
579 if ( rotationExpression )
581 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
587 rotation = -rotation;
592 t.translate( shift.x() + offsetX, shift.y() + offsetY );
595 t.rotate( rotation );
597 double halfWidth = symbolWidth / 2.0;
598 double halfHeight = symbolHeight / 2.0;
600 if ( symbolName ==
"circle" )
604 else if ( symbolName ==
"rectangle" )
606 QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
607 QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
608 QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) );
609 QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) );
610 e.writeSolid( layerName, colorIndex,
QgsPoint( pt1.x(), pt1.y() ),
QgsPoint( pt2.x(), pt2.y() ),
QgsPoint( pt3.x(), pt3.y() ),
QgsPoint( pt4.x(), pt4.y() ) );
613 else if ( symbolName ==
"cross" )
616 QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) );
617 QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
618 line1[0] =
QgsPoint( pt1.x(), pt1.y() );
619 line1[1] =
QgsPoint( pt2.x(), pt2.y() );
620 e.writePolyline( line1, layerName,
"CONTINUOUS", colorIndex, outlineWidth,
false );
622 QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
624 line2[0] =
QgsPoint( pt3.x(), pt3.y() );
625 line2[1] =
QgsPoint( pt3.x(), pt3.y() );
626 e.writePolyline( line2, layerName,
"CONTINUOUS", colorIndex, outlineWidth,
false );
629 else if ( symbolName ==
"triangle" )
631 QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
632 QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
633 QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
634 QPointF pt4( t.map( QPointF( 0, halfHeight ) ) );
635 e.writeSolid( layerName, colorIndex,
QgsPoint( pt1.x(), pt1.y() ),
QgsPoint( pt2.x(), pt2.y() ),
QgsPoint( pt3.x(), pt3.y() ),
QgsPoint( pt4.x(), pt4.y() ) );