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_width_map_unit_scale" ) )
65 if ( properties.contains(
"symbol_height" ) )
69 if ( properties.contains(
"symbol_height_unit" ) )
73 if ( properties.contains(
"symbol_height_map_unit_scale" ) )
77 if ( properties.contains(
"angle" ) )
79 layer->
setAngle( properties[
"angle"].toDouble() );
81 if ( properties.contains(
"outline_style" ) )
85 if ( properties.contains(
"outline_width" ) )
89 if ( properties.contains(
"outline_width_unit" ) )
93 if ( properties.contains(
"outline_width_map_unit_scale" ) )
97 if ( properties.contains(
"fill_color" ) )
101 if ( properties.contains(
"outline_color" ) )
105 if ( properties.contains(
"size" ) )
107 layer->
setSize( properties[
"size"].toDouble() );
109 if ( properties.contains(
"size_unit" ) )
113 if ( properties.contains(
"size_map_unit_scale" ) )
117 if ( properties.contains(
"offset" ) )
121 if ( properties.contains(
"offset_unit" ) )
125 if ( properties.contains(
"offset_map_unit_scale" ) )
129 if ( properties.contains(
"horizontal_anchor_point" ) )
133 if ( properties.contains(
"vertical_anchor_point" ) )
139 if ( properties.contains(
"width_expression" ) )
143 if ( properties.contains(
"height_expression" ) )
147 if ( properties.contains(
"rotation_expression" ) )
151 if ( properties.contains(
"outline_width_expression" ) )
155 if ( properties.contains(
"fill_color_expression" ) )
159 if ( properties.contains(
"outline_color_expression" ) )
163 if ( properties.contains(
"symbol_name_expression" ) )
167 if ( properties.contains(
"offset_expression" ) )
171 if ( properties.contains(
"horizontal_anchor_point_expression" ) )
173 layer->
setDataDefinedProperty(
"horizontal_anchor_point", properties[
"horizontal_anchor_point_expression" ] );
175 if ( properties.contains(
"vertical_anchor_point_expression" ) )
177 layer->
setDataDefinedProperty(
"vertical_anchor_point", properties[
"vertical_anchor_point_expression" ] );
181 if ( !properties[
"width_field"].isEmpty() )
185 if ( !properties[
"height_field"].isEmpty() )
189 if ( !properties[
"rotation_field"].isEmpty() )
193 if ( !properties[
"outline_width_field"].isEmpty() )
197 if ( !properties[
"fill_color_field"].isEmpty() )
201 if ( !properties[
"outline_color_field"].isEmpty() )
205 if ( !properties[
"symbol_name_field"].isEmpty() )
223 if ( outlineWidthExpression )
225 double width = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
227 mPen.setWidthF( width );
229 if ( fillColorExpression )
231 QString colorString = fillColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
234 if ( outlineColorExpression )
236 QString colorString = outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
241 if ( widthExpression || heightExpression || symbolNameExpression )
244 if ( symbolNameExpression )
246 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
255 QPointF off( offsetX, offsetY );
264 double rotation = 0.0;
265 if ( rotationExpression )
267 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
277 transform.translate( point.x() + off.x(), point.y() + off.y() );
280 transform.rotate( rotation );
290 return "EllipseMarker";
318 QDomElement symbolizerElem = doc.createElement(
"se:PointSymbolizer" );
319 if ( !props.value(
"uom",
"" ).isEmpty() )
320 symbolizerElem.setAttribute(
"uom", props.value(
"uom",
"" ) );
321 element.appendChild( symbolizerElem );
332 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
333 element.appendChild( graphicElem );
340 graphicElem.appendChild( factorElem );
344 QString angleFunc = props.value(
"angle",
"" );
345 if ( angleFunc.isEmpty() )
348 if ( rotationExpression )
351 angleFunc = QString::number(
mAngle );
353 else if ( rotationExpression )
357 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg( rotationExpression->
expression() );
363 double angle = angleFunc.toDouble( &ok );
367 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg(
mAngle );
372 angleFunc = QString::number( angle +
mAngle );
382 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
383 if ( graphicElem.isNull() )
386 QString name =
"circle";
388 double borderWidth,
size;
389 double widthHeightFactor = 1.0;
390 Qt::PenStyle borderStyle;
393 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
395 if ( it.key() ==
"widthHeightFactor" )
398 double v = it.value().toDouble( &ok );
400 widthHeightFactor = v;
412 double d = angleFunc.toDouble( &ok );
439 map[
"angle"] = QString::number(
mAngle );
449 map[
"size"] = QString::number(
mSize );
473 if ( widthExpression )
475 width = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
487 *scaledWidth = width;
493 if ( heightExpression )
495 height = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
507 *scaledHeight = height;
511 if ( symbolName ==
"circle" )
513 mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
515 else if ( symbolName ==
"rectangle" )
517 mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
519 else if ( symbolName ==
"cross" )
526 else if ( symbolName ==
"triangle" )
577 if ( widthExpression )
579 symbolWidth = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
587 symbolWidth *= mmMapUnitScaleFactor;
593 if ( heightExpression )
595 symbolHeight = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
599 symbolHeight =
mSize;
603 symbolHeight *= mmMapUnitScaleFactor;
609 if ( outlineWidthExpression )
611 outlineWidth = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
621 if ( fillColorExpression )
623 fc = QColor( fillColorExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString() );
625 int fillColorIndex = e.closestColorMatch( fc.rgb() );
630 if ( outlineColorExpression )
632 oc = QColor( outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString() );
634 int outlineColorIndex = e.closestColorMatch( oc.rgb() );
640 if ( symbolNameExpression )
643 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString();
650 QPointF off( offsetX, offsetY );
653 double rotation = 0.0;
655 if ( rotationExpression )
657 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
663 rotation = -rotation;
668 t.translate( shift.x() + offsetX, shift.y() + offsetY );
671 t.rotate( rotation );
673 double halfWidth = symbolWidth / 2.0;
674 double halfHeight = symbolHeight / 2.0;
676 if ( symbolName ==
"circle" )
680 QPointF pt( t.map( QPointF( 0, 0 ) ) );
681 e.writeCircle( layerName, outlineColorIndex,
QgsPoint( pt.x(), pt.y() ), halfWidth );
686 double stepsize = 2 *
M_PI / 40;
687 for (
int i = 0; i < 39; ++i )
689 double angle = stepsize * i;
690 double x = halfWidth * cos( angle );
691 double y = halfHeight * sin( angle );
692 QPointF pt( t.map( QPointF( x, y ) ) );
693 line.push_back(
QgsPoint( pt.x(), pt.y() ) );
696 line.push_back( line.at( 0 ) );
697 e.writePolyline( line, layerName,
"solid", outlineColorIndex, outlineWidth,
true );
700 else if ( symbolName ==
"rectangle" )
702 QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
703 QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
704 QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) );
705 QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) );
706 e.writeSolid( layerName, fillColorIndex,
QgsPoint( pt1.x(), pt1.y() ),
QgsPoint( pt2.x(), pt2.y() ),
QgsPoint( pt3.x(), pt3.y() ),
QgsPoint( pt4.x(), pt4.y() ) );
709 else if ( symbolName ==
"cross" )
712 QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) );
713 QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
714 line1[0] =
QgsPoint( pt1.x(), pt1.y() );
715 line1[1] =
QgsPoint( pt2.x(), pt2.y() );
716 e.writePolyline( line1, layerName,
"CONTINUOUS", outlineColorIndex, outlineWidth,
false );
718 QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
719 QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
720 line2[0] =
QgsPoint( pt3.x(), pt3.y() );
721 line2[1] =
QgsPoint( pt4.x(), pt4.y() );
722 e.writePolyline( line2, layerName,
"CONTINUOUS", outlineColorIndex, outlineWidth,
false );
725 else if ( symbolName ==
"triangle" )
727 QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
728 QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
729 QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
730 QPointF pt4( t.map( QPointF( 0, halfHeight ) ) );
731 e.writeSolid( layerName, fillColorIndex,
QgsPoint( pt1.x(), pt1.y() ),
QgsPoint( pt2.x(), pt2.y() ),
QgsPoint( pt3.x(), pt3.y() ),
QgsPoint( pt4.x(), pt4.y() ) );
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
Class for parsing and evaluation of expressions (formerly called "search strings").
~QgsEllipseSymbolLayerV2()
void setSymbolHeight(double h)
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mSizeMapUnitScale
bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, const QgsSymbolV2RenderContext *context, const QgsFeature *f, const QPointF &shift=QPointF(0.0, 0.0)) const
QgsSymbolV2::OutputUnit outputUnit() const
QColor fillColor() const
Get fill color.
static Q_DECL_DEPRECATED bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
void setSymbolWidth(double w)
QgsSymbolV2::OutputUnit mOutlineWidthUnit
const QString expression() const
Alias for dump()
void setMapUnitScale(const QgsMapUnitScale &scale)
double outlineWidth() const
QgsSymbolV2::OutputUnit mSymbolHeightUnit
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
void startRender(QgsSymbolV2RenderContext &context)
QgsSymbolV2::OutputUnit mSymbolWidthUnit
static void createRotationElement(QDomDocument &doc, QDomElement &element, QString rotationFunc)
double rendererScale() const
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
QgsSymbolV2::OutputUnit outputUnit() const
static QgsStringMap getVendorOptionList(QDomElement &element)
void setOffset(QPointF offset)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static QPointF decodePoint(QString str)
void setVerticalAnchorPoint(VerticalAnchorPoint v)
static QDomElement createVendorOptionElement(QDomDocument &doc, QString name, QString value)
static QColor decodeColor(QString str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context)
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
A symbol layer for rendering objects with major and minor axis (e.g.
QMap< QString, QString > QgsStringMap
double symbolWidth() const
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QString layerType() const
QgsMapUnitScale mOutlineWidthMapUnitScale
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static QString encodeColor(QColor color)
virtual QgsExpression * expression(const QString &property) const
static QString encodePenStyle(Qt::PenStyle style)
void preparePath(const QString &symbolName, QgsSymbolV2RenderContext &context, double *scaledWidth=0, double *scaledHeight=0, const QgsFeature *f=0)
Setup mPainterPath.
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
void setMapUnitScale(const QgsMapUnitScale &scale)
const QgsFeature * feature() const
Current feature being rendered - may be null.
static QString encodePoint(QPointF point)
void setFillColor(const QColor &c)
Set fill color.
static Qt::PenStyle decodePenStyle(QString str)
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
Qt::PenStyle mOutlineStyle
HorizontalAnchorPoint mHorizontalAnchorPoint
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
virtual void prepareExpressions(const QgsFields *fields, double scale=-1.0)
QgsMapUnitScale mSymbolWidthMapUnitScale
A class to represent a point geometry.
QgsMapUnitScale mapUnitScale() const
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
QPainterPath mPainterPath
bool hasDataDefinedProperty() const
True if this symbol layer uses a data defined property.
static void createGeometryElement(QDomDocument &doc, QDomElement &element, QString geomFunc)
Contains information about the context of a rendering operation.
void startRender(QgsSymbolV2RenderContext &context)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolLayerV2 * clone() const
void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
virtual const QgsExpression * dataDefinedProperty(const QString &property) const
QgsRenderContext & renderContext()
void stopRender(QgsSymbolV2RenderContext &context)
QgsMapUnitScale mapUnitScale() const
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, QString name, QColor color, QColor borderColor=QColor(), double borderWidth=-1, double size=-1)
const QgsFields * fields() const
Fields of the layer.
QgsSymbolV2::OutputUnit mOffsetUnit
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
VerticalAnchorPoint mVerticalAnchorPoint
QgsEllipseSymbolLayerV2()
QgsSymbolV2::OutputUnit mSizeUnit
QgsMapUnitScale mOffsetMapUnitScale
void markerOffset(const QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY) const
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QString symbolName() const
void setSize(double size)
void setAngle(double angle)
QgsStringMap properties() const
double symbolHeight() const
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves data defined properties to string map.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mSymbolHeightMapUnitScale
void setOutlineColor(const QColor &c)
Set outline color.
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
static QgsSymbolV2::OutputUnit decodeOutputUnit(QString str)
void setOutlineWidth(double w)
virtual void setDataDefinedProperty(const QString &property, const QString &expressionString)
static QPointF _rotatedOffset(const QPointF &offset, double angle)