QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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.h"
22#include "qgis_core.h"
23#include "qgsmapunitscale.h"
24#include "qgsrenderer.h"
25
26#include <QFont>
27
28class QgsSpatialIndex;
29class QgsMarkerSymbol;
31
41
43{
44 public:
45
47 struct CORE_EXPORT GroupedFeature
48 {
49
57 GroupedFeature( const QgsFeature &feature, QgsMarkerSymbol *symbol SIP_TRANSFER, bool isSelected, const QString &label = QString() );
59
62
64 QgsMarkerSymbol *symbol() const { return mSymbol.get(); }
65
68
70 QString label;
71
72 private:
73 std::shared_ptr< QgsMarkerSymbol > mSymbol;
74 };
75
77 typedef QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup;
78
84 QgsPointDistanceRenderer( const QString &rendererName, const QString &labelAttributeName = QString() );
85
86 Q_DECL_DEPRECATED void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override SIP_DEPRECATED;
87 bool toSld( QDomDocument &doc, QDomElement &element, QgsSldExportContext &context ) const override;
88 bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
89 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
90 bool filterNeedsGeometry() const override;
92 QgsSymbolList symbols( QgsRenderContext &context ) const override;
93 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
94 QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
95 QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
96 QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
97 QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
98 QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const override;
99 bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
100 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
101 void stopRender( QgsRenderContext &context ) override;
102 QgsLegendSymbolList legendSymbolItems() const override;
104 const QgsFeatureRenderer *embeddedRenderer() const override;
105 void setLegendSymbolItem( const QString &key, QgsSymbol *symbol SIP_TRANSFER ) override;
106 bool legendSymbolItemsCheckable() const override;
107 bool legendSymbolItemChecked( const QString &key ) override;
108 void checkLegendSymbolItem( const QString &key, bool state ) override;
109 QString filter( const QgsFields &fields = QgsFields() ) override;
110 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
111
120 void setLabelAttributeName( const QString &name ) { mLabelAttributeName = name; }
121
130 QString labelAttributeName() const { return mLabelAttributeName; }
131
139 void setLabelFont( const QFont &font ) { mLabelFont = font; }
140
147 QFont labelFont() const { return mLabelFont;}
148
155 void setMinimumLabelScale( double scale ) { mMinLabelScale = scale; }
156
163 double minimumLabelScale() const { return mMinLabelScale; }
164
172 void setLabelColor( const QColor &color ) { mLabelColor = color;}
173
180 QColor labelColor() const { return mLabelColor; }
181
189 void setTolerance( double distance ) { mTolerance = distance; }
190
197 double tolerance() const { return mTolerance; }
198
206
213
222
230
231 protected:
232
234 std::unique_ptr< QgsFeatureRenderer > mRenderer;
235
238
240 int mLabelIndex = -1;
241
243 double mTolerance = 3;
248
254 bool mDrawLabels = true;
256 double mMinLabelScale = 0;
257
259 QList<ClusteredGroup> mClusteredGroups;
260
262 QMap<QgsFeatureId, int> mGroupIndex;
263
265 QMap<QgsFeatureId, QgsPointXY > mGroupLocations;
266
269
278 void drawLabels( QPointF centerPoint, QgsSymbolRenderContext &context, const QList<QPointF> &labelShifts, const ClusteredGroup &group ) const;
279
280 private:
281
288 virtual void drawGroup( QPointF centerPoint, QgsRenderContext &context, const ClusteredGroup &group ) const = 0 SIP_FORCE;
289
291 QgsRectangle searchRect( const QgsPoint *p, double distance ) const;
292
294 void printGroupInfo() const;
295
297 QString getLabel( const QgsFeature &feature ) const;
298
300 void drawGroup( const ClusteredGroup &group, QgsRenderContext &context ) const;
301
307 QgsMarkerSymbol *firstSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context );
308
314 QgsExpressionContextScope *createGroupScope( const ClusteredGroup &group ) const;
315
316};
317
318#endif // QGSPOINTDISTANCERENDERER_H
RenderUnit
Rendering size units.
Definition qgis.h:5183
@ Millimeters
Millimeters.
Definition qgis.h:5184
Custom exception class for Coordinate Reference System related exceptions.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsFeatureRenderer(const QString &type)
QFlags< Capability > Capabilities
virtual Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
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.
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.
double mMinLabelScale
Maximum scale denominator for label display. A zero value indicates no scale limitation.
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()...
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.
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.
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.
void setMinimumLabelScale(double scale)
Sets the minimum map scale (i.e.
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...
double tolerance() const
Returns the tolerance distance for grouping points.
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.
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...
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.
const QgsMapUnitScale & toleranceMapUnitScale() const
Returns the map unit scale object for the distance tolerance.
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.
void setLabelAttributeName(const QString &name)
Sets the attribute name for labeling points.
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.
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 setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
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.
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...
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.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
A spatial index for QgsFeature objects.
An interface for classes which can visit style entity (e.g.
Encapsulates the context in which a symbol is being rendered.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_FORCE
Definition qgis_sip.h:139
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:49
GroupedFeature(const QgsFeature &feature, QgsMarkerSymbol *symbol, bool isSelected, const QString &label=QString())
Constructor for GroupedFeature.
bool isSelected
True if feature is selected and should be rendered in a selected state.
QgsMarkerSymbol * symbol() const
Base symbol for rendering feature.