36 , mSettings( *diagSettings )
37 , mDiagRenderer( diagRenderer->clone() )
41 , mOwnsSource( ownsSource )
49 ,
mSettings( *layer->diagramLayerSettings() )
90 if ( !
prepare( context, attributeNames ) )
139 for (
int i = 0; i < 4; ++i )
141 centerX += label->
getX( i );
142 centerY += label->
getY( i );
144 QgsPoint outPt( centerX / 4.0, centerY / 4.0 );
181 if ( !attributeNames.
contains( field ) )
182 attributeNames << field;
205 if ( !settingList.
isEmpty() && settingList.
at( 0 ).scaleBasedVisibility )
207 double minScale = settingList.
at( 0 ).minScaleDenominator;
213 double maxScale = settingList.
at( 0 ).maxScaleDenominator;
230 const GEOSGeometry* geos_geom =
nullptr;
235 if ( !preparedGeom.
data() )
237 geos_geom = preparedGeom.
data()->asGeos();
241 geos_geom = geom->
asGeos();
249 const GEOSGeometry* geosObstacleGeom =
nullptr;
254 geosObstacleGeom = scopedObstacleGeom.
data()->asGeos();
258 geosObstacleGeom = obstacleGeometry->
asGeos();
260 GEOSGeometry* geosObstacleGeomClone =
nullptr;
261 if ( geosObstacleGeom )
267 double diagramWidth = 0;
268 double diagramHeight = 0;
274 diagramWidth = diagSize.
width();
275 diagramHeight = diagSize.
height();
285 bool ddPos = ( ddColX >= 0 && ddColY >= 0 );
291 if ( !posXOk || !posYOk )
304 ddPosX -= diagramWidth / 2.0;
305 ddPosY -= diagramHeight / 2.0;
317 if ( showOk && ! ddShow )
329 if ( geosObstacleGeomClone )
QgsLabelFeature * registerDiagram(QgsFeature &feat, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
helper method to register one diagram feautre
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
static QgsGeometry * prepareGeometry(const QgsGeometry *geometry, QgsRenderContext &context, const QgsCoordinateTransform *ct, QgsGeometry *clipGeometry=nullptr)
Prepares a geometry for registration with PAL.
double rendererScale() const
QgsPoint center() const
Center point of the rectangle.
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const
Returns size of the diagram for a feature in map units.
QgsAttributes attributes() const
Returns the feature's attributes.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
QgsPalLayerSettings::Placement mPlacement
Placement strategy.
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...
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames)
Prepare for registration of features.
QgsLabelFeature * feature()
Returns the parent feature.
QPointF toQPointF() const
Converts a point to a QPointF.
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
double getZIndex() const
Returns the diagram z-index.
int yPosColumn
Attribute index for y coordinate (or -1 if position not data defined)
double mPriority
Default priority of labels.
void init()
initialization method - called from constructors
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
double getY(int i=0) const
get the down-left y coordinate
const T & at(int i) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
QgsVectorLayerDiagramProvider(QgsVectorLayer *layer, bool ownFeatureLoop=true)
Convenience constructor to initialize the provider from given vector layer.
Container of fields for a vector layer.
QgsPoint toMapCoordinates(int x, int y) const
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.
QgsCoordinateTransform * coordinateTransform()
Returns the coordinate transform associated with the layer.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
QgsDiagramRendererV2 * mDiagRenderer
Diagram renderer instance (owned by mSettings)
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setFixedPosition(const QgsPoint &point)
Set coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
static bool geometryRequiresPreparation(const QgsGeometry *geometry, QgsRenderContext &context, const QgsCoordinateTransform *ct, QgsGeometry *clipGeometry=nullptr)
Checks whether a geometry requires preparation before registration with PAL.
const QgsMapSettings & mapSettings() const
Get associated map settings.
void setAlwaysShow(bool enabled)
Set whether label should be always shown (sets very high label priority)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double y() const
Get the y value of the point.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
void setHasFixedPosition(bool enabled)
Set whether the label should use a fixed position instead of being automatically placed.
The QgsMapSettings class contains configuration for rendering of the map.
QgsPoint transform(const QgsPoint &p) const
Transform the point from map (world) coordinates to device coordinates.
Perform transforms between map coordinates and device coordinates.
bool mOwnsSource
Whether layer's feature source is owned.
int xPosColumn
Attribute index for x coordinate (or -1 if position not data defined)
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.
void setFeatureId(QgsFeatureId id)
Sets the feature ID for this feature.
const QgsRectangle & extent() const
unsigned int mLinePlacementFlags
Extra placement flags for linestring geometries.
~QgsVectorLayerDiagramProvider()
Clean up.
void setFixedAngle(double angle)
Set angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true) ...
const QgsCoordinateTransform * coordinateTransform() const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
draw this label at the position determined by the labeling engine
unsigned int linePlacementFlags() const
Returns the diagram placement flags.
const QgsLabelingEngineV2 * mEngine
Associated labeling engine.
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
Base class that can be used for any class that is capable of returning features.
QgsFields mFields
Layer's fields.
A class to represent a point.
const QgsMapToPixel & mapToPixel() const
Q_DECL_DEPRECATED void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
The QgsAbstractLabelProvider class is an interface class.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures...
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
QgsFeatureId id() const
Get the feature ID for this feature.
QgsLabelingResults * results() const
For internal use by the providers.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsDiagramRendererV2 * getRenderer()
Returns the diagram renderer associated with the layer.
Stores the settings for rendering of all diagrams for a layer.
Class that adds extra information to QgsLabelFeature for labeling of diagrams.
void setCoordinateTransform(QgsCoordinateTransform *transform)
Sets the coordinate transform associated with the layer.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
void setValid(bool validity)
Sets the validity of the feature.
double distance() const
Returns the distance between the diagram and the feature (in mm).
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos) const
Contains information about the context of a rendering operation.
void setRenderer(QgsDiagramRendererV2 *diagramRenderer)
Sets the diagram renderer associated with the layer.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
QString mName
Name of the layer.
double getX(int i=0) const
get the down-left x coordinate
void setHasFixedAngle(bool enabled)
Set whether the label should use a fixed angle instead of using angle from automatic placement...
Placement getPlacement() const
Returns the diagram placement.
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Return list of label features (they are owned by the provider and thus deleted on its destruction) ...
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), const QgsFields &fields=QgsFields()) const
Returns the set of any fields referenced by the layer's diagrams.
void setAttributes(const QgsAttributes &attrs)
Store feature's attributes - used for rendering of diagrams.
const GEOSGeometry * asGeos(double precision=0) const
Returns a geos geometry.
void setObstacleGeometry(GEOSGeometry *obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Class for storing a coordinate reference system (CRS)
int getPriority() const
Returns the diagram priority.
int showColumn
Attribute index for visibility (or -1 if visibility not data defined)
static QgsGeometry * fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
LabelPosition is a candidate feature label position.
double toDouble(bool *ok) const
const QgsAttributes & attributes()
Get feature's attributes - used for rendering of diagrams.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)=0
Get an iterator for features matching the specified request.
QgsAbstractFeatureSource * mSource
Layer's feature source.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString mLayerId
Associated layer's ID, if applicable.
QgsDiagramLayerSettings mSettings
Diagram layer settings.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QList< QgsLabelFeature * > mFeatures
List of generated label features (owned by the provider)
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
double x() const
Get the x value of the point.
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.