25 #include <QDomDocument> 26 #include <QDomElement> 30 , mSymbolName(
"circle" )
35 , mOutlineColor( Qt::black )
36 , mOutlineStyle( Qt::SolidLine )
41 mPen.setColor( mOutlineColor );
42 mPen.setStyle( mOutlineStyle );
44 mPen.setJoinStyle( Qt::MiterJoin );
46 mBrush.setStyle( Qt::SolidPattern );
59 if ( properties.contains(
"symbol_name" ) )
63 if ( properties.contains(
"symbol_width" ) )
67 if ( properties.contains(
"symbol_width_unit" ) )
71 if ( properties.contains(
"symbol_width_map_unit_scale" ) )
75 if ( properties.contains(
"symbol_height" ) )
79 if ( properties.contains(
"symbol_height_unit" ) )
83 if ( properties.contains(
"symbol_height_map_unit_scale" ) )
87 if ( properties.contains(
"angle" ) )
89 layer->
setAngle( properties[
"angle"].toDouble() );
91 if ( properties.contains(
"outline_style" ) )
95 else if ( properties.contains(
"line_style" ) )
99 if ( properties.contains(
"outline_width" ) )
103 else if ( properties.contains(
"line_width" ) )
107 if ( properties.contains(
"outline_width_unit" ) )
111 else if ( properties.contains(
"line_width_unit" ) )
115 if ( properties.contains(
"outline_width_map_unit_scale" ) )
119 if ( properties.contains(
"fill_color" ) )
124 else if ( properties.contains(
"color" ) )
128 if ( properties.contains(
"outline_color" ) )
132 else if ( properties.contains(
"line_color" ) )
136 if ( properties.contains(
"size" ) )
138 layer->
setSize( properties[
"size"].toDouble() );
140 if ( properties.contains(
"size_unit" ) )
144 if ( properties.contains(
"size_map_unit_scale" ) )
148 if ( properties.contains(
"offset" ) )
152 if ( properties.contains(
"offset_unit" ) )
156 if ( properties.contains(
"offset_map_unit_scale" ) )
160 if ( properties.contains(
"horizontal_anchor_point" ) )
164 if ( properties.contains(
"vertical_anchor_point" ) )
170 if ( properties.contains(
"width_expression" ) )
174 if ( properties.contains(
"height_expression" ) )
178 if ( properties.contains(
"rotation_expression" ) )
182 if ( properties.contains(
"outline_width_expression" ) )
186 if ( properties.contains(
"outline_style_expression" ) )
190 if ( properties.contains(
"fill_color_expression" ) )
194 if ( properties.contains(
"outline_color_expression" ) )
198 if ( properties.contains(
"symbol_name_expression" ) )
202 if ( properties.contains(
"offset_expression" ) )
206 if ( properties.contains(
"horizontal_anchor_point_expression" ) )
208 layer->
setDataDefinedProperty(
"horizontal_anchor_point", properties[
"horizontal_anchor_point_expression" ] );
210 if ( properties.contains(
"vertical_anchor_point_expression" ) )
212 layer->
setDataDefinedProperty(
"vertical_anchor_point", properties[
"vertical_anchor_point_expression" ] );
216 if ( !properties[
"width_field"].isEmpty() )
220 if ( !properties[
"height_field"].isEmpty() )
224 if ( !properties[
"rotation_field"].isEmpty() )
228 if ( !properties[
"outline_width_field"].isEmpty() )
232 if ( !properties[
"fill_color_field"].isEmpty() )
236 if ( !properties[
"outline_color_field"].isEmpty() )
240 if ( !properties[
"symbol_name_field"].isEmpty() )
259 if ( outlineWidthExpression )
261 double width = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
263 mPen.setWidthF( width );
265 if ( outlineStyleExpression )
268 mPen.setStyle( style );
270 if ( fillColorExpression )
272 QString colorString = fillColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
275 if ( outlineColorExpression )
277 QString colorString = outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
280 double scaledWidth = mSymbolWidth;
281 double scaledHeight = mSymbolHeight;
282 if ( widthExpression || heightExpression || symbolNameExpression )
285 if ( symbolNameExpression )
287 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
289 preparePath( symbolName, context, &scaledWidth, &scaledHeight, context.
feature() );
295 markerOffset( context, scaledWidth, scaledHeight, mSymbolWidthUnit, mSymbolHeightUnit, offsetX, offsetY, mSymbolWidthMapUnitScale, mSymbolHeightMapUnitScale );
296 QPointF off( offsetX, offsetY );
305 double rotation = 0.0;
306 if ( rotationExpression )
308 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
318 transform.translate( point.x() + off.x(), point.y() + off.y() );
321 transform.rotate( rotation );
325 p->setBrush( mBrush );
326 p->drawPath( transform.map( mPainterPath ) );
331 return "EllipseMarker";
337 if ( !context.
feature() || !hasDataDefinedProperty() )
339 preparePath( mSymbolName, context );
341 mPen.setColor( mOutlineColor );
342 mPen.setStyle( mOutlineStyle );
344 mBrush.setColor(
mColor );
359 QDomElement symbolizerElem = doc.createElement(
"se:PointSymbolizer" );
360 if ( !props.value(
"uom",
"" ).isEmpty() )
361 symbolizerElem.setAttribute(
"uom", props.value(
"uom",
"" ) );
362 element.appendChild( symbolizerElem );
373 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
374 element.appendChild( graphicElem );
379 double widthHeightFactor = mSymbolWidth / mSymbolHeight;
381 graphicElem.appendChild( factorElem );
385 QString angleFunc = props.value(
"angle",
"" );
386 if ( angleFunc.isEmpty() )
389 if ( rotationExpression )
392 angleFunc = QString::number(
mAngle );
394 else if ( rotationExpression )
398 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg( rotationExpression->
expression() );
404 double angle = angleFunc.toDouble( &ok );
408 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg(
mAngle );
413 angleFunc = QString::number( angle +
mAngle );
423 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
424 if ( graphicElem.isNull() )
427 QString name =
"circle";
429 double borderWidth,
size;
430 double widthHeightFactor = 1.0;
431 Qt::PenStyle borderStyle;
434 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
436 if ( it.key() ==
"widthHeightFactor" )
439 double v = it.value().toDouble( &ok );
441 widthHeightFactor = v;
453 double d = angleFunc.toDouble( &ok );
473 map[
"symbol_name"] = mSymbolName;
474 map[
"symbol_width"] = QString::number( mSymbolWidth );
477 map[
"symbol_height"] = QString::number( mSymbolHeight );
480 map[
"angle"] = QString::number(
mAngle );
482 map[
"outline_width"] = QString::number( mOutlineWidth );
490 map[
"size"] = QString::number(
mSize );
499 bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty()
const 508 mPainterPath = QPainterPath();
514 if ( widthExpression )
516 width = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
524 width = mSymbolWidth;
528 *scaledWidth = width;
534 if ( heightExpression )
536 height = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
544 height = mSymbolHeight;
548 *scaledHeight = height;
554 mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
558 mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
562 mPainterPath.moveTo( 0, -height / 2.0 );
563 mPainterPath.lineTo( 0, height / 2.0 );
564 mPainterPath.moveTo( -width / 2.0, 0 );
565 mPainterPath.lineTo( width / 2.0, 0 );
569 mPainterPath.moveTo( 0, -height / 2.0 );
570 mPainterPath.lineTo( -width / 2.0, height / 2.0 );
571 mPainterPath.lineTo( width / 2.0, height / 2.0 );
572 mPainterPath.lineTo( 0, -height / 2.0 );
579 mSymbolWidthUnit = unit;
580 mSymbolHeightUnit = unit;
581 mOutlineWidthUnit = unit;
587 if ( mSymbolWidthUnit != unit || mSymbolHeightUnit != unit || mOutlineWidthUnit != unit )
597 mSymbolWidthMapUnitScale = scale;
598 mSymbolHeightMapUnitScale = scale;
599 mOutlineWidthMapUnitScale = scale;
605 mSymbolWidthMapUnitScale == mSymbolHeightMapUnitScale &&
606 mSymbolHeightMapUnitScale == mOutlineWidthMapUnitScale )
608 return mSymbolWidthMapUnitScale;
618 if ( widthExpression )
620 symbolWidth = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
628 symbolWidth *= mmMapUnitScaleFactor;
634 if ( heightExpression )
636 symbolHeight = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
640 symbolHeight =
mSize;
644 symbolHeight *= mmMapUnitScaleFactor;
650 if ( outlineWidthExpression )
652 outlineWidth = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
662 if ( fillColorExpression )
664 fc = QColor( fillColorExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString() );
668 QColor oc = mOutlineColor;
670 if ( outlineColorExpression )
672 oc = QColor( outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString() );
678 if ( symbolNameExpression )
681 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toString();
688 QPointF off( offsetX, offsetY );
691 double rotation = 0.0;
693 if ( rotationExpression )
695 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context->
feature() ) ).toDouble();
701 rotation = -rotation;
706 t.translate( shift.x() + offsetX, shift.y() + offsetY );
709 t.rotate( rotation );
711 double halfWidth = symbolWidth / 2.0;
712 double halfHeight = symbolHeight / 2.0;
714 if ( symbolName ==
"circle" )
718 QPointF pt( t.map( QPointF( 0, 0 ) ) );
724 double stepsize = 2 *
M_PI / 40;
725 for (
int i = 0; i < 39; ++i )
727 double angle = stepsize * i;
728 double x = halfWidth * cos( angle );
729 double y = halfHeight * sin( angle );
730 QPointF pt( t.map( QPointF( x, y ) ) );
731 line.push_back( pt );
734 line.push_back( line.at( 0 ) );
735 if ( mBrush.style() != Qt::NoBrush )
737 if ( mPen.style() != Qt::NoPen )
738 e.
writePolyline( line, layerName,
"CONTINUOUS", oc, outlineWidth );
741 else if ( symbolName ==
"rectangle" )
745 p[0][0] = t.map( QPointF( -halfWidth, -halfHeight ) );
746 p[0][1] = t.map( QPointF( halfWidth, -halfHeight ) );
747 p[0][2] = t.map( QPointF( halfWidth, halfHeight ) );
748 p[0][3] = t.map( QPointF( -halfWidth, halfHeight ) );
750 if ( mBrush.style() != Qt::NoBrush )
752 if ( mPen.style() != Qt::NoPen )
753 e.
writePolyline( p[0], layerName,
"CONTINUOUS", oc, outlineWidth );
756 else if ( symbolName ==
"cross" && mPen.style() != Qt::NoPen )
759 line[0] = t.map( QPointF( -halfWidth, 0 ) );
760 line[1] = t.map( QPointF( halfWidth, 0 ) );
761 e.
writePolyline( line, layerName,
"CONTINUOUS", oc, outlineWidth );
763 line[0] = t.map( QPointF( 0, halfHeight ) );
764 line[1] = t.map( QPointF( 0, -halfHeight ) );
765 e.
writePolyline( line, layerName,
"CONTINUOUS", oc, outlineWidth );
769 else if ( symbolName ==
"triangle" )
773 p[0][0] = QPointF( t.map( QPointF( -halfWidth, -halfHeight ) ) );
774 p[0][1] = QPointF( t.map( QPointF( halfWidth, -halfHeight ) ) );
775 p[0][2] = QPointF( t.map( QPointF( 0, halfHeight ) ) );
777 if ( mBrush.style() != Qt::NoBrush )
779 if ( mPen.style() != Qt::NoPen )
780 e.
writePolyline( p[0], layerName,
"CONTINUOUS", oc, outlineWidth );
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context) override
Class for parsing and evaluation of expressions (formerly called "search strings").
~QgsEllipseSymbolLayerV2()
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const override
void setSymbolHeight(double h)
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
QColor fillColor() const override
Get fill color.
QgsSymbolV2::OutputUnit outputUnit() const override
QgsMapUnitScale mSizeMapUnitScale
static Q_DECL_DEPRECATED bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
QgsSymbolLayerV2 * clone() const override
void startRender(QgsSymbolV2RenderContext &context) override
void setSymbolWidth(double w)
const QString expression() const
Alias for dump()
double outlineWidth() const
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
void writePolygon(const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color)
Draw dxf polygon (HATCH)
static void createRotationElement(QDomDocument &doc, QDomElement &element, QString rotationFunc)
double rendererScale() const
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
static QgsStringMap getVendorOptionList(QDomElement &element)
void setOffset(QPointF offset)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, const QgsSymbolV2RenderContext *context, const QgsFeature *f, const QPointF &shift=QPointF(0.0, 0.0)) const override
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)
QgsSymbolV2::OutputUnit outputUnit() const override
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
A symbol layer for rendering objects with major and minor axis (e.g.
QMap< QString, QString > QgsStringMap
QgsStringMap properties() const override
double symbolWidth() const
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static QString encodeColor(QColor color)
void setMapUnitScale(const QgsMapUnitScale &scale) override
virtual QgsExpression * expression(const QString &property) const
static QString encodePenStyle(Qt::PenStyle style)
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
const QgsFeature * feature() const
Current feature being rendered - may be null.
static QString encodePoint(QPointF point)
static Qt::PenStyle decodePenStyle(QString str)
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
HorizontalAnchorPoint mHorizontalAnchorPoint
void writePolyline(const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width=-1, bool unusedPolygonFlag=false)
draw dxf primitives
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
virtual void prepareExpressions(const QgsFields *fields, double scale=-1.0)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
void startRender(QgsSymbolV2RenderContext &context) override
static void createGeometryElement(QDomDocument &doc, QDomElement &element, QString geomFunc)
Contains information about the context of a rendering operation.
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.
Struct for storing maximum and minimum scales for measurements in map units.
QgsMapUnitScale mapUnitScale() const override
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual const QgsExpression * dataDefinedProperty(const QString &property) const
QgsRenderContext & renderContext()
void setOutlineColor(const QColor &c) override
Set outline color.
void writeFilledCircle(const QString &layer, QColor color, const QgsPoint &pt, double radius)
Write filled circle (as hatch)
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
void stopRender(QgsSymbolV2RenderContext &context) override
QgsEllipseSymbolLayerV2()
QgsSymbolV2::OutputUnit mSizeUnit
QgsMapUnitScale mOffsetMapUnitScale
void markerOffset(const QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY) const
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QString layerType() const override
void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const override
QString symbolName() const
QgsMapUnitScale mapUnitScale() const override
void setSize(double size)
void setAngle(double angle)
double symbolHeight() const
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves data defined properties to string map.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
void setFillColor(const QColor &c) override
Set fill color.
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
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)