QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
33 , mSettings( *layer->diagramLayerSettings() )
34 , mDiagRenderer( layer->diagramRenderer()->clone() )
35 , mFields( layer->fields() )
36 , mLayerCrs( layer->
crs() )
38 , mOwnsSource( ownFeatureLoop )
75 QSet<QString> attributeNames;
76 if ( !
prepare( context, attributeNames ) )
77 return QList<QgsLabelFeature *>();
91 if ( featureFilterProvider )
134 for (
int i = 0; i < 4; ++i )
136 centerX += label->
getX( i );
137 centerY += label->
getY( i );
139 QgsPointXY outPt( centerX / 4.0, centerY / 4.0 );
195 if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
197 double maxScale = settingList.at( 0 ).maximumScale;
203 double minScale = settingList.at( 0 ).minimumScale;
251 preparedObstacleGeom = obstacleGeometry;
254 double diagramWidth = 0;
255 double diagramHeight = 0;
259 if ( diagSize.isValid() )
261 diagramWidth = diagSize.width();
262 diagramHeight = diagSize.height();
283 ddPos = !std::isnan( ddPosX ) && !std::isnan( ddPosY );
294 ddPosX -= diagramWidth / 2.0;
295 ddPosY -= diagramHeight / 2.0;
316 priorityD = std::clamp( priorityD, 0.0, 10.0 );
317 priorityD = 1 - priorityD / 10.0;
bool isActive() const
Returns whether the property is currently active.
double distance(double x, double y) const SIP_HOLDGIL
Returns the distance between this point and a specified x, y coordinate.
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
bool isObstacle() const
Returns whether the feature associated with a diagram acts as an obstacle for other labels or diagram...
double getY(int i=0) const
Returns the down-left y coordinate.
RAII class to pop scope from an expression context on destruction.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
void setPriority(double priority)
Sets the priority for labeling the feature.
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsDiagramLayerSettings mSettings
Diagram layer settings.
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform associated with the layer, or an invalid transform if no transformat...
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
QgsExpressionContext & expressionContext()
Gets the expression context.
int priority() const
Returns the diagram priority.
void init()
initialization method - called from constructors
QgsDiagramRenderer * renderer()
Returns the diagram renderer associated with the layer.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
QgsDiagramRenderer * mDiagRenderer
Diagram renderer instance (owned by mSettings)
std::unique_ptr< QgsExpressionContextScope > mLayerScope
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
const QgsCoordinateReferenceSystem & crs
QString mName
Name of the layer.
LabelPosition is a candidate feature label position.
QgsVectorLayerDiagramProvider(QgsVectorLayer *layer, bool ownFeatureLoop=true)
Convenience constructor to initialize the provider from given vector layer.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Prepares a geometry for registration with PAL.
Contains information about the context of a rendering operation.
QPointF toQPointF() const
Converts a point to a QPointF.
Class that adds extra information to QgsLabelFeature for labeling of diagrams.
QgsLabelFeature * registerDiagram(const QgsFeature &feat, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
helper method to register one diagram feature
void setIsObstacle(bool isObstacle)
Sets whether features are obstacles to labels of other layers.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Contains settings related to how the label engine treats features as obstacles.
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const
Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
@ Show
Whether to show the diagram.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the layer's diagrams.
A rectangle specified with double values.
FeaturePart * getFeaturePart() const
Returns the feature corresponding to this labelposition.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
@ PositionY
Y-coordinate data defined diagram position.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
@ ZIndex
Z-index for diagram ordering.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
This class wraps a request for features to a vector layer (or directly its vector data provider).
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
virtual void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &featureRequest) const =0
Add additional filters to the feature request to further restrict the features returned by the reques...
QString mLayerId
Associated layer's ID, if applicable.
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Checks whether a geometry requires preparation before registration with PAL.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
The QgsAbstractLabelProvider class is an interface class. Implementations return list of labels and t...
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos, const QgsPropertyCollection &properties=QgsPropertyCollection()) const
Renders the diagram for a specified feature at a specific position in the passed render context.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
bool mOwnsSource
Whether layer's feature source is owned.
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw this label at the position determined by the labeling engine.
@ Distance
Distance to diagram from feature.
void setClipFeatureGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features to when registering them as diagrams.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
void setZIndex(double zIndex)
Sets the label's z-index.
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement.
QList< QgsLabelFeature * > mFeatures
List of generated label features (owned by the provider)
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
QgsFields mFields
Layer's fields.
Stores the settings for rendering of all diagrams for a layer.
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsFeature feature() const
Returns the original feature associated with this label.
Qgis::LabelPlacement mPlacement
Placement strategy.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
const QgsLabelingEngine * mEngine
Associated labeling engine.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Placement placement() const
Returns the diagram placement.
Single scope for storing variables and functions for use within a QgsExpressionContext....
double zIndex() const
Returns the diagram z-index.
QgsWeakMapLayerPointer mLayer
Weak pointer to source layer.
A class to represent a 2D point.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
const QgsMapSettings & mapSettings() const
Gets associated map settings.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
Perform transforms between map coordinates and device coordinates.
double distance() const
Returns the distance between the diagram and the feature (in mm).
QgsLabelingResults * results() const
For internal use by the providers.
Represents a vector layer which manages a vector based data sets.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
double getX(int i=0) const
Returns the down-left x coordinate.
Partial snapshot of vector layer's state (only the members necessary for access to features)
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
~QgsVectorLayerDiagramProvider() override
Clean up.
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
QgsGeometry mLabelClipFeatureGeom
Abstract interface for use by classes that filter the features or attributes of a layer.
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
QgsAbstractFeatureSource * mSource
Layer's feature source.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
The QgsLabelFeature class describes a feature that should be used within the labeling engine....
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
@ PositionX
X-coordinate data defined diagram position.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
double rendererScale() const
Returns the renderer map scale.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QgsLabelFeature * feature()
Returns the parent feature.
QgsWkbTypes::GeometryType type
Wrapper for iterator of features from vector data provider or vector layer.
QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Returns list of label features (they are owned by the provider and thus deleted on its destruction)
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
const QgsMapToPixel & mapToPixel() const
@ Priority
Diagram priority (between 0 and 10)
double mPriority
Default priority of labels.
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.