QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
28 #include <QDomElement>
35 , mLabelAttributeName( labelAttributeName )
53 Q_UNUSED( drawVertexMarker )
84 label = getLabel( feature );
100 const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( *partIt );
105 if ( intersectList.empty() )
120 double minDist =
mGroupLocations.value( minDistFeatureId ).distance( point->
x(), point->
y() );
121 for (
int i = 1; i < intersectList.count(); ++i )
124 const double newDist =
mGroupLocations.value( candidateId ).distance( point->
x(), point->
y() );
125 if ( newDist < minDist )
128 minDistFeatureId = candidateId;
132 const int groupIdx =
mGroupIndex[ minDistFeatureId ];
138 ( oldCenter.
y() * group.size() + point->
y() ) / ( group.size() + 1.0 ) );
150 void QgsPointDistanceRenderer::drawGroup(
const ClusteredGroup &group,
QgsRenderContext &context )
const
154 const auto constGroup = group;
155 for (
const GroupedFeature &f : constGroup )
157 groupMultiPoint->
addGeometry( f.feature.geometry().constGet()->clone() );
165 drawGroup( pt, context, group );
183 mRenderer->setLegendSymbolItem( key, symbol );
191 return mRenderer->legendSymbolItemsCheckable();
199 return mRenderer->legendSymbolItemChecked( key );
207 mRenderer->checkLegendSymbolItem( key, state );
229 QSet<QString> attributeList;
236 attributeList +=
mRenderer->usedAttributes( context );
238 return attributeList;
250 return Capabilities();
270 return mRenderer->symbolForFeature( feature, context );
277 return mRenderer->originalSymbolForFeature( feature, context );
286 return mRenderer->symbolsForFeature( feature, context );
293 return mRenderer->originalSymbolsForFeature( feature, context );
299 return QSet< QString >() << QString();
300 return mRenderer->legendKeysForFeature( feature, context );
308 return mRenderer->legendKeyToExpression( key, layer, ok );
317 return mRenderer->willRenderFeature( feature, context );
325 mRenderer->startRender( context, fields );
362 drawGroup( group, context );
386 return QgsRectangle( p->
x() - distance, p->
y() - distance, p->
x() + distance, p->
y() + distance );
389 void QgsPointDistanceRenderer::printGroupInfo()
const
393 QgsDebugMsgLevel(
"number of displacement groups:" + QString::number( nGroups ), 3 );
394 for (
int i = 0; i < nGroups; ++i )
396 QgsDebugMsgLevel(
"***************displacement group " + QString::number( i ), 3 );
398 for (
const GroupedFeature &feature : constAt )
406 QString QgsPointDistanceRenderer::getLabel(
const QgsFeature &feature )
const
426 p->setPen( labelPen );
432 pixelSizeFont.setPixelSize(
static_cast< int >( std::round( fontSizeInPixels ) ) );
433 QFont scaledFont = pixelSizeFont;
434 scaledFont.setPixelSize( pixelSizeFont.pixelSize() );
435 p->setFont( scaledFont );
437 const QFontMetricsF fontMetrics( pixelSizeFont );
438 QPointF currentLabelShift;
440 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
441 ClusteredGroup::const_iterator groupIt = group.constBegin();
443 for ( ; labelPosIt != labelShifts.constEnd() && groupIt != group.constEnd(); ++labelPosIt, ++groupIt )
445 currentLabelShift = *labelPosIt;
446 if ( currentLabelShift.x() < 0 )
448 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.horizontalAdvance( groupIt->label ) );
450 if ( currentLabelShift.y() > 0 )
452 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
455 const QPointF drawingPoint( centerPoint + currentLabelShift );
457 p->translate( drawingPoint.x(), drawingPoint.y() );
458 p->drawText( QPointF( 0, 0 ), groupIt->label );
465 if ( group.size() > 1 )
469 ClusteredGroup::const_iterator groupIt = group.constBegin();
470 for ( ; groupIt != group.constEnd(); ++groupIt )
472 if ( !groupIt->symbol() )
475 if ( !groupColor.isValid() )
477 groupColor = groupIt->symbol()->color();
481 if ( groupColor != groupIt->symbol()->color() )
483 groupColor = QColor();
489 if ( groupColor.isValid() )
501 if ( !group.empty() )
504 clusterScope->
setFeature( group.at( 0 ).feature );
517 if ( symbolList.isEmpty() )
527 , isSelected( isSelected )
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
RAII class to pop scope from an expression context on destruction.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
static QString encodeColor(const QColor &color)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QMap< QgsFeatureId, QgsPointXY > mGroupLocations
Mapping of feature ID to approximate group location.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsUnitTypes::RenderUnit mToleranceUnit
Unit for distance tolerance.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Point geometry type, with support for z-dimension and m-values.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
#define QgsDebugMsgLevel(str, level)
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.
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
QString mLabelAttributeName
Attribute name for labeling. An empty string indicates that no labels should be rendered.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
@ RenderPoints
Points (e.g., for font sizes)
Container of fields for a vector layer.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
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...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Abstract base class for all rendered symbols.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
void drawLabels(QPointF centerPoint, QgsSymbolRenderContext &context, const QList< QPointF > &labelShifts, const ClusteredGroup &group) const
Renders the labels for a group.
#define FID_TO_STRING(fid)
QFont mLabelFont
Label font.
A rectangle specified with double values.
double mMinLabelScale
Maximum scale denominator for label display. A zero value indicates no scale limitation.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
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
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
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...
std::unique_ptr< QgsFeatureRenderer > mRenderer
Embedded base renderer. This can be used for rendering individual, isolated points.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsSpatialIndex * mSpatialIndex
Spatial index for fast lookup of nearby points.
QList< ClusteredGroup > mClusteredGroups
Groups of features that are considered clustered together.
int mLabelIndex
Label attribute index (or -1 if none). This index is not stored, it is requested in the startRender()...
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
QList< QgsSymbol * > QgsSymbolList
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
QColor mLabelColor
Label text color.
void checkLegendSymbolItem(const QString &key, bool state) override
item in symbology was checked
Helper functions for various unit types.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
void setEmbeddedRenderer(QgsFeatureRenderer *r) override
Sets an embedded renderer (subrenderer) for this feature renderer.
A spatial index for QgsFeature objects.
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
Scoped object for saving and restoring a QPainter object's state.
QgsPointDistanceRenderer(const QString &rendererName, const QString &labelAttributeName=QString())
Constructor for QgsPointDistanceRenderer.
Multi point geometry collection.
Single scope for storing variables and functions for use within a QgsExpressionContext....
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
A class to represent a 2D point.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
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).
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
bool mDrawLabels
Whether labels should be drawn for points. This is set internally from startRender() depending on sca...
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
A vector of attributes. Mostly equal to QVector<QVariant>.
GroupedFeature(const QgsFeature &feature, QgsMarkerSymbol *symbol, bool isSelected, const QString &label=QString())
Constructor for GroupedFeature.
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...
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QPainter * painter()
Returns the destination QPainter for the render operation.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
double rendererScale() const
Returns the renderer map scale.
Single variable definition for use within a QgsExpressionContextScope.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
QMap< QgsFeatureId, int > mGroupIndex
Mapping of feature ID to the feature's group index.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.
double mTolerance
Distance tolerance. Points that are closer together than this distance are considered clustered.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Contains properties for a feature within a clustered group.