30 , mSettings( *layer->diagramLayerSettings() )
31 , mDiagRenderer( layer->diagramRenderer()->clone() )
32 , mFields( layer->fields() )
33 , mLayerCrs( layer->crs() )
35 , mOwnsSource( ownFeatureLoop )
70 QSet<QString> attributeNames;
71 if ( !
prepare( context, attributeNames ) )
72 return QList<QgsLabelFeature *>();
123 for (
int i = 0; i < 4; ++i )
125 centerX += label->
getX( i );
126 centerY += label->
getY( i );
128 QgsPointXY outPt( centerX / 4.0, centerY / 4.0 );
184 if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
186 double maxScale = settingList.at( 0 ).maximumScale;
192 double minScale = settingList.at( 0 ).minimumScale;
217 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
222 if ( preparedGeom->
isNull() )
235 std::unique_ptr<QgsGeometry> scopedObstacleGeom;
246 double diagramWidth = 0;
247 double diagramHeight = 0;
251 if ( diagSize.isValid() )
253 diagramWidth = diagSize.width();
254 diagramHeight = diagSize.height();
275 ddPos = !std::isnan( ddPosX ) && !std::isnan( ddPosY );
286 ddPosX -= diagramWidth / 2.0;
287 ddPosY -= diagramHeight / 2.0;
298 if ( geosObstacleGeomClone )
315 priorityD = qBound( 0.0, priorityD, 10.0 );
316 priorityD = 1 - priorityD / 10.0;
Wrapper for iterator of features from vector data provider or vector layer.
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
A rectangle specified with double values.
y-coordinate data defined diagram position
double rendererScale() const
Returns the renderer map scale.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
QgsPalLayerSettings::Placement mPlacement
Placement strategy.
QgsDiagramRenderer * mDiagRenderer
Diagram renderer instance (owned by mSettings)
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
bool isObstacle() const
Returns whether the feature associated with a diagram acts as an obstacle for other labels or diagram...
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
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...
QgsLabelFeature * feature()
Returns the parent feature.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
const QgsLabelingEngine * mEngine
Associated labeling engine.
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform associated with the layer, or an invalid transform if no transformat...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
double mPriority
Default priority of labels.
void init()
initialization method - called from constructors
QgsDiagramRenderer * renderer()
Returns the diagram renderer associated with the layer.
int priority() const
Returns the diagram priority.
double getY(int i=0) const
Returns the down-left y coordinate.
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
A class to represent a 2D point.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
#define Q_NOWARN_DEPRECATED_PUSH
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
QgsVectorLayerDiagramProvider(QgsVectorLayer *layer, bool ownFeatureLoop=true)
Convenience constructor to initialize the provider from given vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool insertLabel(pal::LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram=false, bool pinned=false, const QString &providerId=QString())
Inserts label position.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the layer's diagrams.
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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...
Z-index for diagram ordering.
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QList< QgsLabelFeature * > mFeatures
List of generated label features (owned by the provider)
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed...
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Diagram priority (between 0 and 10)
QPointF toQPointF() const
Converts a point to a QPointF.
QgsLabelFeature * registerDiagram(QgsFeature &feat, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
helper method to register one diagram feautre
bool mOwnsSource
Whether layer's feature source is owned.
void setIsObstacle(bool enabled)
Sets whether the feature will act as an obstacle for labels.
void setZIndex(double zIndex)
Sets the label's z-index.
const QgsRectangle & extent() const
unsigned int mLinePlacementFlags
Extra placement flags for linestring geometries.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true) ...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
draw this label at the position determined by the labeling engine
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
x-coordinate data defined diagram position
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
Whether diagram features act as obstacles for other diagrams/labels.
QgsFields mFields
Layer's fields.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
const QgsMapToPixel & mapToPixel() const
The QgsAbstractLabelProvider class is an interface class.
double zIndex() const
Returns the diagram z-index.
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
~QgsVectorLayerDiagramProvider() override
Clean up.
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
LinePlacementFlags linePlacementFlags() const
Returns the diagram placement flags.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
QgsExpressionContext & expressionContext()
Gets the expression context.
Stores the settings for rendering of all diagrams for a layer.
Class that adds extra information to QgsLabelFeature for labeling of diagrams.
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...
#define Q_NOWARN_DEPRECATED_POP
Placement
Placement modes which determine how label candidates are generated for a feature. ...
void setValid(bool validity)
Sets the validity of the feature.
Placement placement() const
Returns the diagram placement.
double distance() const
Returns the distance between the diagram and the feature (in mm).
Contains information about the context of a rendering operation.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
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...
QString mName
Name of the layer.
Distance to diagram from feature.
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...
double getX(int i=0) const
Returns the down-left x coordinate.
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement...
QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Returns list of label features (they are owned by the provider and thus deleted on its destruction) ...
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
void setAttributes(const QgsAttributes &attrs)
Store feature's attributes - used for rendering of diagrams.
const QgsMapSettings & mapSettings() const
Gets associated map settings.
QgsLabelingResults * results() const
For internal use by the providers.
LabelPosition is a candidate feature label position.
void setObstacleGeometry(geos::unique_ptr obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry())
Checks whether a geometry requires preparation before registration with PAL.
Whether to show the diagram.
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...
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry())
Prepares a geometry for registration with PAL.
const QgsAttributes & attributes()
Gets feature's attributes - used for rendering of diagrams.
QgsPointXY center() const
Returns the center point of the rectangle.
QgsAbstractFeatureSource * mSource
Layer's feature source.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QString mLayerId
Associated layer's ID, if applicable.
QgsDiagramLayerSettings mSettings
Diagram layer settings.
QgsPointXY toMapCoordinates(int x, int y) const
bool isActive() const
Returns whether the property is currently active.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.
void setPriority(double priority)
Sets the priority for labeling the feature.