QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsgeometrygeneratorsymbollayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrygeneratorsymbollayer.cpp
3 ---------------------
4 begin : November 2015
5 copyright : (C) 2015 by Matthias Kuhn
6 email : matthias at opengis dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsgeometry.h"
18#include "qgsmarkersymbol.h"
19#include "qgslinesymbol.h"
20#include "qgsfillsymbol.h"
21#include "qgspolygon.h"
22#include "qgslegendpatchshape.h"
23#include "qgsstyle.h"
24#include "qgsunittypes.h"
25
27
29
31{
32 QString expression = properties.value( QStringLiteral( "geometryModifier" ) ).toString();
33 if ( expression.isEmpty() )
34 {
35 expression = QStringLiteral( "$geometry" );
36 }
38
39 if ( properties.value( QStringLiteral( "SymbolType" ) ) == QLatin1String( "Marker" ) )
40 {
42 }
43 else if ( properties.value( QStringLiteral( "SymbolType" ) ) == QLatin1String( "Line" ) )
44 {
46 }
47 else
48 {
50 }
51 symbolLayer->setUnits( QgsUnitTypes::decodeRenderUnit( properties.value( QStringLiteral( "units" ), QStringLiteral( "mapunits" ) ).toString() ) );
52
54
55 return symbolLayer;
56}
57
58QgsGeometryGeneratorSymbolLayer::QgsGeometryGeneratorSymbolLayer( const QString &expression )
59 : QgsSymbolLayer( Qgis::SymbolType::Hybrid )
60 , mExpression( new QgsExpression( expression ) )
61 , mSymbolType( Qgis::SymbolType::Marker )
62{
63
64}
65
67{
68 return QStringLiteral( "GeometryGenerator" );
69}
70
72{
74 {
75 if ( !mFillSymbol )
76 mFillSymbol.reset( QgsFillSymbol::createSimple( QVariantMap() ) );
77 mSymbol = mFillSymbol.get();
78 }
80 {
81 if ( !mLineSymbol )
82 mLineSymbol.reset( QgsLineSymbol::createSimple( QVariantMap() ) );
83 mSymbol = mLineSymbol.get();
84 }
86 {
87 if ( !mMarkerSymbol )
88 mMarkerSymbol.reset( QgsMarkerSymbol::createSimple( QVariantMap() ) );
89 mSymbol = mMarkerSymbol.get();
90 }
91 else
92 Q_ASSERT( false );
93
94 mSymbolType = symbolType;
95}
96
98{
99 mExpression->prepare( &context.renderContext().expressionContext() );
100
101 subSymbol()->startRender( context.renderContext() );
102}
103
105{
106 if ( mSymbol )
107 mSymbol->stopRender( context.renderContext() );
108}
109
111{
113 return;
114
115 mRenderingFeature = true;
116 mHasRenderedFeature = false;
117}
118
120{
121 mRenderingFeature = false;
122}
123
125{
126 if ( mFillSymbol )
127 return mFillSymbol->usesMapUnits();
128 else if ( mLineSymbol )
129 return mLineSymbol->usesMapUnits();
130 else if ( mMarkerSymbol )
131 return mMarkerSymbol->usesMapUnits();
132 return false;
133}
134
136{
137 if ( mFillSymbol )
138 return mFillSymbol->color();
139 else if ( mLineSymbol )
140 return mLineSymbol->color();
141 else if ( mMarkerSymbol )
142 return mMarkerSymbol->color();
143 return QColor();
144}
145
147{
148 if ( mFillSymbol )
149 return mFillSymbol->outputUnit();
150 else if ( mLineSymbol )
151 return mLineSymbol->outputUnit();
152 else if ( mMarkerSymbol )
153 return mMarkerSymbol->outputUnit();
154 return Qgis::RenderUnit::Unknown;
155}
156
158{
159 if ( mFillSymbol )
160 mFillSymbol->setOutputUnit( unit );
161 else if ( mLineSymbol )
162 mLineSymbol->setOutputUnit( unit );
163 else if ( mMarkerSymbol )
164 mMarkerSymbol->setOutputUnit( unit );
165}
166
168{
169 if ( mFillSymbol )
170 return mFillSymbol->mapUnitScale();
171 else if ( mLineSymbol )
172 return mLineSymbol->mapUnitScale();
173 else if ( mMarkerSymbol )
174 return mMarkerSymbol->mapUnitScale();
175 return QgsMapUnitScale();
176}
177
179{
181
182 if ( mFillSymbol )
183 clone->mFillSymbol.reset( mFillSymbol->clone() );
184 if ( mLineSymbol )
185 clone->mLineSymbol.reset( mLineSymbol->clone() );
186 if ( mMarkerSymbol )
187 clone->mMarkerSymbol.reset( mMarkerSymbol->clone() );
188
189 clone->setSymbolType( mSymbolType );
190 clone->setUnits( mUnits );
191
194
195 return clone;
196}
197
199{
200 QVariantMap props;
201 props.insert( QStringLiteral( "geometryModifier" ), mExpression->expression() );
202 switch ( mSymbolType )
203 {
205 props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Marker" ) );
206 break;
208 props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Line" ) );
209 break;
210 default:
211 props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Fill" ) );
212 break;
213 }
214 props.insert( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
215
216 return props;
217}
218
220{
221 if ( mSymbol )
222 {
223 // evaluate expression
224 QgsGeometry patchShapeGeometry;
225
226 if ( context.patchShape() && !context.patchShape()->isNull() )
227 {
228 patchShapeGeometry = context.patchShape()->scaledGeometry( size );
229 }
230 if ( patchShapeGeometry.isEmpty() )
231 {
232 Qgis::SymbolType originalSymbolType = Qgis::SymbolType::Hybrid;
233 switch ( context.originalGeometryType() )
234 {
235 case Qgis::GeometryType::Point:
236 originalSymbolType = Qgis::SymbolType::Marker;
237 break;
238 case Qgis::GeometryType::Line:
239 originalSymbolType = Qgis::SymbolType::Line;
240 break;
241 case Qgis::GeometryType::Polygon:
242 originalSymbolType = Qgis::SymbolType::Fill;
243 break;
244 case Qgis::GeometryType::Unknown:
245 case Qgis::GeometryType::Null:
246 originalSymbolType = mSymbol->type();
247 break;
248 }
249 patchShapeGeometry = QgsStyle::defaultStyle()->defaultPatch( originalSymbolType, size ).scaledGeometry( size );
250 }
251
252 // evaluate geometry expression
253 QgsFeature feature;
254 if ( context.feature() )
255 feature = *context.feature();
256 else
257 feature.setGeometry( patchShapeGeometry );
258 const QgsGeometry iconGeometry = evaluateGeometryInPainterUnits( patchShapeGeometry, feature, context.renderContext(), context.renderContext().expressionContext() );
259
260 QgsLegendPatchShape evaluatedPatchShape( mSymbol->type(), coerceToExpectedType( iconGeometry ) );
261 // we don't want to rescale the patch shape to fit the legend symbol size -- we've already considered that here,
262 // and we don't want to undo the effects of a geometry generator which modifies the symbol bounds
263 evaluatedPatchShape.setScaleToOutputSize( false );
264 mSymbol->drawPreviewIcon( context.renderContext().painter(), size, &context.renderContext(), false, &context.renderContext().expressionContext(), &evaluatedPatchShape );
265 }
266}
267
269{
270 mExpression.reset( new QgsExpression( exp ) );
271}
272
274{
275 return mExpression->expression();
276}
277
279{
280 switch ( symbol->type() )
281 {
283 mMarkerSymbol.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
284 break;
285
287 mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
288 break;
289
291 mFillSymbol.reset( static_cast<QgsFillSymbol *>( symbol ) );
292 break;
293
294 default:
295 break;
296 }
297
298 setSymbolType( symbol->type() );
299
300 return true;
301}
302
304{
305 return QgsSymbolLayer::usedAttributes( context )
306 + mSymbol->usedAttributes( context )
307 + mExpression->referencedColumns();
308}
309
311{
312 // we treat geometry generator layers like they have data defined properties,
313 // since the WHOLE layer is based on expressions and requires the full expression
314 // context
315 return true;
316}
317
319{
320 Q_UNUSED( symbol )
321 return true;
322}
323
324QgsGeometry QgsGeometryGeneratorSymbolLayer::evaluateGeometryInPainterUnits( const QgsGeometry &input, const QgsFeature &, const QgsRenderContext &renderContext, QgsExpressionContext &expressionContext ) const
325{
326 QgsGeometry drawGeometry( input );
327 // step 1 - scale the draw geometry from PAINTER units to target units (e.g. millimeters)
328 const double scale = 1 / renderContext.convertToPainterUnits( 1, mUnits );
329 const QTransform painterToTargetUnits = QTransform::fromScale( scale, scale );
330 drawGeometry.transform( painterToTargetUnits );
331
332 // step 2 - set the feature to use the new scaled geometry, and inject it into the expression context
334 QgsExpressionContextScopePopper popper( expressionContext, generatorScope );
335 generatorScope->setGeometry( drawGeometry );
336
337 // step 3 - evaluate the new generated geometry.
338 QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
339
340 // step 4 - transform geometry back from target units to painter units
341 geom.transform( painterToTargetUnits.inverted( ) );
342
343 return geom;
344}
345
346QgsGeometry QgsGeometryGeneratorSymbolLayer::coerceToExpectedType( const QgsGeometry &geometry ) const
347{
348 switch ( mSymbolType )
349 {
351 if ( geometry.type() != Qgis::GeometryType::Point )
352 {
353 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiPoint );
354 if ( !geoms.empty() )
355 return geoms.at( 0 );
356 }
357 break;
359 if ( geometry.type() != Qgis::GeometryType::Line )
360 {
361 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiLineString );
362 if ( !geoms.empty() )
363 return geoms.at( 0 );
364 }
365 break;
367 if ( geometry.type() != Qgis::GeometryType::Polygon )
368 {
369 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiPolygon );
370 if ( !geoms.empty() )
371 return geoms.at( 0 );
372 }
373 break;
375 break;
376 }
377 return geometry;
378}
379
380void QgsGeometryGeneratorSymbolLayer::render( QgsSymbolRenderContext &context, Qgis::GeometryType geometryType, const QPolygonF *points, const QVector<QPolygonF> *rings )
381{
382 if ( mRenderingFeature && mHasRenderedFeature )
383 return;
384
385 QgsExpressionContext &expressionContext = context.renderContext().expressionContext();
386 QgsFeature f = expressionContext.feature();
387
388 if ( ( !context.feature() || context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol ) && points )
389 {
390 // oh dear, we don't have a feature to work from... but that's ok, we are probably being rendered as a plain old symbol!
391 // in this case we need to build up a feature which represents the points being rendered.
392 // note that we also do this same logic when we are rendering a subsymbol. In that case the $geometry part of the
393 // expression should refer to the shape of the subsymbol being rendered, NOT the feature's original geometry
394 QgsGeometry drawGeometry;
395
396 // step 1 - convert points and rings to geometry
397 switch ( geometryType )
398 {
399 case Qgis::GeometryType::Point:
400 {
401 Q_ASSERT( points->size() == 1 );
402 drawGeometry = QgsGeometry::fromPointXY( points->at( 0 ) );
403 break;
404 }
405 case Qgis::GeometryType::Line:
406 {
407 Q_ASSERT( !rings );
408 std::unique_ptr < QgsLineString > ring( QgsLineString::fromQPolygonF( *points ) );
409 drawGeometry = QgsGeometry( std::move( ring ) );
410 break;
411 }
412 case Qgis::GeometryType::Polygon:
413 {
414 std::unique_ptr < QgsLineString > exterior( QgsLineString::fromQPolygonF( *points ) );
415 std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
416 polygon->setExteriorRing( exterior.release() );
417 if ( rings )
418 {
419 for ( const QPolygonF &ring : *rings )
420 {
421 polygon->addInteriorRing( QgsLineString::fromQPolygonF( ring ) );
422 }
423 }
424 drawGeometry = QgsGeometry( std::move( polygon ) );
425 break;
426 }
427
428 case Qgis::GeometryType::Unknown:
429 case Qgis::GeometryType::Null:
430 return; // unreachable
431 }
432
433 // step 2 - evaluate the result
434 QgsGeometry result = evaluateGeometryInPainterUnits( drawGeometry, f, context.renderContext(), expressionContext );
435
436 // We transform back to map units here (from painter units)
437 // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
438 // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
439 QTransform mapToPixel = context.renderContext().mapToPixel().transform();
440 result.transform( mapToPixel.inverted() );
441 // also need to apply the coordinate transform from the render context
442 try
443 {
444 result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
445 }
446 catch ( QgsCsException & )
447 {
448 QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
449 }
450
451 f.setGeometry( coerceToExpectedType( result ) );
452 }
453 else if ( context.feature() )
454 {
455 switch ( mUnits )
456 {
457 case Qgis::RenderUnit::MapUnits:
458 case Qgis::RenderUnit::Unknown: // unsupported, not exposed as an option
459 case Qgis::RenderUnit::MetersInMapUnits: // unsupported, not exposed as an option
460 case Qgis::RenderUnit::Percentage: // unsupported, not exposed as an option
461 {
462 QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
463 f.setGeometry( coerceToExpectedType( geom ) );
464 break;
465 }
466
467 case Qgis::RenderUnit::Millimeters:
468 case Qgis::RenderUnit::Pixels:
469 case Qgis::RenderUnit::Points:
470 case Qgis::RenderUnit::Inches:
471 {
472 // convert feature geometry to painter units
473 QgsGeometry transformed = f.geometry();
474 transformed.transform( context.renderContext().coordinateTransform() );
475 const QTransform mapToPixel = context.renderContext().mapToPixel().transform();
476 transformed.transform( mapToPixel );
477
478 QgsGeometry result = evaluateGeometryInPainterUnits( transformed, f, context.renderContext(), expressionContext );
479
480 // We transform back to map units here (from painter units)
481 // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
482 // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
483 result.transform( mapToPixel.inverted() );
484 // also need to apply the coordinate transform from the render context
485 try
486 {
487 result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
488 }
489 catch ( QgsCsException & )
490 {
491 QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
492 }
493 f.setGeometry( coerceToExpectedType( result ) );
494 break;
495 }
496 }
497 }
498
499 QgsExpressionContextScope *subSymbolExpressionContextScope = mSymbol->symbolRenderContext()->expressionContextScope();
500 // override the $geometry value for all subsymbols -- this should be the generated geometry
501 subSymbolExpressionContextScope->setGeometry( f.geometry() );
502
503 const bool prevIsSubsymbol = context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol;
505
506 mSymbol->renderFeature( f, context.renderContext(), -1, context.selected() );
507
509
510 if ( mRenderingFeature )
511 mHasRenderedFeature = true;
512}
513
515{
516 mSymbol->setColor( color );
517}
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:55
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition: qgis.h:228
RenderUnit
Rendering size units.
Definition: qgis.h:3176
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
SymbolType
Symbol types.
Definition: qgis.h:320
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
@ MultiPoint
MultiPoint.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setGeometry(const QgsGeometry &geometry)
Convenience function for setting a geometry for the scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
Class for parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QgsGeometry geometry
Definition: qgsfeature.h:67
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
QgsMapUnitScale mapUnitScale() const override
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
QString geometryExpression() const
Gets the expression to generate this geometry.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void setUnits(Qgis::RenderUnit units)
Sets the units for the geometry expression.
void setGeometryExpression(const QString &exp)
Set the expression to generate this geometry.
void setSymbolType(Qgis::SymbolType symbolType)
Set the type of symbol which should be created.
QString layerType() const override
Returns a string that represents this layer type.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
bool isCompatibleWithSymbol(QgsSymbol *symbol) const override
Will always return true.
Qgis::SymbolType symbolType() const
Access the symbol type.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
QgsSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void render(QgsSymbolRenderContext &context, Qgis::GeometryType geometryType=Qgis::GeometryType::Unknown, const QPolygonF *points=nullptr, const QVector< QPolygonF > *rings=nullptr)
Will render this symbol layer using the context.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QColor color() const override
Returns the "representative" color of the symbol layer.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0) const
Attempts to coerce this geometry into the specified destination type.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Qgis::GeometryType type
Definition: qgsgeometry.h:167
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Represents a patch shape for use in map legends.
QgsGeometry scaledGeometry(QSizeF size) const
Returns the patch shape's geometry, scaled to the given size.
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
void setScaleToOutputSize(bool scale)
Sets whether the patch shape should by resized to the desired target size when rendering.
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Definition: qgsmaptopixel.h:90
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
QgsLegendPatchShape defaultPatch(Qgis::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
Definition: qgsstyle.cpp:1163
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
void restoreOldDataDefinedProperties(const QVariantMap &stringMap)
Restores older data defined properties from string map.
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
const QgsFeature * feature() const
Returns the current feature being rendered.
Qgis::GeometryType originalGeometryType() const
Returns the geometry type for the original feature geometry being rendered.
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style.
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.
const QgsLegendPatchShape * patchShape() const
Returns the symbol patch shape, to use if rendering symbol preview icons.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
Definition: qgssymbol.cpp:1823
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Definition: qgssymbol.cpp:873
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *patchShape=nullptr)
Draws an icon of the symbol that occupies an area given by size using the specified painter.
Definition: qgssymbol.cpp:923
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:898
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
Definition: qgssymbol.cpp:1183
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, Qgis::VertexMarkerType currentVertexMarkerType=Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize=0.0) SIP_THROW(QgsCsException)
Render a feature.
Definition: qgssymbol.cpp:1284
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:152
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
Definition: qgssymbol.cpp:825
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38