47 #include <QSvgGenerator> 72 ( !
qgsDoubleNear( scaleFactorX, 0.0 ) ?
"tostring(" + QString::number( scaleFactorX ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) +
74 ( !
qgsDoubleNear( scaleFactorY, 0.0 ) ?
"tostring(" + QString::number( scaleFactorY ) +
"*(" + exprString +
"))" : QStringLiteral(
"'0'" ) ) );
86 for (
int i = 0; i <
mLayers.count(); i++ )
92 else if ( !
mLayers.at( i )->isCompatibleWithSymbol(
this ) )
102 const unsigned int nPoints = curve.
numPoints();
109 if ( clipToExtent && nPoints > 1 )
112 const double cw = e.
width() / 10;
113 const double ch = e.
height() / 10;
129 pts.erase( std::remove_if( pts.begin(), pts.end(),
130 [](
const QPointF point )
132 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
135 QPointF *ptr = pts.data();
136 for (
int i = 0; i < pts.size(); ++i, ++ptr )
149 const double cw = e.
width() / 10;
150 const double ch = e.
height() / 10;
159 const QRectF ptsRect = poly.boundingRect();
172 poly.erase( std::remove_if( poly.begin(), poly.end(),
173 [](
const QPointF point )
175 return !std::isfinite( point.x() ) || !std::isfinite( point.y() );
178 QPointF *ptr = poly.data();
179 for (
int i = 0; i < poly.size(); ++i, ++ptr )
195 if ( !hole.isEmpty() ) holes.append( hole );
212 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
216 for ( ; it !=
mLayers.constEnd(); ++it )
218 if ( ( *it )->outputUnit() != unit )
233 QgsSymbolLayerList::const_iterator it =
mLayers.constBegin();
234 if ( it ==
mLayers.constEnd() )
240 for ( ; it !=
mLayers.constEnd(); ++it )
242 if ( ( *it )->mapUnitScale() != scale )
286 if ( !defaultSymbol.isEmpty() )
315 opacity = alpha / 255.0;
318 opacity = newOpacity;
322 if ( defaultSymbol.isEmpty() ||
326 std::random_device rd;
327 std::mt19937 mt( rd() );
328 std::uniform_int_distribution<int> hueDist( 0, 359 );
329 std::uniform_int_distribution<int> satDist( 64, 255 );
330 std::uniform_int_distribution<int> valueDist( 128, 255 );
331 s->
setColor( QColor::fromHsv( hueDist( mt ), satDist( mt ), valueDist( mt ) ) );
344 if ( index < 0 || index >
mLayers.count() )
350 mLayers.insert( index, layer );
367 if ( index < 0 || index >=
mLayers.count() )
378 if ( index < 0 || index >=
mLayers.count() )
381 return mLayers.takeAt( index );
389 if ( oldLayer == layer )
403 Q_ASSERT_X( !mStarted,
"startRender",
"Rendering has already been started for this symbol instance!" );
411 mSymbolRenderContext->setExpressionContextScope( scope.release() );
425 Q_ASSERT_X( mStarted,
"startRender",
"startRender was not called for this symbol instance!" );
429 if ( mSymbolRenderContext )
440 mSymbolRenderContext.reset(
nullptr );
456 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
459 if ( !( *it )->isLocked() )
460 return ( *it )->color();
462 return QColor( 0, 0, 0 );
485 QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
498 if ( format.toLower() == QLatin1String(
"svg" ) )
500 QSvgGenerator generator;
501 generator.setFileName( path );
502 generator.setSize( size );
503 generator.setViewBox( QRect( 0, 0, size.height(), size.height() ) );
505 QPainter painter( &generator );
511 QImage image =
asImage( size );
518 QImage image( size, QImage::Format_ARGB32_Premultiplied );
521 QPainter p( &image );
522 p.setRenderHint( QPainter::Antialiasing );
532 QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
535 QPainter p( &preview );
536 p.setRenderHint( QPainter::Antialiasing );
537 p.translate( 0.5, 0.5 );
541 p.setPen( QPen( Qt::gray ) );
542 p.drawLine( 0, 50, 100, 50 );
543 p.drawLine( 50, 0, 50, 100 );
547 if ( expressionContext )
555 poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
556 static_cast<QgsLineSymbol *
>( this )->renderPolyline( poly,
nullptr, context );
561 polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
562 static_cast<QgsFillSymbol *
>( this )->renderPolygon( polygon,
nullptr,
nullptr, context );
566 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( QPointF( 50, 50 ),
nullptr, context );
580 t = QStringLiteral(
"MARKER" );
583 t = QStringLiteral(
"LINE" );
586 t = QStringLiteral(
"FILL" );
589 Q_ASSERT(
false &&
"unknown symbol type" );
593 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
602 props[ QStringLiteral(
"alpha" )] = QString::number(
opacity() );
603 double scaleFactor = 1.0;
607 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
609 ( *it )->toSld( doc, element, props );
616 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
637 if ( effect && effect->
enabled() )
640 generatorLayer->
render( context );
644 generatorLayer->
render( context );
650 QSet<QString> attributes;
651 QgsSymbolLayerList::const_iterator sIt =
mLayers.constBegin();
652 for ( ; sIt !=
mLayers.constEnd(); ++sIt )
656 attributes.unite( ( *sIt )->usedAttributes( context ) );
671 if ( layer->
layerType() == QLatin1String(
"GeometryGenerator" ) )
682 class ExpressionContextScopePopper
686 ExpressionContextScopePopper() =
default;
688 ~ExpressionContextScopePopper()
707 bool usingSegmentizedGeometry =
false;
721 usingSegmentizedGeometry =
true;
724 mSymbolRenderContext->setGeometryPartCount( segmentizedGeometry.
constGet()->
partCount() );
725 mSymbolRenderContext->setGeometryPartNum( 1 );
728 ExpressionContextScopePopper scopePopper;
729 if ( mSymbolRenderContext->expressionContextScope() )
731 if ( needsExpressionContext )
756 segmentizedGeometry = simplifier.
simplify( segmentizedGeometry );
765 QgsDebugMsg(
"point can be drawn only with marker symbol!" );
770 const QPointF pt =
_getPoint( context, *point );
771 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( pt, &feature, context, layer, selected );
776 context.
painter()->setPen( Qt::red );
777 context.
painter()->setBrush( QColor( 255, 0, 0, 100 ) );
778 context.
painter()->drawRect( static_cast<QgsMarkerSymbol *>(
this )->bounds( pt, context, feature ) );
781 if ( drawVertexMarker && !usingSegmentizedGeometry )
791 QgsDebugMsg(
"linestring can be drawn only with line symbol!" );
796 static_cast<QgsLineSymbol *
>( this )->renderPolyline( pts, &feature, context, layer, selected );
798 if ( drawVertexMarker && !usingSegmentizedGeometry )
808 QList<QPolygonF> holes;
811 QgsDebugMsg(
"polygon can be drawn only with fill symbol!" );
817 QgsDebugMsg(
"cannot render polygon with no exterior ring" );
821 static_cast<QgsFillSymbol *
>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
823 if ( drawVertexMarker && !usingSegmentizedGeometry )
827 Q_FOREACH (
const QPolygonF &hole, holes )
839 QgsDebugMsg(
"multi-point can be drawn only with marker symbol!" );
845 if ( drawVertexMarker && !usingSegmentizedGeometry )
852 mSymbolRenderContext->setGeometryPartNum( i + 1 );
853 if ( needsExpressionContext )
857 const QPointF pt =
_getPoint( context, point );
858 static_cast<QgsMarkerSymbol *
>( this )->renderPoint( pt, &feature, context, layer, selected );
860 if ( drawVertexMarker && !usingSegmentizedGeometry )
862 markers.append( pt );
873 QgsDebugMsg(
"multi-linestring can be drawn only with line symbol!" );
880 for (
unsigned int i = 0; i < num; ++i )
882 mSymbolRenderContext->setGeometryPartNum( i + 1 );
883 if ( needsExpressionContext )
889 static_cast<QgsLineSymbol *
>( this )->renderPolyline( pts, &feature, context, layer, selected );
891 if ( drawVertexMarker && !usingSegmentizedGeometry )
911 QgsDebugMsg(
"multi-polygon can be drawn only with fill symbol!" );
916 QList<QPolygonF> holes;
923 std::map<double, QList<unsigned int> > mapAreaToPartNum;
924 for (
unsigned int i = 0; i < num; ++i )
928 mapAreaToPartNum[ r.width() * r.height()] << i;
934 std::map<double, QList<unsigned int> >::const_reverse_iterator iter = mapAreaToPartNum.rbegin();
935 for ( ; iter != mapAreaToPartNum.rend(); ++iter )
937 const QList<unsigned int> &listPartIndex = iter->second;
938 for (
int idx = 0; idx < listPartIndex.size(); ++idx )
940 const unsigned i = listPartIndex[idx];
941 mSymbolRenderContext->setGeometryPartNum( i + 1 );
942 if ( needsExpressionContext )
951 static_cast<QgsFillSymbol *
>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );
953 if ( drawVertexMarker && !usingSegmentizedGeometry )
964 Q_FOREACH (
const QPolygonF &hole, holes )
985 QgsDebugMsg( QString(
"feature %1: unsupported wkb type %2/%3 for rendering" )
988 .arg( geom.
wkbType(), 0, 16 ) );
991 if ( drawVertexMarker )
993 if ( !markers.isEmpty() )
995 Q_FOREACH ( QPointF marker, markers )
997 renderVertexMarker( marker, context, currentVertexMarkerType, currentVertexMarkerSize );
1012 x = vertexPoint.
x();
1013 y = vertexPoint.
y();
1022 renderVertexMarker( mapPoint, context, currentVertexMarkerType, currentVertexMarkerSize );
1030 return mSymbolRenderContext.get();
1042 : mRenderContext( c )
1044 , mMapUnitScale( mapUnitScale )
1046 , mSelected( selected )
1050 , mGeometryPartCount( 0 )
1051 , mGeometryPartNum( 0 )
1082 return mExpressionContextScope.get();
1087 mExpressionContextScope.reset( contextScope );
1099 layers.append( sl );
1110 layers.append( sl );
1121 layers.append( sl );
1136 double origAngle =
angle();
1137 double angleDiff = symbolAngle - origAngle;
1153 return markerLayer->
angle();
1171 const double symbolRotation =
angle();
1199 const double symbolRotation =
angle();
1229 if ( !layerAngleDD || layerAngleDD != symbolDD )
1235 if ( !layerAngleDD || layerAngleDD != rotatedDD )
1245 double origSize =
size();
1257 markerLayer->
setSize( markerLayer->
size() * s / origSize );
1261 markerLayer->
setOffset( QPointF( markerLayer->
offset().x() * s / origSize,
1262 markerLayer->
offset().y() * s / origSize ) );
1275 double lsize = markerLayer->
size();
1276 if ( lsize > maxSize )
1309 if ( unit != markerLayer->
sizeUnit() )
1345 const double symbolSize =
size();
1372 markerLayer->
offset().x() / symbolSize,
1373 markerLayer->
offset().y() / symbolSize, property ) );
1381 const double symbolSize =
size();
1413 if ( !layerSizeDD || layerSizeDD != symbolDD )
1422 if ( !layerSizeDD || layerSizeDD != scaledDD )
1427 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
1461 static QPointF nullPoint( 0, 0 );
1467 if ( effect && effect->
enabled() )
1470 p->translate( point );
1486 if ( layerIdx != -1 )
1489 if ( symbolLayer && symbolLayer->
enabled() )
1494 renderPointUsingLayer( markerLayer, point, symbolContext );
1504 if ( !symbolLayer->
enabled() )
1510 renderPointUsingLayer( markerLayer, point, symbolContext );
1527 if ( bound.isNull() )
1528 bound = symbolLayer->
bounds( point, symbolContext );
1530 bound = bound.united( symbolLayer->
bounds( point, symbolContext ) );
1558 double origWidth =
width();
1584 double maxWidth = 0;
1594 if ( width > maxWidth )
1603 const double symbolWidth =
width();
1638 const double symbolWidth =
width();
1643 for ( QgsSymbolLayerList::const_iterator it =
mLayers.begin(); it !=
mLayers.end(); ++it )
1668 if ( !layerWidthDD || layerWidthDD != symbolDD )
1677 if ( !layerWidthDD || layerWidthDD != scaledDD )
1682 if ( layerOffsetDD && layerOffsetDD != scaledOffsetDD )
1692 QPainter *renderPainter = context.
painter();
1698 if ( layerIdx != -1 )
1701 if ( symbolLayer && symbolLayer->
enabled() )
1706 renderPolylineUsingLayer( lineLayer, points, symbolContext );
1716 if ( !symbolLayer->
enabled() )
1722 renderPolylineUsingLayer( lineLayer, points, symbolContext );
1739 if ( effect && effect->
enabled() )
1742 p->translate( points.boundingRect().topLeft() );
1744 layer->
renderPolyline( points.translated( -points.boundingRect().topLeft() ), context );
1779 if ( layerIdx != -1 )
1782 if ( symbolLayer && symbolLayer->
enabled() )
1785 renderPolygonUsingLayer( symbolLayer, points, rings, symbolContext );
1794 if ( !symbolLayer->
enabled() )
1798 renderPolygonUsingLayer( symbolLayer, points, rings, symbolContext );
1812 if ( effect && effect->
enabled() )
1814 QRectF bounds = polygonBounds( points, rings );
1815 QList<QPolygonF> *translatedRings = translateRings( rings, -bounds.left(), -bounds.top() );
1818 p->translate( bounds.topLeft() );
1822 (
static_cast<QgsFillSymbolLayer *
>(
layer ) )->renderPolygon( points.translated( -bounds.topLeft() ), translatedRings, context );
1826 (
static_cast<QgsLineSymbolLayer *
>(
layer ) )->renderPolygonStroke( points.translated( -bounds.topLeft() ), translatedRings, context );
1828 delete translatedRings;
1843 QRectF QgsFillSymbol::polygonBounds(
const QPolygonF &points,
const QList<QPolygonF> *rings )
const 1845 QRectF bounds = points.boundingRect();
1848 QList<QPolygonF>::const_iterator it = rings->constBegin();
1849 for ( ; it != rings->constEnd(); ++it )
1851 bounds = bounds.united( ( *it ).boundingRect() );
1857 QList<QPolygonF> *QgsFillSymbol::translateRings(
const QList<QPolygonF> *rings,
double dx,
double dy )
const 1862 QList<QPolygonF> *translatedRings =
new QList<QPolygonF>;
1863 QList<QPolygonF>::const_iterator it = rings->constBegin();
1864 for ( ; it != rings->constEnd(); ++it )
1866 translatedRings->append( ( *it ).translated( dx, dy ) );
1868 return translatedRings;
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
const QgsCurve * interiorRing(int i) const
bool insertSymbolLayer(int index, QgsSymbolLayer *layer)
Insert symbol layer to specified index Ownership will be transferred.
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)
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
Return 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 setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
void setRenderingPass(int renderingPass)
void setLocked(bool locked)
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
void setMapUnitScale(const QgsMapUnitScale &scale)
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.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
Multi point geometry collection.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Append symbol layer at the end of the list Ownership will be transferred.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke...
virtual void setWidth(double width)
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.
virtual void prepareExpressions(const QgsSymbolRenderContext &context)
Prepares all data defined property expressions for evaluation.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsSymbol(SymbolType type, const QgsSymbolLayerList &layers)
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
QgsMapUnitScale mapUnitScale() const
void setExpressionContextScope(QgsExpressionContextScope *contextScope)
Set an expression scope for this symbol.
void setAngle(double angle)
VertexMarkerType
Editing vertex markers.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
void setSize(double size)
Sets the size for the whole symbol.
Base class for visual effects which can be applied to QPicture drawings.
void renderVertexMarker(QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize)
Render editing vertex marker at specified point.
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 clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
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)
delete symbol layer at 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
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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
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
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
static QString encodeColor(const QColor &color)
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
virtual void setColor(const QColor &color)
The fill color.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
QgsSymbolRenderContext & operator=(const QgsSymbolRenderContext &)
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)
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).
QPolygonF asQPolygonF() const
Returns a QPolygonF representing the points.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsSimpleMarkerSymbolLayer.
QgsSymbolLayerList mLayers
int numInteriorRings() const
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)
Generate symbol as image.
void exportImage(const QString &path, const QString &format, QSize size)
export symbol as image format. PNG and SVG supported
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
return new default symbol for 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.
virtual void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol layer.
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 QgsVectorLayer * mLayer
const QgsRectangle & extent() const
#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)
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
Get a deep copy of this symbol.
void setGeometryPartNum(int num)
Sets the part number of current geometry.
static void _getPolygon(QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent=true)
Creates a polygon in screen coordinates from a QgsPolygonXYin map coordinates.
void setWidth(double width)
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...
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides...
void setSize(double size)
Sets the symbol size.
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.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, int currentVertexMarkerSize=0)
Render a feature.
QgsMapUnitScale sizeMapUnitScale() const
Returns the size map unit scale for the whole symbol.
Draw bounds of symbols (for debugging/testing)
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr)
Draw icon of the symbol that occupyies area given by size using the painter.
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.
virtual void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size)=0
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, or an invalid transform is no coordinate tr...
bool enabled() const
Returns whether the effect is enabled.
Abstract base class for curved geometry type.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Abstract base class for all geometries.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
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())
const QgsVectorLayer * layer() const
const QgsCurve * exteriorRing() const
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
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())
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.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the size units for the whole symbol (including all symbol layers).
QgsExpressionContext & expressionContext()
Gets the expression context.
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).
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.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
delete layer at specified index and set a new one
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol's size.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Return 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.
virtual void setMapUnitScale(const QgsMapUnitScale &scale)
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
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())
bool enabled() const
Returns true if symbol layer is enabled and will be drawn.
virtual void stopRender(QgsSymbolRenderContext &context)=0
Struct for storing maximum and minimum scales for measurements in map units.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol's size.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
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.
void setLayer(const QgsVectorLayer *layer)
double size() const
Returns the size for the whole symbol, which is the maximum size of all marker symbol layers in the s...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
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.
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)
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())
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)
Remove symbol layer from the list and return pointer to it.
static QPolygonF _getPolygonRing(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent)
Creates a polygon ring in screen coordinates from a QgsCurve in map coordinates.
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.
static QPolygonF _getLineString(QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent=true)
Creates a line string in screen coordinates from a QgsCurve in map coordinates.
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.
Draw map such that there are no problems between adjacent tiles.
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...
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.
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())
QgsMarkerSymbol * clone() const override
Get 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)
virtual void startRender(QgsSymbolRenderContext &context)=0
QgsLineSymbol * clone() const override
Get a deep copy of this symbol.
virtual QString layerType() const =0
Returns a string that represents this layer type.
void setColor(const QColor &color)
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.