24 #include <QDomDocument>
25 #include <QDomElement>
28 mSymbolHeightUnit(
QgsSymbolV2::MM ), mFillColor( Qt::white ), mOutlineColor( Qt::black ), mOutlineWidth( 0 ), mOutlineWidthUnit(
QgsSymbolV2::MM )
32 mPen.setJoinStyle( Qt::MiterJoin );
34 mBrush.setStyle( Qt::SolidPattern );
47 if ( properties.contains(
"symbol_name" ) )
51 if ( properties.contains(
"symbol_width" ) )
55 if ( properties.contains(
"symbol_width_unit" ) )
59 if ( properties.contains(
"symbol_height" ) )
63 if ( properties.contains(
"symbol_height_unit" ) )
67 if ( properties.contains(
"angle" ) )
69 layer->
setAngle( properties[
"angle"].toDouble() );
71 if ( properties.contains(
"outline_width" ) )
75 if ( properties.contains(
"outline_width_unit" ) )
79 if ( properties.contains(
"fill_color" ) )
83 if ( properties.contains(
"outline_color" ) )
87 if ( properties.contains(
"offset" ) )
91 if ( properties.contains(
"offset_unit" ) )
97 if ( properties.contains(
"width_expression" ) )
101 if ( properties.contains(
"height_expression" ) )
105 if ( properties.contains(
"rotation_expression" ) )
109 if ( properties.contains(
"outline_width_expression" ) )
113 if ( properties.contains(
"fill_color_expression" ) )
117 if ( properties.contains(
"outline_color_expression" ) )
121 if ( properties.contains(
"symbol_name_expression" ) )
125 if ( properties.contains(
"offset_expression" ) )
131 if ( !properties[
"width_field"].isEmpty() )
135 if ( !properties[
"height_field"].isEmpty() )
139 if ( !properties[
"rotation_field"].isEmpty() )
143 if ( !properties[
"outline_width_field"].isEmpty() )
147 if ( !properties[
"fill_color_field"].isEmpty() )
151 if ( !properties[
"outline_color_field"].isEmpty() )
155 if ( !properties[
"symbol_name_field"].isEmpty() )
173 if ( outlineWidthExpression )
175 double width = outlineWidthExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
177 mPen.setWidthF( width );
179 if ( fillColorExpression )
181 QString colorString = fillColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
182 mBrush.setColor( QColor( colorString ) );
184 if ( outlineColorExpression )
186 QString colorString = outlineColorExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
187 mPen.setColor( QColor( colorString ) );
189 if ( widthExpression || heightExpression || symbolNameExpression )
192 if ( symbolNameExpression )
194 symbolName = symbolNameExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toString();
203 QPointF off( offsetX, offsetY );
212 double rotation = 0.0;
213 if ( rotationExpression )
215 rotation = rotationExpression->
evaluate( const_cast<QgsFeature*>( context.
feature() ) ).toDouble();
225 transform.translate( point.x() + off.x(), point.y() + off.y() );
228 transform.rotate( rotation );
238 return "EllipseMarker";
264 QDomElement symbolizerElem = doc.createElement(
"se:PointSymbolizer" );
265 if ( !props.value(
"uom",
"" ).isEmpty() )
266 symbolizerElem.setAttribute(
"uom", props.value(
"uom",
"" ) );
267 element.appendChild( symbolizerElem );
278 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
279 element.appendChild( graphicElem );
286 graphicElem.appendChild( factorElem );
290 QString angleFunc = props.value(
"angle",
"" );
291 if ( angleFunc.isEmpty() )
294 if ( rotationExpression )
295 angleFunc = rotationExpression->
dump();
297 angleFunc = QString::number(
mAngle );
299 else if ( rotationExpression )
303 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg( rotationExpression->
dump() );
309 double angle = angleFunc.toDouble( &ok );
313 angleFunc = QString(
"%1 + %2" ).arg( angleFunc ).arg(
mAngle );
318 angleFunc = QString::number( angle +
mAngle );
328 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
329 if ( graphicElem.isNull() )
332 QString name =
"circle";
334 double borderWidth,
size;
335 double widthHeightFactor = 1.0;
338 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
340 if ( it.key() ==
"widthHeightFactor" )
343 double v = it.value().toDouble( &ok );
345 widthHeightFactor = v;
357 double d = angleFunc.toDouble( &ok );
381 map[
"angle"] = QString::number(
mAngle );
407 if ( widthExpression )
409 width = widthExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
423 if ( heightExpression )
425 height = heightExpression->
evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
437 if ( symbolName ==
"circle" )
439 mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
441 else if ( symbolName ==
"rectangle" )
443 mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
445 else if ( symbolName ==
"cross" )
452 else if ( symbolName ==
"triangle" )
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 markerOffset(QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY)
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
static bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
void setSymbolWidth(double w)
QgsSymbolV2::OutputUnit mOutlineWidthUnit
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)
QgsSymbolV2::OutputUnit outputUnit() const
static QgsStringMap getVendorOptionList(QDomElement &element)
void setOffset(QPointF offset)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static QPointF decodePoint(QString str)
static QDomElement createVendorOptionElement(QDomDocument &doc, QString name, QString value)
static QColor decodeColor(QString str)
QString dump() const
Return the parsed expression as a string - useful for debugging.
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
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QString layerType() const
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static QString encodeColor(QColor color)
const QgsFeature * feature() const
static QString encodePoint(QPointF point)
virtual void prepareExpressions(const QgsVectorLayer *vl)
void setFillColor(const QColor &c)
void setSymbolName(const QString &name)
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 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)
QgsEllipseSymbolLayerV2()
QString symbolName() const
void setAngle(double angle)
QgsStringMap properties() const
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves data defined properties to string map.
virtual QgsExpression * expression(const QString &property)
void preparePath(const QString &symbolName, QgsSymbolV2RenderContext &context, const QgsFeature *f=0)
Setup mPainterPath.
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineColor(const QColor &c)
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)