QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  mFillSymbol->setOutputUnit( unit );
160  else if ( mLineSymbol )
161  mLineSymbol->setOutputUnit( unit );
162  else if ( mMarkerSymbol )
163  mMarkerSymbol->setOutputUnit( unit );
164 }
165 
167 {
168  if ( mFillSymbol )
169  return mFillSymbol->mapUnitScale();
170  else if ( mLineSymbol )
171  return mLineSymbol->mapUnitScale();
172  else if ( mMarkerSymbol )
173  return mMarkerSymbol->mapUnitScale();
174  return QgsMapUnitScale();
175 }
176 
178 {
179  QgsGeometryGeneratorSymbolLayer *clone = new QgsGeometryGeneratorSymbolLayer( mExpression->expression() );
180 
181  if ( mFillSymbol )
182  clone->mFillSymbol.reset( mFillSymbol->clone() );
183  if ( mLineSymbol )
184  clone->mLineSymbol.reset( mLineSymbol->clone() );
185  if ( mMarkerSymbol )
186  clone->mMarkerSymbol.reset( mMarkerSymbol->clone() );
187 
188  clone->setSymbolType( mSymbolType );
189  clone->setUnits( mUnits );
190 
193 
194  return clone;
195 }
196 
198 {
199  QVariantMap props;
200  props.insert( QStringLiteral( "geometryModifier" ), mExpression->expression() );
201  switch ( mSymbolType )
202  {
204  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Marker" ) );
205  break;
207  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Line" ) );
208  break;
209  default:
210  props.insert( QStringLiteral( "SymbolType" ), QStringLiteral( "Fill" ) );
211  break;
212  }
213  props.insert( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
214 
215  return props;
216 }
217 
219 {
220  if ( mSymbol )
221  {
222  // evaluate expression
223  QgsGeometry patchShapeGeometry;
224 
225  if ( context.patchShape() && !context.patchShape()->isNull() )
226  {
227  patchShapeGeometry = context.patchShape()->scaledGeometry( size );
228  }
229  if ( patchShapeGeometry.isEmpty() )
230  {
231  Qgis::SymbolType originalSymbolType = Qgis::SymbolType::Hybrid;
232  switch ( context.originalGeometryType() )
233  {
235  originalSymbolType = Qgis::SymbolType::Marker;
236  break;
238  originalSymbolType = Qgis::SymbolType::Line;
239  break;
241  originalSymbolType = Qgis::SymbolType::Fill;
242  break;
245  originalSymbolType = mSymbol->type();
246  break;
247  }
248  patchShapeGeometry = QgsStyle::defaultStyle()->defaultPatch( originalSymbolType, size ).scaledGeometry( size );
249  }
250 
251  // evaluate geometry expression
252  QgsFeature feature;
253  if ( context.feature() )
254  feature = *context.feature();
255  else
256  feature.setGeometry( patchShapeGeometry );
257  const QgsGeometry iconGeometry = evaluateGeometryInPainterUnits( patchShapeGeometry, feature, context.renderContext(), context.renderContext().expressionContext() );
258 
259  QgsLegendPatchShape evaluatedPatchShape( mSymbol->type(), coerceToExpectedType( iconGeometry ) );
260  // we don't want to rescale the patch shape to fit the legend symbol size -- we've already considered that here,
261  // and we don't want to undo the effects of a geometry generator which modifies the symbol bounds
262  evaluatedPatchShape.setScaleToOutputSize( false );
263  mSymbol->drawPreviewIcon( context.renderContext().painter(), size, &context.renderContext(), false, &context.renderContext().expressionContext(), &evaluatedPatchShape );
264  }
265 }
266 
268 {
269  mExpression.reset( new QgsExpression( exp ) );
270 }
271 
273 {
274  switch ( symbol->type() )
275  {
277  mMarkerSymbol.reset( static_cast<QgsMarkerSymbol *>( symbol ) );
278  break;
279 
281  mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
282  break;
283 
285  mFillSymbol.reset( static_cast<QgsFillSymbol *>( symbol ) );
286  break;
287 
288  default:
289  break;
290  }
291 
292  setSymbolType( symbol->type() );
293 
294  return true;
295 }
296 
298 {
299  return QgsSymbolLayer::usedAttributes( context )
300  + mSymbol->usedAttributes( context )
301  + mExpression->referencedColumns();
302 }
303 
305 {
306  // we treat geometry generator layers like they have data defined properties,
307  // since the WHOLE layer is based on expressions and requires the full expression
308  // context
309  return true;
310 }
311 
313 {
314  Q_UNUSED( symbol )
315  return true;
316 }
317 
318 QgsGeometry QgsGeometryGeneratorSymbolLayer::evaluateGeometryInPainterUnits( const QgsGeometry &input, const QgsFeature &, const QgsRenderContext &renderContext, QgsExpressionContext &expressionContext ) const
319 {
320  QgsGeometry drawGeometry( input );
321  // step 1 - scale the draw geometry from PAINTER units to target units (e.g. millimeters)
322  const double scale = 1 / renderContext.convertToPainterUnits( 1, mUnits );
323  const QTransform painterToTargetUnits = QTransform::fromScale( scale, scale );
324  drawGeometry.transform( painterToTargetUnits );
325 
326  // step 2 - set the feature to use the new scaled geometry, and inject it into the expression context
328  QgsExpressionContextScopePopper popper( expressionContext, generatorScope );
329  generatorScope->setGeometry( drawGeometry );
330 
331  // step 3 - evaluate the new generated geometry.
332  QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
333 
334  // step 4 - transform geometry back from target units to painter units
335  geom.transform( painterToTargetUnits.inverted( ) );
336 
337  return geom;
338 }
339 
340 QgsGeometry QgsGeometryGeneratorSymbolLayer::coerceToExpectedType( const QgsGeometry &geometry ) const
341 {
342  switch ( mSymbolType )
343  {
345  if ( geometry.type() != QgsWkbTypes::PointGeometry )
346  {
347  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiPoint );
348  if ( !geoms.empty() )
349  return geoms.at( 0 );
350  }
351  break;
353  if ( geometry.type() != QgsWkbTypes::LineGeometry )
354  {
355  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiLineString );
356  if ( !geoms.empty() )
357  return geoms.at( 0 );
358  }
359  break;
361  if ( geometry.type() != QgsWkbTypes::PolygonGeometry )
362  {
363  QVector< QgsGeometry > geoms = geometry.coerceToType( QgsWkbTypes::MultiPolygon );
364  if ( !geoms.empty() )
365  return geoms.at( 0 );
366  }
367  break;
369  break;
370  }
371  return geometry;
372 }
373 
374 void QgsGeometryGeneratorSymbolLayer::render( QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType, const QPolygonF *points, const QVector<QPolygonF> *rings )
375 {
376  if ( mRenderingFeature && mHasRenderedFeature )
377  return;
378 
379  QgsExpressionContext &expressionContext = context.renderContext().expressionContext();
380  QgsFeature f = expressionContext.feature();
381 
382  if ( ( !context.feature() || context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol ) && points )
383  {
384  // 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!
385  // in this case we need to build up a feature which represents the points being rendered.
386  // note that we also do this same logic when we are rendering a subsymbol. In that case the $geometry part of the
387  // expression should refer to the shape of the subsymbol being rendered, NOT the feature's original geometry
388  QgsGeometry drawGeometry;
389 
390  // step 1 - convert points and rings to geometry
391  switch ( geometryType )
392  {
394  {
395  Q_ASSERT( points->size() == 1 );
396  drawGeometry = QgsGeometry::fromPointXY( points->at( 0 ) );
397  break;
398  }
400  {
401  Q_ASSERT( !rings );
402  std::unique_ptr < QgsLineString > ring( QgsLineString::fromQPolygonF( *points ) );
403  drawGeometry = QgsGeometry( std::move( ring ) );
404  break;
405  }
407  {
408  std::unique_ptr < QgsLineString > exterior( QgsLineString::fromQPolygonF( *points ) );
409  std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
410  polygon->setExteriorRing( exterior.release() );
411  if ( rings )
412  {
413  for ( const QPolygonF &ring : *rings )
414  {
415  polygon->addInteriorRing( QgsLineString::fromQPolygonF( ring ) );
416  }
417  }
418  drawGeometry = QgsGeometry( std::move( polygon ) );
419  break;
420  }
421 
424  return; // unreachable
425  }
426 
427  // step 2 - evaluate the result
428  QgsGeometry result = evaluateGeometryInPainterUnits( drawGeometry, f, context.renderContext(), expressionContext );
429 
430  // We transform back to map units here (from painter units)
431  // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
432  // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
433  QTransform mapToPixel = context.renderContext().mapToPixel().transform();
434  result.transform( mapToPixel.inverted() );
435  // also need to apply the coordinate transform from the render context
436  try
437  {
438  result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
439  }
440  catch ( QgsCsException & )
441  {
442  QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
443  }
444 
445  f.setGeometry( coerceToExpectedType( result ) );
446  }
447  else if ( context.feature() )
448  {
449  switch ( mUnits )
450  {
452  case QgsUnitTypes::RenderUnknownUnit: // unsupported, not exposed as an option
453  case QgsUnitTypes::RenderMetersInMapUnits: // unsupported, not exposed as an option
454  case QgsUnitTypes::RenderPercentage: // unsupported, not exposed as an option
455  {
456  QgsGeometry geom = mExpression->evaluate( &expressionContext ).value<QgsGeometry>();
457  f.setGeometry( coerceToExpectedType( geom ) );
458  break;
459  }
460 
465  {
466  // convert feature geometry to painter units
467  QgsGeometry transformed = f.geometry();
468  transformed.transform( context.renderContext().coordinateTransform() );
469  const QTransform mapToPixel = context.renderContext().mapToPixel().transform();
470  transformed.transform( mapToPixel );
471 
472  QgsGeometry result = evaluateGeometryInPainterUnits( transformed, f, context.renderContext(), expressionContext );
473 
474  // We transform back to map units here (from painter units)
475  // as we'll ultimately be calling renderFeature, which excepts the feature has a geometry in map units.
476  // Here we also scale the transform by the target unit to painter units factor to reverse that conversion
477  result.transform( mapToPixel.inverted() );
478  // also need to apply the coordinate transform from the render context
479  try
480  {
481  result.transform( context.renderContext().coordinateTransform(), Qgis::TransformDirection::Reverse );
482  }
483  catch ( QgsCsException & )
484  {
485  QgsDebugMsg( QStringLiteral( "Could no transform generated geometry to layer CRS" ) );
486  }
487  f.setGeometry( coerceToExpectedType( result ) );
488  break;
489  }
490  }
491  }
492 
493  QgsExpressionContextScope *subSymbolExpressionContextScope = mSymbol->symbolRenderContext()->expressionContextScope();
494  // override the $geometry value for all subsymbols -- this should be the generated geometry
495  subSymbolExpressionContextScope->setGeometry( f.geometry() );
496 
497  const bool prevIsSubsymbol = context.renderContext().flags() & Qgis::RenderContextFlag::RenderingSubSymbol;
499 
500  mSymbol->renderFeature( f, context.renderContext(), -1, context.selected() );
501 
503 
504  if ( mRenderingFeature )
505  mHasRenderedFeature = true;
506 }
507 
508 void QgsGeometryGeneratorSymbolLayer::setColor( const QColor &color )
509 {
510  mSymbol->setColor( color );
511 }
qgspolygon.h
QgsGeometryGeneratorSymbolLayer::properties
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
Definition: qgsgeometrygeneratorsymbollayer.cpp:197
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
qgsexpressioncontextutils.h
QgsGeometryGeneratorSymbolLayer::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:297
QgsUnitTypes::RenderInches
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
QgsExpressionContextScopePopper
RAII class to pop scope from an expression context on destruction.
Definition: qgsexpressioncontextutils.h:361
QgsGeometryGeneratorSymbolLayer::layerType
QString layerType() const override
Returns a string that represents this layer type.
Definition: qgsgeometrygeneratorsymbollayer.cpp:65
QgsRenderContext::mapToPixel
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Definition: qgsrendercontext.h:258
QgsExpressionContextScope::setGeometry
void setGeometry(const QgsGeometry &geometry)
Convenience function for setting a geometry for the scope.
Definition: qgsexpressioncontext.h:352
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:625
QgsWkbTypes::MultiPolygon
@ MultiPolygon
Definition: qgswkbtypes.h:78
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsGeometry::transform
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.
Definition: qgsgeometry.cpp:3128
QgsSymbolRenderContext::feature
const QgsFeature * feature() const
Returns the current feature being rendered.
Definition: qgssymbolrendercontext.h:143
QgsGeometryGeneratorSymbolLayer::subSymbol
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
Definition: qgsgeometrygeneratorsymbollayer.h:105
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
QgsGeometry::fromPointXY
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
Definition: qgsgeometry.cpp:176
QgsGeometryGeneratorSymbolLayer::setOutputUnit
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:156
QgsRenderContext::flags
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
Definition: qgsrendercontext.cpp:224
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsGeometryGeneratorSymbolLayer::color
QColor color() const override
Returns the "representative" color of the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:134
QgsUnitTypes::RenderPercentage
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsGeometryGeneratorSymbolLayer::usesMapUnits
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
Definition: qgsgeometrygeneratorsymbollayer.cpp:123
QgsGeometryGeneratorSymbolLayer::setSymbolType
void setSymbolType(Qgis::SymbolType symbolType)
Set the type of symbol which should be created.
Definition: qgsgeometrygeneratorsymbollayer.cpp:70
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
QgsGeometryGeneratorSymbolLayer::setColor
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:508
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsLegendPatchShape::setScaleToOutputSize
void setScaleToOutputSize(bool scale)
Sets whether the patch shape should by resized to the desired target size when rendering.
Definition: qgslegendpatchshape.cpp:62
QgsSymbolRenderContext::patchShape
const QgsLegendPatchShape * patchShape() const
Returns the symbol patch shape, to use if rendering symbol preview icons.
Definition: qgssymbolrendercontext.cpp:72
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsLineSymbol::createSimple
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
Definition: qgslinesymbol.cpp:22
QgsLegendPatchShape
Represents a patch shape for use in map legends.
Definition: qgslegendpatchshape.h:33
QgsGeometryGeneratorSymbolLayer::startFeatureRender
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
Definition: qgsgeometrygeneratorsymbollayer.cpp:109
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
QgsSymbolRenderContext::selected
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style.
Definition: qgssymbolrendercontext.h:118
QgsUnitTypes::decodeRenderUnit
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
Definition: qgsunittypes.cpp:2948
QgsSymbolRenderContext
Definition: qgssymbolrendercontext.h:35
QgsSymbolRenderContext::expressionContextScope
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.
Definition: qgssymbolrendercontext.cpp:62
QgsSymbolRenderContext::originalGeometryType
QgsWkbTypes::GeometryType originalGeometryType() const
Returns the geometry type for the original feature geometry being rendered.
Definition: qgssymbolrendercontext.h:160
QgsRenderContext::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Definition: qgsrendercontext.h:178
QgsWkbTypes::MultiLineString
@ MultiLineString
Definition: qgswkbtypes.h:77
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsSymbolLayer
Definition: qgssymbollayer.h:54
QgsGeometryGeneratorSymbolLayer::outputUnit
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:145
QgsUnitTypes::encodeUnit
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
Definition: qgsunittypes.cpp:122
QgsSymbol::stopRender
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Definition: qgssymbol.cpp:842
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsGeometryGeneratorSymbolLayer::clone
QgsSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Definition: qgsgeometrygeneratorsymbollayer.cpp:177
QgsSymbol::type
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:152
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsRenderContext::setFlag
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Definition: qgsrendercontext.cpp:216
QgsLineString::fromQPolygonF
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
Definition: qgslinestring.cpp:248
QgsGeometryGeneratorSymbolLayer::create
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
Definition: qgsgeometrygeneratorsymbollayer.cpp:29
QgsLegendPatchShape::scaledGeometry
QgsGeometry scaledGeometry(QSizeF size) const
Returns the patch shape's geometry, scaled to the given size.
Definition: qgslegendpatchshape.cpp:94
QgsSymbolLayer::copyPaintEffect
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
Definition: qgssymbollayer.cpp:491
QgsGeometryGeneratorSymbolLayer
Definition: qgsgeometrygeneratorsymbollayer.h:31
QgsGeometryGeneratorSymbolLayer::~QgsGeometryGeneratorSymbolLayer
~QgsGeometryGeneratorSymbolLayer() override
QgsGeometryGeneratorSymbolLayer::mapUnitScale
QgsMapUnitScale mapUnitScale() const override
Definition: qgsgeometrygeneratorsymbollayer.cpp:166
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsSymbol::renderFeature
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:1252
QgsGeometry::isEmpty
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Definition: qgsgeometry.cpp:379
QgsSymbolLayer::restoreOldDataDefinedProperties
void restoreOldDataDefinedProperties(const QVariantMap &stringMap)
Restores older data defined properties from string map.
Definition: qgssymbollayer.cpp:362
qgslegendpatchshape.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:36
QgsSymbol::startRender
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
Definition: qgssymbol.cpp:794
QgsGeometryGeneratorSymbolLayer::hasDataDefinedProperties
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
Definition: qgsgeometrygeneratorsymbollayer.cpp:304
QgsGeometryGeneratorSymbolLayer::symbolType
Qgis::SymbolType symbolType() const
Access the symbol type.
Definition: qgsgeometrygeneratorsymbollayer.h:55
QgsGeometryGeneratorSymbolLayer::setUnits
void setUnits(QgsUnitTypes::RenderUnit units)
Sets the units for the geometry expression.
Definition: qgsgeometrygeneratorsymbollayer.h:103
QgsFillSymbol::createSimple
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
Definition: qgsfillsymbol.cpp:20
QgsSymbol::symbolRenderContext
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
Definition: qgssymbol.cpp:1793
QgsGeometryGeneratorSymbolLayer::isCompatibleWithSymbol
bool isCompatibleWithSymbol(QgsSymbol *symbol) const override
Will always return true.
Definition: qgsgeometrygeneratorsymbollayer.cpp:312
QgsGeometryGeneratorSymbolLayer::render
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.
Definition: qgsgeometrygeneratorsymbollayer.cpp:374
QgsMapToPixel::transform
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Definition: qgsmaptopixel.h:90
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsSymbolLayer::usedAttributes
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Definition: qgssymbollayer.cpp:328
qgsstyle.h
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
QgsGeometryGeneratorSymbolLayer::setGeometryExpression
void setGeometryExpression(const QString &exp)
Set the expression to generate this geometry.
Definition: qgsgeometrygeneratorsymbollayer.cpp:267
QgsRenderContext::convertToPainterUnits
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).
Definition: qgsrendercontext.cpp:367
Qgis::SymbolType::Hybrid
@ Hybrid
Hybrid symbol.
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsGeometryGeneratorSymbolLayer::startRender
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
Definition: qgsgeometrygeneratorsymbollayer.cpp:96
QgsGeometryGeneratorSymbolLayer::stopFeatureRender
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
Definition: qgsgeometrygeneratorsymbollayer.cpp:118
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsGeometry::coerceToType
QVector< QgsGeometry > coerceToType(QgsWkbTypes::Type type, double defaultZ=0, double defaultM=0) const
Attempts to coerce this geometry into the specified destination type.
Definition: qgsgeometry.cpp:1431
qgsgeometry.h
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsSymbol::drawPreviewIcon
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:892
QgsGeometryGeneratorSymbolLayer::stopRender
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Definition: qgsgeometrygeneratorsymbollayer.cpp:103
qgsmarkersymbol.h
QgsWkbTypes::MultiPoint
@ MultiPoint
Definition: qgswkbtypes.h:76
QgsExpressionContext::feature
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
Definition: qgsexpressioncontext.cpp:543
QgsSymbol::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
Definition: qgssymbol.cpp:1151
QgsGeometryGeneratorSymbolLayer::drawPreviewIcon
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Definition: qgsgeometrygeneratorsymbollayer.cpp:218
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsUnitTypes::RenderMetersInMapUnits
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
QgsUnitTypes::RenderUnknownUnit
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsStyle::defaultPatch
QgsLegendPatchShape defaultPatch(Qgis::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
Definition: qgsstyle.cpp:1157
QgsGeometryGeneratorSymbolLayer::setSubSymbol
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
Definition: qgsgeometrygeneratorsymbollayer.cpp:272
Qgis
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:71
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsSymbolRenderContext::renderContext
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Definition: qgssymbolrendercontext.h:62
qgsgeometrygeneratorsymbollayer.h
Qgis::RenderContextFlag::RenderingSubSymbol
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:112
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
QgsMarkerSymbol::createSimple
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
Definition: qgsmarkersymbol.cpp:22
QgsSymbolLayer::copyDataDefinedProperties
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
Definition: qgssymbollayer.cpp:483
qgsfillsymbol.h
QgsSymbol::setColor
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:867
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
qgslinesymbol.h
QgsLegendPatchShape::isNull
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
Definition: qgslegendpatchshape.cpp:32