QGIS API Documentation 3.43.0-Master (ac9f54ad1f7)
qgspointdistancerenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointdistancerenderer.cpp
3 ----------------------------
4 begin : January 26, 2010
5 copyright : (C) 2010 by Marco Hugentobler
6 email : marco at hugis dot net
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsgeometry.h"
20#include "qgssymbollayerutils.h"
21#include "qgsspatialindex.h"
22#include "qgsmultipoint.h"
23#include "qgslogger.h"
26#include "qgsmarkersymbol.h"
27#include "qgssldexportcontext.h"
28#include <QDomElement>
29#include <QPainter>
30
31#include <cmath>
32
33QgsPointDistanceRenderer::QgsPointDistanceRenderer( const QString &rendererName, const QString &labelAttributeName )
34 : QgsFeatureRenderer( rendererName )
35 , mLabelAttributeName( labelAttributeName )
36 , mLabelIndex( -1 )
37 , mTolerance( 3 )
38 , mToleranceUnit( Qgis::RenderUnit::Millimeters )
39 , mDrawLabels( true )
40
41{
43}
44
45void QgsPointDistanceRenderer::toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props ) const
46{
47 QgsSldExportContext context;
48 context.setExtraProperties( props );
49 toSld( doc, element, context );
50}
51
52bool QgsPointDistanceRenderer::toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const
53{
54 return mRenderer->toSld( doc, element, context );
55}
56
57bool QgsPointDistanceRenderer::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
58{
59 Q_UNUSED( drawVertexMarker )
60 Q_UNUSED( context )
61 Q_UNUSED( layer )
62
63 /*
64 * IMPORTANT: This algorithm is ported to Python in the processing "Points Displacement" algorithm.
65 * Please port any changes/improvements to that algorithm too!
66 */
67
68 //check if there is already a point at that position
69 if ( !feature.hasGeometry() )
70 return false;
71
72 QgsMarkerSymbol *symbol = firstSymbolForFeature( feature, context );
73
74 //if the feature has no symbol (e.g., no matching rule in a rule-based renderer), skip it
75 if ( !symbol )
76 return false;
77
78 //point position in screen coords
79 QgsGeometry geom = feature.geometry();
80 const Qgis::WkbType geomType = geom.wkbType();
82 {
83 //can only render point type
84 return false;
85 }
86
87 QString label;
88 if ( mDrawLabels )
89 {
90 label = getLabel( feature );
91 }
92
93 const QgsCoordinateTransform xform = context.coordinateTransform();
94 QgsFeature transformedFeature = feature;
95 if ( xform.isValid() )
96 {
97 geom.transform( xform );
98 transformedFeature.setGeometry( geom );
99 }
100
101 const double searchDistance = context.convertToMapUnits( mTolerance, mToleranceUnit, mToleranceMapUnitScale );
102
103 const QgsGeometry transformedGeometry = transformedFeature.geometry();
104 for ( auto partIt = transformedGeometry.const_parts_begin(); partIt != transformedGeometry.const_parts_end(); ++partIt )
105 {
106 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( *partIt );
107 // create a new feature which is JUST this point, no other parts from the multi-point
108 QgsFeature pointFeature = transformedFeature;
109 pointFeature.setGeometry( QgsGeometry( point->clone() ) );
110 const QList<QgsFeatureId> intersectList = mSpatialIndex->intersects( searchRect( point, searchDistance ) );
111 if ( intersectList.empty() )
112 {
113 mSpatialIndex->addFeature( pointFeature );
114 // create new group
115 ClusteredGroup newGroup;
116 newGroup << GroupedFeature( pointFeature, symbol->clone(), selected, label );
117 mClusteredGroups.push_back( newGroup );
118 // add to group index
119 mGroupIndex.insert( pointFeature.id(), mClusteredGroups.count() - 1 );
120 mGroupLocations.insert( pointFeature.id(), QgsPointXY( *point ) );
121 }
122 else
123 {
124 // find group with closest location to this point (may be more than one within search tolerance)
125 QgsFeatureId minDistFeatureId = intersectList.at( 0 );
126 double minDist = mGroupLocations.value( minDistFeatureId ).distance( point->x(), point->y() );
127 for ( int i = 1; i < intersectList.count(); ++i )
128 {
129 const QgsFeatureId candidateId = intersectList.at( i );
130 const double newDist = mGroupLocations.value( candidateId ).distance( point->x(), point->y() );
131 if ( newDist < minDist )
132 {
133 minDist = newDist;
134 minDistFeatureId = candidateId;
135 }
136 }
137
138 const int groupIdx = mGroupIndex[ minDistFeatureId ];
139 ClusteredGroup &group = mClusteredGroups[groupIdx];
140
141 // calculate new centroid of group
142 const QgsPointXY oldCenter = mGroupLocations.value( minDistFeatureId );
143 mGroupLocations[ minDistFeatureId ] = QgsPointXY( ( oldCenter.x() * group.size() + point->x() ) / ( group.size() + 1.0 ),
144 ( oldCenter.y() * group.size() + point->y() ) / ( group.size() + 1.0 ) );
145
146 // add to a group
147 group << GroupedFeature( pointFeature, symbol->clone(), selected, label );
148 // add to group index
149 mGroupIndex.insert( pointFeature.id(), groupIdx );
150 }
151 }
152
153 return true;
154}
155
156void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup &group, QgsRenderContext &context ) const
157{
158 //calculate centroid of all points, this will be center of group
159 QgsMultiPoint *groupMultiPoint = new QgsMultiPoint();
160 const auto constGroup = group;
161 for ( const GroupedFeature &f : constGroup )
162 {
163 groupMultiPoint->addGeometry( f.feature.geometry().constGet()->clone() );
164 }
165 const QgsGeometry groupGeom( groupMultiPoint );
166 const QgsGeometry centroid = groupGeom.centroid();
167 QPointF pt = centroid.asQPointF();
168 context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
169
170 const QgsExpressionContextScopePopper scopePopper( context.expressionContext(), createGroupScope( group ) );
171 drawGroup( pt, context, group );
172}
173
178
183
185{
186 if ( !mRenderer )
187 return;
188
189 mRenderer->setLegendSymbolItem( key, symbol );
190}
191
193{
194 if ( !mRenderer )
195 return false;
196
197 return mRenderer->legendSymbolItemsCheckable();
198}
199
201{
202 if ( !mRenderer )
203 return false;
204
205 return mRenderer->legendSymbolItemChecked( key );
206}
207
208void QgsPointDistanceRenderer::checkLegendSymbolItem( const QString &key, bool state )
209{
210 if ( !mRenderer )
211 return;
212
213 mRenderer->checkLegendSymbolItem( key, state );
214}
215
217{
218 if ( !mRenderer )
219 return QgsFeatureRenderer::filter( fields );
220 else
221 return mRenderer->filter( fields );
222}
223
225{
226 if ( mRenderer )
227 if ( !mRenderer->accept( visitor ) )
228 return false;
229
230 return true;
231}
232
234{
235 QSet<QString> attributeList;
236 if ( !mLabelAttributeName.isEmpty() )
237 {
238 attributeList.insert( mLabelAttributeName );
239 }
240 if ( mRenderer )
241 {
242 attributeList += mRenderer->usedAttributes( context );
243 }
244 return attributeList;
245}
246
248{
249 return mRenderer ? mRenderer->filterNeedsGeometry() : false;
250}
251
253{
254 if ( !mRenderer )
255 {
256 return Capabilities();
257 }
258 return mRenderer->capabilities();
259}
260
262{
263 if ( !mRenderer )
264 {
265 return QgsSymbolList();
266 }
267 return mRenderer->symbols( context );
268}
269
271{
272 if ( !mRenderer )
273 {
274 return nullptr;
275 }
276 return mRenderer->symbolForFeature( feature, context );
277}
278
280{
281 if ( !mRenderer )
282 return nullptr;
283 return mRenderer->originalSymbolForFeature( feature, context );
284}
285
287{
288 if ( !mRenderer )
289 {
290 return QgsSymbolList();
291 }
292 return mRenderer->symbolsForFeature( feature, context );
293}
294
296{
297 if ( !mRenderer )
298 return QgsSymbolList();
299 return mRenderer->originalSymbolsForFeature( feature, context );
300}
301
302QSet< QString > QgsPointDistanceRenderer::legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const
303{
304 if ( !mRenderer )
305 return QSet< QString >() << QString();
306 return mRenderer->legendKeysForFeature( feature, context );
307}
308
309QString QgsPointDistanceRenderer::legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const
310{
311 ok = false;
312 if ( !mRenderer )
313 return QString();
314 return mRenderer->legendKeyToExpression( key, layer, ok );
315}
316
318{
319 if ( !mRenderer )
320 {
321 return false;
322 }
323 return mRenderer->willRenderFeature( feature, context );
324}
325
326
328{
329 QgsFeatureRenderer::startRender( context, fields );
330
331 mRenderer->startRender( context, fields );
332
333 mClusteredGroups.clear();
334 mGroupIndex.clear();
335 mGroupLocations.clear();
337
338 if ( mLabelAttributeName.isEmpty() )
339 {
340 mLabelIndex = -1;
341 }
342 else
343 {
345 }
346
347 if ( mMinLabelScale <= 0 || context.rendererScale() < mMinLabelScale )
348 {
349 mDrawLabels = true;
350 }
351 else
352 {
353 mDrawLabels = false;
354 }
355}
356
358{
360
361 //printInfoDisplacementGroups(); //just for debugging
362
363 if ( !context.renderingStopped() )
364 {
365 const auto constMClusteredGroups = mClusteredGroups;
366 for ( const ClusteredGroup &group : constMClusteredGroups )
367 {
368 drawGroup( group, context );
369 }
370 }
371
372 mClusteredGroups.clear();
373 mGroupIndex.clear();
374 mGroupLocations.clear();
375 delete mSpatialIndex;
376 mSpatialIndex = nullptr;
377
378 mRenderer->stopRender( context );
379}
380
382{
383 if ( mRenderer )
384 {
385 return mRenderer->legendSymbolItems();
386 }
387 return QgsLegendSymbolList();
388}
389
390QgsRectangle QgsPointDistanceRenderer::searchRect( const QgsPoint *p, double distance ) const
391{
392 return QgsRectangle( p->x() - distance, p->y() - distance, p->x() + distance, p->y() + distance );
393}
394
395void QgsPointDistanceRenderer::printGroupInfo() const
396{
397#ifdef QGISDEBUG
398 const int nGroups = mClusteredGroups.size();
399 QgsDebugMsgLevel( "number of displacement groups:" + QString::number( nGroups ), 3 );
400 for ( int i = 0; i < nGroups; ++i )
401 {
402 QgsDebugMsgLevel( "***************displacement group " + QString::number( i ), 3 );
403 const auto constAt = mClusteredGroups.at( i );
404 for ( const GroupedFeature &feature : constAt )
405 {
406 QgsDebugMsgLevel( FID_TO_STRING( feature.feature.id() ), 3 );
407 }
408 }
409#endif
410}
411
412QString QgsPointDistanceRenderer::getLabel( const QgsFeature &feature ) const
413{
414 QString attribute;
415 const QgsAttributes attrs = feature.attributes();
416 if ( mLabelIndex >= 0 && mLabelIndex < attrs.count() )
417 {
418 attribute = attrs.at( mLabelIndex ).toString();
419 }
420 return attribute;
421}
422
423void QgsPointDistanceRenderer::drawLabels( QPointF centerPoint, QgsSymbolRenderContext &context, const QList<QPointF> &labelShifts, const ClusteredGroup &group ) const
424{
425 QPainter *p = context.renderContext().painter();
426 if ( !p )
427 {
428 return;
429 }
430
431 const QPen labelPen( mLabelColor );
432 p->setPen( labelPen );
433
434 //scale font (for printing)
435 QFont pixelSizeFont = mLabelFont;
436
437 const double fontSizeInPixels = context.renderContext().convertToPainterUnits( mLabelFont.pointSizeF(), Qgis::RenderUnit::Points );
438 pixelSizeFont.setPixelSize( static_cast< int >( std::round( fontSizeInPixels ) ) );
439 QFont scaledFont = pixelSizeFont;
440 scaledFont.setPixelSize( pixelSizeFont.pixelSize() );
441 p->setFont( scaledFont );
442
443 const QFontMetricsF fontMetrics( pixelSizeFont );
444 QPointF currentLabelShift; //considers the signs to determine the label position
445
446 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
447 ClusteredGroup::const_iterator groupIt = group.constBegin();
448
449 for ( ; labelPosIt != labelShifts.constEnd() && groupIt != group.constEnd(); ++labelPosIt, ++groupIt )
450 {
451 currentLabelShift = *labelPosIt;
452 if ( currentLabelShift.x() < 0 )
453 {
454 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.horizontalAdvance( groupIt->label ) );
455 }
456 if ( currentLabelShift.y() > 0 )
457 {
458 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
459 }
460
461 const QPointF drawingPoint( centerPoint + currentLabelShift );
462 const QgsScopedQPainterState painterState( p );
463 p->translate( drawingPoint.x(), drawingPoint.y() );
464 p->drawText( QPointF( 0, 0 ), groupIt->label );
465 }
466}
467
468QgsExpressionContextScope *QgsPointDistanceRenderer::createGroupScope( const ClusteredGroup &group ) const
469{
471 if ( group.size() > 1 )
472 {
473 //scan through symbols to check color, e.g., if all clustered symbols are same color
474 QColor groupColor;
475 ClusteredGroup::const_iterator groupIt = group.constBegin();
476 for ( ; groupIt != group.constEnd(); ++groupIt )
477 {
478 if ( !groupIt->symbol() )
479 continue;
480
481 if ( !groupColor.isValid() )
482 {
483 groupColor = groupIt->symbol()->color();
484 }
485 else
486 {
487 if ( groupColor != groupIt->symbol()->color() )
488 {
489 groupColor = QColor();
490 break;
491 }
492 }
493 }
494
495 if ( groupColor.isValid() )
496 {
498 }
499 else
500 {
501 //mixed colors
503 }
504
506 }
507 if ( !group.empty() )
508 {
509 // data defined properties may require a feature in the expression context, so just use first feature in group
510 clusterScope->setFeature( group.at( 0 ).feature );
511 }
512 return clusterScope;
513}
514
515QgsMarkerSymbol *QgsPointDistanceRenderer::firstSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context )
516{
517 if ( !mRenderer )
518 {
519 return nullptr;
520 }
521
522 const QgsSymbolList symbolList = mRenderer->symbolsForFeature( feature, context );
523 if ( symbolList.isEmpty() )
524 {
525 return nullptr;
526 }
527
528 return dynamic_cast< QgsMarkerSymbol * >( symbolList.at( 0 ) );
529}
530
531QgsPointDistanceRenderer::GroupedFeature::GroupedFeature( const QgsFeature &feature, QgsMarkerSymbol *symbol, bool isSelected, const QString &label )
532 : feature( feature )
533 , isSelected( isSelected )
534 , label( label )
535 , mSymbol( symbol )
536{}
537
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
@ Points
Points (e.g., for font sizes)
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
A vector of attributes.
Handles coordinate transforms between two coordinate systems.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Abstract base class for all 2D vector feature renderers.
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
static QgsFeatureRenderer * defaultRenderer(Qgis::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QFlags< Capability > Capabilities
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsAttributes attributes
Definition qgsfeature.h:67
QgsFeatureId id
Definition qgsfeature.h:66
QgsGeometry geometry
Definition qgsfeature.h:69
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
Definition qgsfields.h:46
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
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.
QPointF asQPointF() const
Returns contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPoint...
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
Multi point geometry collection.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
QMap< QgsFeatureId, QgsPointXY > mGroupLocations
Mapping of feature ID to approximate group location.
double mMinLabelScale
Maximum scale denominator for label display. A zero value indicates no scale limitation.
int mLabelIndex
Label attribute index (or -1 if none). This index is not stored, it is requested in the startRender()...
bool legendSymbolItemChecked(const QString &key) override
Returns true if the legend symbology item with the specified key is checked.
QgsSpatialIndex * mSpatialIndex
Spatial index for fast lookup of nearby points.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QColor mLabelColor
Label text color.
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
QString filter(const QgsFields &fields=QgsFields()) override
If a renderer does not require all the features this method may be overridden and return an expressio...
QList< ClusteredGroup > mClusteredGroups
Groups of features that are considered clustered together.
QMap< QgsFeatureId, int > mGroupIndex
Mapping of feature ID to the feature's group index.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const override
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
QgsPointDistanceRenderer(const QString &rendererName, const QString &labelAttributeName=QString())
Constructor for QgsPointDistanceRenderer.
void drawLabels(QPointF centerPoint, QgsSymbolRenderContext &context, const QList< QPointF > &labelShifts, const ClusteredGroup &group) const
Renders the labels for a group.
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Render a feature using this renderer in the given context.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const override
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
bool legendSymbolItemsCheckable() const override
Returns true if symbology items in legend are checkable.
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
void setEmbeddedRenderer(QgsFeatureRenderer *r) override
Sets an embedded renderer (subrenderer) for this feature renderer.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QString mLabelAttributeName
Attribute name for labeling. An empty string indicates that no labels should be rendered.
void checkLegendSymbolItem(const QString &key, bool state) override
Sets whether the legend symbology item with the specified ley should be checked.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
double mTolerance
Distance tolerance. Points that are closer together than this distance are considered clustered.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
bool mDrawLabels
Whether labels should be drawn for points. This is set internally from startRender() depending on sca...
std::unique_ptr< QgsFeatureRenderer > mRenderer
Embedded base renderer. This can be used for rendering individual, isolated points.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
Qgis::RenderUnit mToleranceUnit
Unit for distance tolerance.
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Represents a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
Definition qgspoint.cpp:105
double x
Definition qgspoint.h:52
double y
Definition qgspoint.h:53
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
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.
double rendererScale() const
Returns the renderer map scale.
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...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Scoped object for saving and restoring a QPainter object's state.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
A spatial index for QgsFeature objects.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.
An interface for classes which can visit style entity (e.g.
static QString encodeColor(const QColor &color)
Encapsulates the context in which a symbol is being rendered.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based dataset.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:41
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:48
Single variable definition for use within a QgsExpressionContextScope.
Contains properties for a feature within a clustered group.
GroupedFeature(const QgsFeature &feature, QgsMarkerSymbol *symbol, bool isSelected, const QString &label=QString())
Constructor for GroupedFeature.