QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
qgspointdistancerenderer.h
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
18#ifndef QGSPOINTDISTANCERENDERER_H
19#define QGSPOINTDISTANCERENDERER_H
20
21#include "qgis_core.h"
22#include "qgis.h"
23#include "qgsrenderer.h"
24#include "qgsmapunitscale.h"
25#include <QFont>
26
27class QgsSpatialIndex;
28class QgsMarkerSymbol;
30
41{
42 public:
43
45 struct CORE_EXPORT GroupedFeature
46 {
47
55 GroupedFeature( const QgsFeature &feature, QgsMarkerSymbol *symbol SIP_TRANSFER, bool isSelected, const QString &label = QString() );
57
60
62 QgsMarkerSymbol *symbol() const { return mSymbol.get(); }
63
66
68 QString label;
69
70 private:
71 std::shared_ptr< QgsMarkerSymbol > mSymbol;
72 };
73
75 typedef QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup;
76
82 QgsPointDistanceRenderer( const QString &rendererName, const QString &labelAttributeName = QString() );
83
84 void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override;
85 bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
86 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
87 bool filterNeedsGeometry() const override;
88 QgsFeatureRenderer::Capabilities capabilities() override;
89 QgsSymbolList symbols( QgsRenderContext &context ) const override;
90 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
91 QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
92 QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
93 QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
94 QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
95 QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const override;
96 bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
97 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
98 void stopRender( QgsRenderContext &context ) override;
99 QgsLegendSymbolList legendSymbolItems() const override;
100 void setEmbeddedRenderer( QgsFeatureRenderer *r SIP_TRANSFER ) override;
101 const QgsFeatureRenderer *embeddedRenderer() const override;
102 void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER ) override;
103 bool legendSymbolItemsCheckable() const override;
104 bool legendSymbolItemChecked( const QString &key ) override;
105 void checkLegendSymbolItem( const QString &key, bool state ) override;
106 QString filter( const QgsFields &fields = QgsFields() ) override;
107 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
108
117 void setLabelAttributeName( const QString &name ) { mLabelAttributeName = name; }
118
127 QString labelAttributeName() const { return mLabelAttributeName; }
128
136 void setLabelFont( const QFont &font ) { mLabelFont = font; }
137
144 QFont labelFont() const { return mLabelFont;}
145
152 void setMinimumLabelScale( double scale ) { mMinLabelScale = scale; }
153
160 double minimumLabelScale() const { return mMinLabelScale; }
161
169 void setLabelColor( const QColor &color ) { mLabelColor = color;}
170
177 QColor labelColor() const { return mLabelColor; }
178
186 void setTolerance( double distance ) { mTolerance = distance; }
187
194 double tolerance() const { return mTolerance; }
195
202 void setToleranceUnit( Qgis::RenderUnit unit ) { mToleranceUnit = unit; }
203
209 Qgis::RenderUnit toleranceUnit() const { return mToleranceUnit; }
210
218 void setToleranceMapUnitScale( const QgsMapUnitScale &scale ) { mToleranceMapUnitScale = scale; }
219
226 const QgsMapUnitScale &toleranceMapUnitScale() const { return mToleranceMapUnitScale; }
227
228 protected:
229
231 std::unique_ptr< QgsFeatureRenderer > mRenderer;
232
235
238
245
253 double mMinLabelScale = 0;
254
256 QList<ClusteredGroup> mClusteredGroups;
257
259 QMap<QgsFeatureId, int> mGroupIndex;
260
262 QMap<QgsFeatureId, QgsPointXY > mGroupLocations;
263
265 QgsSpatialIndex *mSpatialIndex = nullptr;
266
275 void drawLabels( QPointF centerPoint, QgsSymbolRenderContext &context, const QList<QPointF> &labelShifts, const ClusteredGroup &group ) const;
276
277 private:
278
285 virtual void drawGroup( QPointF centerPoint, QgsRenderContext &context, const ClusteredGroup &group ) const = 0 SIP_FORCE;
286
288 QgsRectangle searchRect( const QgsPoint *p, double distance ) const;
289
291 void printGroupInfo() const;
292
294 QString getLabel( const QgsFeature &feature ) const;
295
297 void drawGroup( const ClusteredGroup &group, QgsRenderContext &context ) const;
298
304 QgsMarkerSymbol *firstSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context );
305
311 QgsExpressionContextScope *createGroupScope( const ClusteredGroup &group ) const;
312
313};
314
315#endif // QGSPOINTDISTANCERENDERER_H
RenderUnit
Rendering size units.
Definition qgis.h:4494
Custom exception class for Coordinate Reference System related exceptions.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QFlags< Capability > Capabilities
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
QMap< QgsFeatureId, QgsPointXY > mGroupLocations
Mapping of feature ID to approximate group location.
void setLabelColor(const QColor &color)
Sets the color to use for for labeling points.
QColor labelColor() const
Returns the color used for for labeling points.
int mLabelIndex
Label attribute index (or -1 if none). This index is not stored, it is requested in the startRender()...
QColor mLabelColor
Label text color.
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
QList< ClusteredGroup > mClusteredGroups
Groups of features that are considered clustered together.
void setLabelFont(const QFont &font)
Sets the font used for labeling points.
QMap< QgsFeatureId, int > mGroupIndex
Mapping of feature ID to the feature's group index.
double minimumLabelScale() const
Returns the minimum map scale (i.e.
void setToleranceUnit(Qgis::RenderUnit unit)
Sets the units for the tolerance distance.
void setMinimumLabelScale(double scale)
Sets the minimum map scale (i.e.
double tolerance() const
Returns the tolerance distance for grouping points.
QFont labelFont() const
Returns the font used for labeling points.
QString labelAttributeName() const
Returns the attribute name used for labeling points, or an empty string if no labeling will be done b...
const QgsMapUnitScale & toleranceMapUnitScale() const
Returns the map unit scale object for the distance tolerance.
QString mLabelAttributeName
Attribute name for labeling. An empty string indicates that no labels should be rendered.
double mTolerance
Distance tolerance. Points that are closer together than this distance are considered clustered.
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.
Qgis::RenderUnit toleranceUnit() const
Returns the units for the tolerance distance.
void setToleranceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the distance tolerance.
void setTolerance(double distance)
Sets the tolerance distance for grouping points.
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
Qgis::RenderUnit mToleranceUnit
Unit for distance tolerance.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A rectangle specified with double values.
Contains information about the context of a rendering operation.
A spatial index for QgsFeature objects.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
Represents a vector layer which manages a vector based data sets.
#define SIP_FORCE
Definition qgis_sip.h:131
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:47
Contains properties for a feature within a clustered group.
bool isSelected
True if feature is selected and should be rendered in a selected state.
QgsMarkerSymbol * symbol() const
Base symbol for rendering feature.