27 #include <QDomDocument> 28 #include <QDomElement> 32 , mSymbolName(
"circle" )
37 , mOutlineColor(
Qt::black )
38 , mOutlineStyle(
Qt::SolidLine )
61 if ( properties.
contains(
"symbol_name" ) )
65 if ( properties.
contains(
"symbol_width" ) )
69 if ( properties.
contains(
"symbol_width_unit" ) )
73 if ( properties.
contains(
"symbol_width_map_unit_scale" ) )
77 if ( properties.
contains(
"symbol_height" ) )
81 if ( properties.
contains(
"symbol_height_unit" ) )
85 if ( properties.
contains(
"symbol_height_map_unit_scale" ) )
89 if ( properties.
contains(
"angle" ) )
91 layer->
setAngle( properties[
"angle"].toDouble() );
93 if ( properties.
contains(
"outline_style" ) )
97 else if ( properties.
contains(
"line_style" ) )
101 if ( properties.
contains(
"joinstyle" ) )
105 if ( properties.
contains(
"outline_width" ) )
109 else if ( properties.
contains(
"line_width" ) )
113 if ( properties.
contains(
"outline_width_unit" ) )
117 else if ( properties.
contains(
"line_width_unit" ) )
121 if ( properties.
contains(
"outline_width_map_unit_scale" ) )
125 if ( properties.
contains(
"fill_color" ) )
130 else if ( properties.
contains(
"color" ) )
134 if ( properties.
contains(
"outline_color" ) )
138 else if ( properties.
contains(
"line_color" ) )
142 if ( properties.
contains(
"size" ) )
144 layer->
setSize( properties[
"size"].toDouble() );
146 if ( properties.
contains(
"size_unit" ) )
150 if ( properties.
contains(
"size_map_unit_scale" ) )
154 if ( properties.
contains(
"offset" ) )
158 if ( properties.
contains(
"offset_unit" ) )
162 if ( properties.
contains(
"offset_map_unit_scale" ) )
166 if ( properties.
contains(
"horizontal_anchor_point" ) )
170 if ( properties.
contains(
"vertical_anchor_point" ) )
179 if ( !properties[
"width_field"].isEmpty() )
183 if ( !properties[
"height_field"].isEmpty() )
187 if ( !properties[
"rotation_field"].isEmpty() )
191 if ( !properties[
"outline_width_field"].isEmpty() )
195 if ( !properties[
"fill_color_field"].isEmpty() )
199 if ( !properties[
"outline_color_field"].isEmpty() )
203 if ( !properties[
"symbol_name_field"].isEmpty() )
247 if ( context.
alpha() < 1.0 )
261 if ( context.
alpha() < 1.0 )
268 double scaledWidth = mSymbolWidth;
269 double scaledHeight = mSymbolHeight;
278 preparePath( symbolName, context, &scaledWidth, &scaledHeight, context.
feature() );
282 bool hasDataDefinedRotation =
false;
285 calculateOffsetAndRotation( context, scaledWidth, scaledHeight, hasDataDefinedRotation, offset, angle );
294 transform.
translate( point.
x() + offset.
x(), point.
y() + offset.
y() );
297 transform.
rotate( angle );
309 bool& hasDataDefinedRotation,
311 double&
angle )
const 315 markerOffset( context, scaledWidth, scaledHeight, mSymbolWidthUnit, mSymbolHeightUnit, offsetX, offsetY, mSymbolWidthMapUnitScale, mSymbolHeightMapUnitScale );
316 offset =
QPointF( offsetX, offsetY );
321 bool usingDataDefinedRotation =
false;
326 usingDataDefinedRotation = ok;
330 if ( hasDataDefinedRotation )
355 return "EllipseMarker";
363 preparePath( mSymbolName, context );
369 if ( context.
alpha() < 1.0 )
420 if ( !props.
value(
"uom",
"" ).isEmpty() )
446 if ( ddRotation && ddRotation->
isActive() )
453 else if ( ddRotation && ddRotation->
isActive() )
483 double widthHeightFactor = mSymbolWidth / mSymbolHeight;
493 if ( graphicElem.
isNull() )
498 double borderWidth,
size;
499 double widthHeightFactor = 1.0;
500 Qt::PenStyle borderStyle;
505 if ( it.key() ==
"widthHeightFactor" )
508 double v = it.value().toDouble( &ok );
510 widthHeightFactor = v;
526 double d = angleFunc.
toDouble( &ok );
547 map[
"symbol_name"] = mSymbolName;
589 width = mSymbolWidth;
593 *scaledWidth = width;
609 height = mSymbolHeight;
613 *scaledHeight = height;
616 return QSizeF( width, height );
623 QSizeF size = calculateSize( context, scaledWidth, scaledHeight );
625 if ( symbolName ==
"circle" )
629 else if ( symbolName ==
"semi_circle" )
632 mPainterPath.
lineTo( 0, 0 );
634 else if ( symbolName ==
"rectangle" )
638 else if ( symbolName ==
"diamond" )
646 else if ( symbolName ==
"cross" )
653 else if ( symbolName ==
"triangle" )
660 else if ( symbolName ==
"left_half_triangle" )
667 else if ( symbolName ==
"right_half_triangle" )
679 mSymbolWidthUnit = unit;
680 mSymbolHeightUnit = unit;
681 mOutlineWidthUnit = unit;
687 if ( mSymbolWidthUnit != unit || mSymbolHeightUnit != unit || mOutlineWidthUnit != unit )
697 mSymbolWidthMapUnitScale = scale;
698 mSymbolHeightMapUnitScale = scale;
699 mOutlineWidthMapUnitScale = scale;
705 mSymbolWidthMapUnitScale == mSymbolHeightMapUnitScale &&
706 mSymbolHeightMapUnitScale == mOutlineWidthMapUnitScale )
708 return mSymbolWidthMapUnitScale;
717 bool hasDataDefinedRotation =
false;
720 calculateOffsetAndRotation( context, size.
width(), size.
height(), hasDataDefinedRotation,
offset,
angle );
727 transform.
translate( point.
x() + offset.x(), point.
y() + offset.y() );
730 transform.
rotate( angle );
732 double penWidth = 0.0;
747 if ( ok && outlineStyle ==
"no" )
754 penWidth += pixelSize;
762 symbolBounds.
adjust( -penWidth / 2.0, -penWidth / 2.0,
763 penWidth / 2.0, penWidth / 2.0 );
784 symbolWidth *= mmMapUnitScaleFactor;
796 symbolHeight =
mSize;
800 symbolHeight *= mmMapUnitScaleFactor;
828 QColor oc = mOutlineColor;
838 QString symbolName = mSymbolName;
849 QPointF off( offsetX, offsetY );
852 double rotation = 0.0;
862 rotation = -rotation;
867 t.
translate( shift.
x() + offsetX, shift.
y() + offsetY );
872 double halfWidth = symbolWidth / 2.0;
873 double halfHeight = symbolHeight / 2.0;
875 if ( symbolName ==
"circle" )
886 double stepsize = 2 *
M_PI / 40;
887 for (
int i = 0; i < 39; ++i )
889 double angle = stepsize * i;
890 double x = halfWidth * cos( angle );
891 double y = halfHeight * sin( angle );
895 line << line.
at( 0 );
897 if ( mBrush.
style() != Qt::NoBrush )
899 if ( mPen.
style() != Qt::NoPen )
900 e.
writePolyline( line, layerName,
"CONTINUOUS", oc, outlineWidth );
903 else if ( symbolName ==
"rectangle" )
912 if ( mBrush.
style() != Qt::NoBrush )
914 if ( mPen.
style() != Qt::NoPen )
915 e.
writePolyline( p, layerName,
"CONTINUOUS", oc, outlineWidth );
918 else if ( symbolName ==
"cross" && mPen.
style() != Qt::NoPen )
923 layerName,
"CONTINUOUS", oc, outlineWidth );
927 layerName,
"CONTINUOUS", oc, outlineWidth );
930 else if ( symbolName ==
"triangle" )
937 if ( mBrush.
style() != Qt::NoBrush )
939 if ( mPen.
style() != Qt::NoPen )
940 e.
writePolyline( p, layerName,
"CONTINUOUS", oc, outlineWidth );
void addEllipse(const QRectF &boundingRectangle)
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
~QgsEllipseSymbolLayerV2()
static const QString EXPR_OUTLINE_COLOR
void writeSldMarker(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
Writes the symbol layer definition as a SLD XML element.
static void createRotationElement(QDomDocument &doc, QDomElement &element, const QString &rotationFunc)
void markerOffset(QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY) const
Calculates the required marker offset, including both the symbol offset and any displacement required...
void setSymbolHeight(double h)
Qt::PenStyle style() const
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
QColor fillColor() const override
Get fill color.
QgsSymbolV2::OutputUnit outputUnit() const override
void setStyle(Qt::PenStyle style)
static QPointF _rotatedOffset(QPointF offset, double angle)
Adjusts a marker offset to account for rotation.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
void renderPoint(QPointF point, QgsSymbolV2RenderContext &context) override
Renders a marker at the specified point.
OutputUnit
The unit of the output.
QgsMapUnitScale mSizeMapUnitScale
Marker size map unit scale.
A container class for data source field mapping or expression.
bool contains(const Key &key) const
static Q_DECL_DEPRECATED bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
void startRender(QgsSymbolV2RenderContext &context) override
void setSymbolWidth(double w)
QDomNode appendChild(const QDomNode &newChild)
static double rescaleUom(double size, QgsSymbolV2::OutputUnit unit, const QgsStringMap &props)
Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified.
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
Qt::BrushStyle style() const
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
QString attribute(const QString &name, const QString &defValue) const
double size() const
Returns the symbol size.
static double sizeInPixelsFromSldUom(const QString &uom, double size)
Returns the size scaled in pixels according to the uom attribute.
static QString encodeColor(const QColor &color)
static const QString EXPR_WIDTH
static QgsStringMap getVendorOptionList(QDomElement &element)
The output shall be in pixels.
const T & at(int i) const
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
virtual bool hasDataDefinedProperties() const
Checks whether the layer has any associated data defined properties.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
QgsEllipseSymbolLayerV2 * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
A geometry is the spatial representation of a feature.
void setJoinStyle(Qt::PenJoinStyle style)
void moveTo(const QPointF &point)
static QPointF decodePoint(const QString &str)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
const QgsFeature * feature() const
Current feature being rendered - may be null.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
QRectF bounds(QPointF point, QgsSymbolV2RenderContext &context) override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
QgsSymbolV2::OutputUnit outputUnit() const override
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QColor outlineColor() const override
Get outline color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's offset.
virtual QgsDataDefined * getDataDefinedProperty(const QString &property) const
Returns the data defined property corresponding to the specified property key.
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
double toDouble(bool *ok) const
void setStyle(Qt::BrushStyle style)
A symbol layer for rendering objects with major and minor axis (e.g.
double symbolHeight() const
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
void setMapUnitScale(const QgsMapUnitScale &scale) override
virtual Q_DECL_DEPRECATED QVariant evaluateDataDefinedProperty(const QString &property, const QgsFeature *feature, const QVariant &defaultVal=QVariant(), bool *ok=nullptr) const
Evaluates the matching data defined property and returns the calculated value.
double mapRotation() const
Return current map rotation in degrees.
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the symbol's offset.
bool useExpression() const
Returns if the field or the expression part is active.
void setMapUnitScale(const QgsMapUnitScale &scale) override
static const QString EXPR_JOIN_STYLE
static QgsSymbolV2::OutputUnit decodeOutputUnit(const QString &str)
static QString encodePenStyle(Qt::PenStyle style)
Perform transforms between map coordinates and device coordinates.
Mixed units in symbol layers.
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
The output shall be in millimeters.
QString number(int n, int base)
static const QString EXPR_FILL_COLOR
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
Writes the SLD element following the SLD v1.1 specs.
static QString encodePoint(QPointF point)
static double convertToPainterUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to painter units.
void setPen(const QColor &color)
void lineTo(const QPointF &endPoint)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
void setAttribute(const QString &name, const QString &value)
QMatrix & translate(qreal dx, qreal dy)
QString expressionString() const
Returns the expression string of this QgsDataDefined.
Point geometry type, with support for z-dimension and m-values.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
void addRect(const QRectF &rectangle)
double outlineWidth() const
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the symbol's size.
bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const override
write as DXF
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
Q_DECL_DEPRECATED void writeFilledCircle(const QString &layer, const QColor &color, const QgsPoint &pt, double radius)
Write filled circle (as hatch)
Qt::PenStyle outlineStyle() const
HorizontalAnchorPoint mHorizontalAnchorPoint
Horizontal anchor point.
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setColor(const QColor &color)
void setSymbolName(const QString &name)
virtual Q_DECL_DEPRECATED void prepareExpressions(const QgsFields *fields, double scale=-1.0)
Prepares all data defined property expressions for evaluation.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
virtual QColor color() const
The fill color.
double mAngle
Marker rotation angle, in degrees clockwise from north.
static Qt::PenStyle decodePenStyle(const QString &str)
double mLineAngle
Line rotation angle (see setLineAngle() for details)
static const QString EXPR_OUTLINE_STYLE
Q_DECL_DEPRECATED void writePolyline(const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Draw dxf primitives (LWPOLYLINE)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
void copyDataDefinedProperties(QgsSymbolLayerV2 *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves all data defined properties to a string map.
QString symbolName() const
QRect mapRect(const QRect &rectangle) const
QString field() const
Get the field which this QgsDataDefined represents.
void startRender(QgsSymbolV2RenderContext &context) override
static const QString EXPR_OUTLINE_WIDTH
void copyPaintEffect(QgsSymbolLayerV2 *destLayer) const
Copies paint effect of this layer to another symbol layer.
QMatrix & rotate(qreal degrees)
VerticalAnchorPoint
Symbol vertical anchor points.
const QgsMapToPixel & mapToPixel() const
void drawPath(const QPainterPath &path)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Struct for storing maximum and minimum scales for measurements in map units.
QgsMapUnitScale mapUnitScale() const override
virtual bool hasDataDefinedProperty(const QString &property) const
Checks whether the layer has a matching data defined property and if that property is currently activ...
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
double symbolWidth() const
QgsRenderContext & renderContext()
QDomElement firstChildElement(const QString &tagName) const
void setOutlineColor(const QColor &c) override
Set outline color.
Q_DECL_DEPRECATED void writePolygon(const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor &color)
Draw dxf filled polygon (HATCH)
static const QString EXPR_ROTATION
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
QgsSymbolV2::OutputUnit mOffsetUnit
Offset units.
void setAlphaF(qreal alpha)
virtual void setColor(const QColor &color)
The fill color.
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
double toDouble(bool *ok) const
static QColor decodeColor(const QString &str)
Abstract base class for marker symbol layers.
VerticalAnchorPoint mVerticalAnchorPoint
Vertical anchor point.
void stopRender(QgsSymbolV2RenderContext &context) override
QgsEllipseSymbolLayerV2()
QgsSymbolV2::OutputUnit mSizeUnit
Marker size unit.
QgsMapUnitScale mOffsetMapUnitScale
Offset map unit scale.
HorizontalAnchorPoint
Symbol horizontal anchor points.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set outline join style.
void restoreDataDefinedProperties(const QgsStringMap &stringMap)
Restores all data defined properties from string map.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QString layerType() const override
Returns a string that represents this layer type.
double rasterScaleFactor() const
QDomElement createElement(const QString &tagName)
static const QString EXPR_SYMBOL_NAME
QgsMapUnitScale mapUnitScale() const override
void setSize(double size)
Sets the symbol size.
void map(int x, int y, int *tx, int *ty) const
void setAngle(double angle)
Sets the rotation angle for the marker.
void arcTo(const QRectF &rectangle, qreal startAngle, qreal sweepLength)
void setColor(const QColor &color)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QPointF mOffset
Marker offset.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's size.
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)
#define DEFAULT_ELLIPSE_JOINSTYLE
void setOutlineWidth(double w)
QList< QgsPointV2 > QgsPointSequenceV2
static const QString EXPR_HEIGHT
const T value(const Key &key) const
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, const QString &name, const QColor &color, const QColor &borderColor=QColor(), double borderWidth=-1, double size=-1)
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.