46 toSld( doc, element, context );
51 return mRenderer->toSld( doc, element, context );
56 Q_UNUSED( drawVertexMarker )
87 label = getLabel( feature );
107 const QList<QgsFeatureId> intersectList =
mSpatialIndex->intersects( searchRect( point, searchDistance ) );
108 if ( intersectList.empty() )
123 double minDist =
mGroupLocations.value( minDistFeatureId ).distance( point->
x(), point->
y() );
124 for (
int i = 1; i < intersectList.count(); ++i )
127 const double newDist =
mGroupLocations.value( candidateId ).distance( point->
x(), point->
y() );
128 if ( newDist < minDist )
131 minDistFeatureId = candidateId;
135 const int groupIdx =
mGroupIndex[ minDistFeatureId ];
141 ( oldCenter.
y() * group.size() + point->
y() ) / ( group.size() + 1.0 ) );
153void QgsPointDistanceRenderer::drawGroup(
const ClusteredGroup &group,
QgsRenderContext &context )
const
157 const auto constGroup = group;
158 for (
const GroupedFeature &f : constGroup )
160 groupMultiPoint->
addGeometry( f.feature.geometry().constGet()->clone() );
162 const QgsGeometry groupGeom( groupMultiPoint );
163 const QgsGeometry centroid = groupGeom.centroid();
167 const QgsExpressionContextScopePopper scopePopper( context.
expressionContext(), createGroupScope( group ) );
168 drawGroup( pt, context, group );
186 mRenderer->setLegendSymbolItem( key, symbol );
194 return mRenderer->legendSymbolItemsCheckable();
202 return mRenderer->legendSymbolItemChecked( key );
210 mRenderer->checkLegendSymbolItem( key, state );
232 QSet<QString> attributeList;
239 attributeList +=
mRenderer->usedAttributes( context );
241 return attributeList;
273 return mRenderer->symbolForFeature( feature, context );
280 return mRenderer->originalSymbolForFeature( feature, context );
289 return mRenderer->symbolsForFeature( feature, context );
296 return mRenderer->originalSymbolsForFeature( feature, context );
302 return QSet< QString >() << QString();
303 return mRenderer->legendKeysForFeature( feature, context );
311 return mRenderer->legendKeyToExpression( key, layer, ok );
320 return mRenderer->willRenderFeature( feature, context );
328 mRenderer->startRender( context, fields );
365 drawGroup( group, context );
389 return QgsRectangle( p->
x() - distance, p->
y() - distance, p->
x() + distance, p->
y() + distance );
392void QgsPointDistanceRenderer::printGroupInfo()
const
396 QgsDebugMsgLevel(
"number of displacement groups:" + QString::number( nGroups ), 3 );
397 for (
int i = 0; i < nGroups; ++i )
399 QgsDebugMsgLevel(
"***************displacement group " + QString::number( i ), 3 );
409QString QgsPointDistanceRenderer::getLabel(
const QgsFeature &feature )
const
412 const QgsAttributes attrs = feature.
attributes();
429 p->setPen( labelPen );
435 pixelSizeFont.setPixelSize(
static_cast< int >( std::round( fontSizeInPixels ) ) );
436 QFont scaledFont = pixelSizeFont;
437 scaledFont.setPixelSize( pixelSizeFont.pixelSize() );
438 p->setFont( scaledFont );
440 const QFontMetricsF fontMetrics( pixelSizeFont );
441 QPointF currentLabelShift;
443 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
444 ClusteredGroup::const_iterator groupIt = group.constBegin();
446 for ( ; labelPosIt != labelShifts.constEnd() && groupIt != group.constEnd(); ++labelPosIt, ++groupIt )
448 currentLabelShift = *labelPosIt;
449 if ( currentLabelShift.x() < 0 )
451 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.horizontalAdvance( groupIt->label ) );
453 if ( currentLabelShift.y() > 0 )
455 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
458 const QPointF drawingPoint( centerPoint + currentLabelShift );
460 p->translate( drawingPoint.x(), drawingPoint.y() );
461 p->drawText( QPointF( 0, 0 ), groupIt->label );
468 if ( group.size() > 1 )
472 ClusteredGroup::const_iterator groupIt = group.constBegin();
473 for ( ; groupIt != group.constEnd(); ++groupIt )
475 if ( !groupIt->symbol() )
478 if ( !groupColor.isValid() )
480 groupColor = groupIt->symbol()->color();
484 if ( groupColor != groupIt->symbol()->color() )
486 groupColor = QColor();
492 if ( groupColor.isValid() )
504 if ( !group.empty() )
507 clusterScope->
setFeature( group.at( 0 ).feature );
520 if ( symbolList.isEmpty() )
525 return dynamic_cast< QgsMarkerSymbol *
>( symbolList.at( 0 ) );
@ Points
Points (e.g., for font sizes).
WkbType
The WKB type describes the number of dimensions a geometry has.
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.
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...
QgsFeatureRenderer(const QString &type)
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...
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.
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...
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.
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.
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...
QFont mLabelFont
Label font.
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...
Point geometry type, with support for z-dimension and m-values.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
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.
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.
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...
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#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)
QList< QgsSymbol * > QgsSymbolList
Contains properties for a feature within a clustered group.
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.
QString label
Optional label text.
QgsMarkerSymbol * symbol() const
Base symbol for rendering feature.
QgsFeature feature
Feature.