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() ) );
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)
bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, const QgsSymbolV2RenderContext *context, const QgsFeature *f, const QPointF &shift=QPointF(0.0, 0.0)) 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
Return the expression string that was given when created.
double outlineWidth() const
QgsSymbolV2::OutputUnit mSymbolHeightUnit
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
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)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context)
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
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static QString encodeColor(QColor color)
virtual QgsExpression * expression(const QString &property) const
static QString encodePenStyle(Qt::PenStyle style)
virtual void prepareExpressions(const QgsVectorLayer *vl, double scale=-1.0)
const QgsFeature * feature() const
static QString encodePoint(QPointF point)
void setFillColor(const QColor &c)
Set fill color.
static Qt::PenStyle decodePenStyle(QString str)
Qt::PenStyle mOutlineStyle
HorizontalAnchorPoint mHorizontalAnchorPoint
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
A class to represent a point geometry.
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)
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)
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u)
Returns the line width scale factor depending on the unit and the paint device.
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, QString name, QColor color, QColor borderColor=QColor(), double borderWidth=-1, double size=-1)
QgsSymbolV2::OutputUnit mOffsetUnit
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
VerticalAnchorPoint mVerticalAnchorPoint
QgsEllipseSymbolLayerV2()
void markerOffset(const QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY) const
QString symbolName() const
void setAngle(double angle)
QgsStringMap properties() const
double symbolHeight() const
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves data defined properties to string map.
void preparePath(const QString &symbolName, QgsSymbolV2RenderContext &context, const QgsFeature *f=0)
Setup mPainterPath.
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineColor(const QColor &c)
Set outline color.
static QgsSymbolV2::OutputUnit decodeOutputUnit(QString str)
void setOutlineWidth(double w)
const QgsVectorLayer * layer() const
virtual void setDataDefinedProperty(const QString &property, const QString &expressionString)
static QPointF _rotatedOffset(const QPointF &offset, double angle)