QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
18#include <memory>
19
21#include "qgsexpressionutils.h"
22#include "qgsfillsymbol.h"
23#include "qgsgeometry.h"
24#include "qgslegendpatchshape.h"
25#include "qgslinesymbol.h"
26#include "qgsmarkersymbol.h"
27#include "qgspolygon.h"
28#include "qgsstyle.h"
29#include "qgsunittypes.h"
30
31#include <QString>
32
33using namespace Qt::StringLiterals;
34
36
38{
39 QString expression = properties.value( u"geometryModifier"_s ).toString();
40 if ( expression.isEmpty() )
41 {
42 expression = u"@geometry"_s;
43 }
44 QgsGeometryGeneratorSymbolLayer *symbolLayer = new QgsGeometryGeneratorSymbolLayer( expression );
45
46 if ( properties.value( u"SymbolType"_s ) == "Marker"_L1 )
47 {
48 symbolLayer->setSubSymbol( QgsMarkerSymbol::createSimple( properties ).release() );
49 }
50 else if ( properties.value( u"SymbolType"_s ) == "Line"_L1 )
51 {
52 symbolLayer->setSubSymbol( QgsLineSymbol::createSimple( properties ).release() );
53 }
54 else
55 {
56 symbolLayer->setSubSymbol( QgsFillSymbol::createSimple( properties ).release() );
57 }
58 symbolLayer->setUnits( QgsUnitTypes::decodeRenderUnit( properties.value( u"units"_s, u"mapunits"_s ).toString() ) );
59
61
62 return symbolLayer;
63}
64
65QgsGeometryGeneratorSymbolLayer::QgsGeometryGeneratorSymbolLayer( const QString &expression )
66 : QgsSymbolLayer( Qgis::SymbolType::Hybrid )
67 , mExpression( new QgsExpression( expression ) )
68{
69
70}
71
73{
74 return u"GeometryGenerator"_s;
75}
76
78{
80 {
81 if ( !mFillSymbol )
82 mFillSymbol = QgsFillSymbol::createSimple( QVariantMap() );
83 mSymbol = mFillSymbol.get();
84 }
86 {
87 if ( !mLineSymbol )
88 mLineSymbol = QgsLineSymbol::createSimple( QVariantMap() );
89 mSymbol = mLineSymbol.get();
90 }
92 {
93 if ( !mMarkerSymbol )
94 mMarkerSymbol = QgsMarkerSymbol::createSimple( QVariantMap() );
95 mSymbol = mMarkerSymbol.get();
96 }
97 else
98 Q_ASSERT( false );
99
100 mSymbolType = symbolType;
101}
102
104{
105 mExpression->prepare( &context.renderContext().expressionContext() );
106
108
109 subSymbol()->startRender( context.renderContext(), context.fields() );
110}
111
113{
114 if ( mSymbol )
115 mSymbol->stopRender( context.renderContext() );
116}
117
119{
121 return;
122
123 mRenderingFeature = true;
124 mHasRenderedFeature = false;
125}
126
128{
129 mRenderingFeature = false;
130}
131
133{
134 if ( mFillSymbol )
135 return mFillSymbol->usesMapUnits();
136 else if ( mLineSymbol )
137 return mLineSymbol->usesMapUnits();
138 else if ( mMarkerSymbol )
139 return mMarkerSymbol->usesMapUnits();
140 return false;
141}
142
144{
145 if ( mFillSymbol )
146 return mFillSymbol->color();
147 else if ( mLineSymbol )
148 return mLineSymbol->color();
149 else if ( mMarkerSymbol )
150 return mMarkerSymbol->color();
151 return QColor();
152}
153
155{
156 if ( mFillSymbol )
157 return mFillSymbol->outputUnit();
158 else if ( mLineSymbol )
159 return mLineSymbol->outputUnit();
160 else if ( mMarkerSymbol )
161 return mMarkerSymbol->outputUnit();
163}
164
166{
167 if ( mFillSymbol )
168 mFillSymbol->setOutputUnit( unit );
169 else if ( mLineSymbol )
170 mLineSymbol->setOutputUnit( unit );
171 else if ( mMarkerSymbol )
172 mMarkerSymbol->setOutputUnit( unit );
173}
174
176{
177 if ( mFillSymbol )
178 return mFillSymbol->mapUnitScale();
179 else if ( mLineSymbol )
180 return mLineSymbol->mapUnitScale();
181 else if ( mMarkerSymbol )
182 return mMarkerSymbol->mapUnitScale();
183 return QgsMapUnitScale();
184}
185
187{
188 // since rendersIdenticallyTo must be pessimistic, we always return FALSE here as it's
189 // non-trivial to determine if a QGIS expression will always return the same result
190 // TODO: we could potentially investigate the actual expression and catch cases where we
191 // are CERTAIN that the result will always be the same
192 return false;
193}
194
196{
197 QgsGeometryGeneratorSymbolLayer *clone = new QgsGeometryGeneratorSymbolLayer( mExpression->expression() );
198
199 if ( mFillSymbol )
200 clone->mFillSymbol.reset( mFillSymbol->clone() );
201 if ( mLineSymbol )
202 clone->mLineSymbol.reset( mLineSymbol->clone() );
203 if ( mMarkerSymbol )
204 clone->mMarkerSymbol.reset( mMarkerSymbol->clone() );
205
206 clone->setSymbolType( mSymbolType );
207 clone->setUnits( mUnits );
208
211
212 return clone;
213}
214
216{
217 QVariantMap props;
218 props.insert( u"geometryModifier"_s, mExpression->expression() );
219 switch ( mSymbolType )
220 {
222 props.insert( u"SymbolType"_s, u"Marker"_s );
223 break;
225 props.insert( u"SymbolType"_s, u"Line"_s );
226 break;
227 default:
228 props.insert( u"SymbolType"_s, u"Fill"_s );
229 break;
230 }
231 props.insert( u"units"_s, QgsUnitTypes::encodeUnit( mUnits ) );
232
233 return props;
234}
235
237{
238 if ( mSymbol )
239 {
240 // evaluate expression
241 QgsGeometry patchShapeGeometry;
242
243 if ( context.patchShape() && !context.patchShape()->isNull() )
244 {
245 patchShapeGeometry = context.patchShape()->scaledGeometry( size );
246 }
247 if ( patchShapeGeometry.isEmpty() )
248 {
249 Qgis::SymbolType originalSymbolType = Qgis::SymbolType::Hybrid;
250 switch ( context.originalGeometryType() )
251 {
253 originalSymbolType = Qgis::SymbolType::Marker;
254 break;
256 originalSymbolType = Qgis::SymbolType::Line;
257 break;
259 originalSymbolType = Qgis::SymbolType::Fill;
260 break;
263 originalSymbolType = mSymbol->type();
264 break;
265 }
266 patchShapeGeometry = QgsStyle::defaultStyle()->defaultPatch( originalSymbolType, size ).scaledGeometry( size );
267 }
268
269 // evaluate geometry expression
270 QgsFeature feature;
271 if ( context.feature() )
272 feature = *context.feature();
273 else
274 feature.setGeometry( patchShapeGeometry );
275 const QgsGeometry iconGeometry = evaluateGeometryInPainterUnits( patchShapeGeometry, feature, context.renderContext(), context.renderContext().expressionContext() );
276
277 QgsLegendPatchShape evaluatedPatchShape( mSymbol->type(), coerceToExpectedType( iconGeometry ) );
278 // we don't want to rescale the patch shape to fit the legend symbol size -- we've already considered that here,
279 // and we don't want to undo the effects of a geometry generator which modifies the symbol bounds
280 evaluatedPatchShape.setScaleToOutputSize( false );
281 mSymbol->drawPreviewIcon( context.renderContext().painter(), size, &context.renderContext(), false, &context.renderContext().expressionContext(), &evaluatedPatchShape );
282 }
283}
284
286{
287 mExpression = std::make_unique<QgsExpression>( exp );
288}
289
291{
292 return mExpression->expression();
293}
294
296{
297 switch ( symbol->type() )
298 {
300 mMarkerSymbol.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
301 break;
302
304 mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
305 break;
306
308 mFillSymbol.reset( static_cast<QgsFillSymbol *>( symbol ) );
309 break;
310
311 default:
312 break;
313 }
314
315 setSymbolType( symbol->type() );
316
317 return true;
318}
319
321{
322 return QgsSymbolLayer::usedAttributes( context )
323 + mSymbol->usedAttributes( context )
324 + mExpression->referencedColumns();
325}
326
328{
329 // we treat geometry generator layers like they have data defined properties,
330 // since the WHOLE layer is based on expressions and requires the full expression
331 // context
332 return true;
333}
334
336{
337 Q_UNUSED( symbol )
338 return true;
339}
340
341QgsGeometry QgsGeometryGeneratorSymbolLayer::evaluateGeometryInPainterUnits( const QgsGeometry &input, const QgsFeature &, const QgsRenderContext &renderContext, QgsExpressionContext &expressionContext ) const
342{
343 QgsGeometry drawGeometry( input );
344 // step 1 - scale the draw geometry from PAINTER units to target units (e.g. millimeters)
345 const double scale = 1 / renderContext.convertToPainterUnits( 1, mUnits );
346 const QTransform painterToTargetUnits = QTransform::fromScale( scale, scale );
347 drawGeometry.transform( painterToTargetUnits );
348
349 // step 2 - set the feature to use the new scaled geometry, and inject it into the expression context
351 QgsExpressionContextScopePopper popper( expressionContext, generatorScope );
352 generatorScope->setGeometry( drawGeometry );
353
354 // step 3 - evaluate the new generated geometry.
355 QVariant value = mExpression->evaluate( &expressionContext );
356 QgsGeometry geom = QgsExpressionUtils::getGeometry( value, mExpression.get() );
357
358 // step 4 - transform geometry back from target units to painter units
359 geom.transform( painterToTargetUnits.inverted( ) );
360
361 return geom;
362}
363
364QgsGeometry QgsGeometryGeneratorSymbolLayer::coerceToExpectedType( const QgsGeometry &geometry ) const
365{
366 switch ( mSymbolType )
367 {
369 if ( geometry.type() != Qgis::GeometryType::Point )
370 {
371 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiPoint );
372 if ( !geoms.empty() )
373 return geoms.at( 0 );
374 }
375 break;
377 if ( geometry.type() != Qgis::GeometryType::Line )
378 {
379 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiLineString );
380 if ( !geoms.empty() )
381 return geoms.at( 0 );
382 }
383 break;
385 if ( geometry.type() != Qgis::GeometryType::Polygon )
386 {
387 QVector< QgsGeometry > geoms = geometry.coerceToType( Qgis::WkbType::MultiPolygon );
388 if ( !geoms.empty() )
389 return geoms.at( 0 );
390 }
391 break;
393 break;
394 }
395 return geometry;
396}
397
398void QgsGeometryGeneratorSymbolLayer::render( QgsSymbolRenderContext &context, Qgis::GeometryType geometryType, const QPolygonF *points, const QVector<QPolygonF> *rings )
399{
400 if ( mRenderingFeature && mHasRenderedFeature )
401 return;
402
403 QgsExpressionContext &expressionContext = context.renderContext().expressionContext();
404 QgsFeature f = expressionContext.feature();
405
406 if ( ( !context.feature() || context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol ) && points )
407 {
408 // 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!
409 // in this case we need to build up a feature which represents the points being rendered.
410 // note that we also do this same logic when we are rendering a subsymbol. In that case the $geometry part of the
411 // expression should refer to the shape of the subsymbol being rendered, NOT the feature's original geometry
412 QgsGeometry drawGeometry;
413
414 // step 1 - convert points and rings to geometry
415 switch ( geometryType )
416 {
418 {
419 Q_ASSERT( points->size() == 1 );
420 drawGeometry = QgsGeometry::fromPointXY( points->at( 0 ) );
421 break;
422 }
424 {
425 Q_ASSERT( !rings );
426 std::unique_ptr < QgsLineString > ring( QgsLineString::fromQPolygonF( *points ) );
427 drawGeometry = QgsGeometry( std::move( ring ) );
428 break;
429 }
431 {
432 std::unique_ptr < QgsLineString > exterior( QgsLineString::fromQPolygonF( *points ) );
433 auto polygon = std::make_unique< QgsPolygon >();
434 polygon->setExteriorRing( exterior.release() );
435 if ( rings )
436 {
437 for ( const QPolygonF &ring : *rings )
438 {
439 std::unique_ptr< QgsLineString > fromRing = QgsLineString::fromQPolygonF( ring );
440 polygon->addInteriorRing( fromRing.release() );
441 }
442 }
443 drawGeometry = QgsGeometry( std::move( polygon ) );
444 break;
445 }
446
449 return; // unreachable
450 }
451
452 // step 2 - evaluate the result
453 QgsGeometry result = evaluateGeometryInPainterUnits( drawGeometry, f, context.renderContext(), expressionContext );
454
455 // We transform back to map units here (from painter units)
456 // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
457 // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
458 QTransform mapToPixel = context.renderContext().mapToPixel().transform();
459 result.transform( mapToPixel.inverted() );
460 // also need to apply the coordinate transform from the render context
461 try
462 {
464 }
465 catch ( QgsCsException & )
466 {
467 QgsDebugError( u"Could no transform generated geometry to layer CRS"_s );
468 }
469
470 f.setGeometry( coerceToExpectedType( result ) );
471 }
472 else if ( context.feature() )
473 {
474 switch ( mUnits )
475 {
477 case Qgis::RenderUnit::Unknown: // unsupported, not exposed as an option
478 case Qgis::RenderUnit::MetersInMapUnits: // unsupported, not exposed as an option
479 case Qgis::RenderUnit::Percentage: // unsupported, not exposed as an option
480 {
481 QVariant value = mExpression->evaluate( &expressionContext );
482 f.setGeometry( coerceToExpectedType( QgsExpressionUtils::getGeometry( value, mExpression.get() ) ) );
483 break;
484 }
485
490 {
491 // convert feature geometry to painter units
492 QgsGeometry transformed = f.geometry();
493
494 try
495 {
496 transformed.transform( context.renderContext().coordinateTransform() );
497 }
498 catch ( QgsCsException & )
499 {
500 QgsDebugError( u"Could no transform generated geometry to layer CRS"_s );
501 }
502 const QTransform mapToPixel = context.renderContext().mapToPixel().transform();
503 transformed.transform( mapToPixel );
504
505 QgsGeometry result = evaluateGeometryInPainterUnits( transformed, f, context.renderContext(), expressionContext );
506
507 // We transform back to map units here (from painter units)
508 // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
509 // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
510 result.transform( mapToPixel.inverted() );
511 // also need to apply the coordinate transform from the render context
512 try
513 {
515 }
516 catch ( QgsCsException & )
517 {
518 QgsDebugError( u"Could no transform generated geometry to layer CRS"_s );
519 }
520 f.setGeometry( coerceToExpectedType( result ) );
521 break;
522 }
523 }
524 }
525
526 QgsExpressionContextScope *subSymbolExpressionContextScope = mSymbol->symbolRenderContext()->expressionContextScope();
527 // override the $geometry value for all subsymbols -- this should be the generated geometry
528 subSymbolExpressionContextScope->setGeometry( f.geometry() );
529
530 const bool prevIsSubsymbol = context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol;
532
533 const bool useSelectedColor = shouldRenderUsingSelectionColor( context );
534 mSymbol->renderFeature( f, context.renderContext(), -1, useSelectedColor );
535
537
538 if ( mRenderingFeature )
539 mHasRenderedFeature = true;
540}
541
543{
544 mSymbol->setColor( color );
545}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
@ IsSymbolLayerSubSymbol
Symbol is being rendered as a sub-symbol of a QgsSymbolLayer.
Definition qgis.h:790
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
RenderUnit
Rendering size units.
Definition qgis.h:5255
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size).
Definition qgis.h:5259
@ Millimeters
Millimeters.
Definition qgis.h:5256
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5260
@ Unknown
Mixed or unknown units.
Definition qgis.h:5262
@ MapUnits
Map units.
Definition qgis.h:5257
@ Pixels
Pixels.
Definition qgis.h:5258
@ Inches
Inches.
Definition qgis.h:5261
@ MetersInMapUnits
Meters value as Map units.
Definition qgis.h:5263
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
Definition qgis.h:2823
SymbolType
Symbol types.
Definition qgis.h:629
@ Marker
Marker symbol.
Definition qgis.h:630
@ Line
Line symbol.
Definition qgis.h:631
@ Fill
Fill symbol.
Definition qgis.h:632
@ Hybrid
Hybrid symbol.
Definition qgis.h:633
@ MultiPoint
MultiPoint.
Definition qgis.h:286
@ MultiPolygon
MultiPolygon.
Definition qgis.h:288
@ MultiLineString
MultiLineString.
Definition qgis.h:287
@ Reverse
Reverse/inverse transform (from destination to source).
Definition qgis.h:2731
Custom exception class for Coordinate Reference System related exceptions.
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.
Handles 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:60
QgsGeometry geometry
Definition qgsfeature.h:71
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static std::unique_ptr< 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.
bool rendersIdenticallyTo(const QgsSymbolLayer *other) const override
Returns true if this symbol layer will always render identically to an other symbol layer.
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.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Qgis::GeometryType type
QVector< QgsGeometry > coerceToType(Qgis::WkbType type, double defaultZ=0, double defaultM=0, bool avoidDuplicates=true) const
Attempts to coerce this geometry into the specified destination type.
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 std::unique_ptr< QgsLineString > fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
A line symbol type, for rendering LineString and MultiLineString geometries.
static std::unique_ptr< 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.
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
static std::unique_ptr< 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.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:150
Abstract base class for symbol layers.
bool shouldRenderUsingSelectionColor(const QgsSymbolRenderContext &context) const
Returns true if the symbol layer should be rendered using the selection color from the render context...
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.
QgsSymbolLayer(const QgsSymbolLayer &other)
Encapsulates the context in which a symbol is being rendered.
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.
QgsFields fields() const
Fields of the layer.
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:231
void setRenderHints(Qgis::SymbolRenderHints hints)
Sets rendering hint flags for the symbol.
Definition qgssymbol.h:672
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:294
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
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 QgsDebugError(str)
Definition qgslogger.h:59