26 #include <QDomDocument>
27 #include <QDomElement>
32 : mPenStyle( penStyle )
35 , mUseCustomDashPattern( false )
37 , mDrawInsidePolygon( false )
87 if ( props.
contains(
"line_color" ) )
91 else if ( props.
contains(
"outline_color" ) )
95 else if ( props.
contains(
"color" ) )
100 if ( props.
contains(
"line_width" ) )
102 width = props[
"line_width"].toDouble();
104 else if ( props.
contains(
"outline_width" ) )
106 width = props[
"outline_width"].toDouble();
108 else if ( props.
contains(
"width" ) )
111 width = props[
"width"].toDouble();
113 if ( props.
contains(
"line_style" ) )
117 else if ( props.
contains(
"outline_style" ) )
121 else if ( props.
contains(
"penstyle" ) )
127 if ( props.
contains(
"line_width_unit" ) )
131 else if ( props.
contains(
"outline_width_unit" ) )
135 else if ( props.
contains(
"width_unit" ) )
140 if ( props.
contains(
"width_map_unit_scale" ) )
143 l->
setOffset( props[
"offset"].toDouble() );
144 if ( props.
contains(
"offset_unit" ) )
146 if ( props.
contains(
"offset_map_unit_scale" ) )
148 if ( props.
contains(
"joinstyle" ) )
153 if ( props.
contains(
"use_custom_dash" ) )
157 if ( props.
contains(
"customdash" ) )
161 if ( props.
contains(
"customdash_unit" ) )
165 if ( props.
contains(
"customdash_map_unit_scale" ) )
170 if ( props.
contains(
"draw_inside_polygon" ) )
198 double dashWidthDiv = scaledWidth;
201 if ( versionSplit.
size() > 1
202 && versionSplit.
at( 1 ).toInt() >= 8
257 for ( ; it != rings->
constEnd(); ++it )
272 foreach (
const QPolygonF& ring, *rings )
300 applyDataDefinedSymbology( context,
mPen,
mSelPen, offset );
305 if ( points.
size() <= 2 &&
324 for (
int part = 0; part < mline.count(); ++part )
377 if ( !props.
value(
"uom",
"" ).isEmpty() )
421 if ( strokeElem.
isNull() )
433 &penJoinStyle, &penCapStyle,
434 &customDashVector ) )
439 if ( !perpOffsetElem.
isNull() )
469 bool hasStrokeWidthExpression =
false;
476 hasStrokeWidthExpression =
true;
500 if ( hasStrokeWidthExpression )
502 dashWidthDiv = pen.
widthF();
503 scaledWidth = pen.
widthF();
508 if ( versionSplit.
size() > 1
509 && versionSplit.
at( 1 ).toInt() >= 8
520 for ( ; dashIt != dashList.
constEnd(); ++dashIt )
629 if ( p1.
x() == p2.
x() )
638 mT = float( p2.
y() - p1.
y() ) / ( p2.
x() - p1.
x() );
643 double x = ( p2.
x() - p1.
x() );
644 double y = ( p2.
y() - p1.
y() );
645 mLength = sqrt( x * x + y * y );
664 double alpha = atan(
mT );
665 double dx = cos( alpha ) * interval;
666 double dy = sin( alpha ) * interval;
705 interval = props[
"interval"].toDouble();
707 rotate = ( props[
"rotate"] ==
"1" );
712 x->
setOffset( props[
"offset"].toDouble() );
714 if ( props.
contains(
"offset_unit" ) )
718 if ( props.
contains(
"interval_unit" ) )
722 if ( props.
contains(
"offset_along_line" ) )
726 if ( props.
contains(
"offset_along_line_unit" ) )
730 if ( props.
contains((
"offset_along_line_map_unit_scale" ) ) )
735 if ( props.
contains(
"offset_map_unit_scale" ) )
739 if ( props.
contains(
"interval_map_unit_scale" ) )
744 if ( props.
contains(
"placement" ) )
746 if ( props[
"placement"] ==
"vertex" )
748 else if ( props[
"placement"] ==
"lastvertex" )
750 else if ( props[
"placement"] ==
"firstvertex" )
752 else if ( props[
"placement"] ==
"centralpoint" )
814 if ( placementString.
compare(
"vertex", Qt::CaseInsensitive ) == 0 )
818 else if ( placementString.
compare(
"lastvertex", Qt::CaseInsensitive ) == 0 )
822 else if ( placementString.
compare(
"firstvertex", Qt::CaseInsensitive ) == 0 )
826 else if ( placementString.
compare(
"centerpoint", Qt::CaseInsensitive ) == 0 )
850 for (
int part = 0; part < mline.
count(); ++part )
852 const QPolygonF &points2 = mline[ part ];
870 foreach (
const QPolygonF& ring, *rings )
882 double lengthLeft = 0;
905 for (
int i = 1; i < points.
count(); ++i )
918 double c = 1 - lengthLeft / painterUnitInterval;
936 while ( lengthLeft > painterUnitInterval )
940 lengthLeft -= painterUnitInterval;
954 double unitX = cos( a1 ) + cos( a2 ), unitY = sin( a1 ) + sin( a2 );
956 return atan2( unitY, unitX );
975 if ( offsetAlongLine != 0 )
988 i = points.
count() - 1;
989 maxCount = points.
count();
994 maxCount = points.
count();
1003 renderOffsetVertexAlongLine( points, i, distance, context );
1009 for ( ; i < maxCount; ++i )
1011 if ( isRing && placement ==
Vertex && i == points.
count() - 1 )
1032 const QPointF& pt = points[vertex];
1034 if ( isRing || ( vertex > 0 && vertex < points.
count() - 1 ) )
1036 int prevIndex = vertex - 1;
1037 int nextIndex = vertex + 1;
1039 if ( isRing && ( vertex == 0 || vertex == points.
count() - 1 ) )
1041 prevIndex = points.
count() - 2;
1046 while ( prevIndex >= 0 )
1048 prevPoint = points[ prevIndex ];
1049 if ( prevPoint != pt )
1056 while ( nextIndex < points.
count() )
1058 nextPoint = points[ nextIndex ];
1059 if ( nextPoint != pt )
1066 if ( prevIndex >= 0 && nextIndex < points.
count() )
1075 while ( vertex < points.
size() - 1 )
1077 const QPointF& nextPt = points[vertex+1];
1089 while ( vertex >= 1 )
1091 const QPointF& prevPt = points[vertex-1];
1111 if ( distance == 0 )
1116 bool isRing =
false;
1126 int pointIncrement = distance > 0 ? 1 : -1;
1127 QPointF previousPoint = points[vertex];
1128 int startPoint = distance > 0 ? qMin( vertex + 1, points.
count() - 1 ) : qMax( vertex - 1, 0 );
1129 int endPoint = distance > 0 ? points.
count() - 1 : 0;
1130 double distanceLeft = qAbs( distance );
1132 for (
int i = startPoint; pointIncrement > 0 ? i <= endPoint : i >= endPoint; i += pointIncrement )
1134 const QPointF& pt = points[i];
1136 if ( previousPoint == pt )
1140 MyLine l( previousPoint, pt );
1142 if ( distanceLeft < l.length() )
1145 QPointF markerPoint = previousPoint + l.diffForInterval( distanceLeft );
1155 distanceLeft -= l.length();
1165 if ( points.
size() > 0 )
1171 for ( ++it; it != points.
constEnd(); ++it )
1173 length += sqrt(( last.
x() - it->x() ) * ( last.
x() - it->x() ) +
1174 ( last.
y() - it->y() ) * ( last.
y() - it->y() ) );
1181 qreal last_at = 0, next_at = 0;
1184 for ( ++it; it != points.
constEnd(); ++it )
1187 next_at += sqrt(( last.
x() - it->x() ) * ( last.
x() - it->x() ) +
1188 ( last.
y() - it->y() ) * ( last.
y() - it->y() ) );
1189 if ( next_at >= length / 2 )
1198 qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
1199 QPointF pt = last + ( next - last ) * k;
1226 map[
"placement"] =
"vertex";
1228 map[
"placement"] =
"lastvertex";
1230 map[
"placement"] =
"firstvertex";
1232 map[
"placement"] =
"centralpoint";
1234 map[
"placement"] =
"interval";
1282 if ( !props.
value(
"uom",
"" ).isEmpty() )
1336 if ( !gap.isEmpty() )
1357 if ( strokeElem.
isNull() )
1361 if ( graphicStrokeElem.
isNull() )
1371 if ( it.key() ==
"placement" )
1373 if ( it.value() ==
"points" ) placement =
Vertex;
1374 else if ( it.value() ==
"firstPoint" ) placement =
FirstVertex;
1375 else if ( it.value() ==
"lastPoint" ) placement =
LastVertex;
1376 else if ( it.value() ==
"centralPoint" ) placement =
CentralPoint;
1378 else if ( it.value() ==
"rotateMarker" )
1380 rotateMarker = it.value() ==
"0";
1407 double offset = 0.0;
1409 if ( !perpOffsetElem.
isNull() )
static double _averageAngle(const QPointF &prevPt, const QPointF &pt, const QPointF &nextPt)
virtual QSet< QString > usedAttributes() const
Returns the set of attributes referenced by the layer.
static double mapUnitScaleFactor(double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits)
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
#define DEFAULT_SIMPLELINE_PENSTYLE
#define DEFAULT_MARKERLINE_ROTATE
static const QString EXPR_JOINSTYLE
double estimateMaxBleed() const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
void setStyle(Qt::PenStyle style)
float threshold() const
Gets the simplification threshold of the vector layer managed.
QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const override
bool contains(const Key &key) const
virtual double width() const
void setClipPath(const QPainterPath &path, Qt::ClipOperation operation)
double markerAngle(const QPolygonF &points, bool isRing, int vertex)
void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context) override
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
#define DEFAULT_MARKERLINE_INTERVAL
QgsStringMap properties() const override
RenderHints renderHints() const
QColor selectionColor() const
QSet< QString > usedAttributes() const
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
QString nodeValue() const
virtual void setWidth(double width) override
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QgsMapUnitScale mCustomDashPatternMapUnitScale
double rendererScale() const
void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context) override
static const QString EXPR_WIDTH
static const QString EXPR_CUSTOMDASH
void drawPolyline(const QPointF *points, int pointCount)
static QgsStringMap getVendorOptionList(QDomElement &element)
QGis::UnitType mapUnits() const
const_iterator constEnd() const
void startRender(QgsSymbolV2RenderContext &context) override
const T & at(int i) const
void setUseCustomDashPattern(bool b)
static QVector< qreal > decodeRealVector(const QString &s)
void renderPolylineInterval(const QPolygonF &points, QgsSymbolV2RenderContext &context)
QgsSymbolV2::OutputUnit outputUnit() const override
QVector< qreal > customDashVector() const
bool setSubSymbol(QgsSymbolV2 *symbol) override
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
void setPenJoinStyle(Qt::PenJoinStyle style)
void setJoinStyle(Qt::PenJoinStyle style)
static QDomElement createVendorOptionElement(QDomDocument &doc, QString name, QString value)
Qt::PenCapStyle mPenCapStyle
static QColor decodeColor(QString str)
void copyPaintEffect(QgsSymbolLayerV2 *destLayer) const
Copies paint effect of this layer to another symbol layer.
static const bool selectionIsOpaque
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
virtual bool hasDataDefinedProperty(const QString &property) const
Checks whether the layer has a matching data defined property and if that property is currently activ...
static const QString EXPR_OFFSET_ALONG_LINE
QgsMapUnitScale mWidthMapUnitScale
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
QString layerType() const override
double toDouble(bool *ok) const
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsMapUnitScale mOffsetMapUnitScale
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
static const QString EXPR_OFFSET
Qt::PenStyle penStyle() const
QgsSymbolV2::OutputUnit mOffsetUnit
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
QgsMapUnitScale mOffsetAlongLineMapUnitScale
double dxfWidth(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const override
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
static QString encodeColor(QColor color)
void setInterval(double interval)
QgsMapUnitScale mapUnitScale() const override
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
bool mUseCustomDashPattern
void setDrawInsidePolygon(bool drawInsidePolygon)
static QString encodePenStyle(Qt::PenStyle style)
QPointF diffForInterval(double interval)
void setCapStyle(Qt::PenCapStyle style)
void setColor(const QColor &color)
QgsSymbolV2::OutputUnit mIntervalUnit
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
QgsSymbolLayerV2 * clone() const override
QgsSymbolLayerV2 * clone() const override
static QgsSymbolLayerV2 * createMarkerLayerFromSld(QDomElement &element)
static const QString EXPR_PLACEMENT
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
void setDashPattern(const QVector< qreal > &pattern)
static QString ogrFeatureStylePen(double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor &c, Qt::PenJoinStyle joinStyle=Qt::MiterJoin, Qt::PenCapStyle capStyle=Qt::FlatCap, double offset=0.0, const QVector< qreal > *dashPattern=0)
Create ogr feature style string for pen.
void addPolygon(const QPolygonF &polygon)
void setOffset(double offset)
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
void setMapUnitScale(const QgsMapUnitScale &scale) override
const QgsFeature * feature() const
Current feature being rendered - may be null.
void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context) override
QgsSymbolV2::OutputUnit outputUnit() const override
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
The geometries can be rendered with 'AntiAliasing' disabled because of it is '1-pixel size'...
Qt::PenJoinStyle mPenJoinStyle
static Qt::PenCapStyle decodePenCapStyle(QString str)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static Qt::PenStyle decodePenStyle(QString str)
void setPen(const QColor &color)
QgsSymbolV2::OutputUnit mWidthUnit
void setAttribute(const QString &name, const QString &value)
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, QString function)
QVector< qreal > mCustomDashVector
Vector with an even number of entries for the.
#define DEFAULT_SIMPLELINE_WIDTH
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context) override
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const override
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
void setAngle(double angle)
bool rotateMarker() const
#define DEFAULT_SIMPLELINE_CAPSTYLE
virtual QgsSymbolV2 * clone() const override
#define DEFAULT_SIMPLELINE_JOINSTYLE
void setWidthF(qreal width)
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
QString layerType() const override
void setSize(double size)
double rasterScaleFactor() const
void stopRender(QgsSymbolV2RenderContext &context) override
virtual QColor color() const
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
void setOffsetAlongLineUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit used for calculating the offset along line for markers.
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void setColor(const QColor &color)
virtual void prepareExpressions(const QgsFields *fields, double scale=-1.0)
Prepares all data defined property expressions for evaluation.
double estimateMaxBleed() const override
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
QgsSymbolV2 * subSymbol() override
void setPenCapStyle(Qt::PenCapStyle style)
virtual bool hasDataDefinedProperties() const
Checks whether the layer has any associated data defined properties.
void setCustomDashVector(const QVector< qreal > &vector)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static const QString EXPR_CAPSTYLE
QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const override
double dxfOffset(const QgsDxfExport &e, const QgsSymbolV2RenderContext &context) const override
QDomText createTextNode(const QString &value)
QgsMarkerSymbolV2 * mMarker
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static const QString EXPR_COLOR
static QString encodeRealVector(const QVector< qreal > &v)
QgsSymbolV2::OutputUnit outputUnit() const override
QgsSymbolV2::OutputUnit mCustomDashPatternUnit
virtual QString layerType() const =0
QColor dxfColor(const QgsSymbolV2RenderContext &context) const override
double symbologyScaleDenominator() const
~QgsMarkerLineSymbolLayerV2()
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const override
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
const T & at(int i) const
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, QColor color, double width=-1, const Qt::PenJoinStyle *penJoinStyle=0, const Qt::PenCapStyle *penCapStyle=0, const QVector< qreal > *customDashPattern=0, double dashOffset=0.0)
#define DEFAULT_SIMPLELINE_COLOR
static void createGeometryElement(QDomDocument &doc, QDomElement &element, QString geomFunc)
const_iterator constBegin() const
QgsMapUnitScale mIntervalMapUnitScale
Contains information about the context of a rendering operation.
QgsMapUnitScale mapUnitScale() const override
QgsSymbolV2::OutputUnit mOffsetAlongLineUnit
QDomNode firstChild() const
void stopRender(QgsRenderContext &context)
QgsSimpleLineSymbolLayerV2(QColor color=DEFAULT_SIMPLELINE_COLOR, double width=DEFAULT_SIMPLELINE_WIDTH, Qt::PenStyle penStyle=DEFAULT_SIMPLELINE_PENSTYLE)
void setMapUnitScale(const QgsMapUnitScale &scale) override
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.
char * toString(const T &value)
QSet< T > & unite(const QSet< T > &other)
void setPlacement(Placement p)
virtual QVariant evaluateDataDefinedProperty(const QString &property, const QgsFeature *feature, const QVariant &defaultVal=QVariant(), bool *ok=0) const
Evaluates the matching data defined property and returns the calculated value.
Qt::PenStyle dxfPenStyle() const override
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, QGis::GeometryType geometryType)
calculate geometry shifted by a specified distance
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
void stopRender(QgsSymbolV2RenderContext &context) override
QgsRenderContext & renderContext()
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
QDomElement firstChildElement(const QString &tagName) const
int count(const T &value) const
QgsMapUnitScale mapUnitScale() const override
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
void setColor(const QColor &color) override
const QgsFields * fields() const
Fields of the layer.
void push_back(const T &value)
void setRenderHints(int hints)
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
MyLine(QPointF p1, QPointF p2)
void setAlphaF(qreal alpha)
Placement placement() const
void restoreDataDefinedProperties(const QgsStringMap &stringMap)
Restores all data defined properties from string map.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=0, Qt::PenCapStyle *penCapStyle=0, QVector< qreal > *customDashPattern=0, double *dashOffset=0)
void startRender(QgsSymbolV2RenderContext &context) override
QgsMarkerLineSymbolLayerV2(bool rotateMarker=DEFAULT_MARKERLINE_ROTATE, double interval=DEFAULT_MARKERLINE_INTERVAL)
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
static bool isGeneralizableByDeviceBoundingBox(const QgsRectangle &envelope, float mapToPixelTol=1.0f)
Returns whether the device-envelope can be replaced by its BBOX when is applied the specified toleran...
int compare(const QString &other) const
static const QString EXPR_LINE_STYLE
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves all data defined properties to a string map.
static const QString EXPR_INTERVAL
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
void renderPolylineCentral(const QPolygonF &points, QgsSymbolV2RenderContext &context)
virtual double width() const override
QgsSymbolV2::OutputUnit widthUnit() const
static QgsSymbolV2::OutputUnit decodeOutputUnit(QString str)
QSet< QString > usedAttributes() const override
Returns the set of attributes referenced by the layer.
Qt::PenJoinStyle penJoinStyle() const
void renderPolylineVertex(const QPolygonF &points, QgsSymbolV2RenderContext &context, Placement placement=Vertex)
void copyDataDefinedProperties(QgsSymbolLayerV2 *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
Qt::PenCapStyle penCapStyle() const
const T value(const Key &key) const
static QString encodePenCapStyle(Qt::PenCapStyle style)
QgsStringMap properties() const override