QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
26 
28 
30 {
31  QString expression = properties.value( QStringLiteral( "geometryModifier" ) ).toString();
32  if ( expression.isEmpty() )
33  {
34  expression = QStringLiteral( "$geometry" );
35  }
37 
38  if ( properties.value( QStringLiteral( "SymbolType" ) ) == QLatin1String( "Marker" ) )
39  {
41  }
42  else if ( properties.value( QStringLiteral( "SymbolType" ) ) == QLatin1String( "Line" ) )
43  {
45  }
46  else
47  {
49  }
50  symbolLayer->setUnits( QgsUnitTypes::decodeRenderUnit( properties.value( QStringLiteral( "units" ), QStringLiteral( "mapunits" ) ).toString() ) );
51 
53 
54  return symbolLayer;
55 }
56 
57 QgsGeometryGeneratorSymbolLayer::QgsGeometryGeneratorSymbolLayer( const QString &expression )
58  : QgsSymbolLayer( Qgis::SymbolType::Hybrid )
59  , mExpression( new QgsExpression( expression ) )
60  , mSymbolType( Qgis::SymbolType::Marker )
61 {
62 
63 }
64 
66 {
67  return QStringLiteral( "GeometryGenerator" );
68 }
69 
71 {
73  {
74  if ( !mFillSymbol )
75  mFillSymbol.reset( QgsFillSymbol::createSimple( QVariantMap() ) );
76  mSymbol = mFillSymbol.get();
77  }
78  else if ( symbolType == Qgis::SymbolType::Line )
79  {
80  if ( !mLineSymbol )
81  mLineSymbol.reset( QgsLineSymbol::createSimple( QVariantMap() ) );
82  mSymbol = mLineSymbol.get();
83  }
85  {
86  if ( !mMarkerSymbol )
87  mMarkerSymbol.reset( QgsMarkerSymbol::createSimple( QVariantMap() ) );
88  mSymbol = mMarkerSymbol.get();
89  }
90  else
91  Q_ASSERT( false );
92 
93  mSymbolType = symbolType;
94 }
95 
97 {
98  mExpression->prepare( &context.renderContext().expressionContext() );
99 
100  subSymbol()->startRender( context.renderContext() );
101 }
102 
104 {
105  if ( mSymbol )
106  mSymbol->stopRender( context.renderContext() );
107 }
108 
110 {
112  return;
113 
114  mRenderingFeature = true;
115  mHasRenderedFeature = false;
116 }
117 
119 {
120  mRenderingFeature = false;
121 }
122 
124 {
125  if ( mFillSymbol )
126  return mFillSymbol->usesMapUnits();
127  else if ( mLineSymbol )
128  return mLineSymbol->usesMapUnits();
129  else if ( mMarkerSymbol )
130  return mMarkerSymbol->usesMapUnits();
131  return false;
132 }
133 
135 {
136  if ( mFillSymbol )
137  return mFillSymbol->color();
138  else if ( mLineSymbol )
139  return mLineSymbol->color();
140  else if ( mMarkerSymbol )
141  return mMarkerSymbol->color();
142  return QColor();
143 }
144 
146 {
147  if ( mFillSymbol )
148  return mFillSymbol->outputUnit();
149  else if ( mLineSymbol )
150  return mLineSymbol->outputUnit();
151  else if ( mMarkerSymbol )
152  return mMarkerSymbol->outputUnit();
154 }
155 
157 {
158  if ( mFillSymbol )
159  return mFillSymbol->mapUnitScale();
160  else if ( mLineSymbol )
161  return mLineSymbol->mapUnitScale();
162  else if ( mMarkerSymbol )
163  return mMarkerSymbol->mapUnitScale();
164  return QgsMapUnitScale();
165 }
166 
168 {
169  QgsGeometryGeneratorSymbolLayer *clone = new QgsGeometryGeneratorSymbolLayer( mExpression->expression() );
170 
171  if ( mFillSymbol )
172  clone->mFillSymbol.reset( mFillSymbol->clone() );
173  if ( mLineSymbol )
174  clone->mLineSymbol.reset( mLineSymbol->clone() );
175  if ( mMarkerSymbol )
176  clone->mMarkerSymbol.reset( mMarkerSymbol->clone() );
177 
178  clone->setSymbolType( mSymbolType );
179  clone->setUnits( mUnits );
180 
183 
184  return clone;
185 }
186 
188 {
189  QVariantMap props;
190  props.insert( QStringLiteral( "geometryModifier" ), mExpression->expression() );
191  switch ( mSymbolType )
192  {
194  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Marker" ) );
195  break;
197  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Line" ) );
198  break;
199  default:
200  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Fill" ) );
201  break;
202  }
203  props.insert( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
204 
205  return props;
206 }
207 
209 {
210  if ( mSymbol )
211  {
212  // evaluate expression
213  QgsGeometry patchShapeGeometry;
214 
215  if ( context.patchShape() && !context.patchShape()->isNull() )
216  {
217  patchShapeGeometry = context.patchShape()->scaledGeometry( size );
218  }
219  if ( patchShapeGeometry.isEmpty() )
220  {
221  Qgis::SymbolType originalSymbolType = Qgis::SymbolType::Hybrid;
222  switch ( context.originalGeometryType() )
223  {
225  originalSymbolType = Qgis::SymbolType::Marker;
226  break;
228  originalSymbolType = Qgis::SymbolType::Line;
229  break;
231  originalSymbolType = Qgis::SymbolType::Fill;
232  break;
235  originalSymbolType = mSymbol->type();
236  break;
237  }
238  patchShapeGeometry = QgsStyle::defaultStyle()->defaultPatch( originalSymbolType, size ).scaledGeometry( size );
239  }
240 
241  // evaluate geometry expression
242  QgsFeature feature;
243  if ( context.feature() )
244  feature = *context.feature();
245  else
246  feature.setGeometry( patchShapeGeometry );
247  const QgsGeometry iconGeometry = evaluateGeometryInPainterUnits( patchShapeGeometry, feature, context.renderContext(), context.renderContext().expressionContext() );
248 
249  QgsLegendPatchShape evaluatedPatchShape( mSymbol->type(), coerceToExpectedType( iconGeometry ) );
250  // we don't want to rescale the patch shape to fit the legend symbol size -- we've already considered that here,
251  // and we don't want to undo the effects of a geometry generator which modifies the symbol bounds
252  evaluatedPatchShape.setScaleToOutputSize( false );
253  mSymbol->drawPreviewIcon( context.renderContext().painter(), size, &context.renderContext(), false, &context.renderContext().expressionContext(), &evaluatedPatchShape );
254  }
255 }
256 
258 {
259  mExpression.reset( new QgsExpression( exp ) );
260 }
261 
263 {
264  switch ( symbol->type() )
265  {
267  mMarkerSymbol.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
268  break;
269 
271  mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
272  break;
273 
275  mFillSymbol.reset( static_cast<QgsFillSymbol *>( symbol ) );
276  break;
277 
278  default:
279  break;
280  }
281 
282  setSymbolType( symbol->type() );
283 
284  return true;
285 }
286 
288 {
289  return QgsSymbolLayer::usedAttributes( context )
290  + mSymbol->usedAttributes( context )
291  + mExpression->referencedColumns();
292 }
293 
295 {
296  // we treat geometry generator layers like they have data defined properties,
297  // since the WHOLE layer is based on expressions and requires the full expression
298  // context
299  return true;
300 }
301 
303 {
304  Q_UNUSED( symbol )
305  return true;
306 }
307 
308 QgsGeometry QgsGeometryGeneratorSymbolLayer::evaluateGeometryInPainterUnits( const QgsGeometry &input, const QgsFeature &, const QgsRenderContext &renderContext, QgsExpressionContext &expressionContext ) const
309 {
310  QgsGeometry drawGeometry( input );
311  // step 1 - scale the draw geometry from PAINTER units to target units (e.g. millimeters)
312  const double scale = 1 / renderContext.convertToPainterUnits( 1, mUnits );
313  const QTransform painterToTargetUnits = QTransform::fromScale( scale, scale );
314  drawGeometry.transform( painterToTargetUnits );
315 
316  // step 2 - set the feature to use the new scaled geometry, and inject it into the expression context
318  QgsExpressionContextScopePopper popper( expressionContext, generatorScope );
319  generatorScope->setGeometry( drawGeometry );
320 
321  // step 3 - evaluate the new generated geometry.
322  QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
323 
324  // step 4 - transform geometry back from target units to painter units
325  geom.transform( painterToTargetUnits.inverted( ) );
326 
327  return geom;
328 }
329 
330 QgsGeometry QgsGeometryGeneratorSymbolLayer::coerceToExpectedType( const QgsGeometry &geometry ) const
331 {
332  switch ( mSymbolType )
333  {
335  if ( geometry.type() != QgsWkbTypes::PointGeometry )
336  {
337  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiPoint );
338  if ( !geoms.empty() )
339  return geoms.at( 0 );
340  }
341  break;
343  if ( geometry.type() != QgsWkbTypes::LineGeometry )
344  {
345  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiLineString );
346  if ( !geoms.empty() )
347  return geoms.at( 0 );
348  }
349  break;
351  if ( geometry.type() != QgsWkbTypes::PolygonGeometry )
352  {
353  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiPolygon );
354  if ( !geoms.empty() )
355  return geoms.at( 0 );
356  }
357  break;
359  break;
360  }
361  return geometry;
362 }
363 
364 void QgsGeometryGeneratorSymbolLayer::render( QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType, const QPolygonF *points, const QVector<QPolygonF> *rings )
365 {
366  if ( mRenderingFeature && mHasRenderedFeature )
367  return;
368 
369  QgsExpressionContext &expressionContext = context.renderContext().expressionContext();
370  QgsFeature f = expressionContext.feature();
371 
372  if ( ( !context.feature() || context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol ) && points )
373  {
374  // 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!
375  // in this case we need to build up a feature which represents the points being rendered.
376  // note that we also do this same logic when we are rendering a subsymbol. In that case the $geometry part of the
377  // expression should refer to the shape of the subsymbol being rendered, NOT the feature's original geometry
378  QgsGeometry drawGeometry;
379 
380  // step 1 - convert points and rings to geometry
381  switch ( geometryType )
382  {
384  {
385  Q_ASSERT( points->size() == 1 );
386  drawGeometry = QgsGeometry::fromPointXY( points->at( 0 ) );
387  break;
388  }
390  {
391  Q_ASSERT( !rings );
392  std::unique_ptr < QgsLineString > ring( QgsLineString::fromQPolygonF( *points ) );
393  drawGeometry = QgsGeometry( std::move( ring ) );
394  break;
395  }
397  {
398  std::unique_ptr < QgsLineString > exterior( QgsLineString::fromQPolygonF( *points ) );
399  std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
400  polygon->setExteriorRing( exterior.release() );
401  if ( rings )
402  {
403  for ( const QPolygonF &ring : *rings )
404  {
405  polygon->addInteriorRing( QgsLineString::fromQPolygonF( ring ) );
406  }
407  }
408  drawGeometry = QgsGeometry( std::move( polygon ) );
409  break;
410  }
411 
414  return; // unreachable
415  }
416 
417  // step 2 - evaluate the result
418  QgsGeometry result = evaluateGeometryInPainterUnits( drawGeometry, f, context.renderContext(), expressionContext );
419 
420  // We transform back to map units here (from painter units)
421  // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
422  // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
423  QTransform mapToPixel = context.renderContext().mapToPixel().transform();
424  result.transform( mapToPixel.inverted() );
425  // also need to apply the coordinate transform from the render context
426  try
427  {
428  result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
429  }
430  catch ( QgsCsException & )
431  {
432  QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
433  }
434 
435  f.setGeometry( coerceToExpectedType( result ) );
436  }
437  else if ( context.feature() )
438  {
439  switch ( mUnits )
440  {
442  case QgsUnitTypes::RenderUnknownUnit: // unsupported, not exposed as an option
443  case QgsUnitTypes::RenderMetersInMapUnits: // unsupported, not exposed as an option
444  case QgsUnitTypes::RenderPercentage: // unsupported, not exposed as an option
445  {
446  QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
447  f.setGeometry( coerceToExpectedType( geom ) );
448  break;
449  }
450 
455  {
456  // convert feature geometry to painter units
457  QgsGeometry transformed = f.geometry();
458  transformed.transform( context.renderContext().coordinateTransform() );
459  const QTransform mapToPixel = context.renderContext().mapToPixel().transform();
460  transformed.transform( mapToPixel );
461 
462  QgsGeometry result = evaluateGeometryInPainterUnits( transformed, f, context.renderContext(), expressionContext );
463 
464  // We transform back to map units here (from painter units)
465  // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
466  // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
467  result.transform( mapToPixel.inverted() );
468  // also need to apply the coordinate transform from the render context
469  try
470  {
471  result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
472  }
473  catch ( QgsCsException & )
474  {
475  QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
476  }
477  f.setGeometry( coerceToExpectedType( result ) );
478  break;
479  }
480  }
481  }
482 
483  QgsExpressionContextScope *subSymbolExpressionContextScope = mSymbol->symbolRenderContext()->expressionContextScope();
484  // override the $geometry value for all subsymbols -- this should be the generated geometry
485  subSymbolExpressionContextScope->setGeometry( f.geometry() );
486 
487  const bool prevIsSubsymbol = context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol;
489 
490  mSymbol->renderFeature( f, context.renderContext(), -1, context.selected() );
491 
493 
494  if ( mRenderingFeature )
495  mHasRenderedFeature = true;
496 }
497 
498 void QgsGeometryGeneratorSymbolLayer::setColor( const QColor &color )
499 {
500  mSymbol->setColor( color );
501 }
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:64
@ 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:183
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
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:163
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 render(QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::GeometryType::UnknownGeometry, const QPolygonF *points=nullptr, const QVector< QPolygonF > *rings=nullptr)
Will render this symbol layer using the context.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
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.
void setUnits(QgsUnitTypes::RenderUnit units)
Sets the units for the geometry expression.
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.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates 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.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
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.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
QVector< QgsGeometry > coerceToType(QgsWkbTypes::Type 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.
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
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.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
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:1176
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:131
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.
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsWkbTypes::GeometryType originalGeometryType() const
Returns the geometry type for the original feature geometry being rendered.
const QgsFeature * feature() const
Returns the current feature being rendered.
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.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
Definition: qgssymbol.cpp:1467
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Definition: qgssymbol.cpp:516
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:566
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
Definition: qgssymbol.cpp:825
void setColor(const QColor &color)
Sets the color for the symbol.
Definition: qgssymbol.cpp:541
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:926
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:97
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
Definition: qgssymbol.cpp:489
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define QgsDebugMsg(str)
Definition: qgslogger.h:38