20 #include <QSvgGenerator> 73 ( !
qgsDoubleNear( scaleFactorX, 0.0 ) ?
"tostring(" + QString::number( scaleFactorX ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) +
75 ( !
qgsDoubleNear( scaleFactorY, 0.0 ) ?
"tostring(" + QString::number( scaleFactorY ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) );
88 for (
int i = 0; i <
mLayers.count(); i++ )
94 else if ( !
mLayers.at( i )->isCompatibleWithSymbol(
this ) )
105 const unsigned int nPoints = curve.
numPoints();
112 if ( clipToExtent && nPoints > 1 )
115 const double cw = e.
width() / 10;
116 const double ch = e.
height() / 10;
139 pts.erase( std::remove_if( pts.begin(), pts.end(),
140 [](
const QPointF point )
142 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
145 QPointF *ptr = pts.data();
146 for (
int i = 0; i < pts.size(); ++i, ++ptr )
159 const double cw = e.
width() / 10;
160 const double ch = e.
height() / 10;
168 if ( correctRingOrientation )
172 std::reverse( poly.begin(), poly.end() );
174 std::reverse( poly.begin(), poly.end() );
178 const QRectF ptsRect = poly.boundingRect();
198 poly.erase( std::remove_if( poly.begin(), poly.end(),
199 [](
const QPointF point )
201 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
204 QPointF *ptr = poly.data();
205 for (
int i = 0; i < poly.size(); ++i, ++ptr )
210 if ( !poly.empty() && !poly.isClosed() )
211 poly << poly.at( 0 );
224 if ( !hole.isEmpty() ) holes.append( hole );
241 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
245 for ( ; it !=
mLayers.constEnd(); ++it )
247 if ( ( *it )->outputUnit() != unit )
262 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
263 if ( it ==
mLayers.constEnd() )
269 for ( ; it !=
mLayers.constEnd(); ++it )
271 if ( ( *it )->mapUnitScale() != scale )
281 const auto constMLayers =
mLayers;
284 layer->setOutputUnit( u );
290 const auto constMLayers =
mLayers;
293 layer->setMapUnitScale( scale );
299 std::unique_ptr< QgsSymbol > s;
317 if ( !defaultSymbol.isEmpty() )
326 s = qgis::make_unique< QgsMarkerSymbol >();
329 s = qgis::make_unique< QgsLineSymbol >();
332 s = qgis::make_unique< QgsFillSymbol >();
335 QgsDebugMsg( QStringLiteral(
"unknown layer's geometry type" ) );
346 opacity = alpha / 255.0;
349 opacity = newOpacity;
350 s->setOpacity( opacity );
353 if ( defaultSymbol.isEmpty() ||
374 if ( index < 0 || index >
mLayers.count() )
380 mLayers.insert( index, layer );
397 if ( index < 0 || index >=
mLayers.count() )
408 if ( index < 0 || index >=
mLayers.count() )
411 return mLayers.takeAt( index );
419 if ( oldLayer == layer )
433 Q_ASSERT_X( !mStarted,
"startRender",
"Rendering has already been started for this symbol instance!" );
443 mSymbolRenderContext->setExpressionContextScope( scope.release() );
445 const auto constMLayers =
mLayers;
451 layer->prepareExpressions( symbolContext );
452 layer->startRender( symbolContext );
458 Q_ASSERT_X( mStarted,
"startRender",
"startRender was not called for this symbol instance!" );
462 if ( mSymbolRenderContext )
464 const auto constMLayers =
mLayers;
470 layer->stopRender( *mSymbolRenderContext );
474 mSymbolRenderContext.reset(
nullptr );
483 const auto constMLayers =
mLayers;
486 if ( !
layer->isLocked() )
487 layer->setColor( color );
493 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
496 if ( !( *it )->isLocked() )
497 return ( *it )->color();
499 return QColor( 0, 0, 0 );
505 std::unique_ptr< QgsRenderContext > tempContext;
509 context = tempContext.get();
518 if ( !customContext && expressionContext )
522 else if ( !customContext )
543 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
546 if ( effect && effect->
enabled() )
559 layer->drawPreviewIcon( symbolContext, size );
567 if ( format.compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
569 QSvgGenerator generator;
570 generator.setFileName( path );
571 generator.setSize( size );
572 generator.setViewBox( QRect( 0, 0, size.height(), size.height() ) );
574 QPainter painter( &generator );
580 QImage image =
asImage( size );
587 QImage image( size, QImage::Format_ARGB32_Premultiplied );
590 QPainter p( &image );
591 p.setRenderHint( QPainter::Antialiasing );
601 QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
604 QPainter p( &preview );
605 p.setRenderHint( QPainter::Antialiasing );
606 p.translate( 0.5, 0.5 );
610 p.setPen( QPen( Qt::gray ) );
611 p.drawLine( 0, 50, 100, 50 );
612 p.drawLine( 50, 0, 50, 100 );
616 if ( expressionContext )
625 poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
626 static_cast<QgsLineSymbol *
>( this )->renderPolyline( poly,
nullptr, context );
631 polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
632 static_cast<QgsFillSymbol *
>( this )->renderPolygon( polygon,
nullptr,
nullptr, context );
636 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( QPointF( 50, 50 ),
nullptr, context );
650 t = QStringLiteral(
"MARKER" );
653 t = QStringLiteral(
"LINE" );
656 t = QStringLiteral(
"FILL" );
659 Q_ASSERT(
false &&
"unknown symbol type" );
663 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
672 props[ QStringLiteral(
"alpha" )] = QString::number(
opacity() );
673 double scaleFactor = 1.0;
677 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
679 ( *it )->toSld( doc, element, props );
686 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
707 if ( effect && effect->
enabled() )
710 generatorLayer->
render( context );
714 generatorLayer->
render( context );
720 QSet<QString> attributes;
721 QgsSymbolLayerList::const_iterator sIt =
mLayers.constBegin();
722 for ( ; sIt !=
mLayers.constEnd(); ++sIt )
726 attributes.unite( ( *sIt )->usedAttributes( context ) );
734 const auto constMLayers =
mLayers;
737 if (
layer->hasDataDefinedProperties() )
762 class ExpressionContextScopePopper
766 ExpressionContextScopePopper() =
default;
768 ~ExpressionContextScopePopper()
780 class GeometryRestorer
784 : mContext( context ),
790 mContext.setGeometry( mGeometry );
810 GeometryRestorer geomRestorer( context );
812 bool usingSegmentizedGeometry =
false;
826 usingSegmentizedGeometry =
true;
829 mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.
constGet()->
partCount() );
830 mSymbolRenderContext->setGeometryPartNum( 1 );
833 ExpressionContextScopePopper scopePopper;
834 if ( mSymbolRenderContext->expressionContextScope() )
836 if ( needsExpressionContext )
861 segmentizedGeometry = simplifier.
simplify( segmentizedGeometry );
866 startFeatureRender( feature, context, layer );
874 QgsDebugMsg( QStringLiteral(
"point can be drawn only with marker symbol!" ) );
879 const QPointF pt =
_getPoint( context, *point );
880 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( pt, &feature, context, layer, selected );
884 const QRectF bounds =
static_cast<QgsMarkerSymbol *
>( this )->bounds( pt, context, feature );
892 context.
painter()->setPen( Qt::red );
893 context.
painter()->setBrush( QColor( 255, 0, 0, 100 ) );
894 context.
painter()->drawRect( bounds );
898 if ( drawVertexMarker && !usingSegmentizedGeometry )
908 QgsDebugMsg( QStringLiteral(
"linestring can be drawn only with line symbol!" ) );
913 static_cast<QgsLineSymbol *
>( this )->renderPolyline( pts, &feature, context, layer, selected );
918 if ( drawVertexMarker && !usingSegmentizedGeometry )
928 QList<QPolygonF> holes;
931 QgsDebugMsg( QStringLiteral(
"polygon can be drawn only with fill symbol!" ) );
937 QgsDebugMsg( QStringLiteral(
"cannot render polygon with no exterior ring" ) );
941 static_cast<QgsFillSymbol *
>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
946 if ( drawVertexMarker && !usingSegmentizedGeometry )
950 const auto constHoles = holes;
951 for (
const QPolygonF &hole : constHoles )
963 QgsDebugMsg( QStringLiteral(
"multi-point can be drawn only with marker symbol!" ) );
969 if ( drawVertexMarker && !usingSegmentizedGeometry )
979 mSymbolRenderContext->setGeometryPartNum( i + 1 );
980 if ( needsExpressionContext )
984 const QPointF pt =
_getPoint( context, point );
985 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( pt, &feature, context, layer, selected );
989 const QRectF bounds =
static_cast<QgsMarkerSymbol *
>( this )->bounds( pt, context, feature );
993 if ( drawVertexMarker && !usingSegmentizedGeometry )
995 markers.append( pt );
1006 QgsDebugMsg( QStringLiteral(
"multi-linestring can be drawn only with line symbol!" ) );
1013 for (
unsigned int i = 0; i < num; ++i )
1018 mSymbolRenderContext->setGeometryPartNum( i + 1 );
1019 if ( needsExpressionContext )
1025 static_cast<QgsLineSymbol *
>( this )->renderPolyline( pts, &feature, context, layer, selected );
1032 if ( drawVertexMarker && !usingSegmentizedGeometry )
1045 QgsDebugMsg( QStringLiteral(
"multi-polygon can be drawn only with fill symbol!" ) );
1050 QList<QPolygonF> holes;
1057 std::map<double, QList<unsigned int> > mapAreaToPartNum;
1058 for (
unsigned int i = 0; i < num; ++i )
1062 mapAreaToPartNum[ r.width() * r.height()] << i;
1068 std::map<double, QList<unsigned int> >::const_reverse_iterator iter = mapAreaToPartNum.rbegin();
1069 for ( ; iter != mapAreaToPartNum.rend(); ++iter )
1071 const QList<unsigned int> &listPartIndex = iter->second;
1072 for (
int idx = 0; idx < listPartIndex.size(); ++idx )
1077 const unsigned i = listPartIndex[idx];
1078 mSymbolRenderContext->setGeometryPartNum( i + 1 );
1079 if ( needsExpressionContext )
1088 static_cast<QgsFillSymbol *
>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
1095 if ( drawVertexMarker && !usingSegmentizedGeometry )
1099 const auto constHoles = holes;
1100 for (
const QPolygonF &hole : constHoles )
1121 QgsDebugMsg( QStringLiteral(
"feature %1: unsupported wkb type %2/%3 for rendering" )
1122 .arg( feature.
id() )
1124 .arg( geom.
wkbType(), 0, 16 ) );
1127 stopFeatureRender( feature, context, layer );
1134 handler->handleRenderedFeature( feature, renderedBoundsGeom, featureContext );
1137 if ( drawVertexMarker )
1141 const auto constMarkers = markers;
1142 for ( QPointF marker : constMarkers )
1144 renderVertexMarker( marker, context, currentVertexMarkerType, currentVertexMarkerSize );
1159 x = vertexPoint.
x();
1160 y = vertexPoint.
y();
1169 renderVertexMarker( mapPoint, context, currentVertexMarkerType, currentVertexMarkerSize );
1177 return mSymbolRenderContext.get();
1191 if ( symbolLayer && symbolLayer->
enabled() )
1199 const QList< QgsSymbolLayer * > layers =
mLayers;
1215 if ( symbolLayer && symbolLayer->
enabled() )
1223 const QList< QgsSymbolLayer * > layers =
mLayers;
1238 : mRenderContext( c )
1240 , mMapUnitScale( mapUnitScale )
1242 , mSelected( selected )
1246 , mGeometryPartCount( 0 )
1247 , mGeometryPartNum( 0 )
1278 return mExpressionContextScope.get();
1283 mExpressionContextScope.reset( contextScope );
1295 layers.append( sl );
1306 layers.append( sl );
1317 layers.append( sl );
1332 double origAngle =
angle();
1333 double angleDiff = symbolAngle - origAngle;
1334 const auto constMLayers =
mLayers;
1350 return markerLayer->
angle();
1357 const auto constMLayers =
mLayers;
1369 const double symbolRotation =
angle();
1398 const double symbolRotation =
angle();
1429 if ( !layerAngleDD || layerAngleDD != symbolDD )
1435 if ( !layerAngleDD || layerAngleDD != rotatedDD )
1445 double origSize =
size();
1447 const auto constMLayers =
mLayers;
1458 markerLayer->
setSize( markerLayer->
size() * s / origSize );
1462 markerLayer->
setOffset( QPointF( markerLayer->
offset().x() * s / origSize,
1463 markerLayer->
offset().y() * s / origSize ) );
1471 const auto constMLayers =
mLayers;
1477 double lsize = markerLayer->
size();
1478 if ( lsize > maxSize )
1494 maxSize = std::max( maxSize, layerSize );
1501 const auto constMLayers =
mLayers;
1517 const auto constMLayers =
mLayers;
1528 if ( unit != markerLayer->
sizeUnit() )
1539 const auto constMLayers =
mLayers;
1552 const auto constMLayers =
mLayers;
1566 const double symbolSize =
size();
1568 const auto constMLayers =
mLayers;
1594 markerLayer->
offset().x() / symbolSize,
1595 markerLayer->
offset().y() / symbolSize, property ) );
1603 const double symbolSize =
size();
1636 if ( !layerSizeDD || layerSizeDD != symbolDD )
1645 if ( !layerSizeDD || layerSizeDD != scaledDD )
1650 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
1659 const auto constMLayers =
mLayers;
1671 const auto constMLayers =
mLayers;
1686 static QPointF nullPoint( 0, 0 );
1692 if ( effect && effect->
enabled() )
1695 p->translate( point );
1711 if ( layerIdx != -1 )
1719 renderPointUsingLayer( markerLayer, point, symbolContext );
1739 renderPointUsingLayer( markerLayer, point, symbolContext );
1751 const auto constMLayers =
mLayers;
1757 if ( bound.isNull() )
1758 bound = symbolLayer->
bounds( point, symbolContext );
1760 bound = bound.united( symbolLayer->
bounds( point, symbolContext ) );
1791 double origWidth =
width();
1793 const auto constMLayers =
mLayers;
1818 double maxWidth = 0;
1822 const auto constMLayers =
mLayers;
1829 if ( width > maxWidth )
1839 double maxWidth = 0;
1845 const double layerWidth = lineLayer->
width( context );
1846 maxWidth = std::max( maxWidth, layerWidth );
1853 const double symbolWidth =
width();
1855 const auto constMLayers =
mLayers;
1889 const double symbolWidth =
width();
1894 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1908 const auto constMLayers =
mLayers;
1920 if ( !layerWidthDD || layerWidthDD != symbolDD )
1929 if ( !layerWidthDD || layerWidthDD != scaledDD )
1934 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
1944 QPainter *renderPainter = context.
painter();
1950 if ( layerIdx != -1 )
1958 renderPolylineUsingLayer( lineLayer, points, symbolContext );
1966 const auto constMLayers =
mLayers;
1978 renderPolylineUsingLayer( lineLayer, points, symbolContext );
1995 if ( effect && effect->
enabled() )
1998 p->translate( points.boundingRect().topLeft() );
2000 layer->
renderPolyline( points.translated( -points.boundingRect().topLeft() ), context );
2038 if ( layerIdx != -1 )
2044 renderPolygonUsingLayer( symbolLayer, points, rings, symbolContext );
2051 const auto constMLayers =
mLayers;
2061 renderPolygonUsingLayer(
symbolLayer, points, rings, symbolContext );
2075 if ( effect && effect->
enabled() )
2077 QRectF bounds = polygonBounds( points, rings );
2078 QList<QPolygonF> *translatedRings = translateRings( rings, -bounds.left(), -bounds.top() );
2081 p->translate( bounds.topLeft() );
2085 (
static_cast<QgsFillSymbolLayer *
>(
layer ) )->renderPolygon( points.translated( -bounds.topLeft() ), translatedRings, context );
2089 (
static_cast<QgsLineSymbolLayer *
>(
layer ) )->renderPolygonStroke( points.translated( -bounds.topLeft() ), translatedRings, context );
2091 delete translatedRings;
2106 QRectF QgsFillSymbol::polygonBounds(
const QPolygonF &points,
const QList<QPolygonF> *rings )
const 2108 QRectF bounds = points.boundingRect();
2111 QList<QPolygonF>::const_iterator it = rings->constBegin();
2112 for ( ; it != rings->constEnd(); ++it )
2114 bounds = bounds.united( ( *it ).boundingRect() );
2120 QList<QPolygonF> *QgsFillSymbol::translateRings(
const QList<QPolygonF> *rings,
double dx,
double dy )
const 2125 QList<QPolygonF> *translatedRings =
new QList<QPolygonF>;
2126 QList<QPolygonF>::const_iterator it = rings->constBegin();
2127 for ( ; it != rings->constEnd(); ++it )
2129 translatedRings->append( ( *it ).translated( dx, dy ) );
2131 return translatedRings;
2148 const auto constMLayers =
mLayers;
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
bool insertSymbolLayer(int index, QgsSymbolLayer *layer)
Inserts a symbol layer to specified index.
QgsSymbolRenderContext(QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity=1.0, bool selected=false, QgsSymbol::RenderHints renderHints=nullptr, const QgsFeature *f=nullptr, const QgsFields &fields=QgsFields(), const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Constructor for QgsSymbolRenderContext.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
Single variable definition for use within a QgsExpressionContextScope.
A rectangle specified with double values.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr)
Draws an icon of the symbol that occupies an area given by size using the specified painter...
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
void setRenderingPass(int renderingPass)
Specifies the rendering pass in which this symbol layer should be rendered.
void setLocked(bool locked)
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsMapLayerType type() const
Returns the type of the layer.
static QPolygonF _getPolygonRing(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing=false, bool correctRingOrientation=false)
Creates a polygon ring in screen coordinates from a QgsCurve in map coordinates.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
Abstract base class for all rendered symbols.
void renderVertexMarker(QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize)
Render editing vertex marker at specified point.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
Multi point geometry collection.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke...
virtual void setWidth(double width)
Sets the width of the line symbol layer.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
ScaleMethod scaleMethod()
const QgsMapUnitScale & sizeMapUnitScale() const
Returns the map unit scale for the symbol's size.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
A simple line symbol layer, which renders lines using a line in a variety of styles (e...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setExpressionContextScope(QgsExpressionContextScope *contextScope)
Set an expression scope for this symbol.
void setAngle(double angle)
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol along the line joining points, using the given render context. ...
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Converts the symbol to a SLD representation.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
#define Q_NOWARN_DEPRECATED_PUSH
void setSize(double size)
Sets the size for the whole symbol.
Base class for visual effects which can be applied to QPicture drawings.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the size map unit scale for the whole symbol (including all symbol layers).
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
void setIsGuiPreview(bool preview)
Sets GUI preview mode.
Q_DECL_DEPRECATED double outputLineWidth(double width) const
bool mClipFeaturesToExtent
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
virtual void render(QgsSymbolRenderContext &context)
Will render this symbol layer using the context.
void setGeometryPartCount(int count)
Sets the part count of current geometry.
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Sets the method to use for scaling the marker's size.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QMap< QString, QString > QgsStringMap
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
virtual double width() const
Returns the estimated width for the line symbol layer.
A marker symbol type, for rendering Point and MultiPoint geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
static QgsStyle * defaultStyle()
Returns default application-wide style.
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
Renders the line symbol layer along the line joining points, using the given render context...
Q_DECL_DEPRECATED const QgsVectorLayer * mLayer
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
static QString encodeColor(const QColor &color)
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
QgsSymbolRenderContext & operator=(const QgsSymbolRenderContext &)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
SymbolType
Type of the symbol.
void renderPoint(QPointF point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol at the specified point, using the given render context.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
Perform transforms between map coordinates and device coordinates.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
virtual QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleMarkerSymbolLayer.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsSymbolLayerList mLayers
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
virtual QRectF bounds(QPointF point, QgsSymbolRenderContext &context)=0
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
QImage asImage(QSize size, QgsRenderContext *customContext=nullptr)
Returns an image of the symbol at the specified size.
void exportImage(const QString &path, const QString &format, QSize size)
Export the symbol as an image format, to the specified path and with the given size.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setOriginalGeometryType(QgsWkbTypes::GeometryType type)
Sets the geometry type for the original feature geometry being rendered.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
QString dump() const
Returns a string dump of the symbol's properties.
Utility class for identifying a unique vertex within a geometry.
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
void setGeometry(const QgsAbstractGeometry *geometry)
Sets pointer to original (unsegmentized) geometry.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
#define DEFAULT_SCALE_METHOD
QRectF bounds(QPointF point, QgsRenderContext &context, const QgsFeature &feature=QgsFeature()) const
Returns the approximate bounding box of the marker symbol, which includes the bounding box of all sym...
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol using the given render context.
Q_DECL_DEPRECATED double outputPixelSize(double size) const
void renderUsingLayer(QgsSymbolLayer *layer, QgsSymbolRenderContext &context)
Renders a context using a particular symbol layer without passing in a geometry.
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
void setGeometryPartNum(int num)
Sets the part number of current geometry.
void setWidth(double width)
Sets the width for the whole line symbol.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
double size() const
Returns the symbol size.
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
An interface for classes which provider custom handlers for features rendered as part of a map render...
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
QgsProperty scaleWholeSymbol(double scaleFactor, const QgsProperty &property)
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's size.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
QgsMapUnitScale sizeMapUnitScale() const
Returns the size map unit scale for the whole symbol.
Draw bounds of symbols (for debugging/testing)
QList< QgsSymbolLayer * > QgsSymbolLayerList
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
static QString encodeSldUom(QgsUnitTypes::RenderUnit unit, double *scaleFactor)
Encodes a render unit into an SLD unit of measure string.
QColor color() const
Returns the symbol's color.
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
QgsSymbol::SymbolType type() const
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setSelected(bool selected)
Sets whether symbols should be rendered using the selected symbol coloring and style.
bool enabled() const
Returns whether the effect is enabled.
Abstract base class for curved geometry type.
double offset() const
Returns the line's offset.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Abstract base class for all geometries.
void setEnabled(bool enabled)
Sets whether symbol layer is enabled and should be drawn.
void setAngle(double angle)
A store for object properties.
QgsMarkerSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsMarkerSymbol, with the specified list of initial symbol layers.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Counter-clockwise orientation.
Point geometry type, with support for z-dimension and m-values.
void setEffect(QgsPaintEffect *effect)
Sets the effect to be painted.
static QPolygonF clippedLine(const QgsCurve &curve, const QgsRectangle &clipExtent)
Takes a linestring and clips it to clipExtent.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the size units for the whole symbol (including all symbol layers).
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleLineSymbolLayer, using the settings serialized in the properties map (correspo...
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsSymbol::ScaleMethod scaleMethod() const
Returns the method to use for scaling the marker's size.
Orientation orientation() const
Returns the curve's orientation, e.g.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the size units for the whole symbol (including all symbol layers).
QgsExpressionContext & expressionContext()
Gets the expression context.
static QPolygonF _getLineString(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent=true)
Creates a line string in screen coordinates from a QgsCurve in map coordinates.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
#define Q_NOWARN_DEPRECATED_POP
VertexMarkerType
Editing vertex markers.
static void drawVertexMarker(double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol's size.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
bool isSymbolLayerEnabled(const QgsSymbolLayer *layer) const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes. ...
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
Contains information about the context of a rendering operation.
Abstract base class for marker symbol layers.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsSymbolLayerList cloneLayers() const
Retrieve a cloned list of all layers that make up this symbol.
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
bool hasDataDefinedProperties() const
Returns whether the symbol utilizes any data defined properties.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleFillSymbolLayer using the specified properties map containing symbol propertie...
bool enabled() const
Returns true if symbol layer is enabled and will be drawn.
SymbolType type() const
Returns the symbol's type.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
Struct for storing maximum and minimum scales for measurements in map units.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, double currentVertexMarkerSize=0.0) SIP_THROW(QgsCsException)
Render a feature.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol's size.
QgsProperty rotateWholeSymbol(double additionalRotation, const QgsProperty &property)
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
Q_DECL_DEPRECATED void setLayer(const QgsVectorLayer *layer)
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
static void _getPolygon(QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent=true, bool correctRingOrientation=false)
Creates a polygon in screen coordinates from a QgsPolygonXYin map coordinates.
RenderHints renderHints() const
Returns the rendering hint flags for the symbol.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsSymbol(SymbolType type, const QgsSymbolLayerList &layers)
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
virtual void setSize(double size)
Sets the symbol size.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
double xMinimum() const
Returns the x minimum value (left side of rectangle).
virtual void renderPolygonStroke(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolRenderContext &context)
Renders the line symbol layer along the outline of polygon, using the given render context...
void setAngle(double angle)
Sets the rotation angle for the marker.
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
QgsLineSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsLineSymbol, with the specified list of initial symbol layers.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QgsSymbolLayer * takeSymbolLayer(int index)
Removes a symbol layer from the list and returns a pointer to it.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Custom exception class for Coordinate Reference System related exceptions.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent...
qreal opacity() const
Returns the opacity for the symbol.
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Draw map such that there are no problems between adjacent tiles.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=nullptr)
Returns a large (roughly 100x100 pixel) preview image for the symbol.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
Q_DECL_DEPRECATED const QgsVectorLayer * layer() const
Represents a vector layer which manages a vector based data sets.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
static Type flatType(Type type)
Returns the flat type for a WKB type.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Whether symbol layer is enabled.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
virtual int numPoints() const =0
Returns the number of points in the curve.
qreal mOpacity
Symbol opacity (in the range 0 - 1)
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
A class to manager painter saving and restoring required for effect drawing.
double angle() const
Returns the marker angle for the whole symbol.
QgsFillSymbol(const QgsSymbolLayerList &layers=QgsSymbolLayerList())
Constructor for QgsFillSymbol, with the specified list of initial symbol layers.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
RenderUnit
Rendering size units.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
double height() const
Returns the height of the rectangle.
void setOffset(double offset)
Sets the line's offset.
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
void setColor(const QColor &color)
Sets the color for the symbol.
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.