QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsAbstractLabelingEngineRuleDistanceFromFeature Class Reference

Base class for labeling engine rules which prevents labels being placed too close or to far from features from a different layer. More...

#include <qgslabelingenginerule_impl.h>

Inheritance diagram for QgsAbstractLabelingEngineRuleDistanceFromFeature:
Inheritance graph
[legend]

Public Member Functions

 QgsAbstractLabelingEngineRuleDistanceFromFeature ()
 
 ~QgsAbstractLabelingEngineRuleDistanceFromFeature () override
 
void alterCandidateCost (pal::LabelPosition *candidate, QgsLabelingEngineContext &context) const override
 Provides an opportunity for the rule to alter the cost for a candidate.
 
bool candidateIsIllegal (const pal::LabelPosition *candidate, QgsLabelingEngineContext &context) const override
 Returns true if a labeling candidate violates the rule and should be eliminated.
 
double cost () const
 Returns the penalty cost incurred when the rule is violated.
 
double distance () const
 Returns the acceptable distance threshold between labels and the features from the targetLayer().
 
Qgis::RenderUnit distanceUnit () const
 Returns the units for the distance between labels and the features from the targetLayer().
 
const QgsMapUnitScaledistanceUnitScale () const
 Returns the scaling for the distance between labels and the features from the targetLayer().
 
bool isAvailable () const override
 Returns true if the rule is available for use within the current QGIS environment.
 
QgsMapLayerlabeledLayer () const
 Returns the layer providing the labels.
 
bool prepare (QgsRenderContext &context) override
 Prepares the rule.
 
void readXml (const QDomElement &element, const QgsReadWriteContext &context) override
 Reads the rule properties from an XML element.
 
void resolveReferences (const QgsProject *project) override
 Resolves reference to layers from stored layer ID.
 
void setCost (double cost)
 Sets the penalty cost incurred when the rule is violated.
 
void setDistance (double distance)
 Sets the acceptable distance threshold between labels and the features from the targetLayer().
 
void setDistanceUnit (Qgis::RenderUnit unit)
 Sets the unit for the distance between labels and the features from the targetLayer().
 
void setDistanceUnitScale (const QgsMapUnitScale &scale)
 Sets the scale for the distance between labels and the features from the targetLayer().
 
void setLabeledLayer (QgsMapLayer *layer)
 Sets the layer providing the labels.
 
void setTargetLayer (QgsVectorLayer *layer)
 Sets the layer providing the features which labels must be distant from (or close to).
 
QgsVectorLayertargetLayer () const
 Returns the layer providing the features which labels must be distant from (or close to).
 
void writeXml (QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const override
 Writes the rule properties to an XML element.
 
- Public Member Functions inherited from QgsAbstractLabelingEngineRule
virtual ~QgsAbstractLabelingEngineRule ()
 
bool active () const
 Returns true if the rule is active.
 
virtual bool candidatesAreConflicting (const pal::LabelPosition *lp1, const pal::LabelPosition *lp2) const
 Returns true if a labeling candidate lp1 conflicts with lp2 after applying the rule.
 
virtual QgsAbstractLabelingEngineRuleclone () const =0
 Creates a clone of this rule.
 
virtual QString description () const
 Returns a user-friendly description of the rule.
 
virtual QString displayType () const =0
 Returns a user-friendly, translated string representing the rule type.
 
virtual QString id () const =0
 Returns a string uniquely identifying the rule subclass.
 
virtual QgsRectangle modifyCandidateConflictSearchBoundingBox (const QgsRectangle &candidateBounds) const
 Returns a (possibly expanded) bounding box to use when searching for conflicts for a candidate.
 
QString name () const
 Returns the name for this instance of the rule.
 
void setActive (bool active)
 Sets whether the rule is active.
 
void setName (const QString &name)
 Sets the name for this instance of the rule.
 

Protected Member Functions

void copyCommonProperties (QgsAbstractLabelingEngineRule *other) const override
 Copies common properties from this object to an other.
 

Protected Attributes

bool mMustBeDistant = true
 true if labels must be distant from features, false if they must be close
 

Detailed Description

Base class for labeling engine rules which prevents labels being placed too close or to far from features from a different layer.

Since
QGIS 3.40

Definition at line 34 of file qgslabelingenginerule_impl.h.

Constructor & Destructor Documentation

◆ QgsAbstractLabelingEngineRuleDistanceFromFeature()

QgsAbstractLabelingEngineRuleDistanceFromFeature::QgsAbstractLabelingEngineRuleDistanceFromFeature ( )
default

◆ ~QgsAbstractLabelingEngineRuleDistanceFromFeature()

QgsAbstractLabelingEngineRuleDistanceFromFeature::~QgsAbstractLabelingEngineRuleDistanceFromFeature ( )
overridedefault

Member Function Documentation

◆ alterCandidateCost()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::alterCandidateCost ( pal::LabelPosition candidate,
QgsLabelingEngineContext context 
) const
overridevirtual

Provides an opportunity for the rule to alter the cost for a candidate.

The default implementation does nothing.

Reimplemented from QgsAbstractLabelingEngineRule.

Definition at line 117 of file qgslabelingenginerule_impl.cpp.

◆ candidateIsIllegal()

bool QgsAbstractLabelingEngineRuleDistanceFromFeature::candidateIsIllegal ( const pal::LabelPosition candidate,
QgsLabelingEngineContext context 
) const
overridevirtual

Returns true if a labeling candidate violates the rule and should be eliminated.

The default implementation returns false.

Reimplemented from QgsAbstractLabelingEngineRule.

Definition at line 100 of file qgslabelingenginerule_impl.cpp.

◆ copyCommonProperties()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::copyCommonProperties ( QgsAbstractLabelingEngineRule other) const
overrideprotectedvirtual

Copies common properties from this object to an other.

Reimplemented from QgsAbstractLabelingEngineRule.

Definition at line 168 of file qgslabelingenginerule_impl.cpp.

◆ cost()

double QgsAbstractLabelingEngineRuleDistanceFromFeature::cost ( ) const
inline

Returns the penalty cost incurred when the rule is violated.

This is a value between 0 and 10, where 10 indicates that the rule must never be violated, and 1-9 = nice to have if possible, where higher numbers will try harder to avoid violating the rule.

See also
setCost()

Definition at line 138 of file qgslabelingenginerule_impl.h.

◆ distance()

double QgsAbstractLabelingEngineRuleDistanceFromFeature::distance ( ) const
inline

Returns the acceptable distance threshold between labels and the features from the targetLayer().

See also
setDistance()
distanceUnit()

Definition at line 83 of file qgslabelingenginerule_impl.h.

◆ distanceUnit()

Qgis::RenderUnit QgsAbstractLabelingEngineRuleDistanceFromFeature::distanceUnit ( ) const
inline

Returns the units for the distance between labels and the features from the targetLayer().

See also
setDistanceUnit()
distance()

Definition at line 101 of file qgslabelingenginerule_impl.h.

◆ distanceUnitScale()

const QgsMapUnitScale & QgsAbstractLabelingEngineRuleDistanceFromFeature::distanceUnitScale ( ) const
inline

Returns the scaling for the distance between labels and the features from the targetLayer().

See also
setDistanceUnitScale()
distance()

Definition at line 119 of file qgslabelingenginerule_impl.h.

◆ isAvailable()

bool QgsAbstractLabelingEngineRuleDistanceFromFeature::isAvailable ( ) const
overridevirtual

Returns true if the rule is available for use within the current QGIS environment.

The base class method returns true.

Rules can return false if required dependencies are not available, e.g. if a library version is too old for the rule.

Reimplemented from QgsAbstractLabelingEngineRule.

Definition at line 139 of file qgslabelingenginerule_impl.cpp.

◆ labeledLayer()

QgsMapLayer * QgsAbstractLabelingEngineRuleDistanceFromFeature::labeledLayer ( ) const

Returns the layer providing the labels.

See also
setLabeledLayer()

Definition at line 148 of file qgslabelingenginerule_impl.cpp.

◆ prepare()

bool QgsAbstractLabelingEngineRuleDistanceFromFeature::prepare ( QgsRenderContext context)
overridevirtual

Prepares the rule.

This must be called on the main render thread, prior to commencing the render operation. Thread sensitive logic (such as creation of feature sources) can be performed in this method.

Implements QgsAbstractLabelingEngineRule.

Definition at line 36 of file qgslabelingenginerule_impl.cpp.

◆ readXml()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::readXml ( const QDomElement &  element,
const QgsReadWriteContext context 
)
overridevirtual

Reads the rule properties from an XML element.

See also
resolveReferences()
writeXml()

Implements QgsAbstractLabelingEngineRule.

Definition at line 71 of file qgslabelingenginerule_impl.cpp.

◆ resolveReferences()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::resolveReferences ( const QgsProject project)
overridevirtual

Resolves reference to layers from stored layer ID.

Should be called following a call readXml().

Reimplemented from QgsAbstractLabelingEngineRule.

Definition at line 94 of file qgslabelingenginerule_impl.cpp.

◆ setCost()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setCost ( double  cost)
inline

Sets the penalty cost incurred when the rule is violated.

This is a value between 0 and 10, where 10 indicates that the rule must never be violated, and 1-9 = nice to have if possible, where higher numbers will try harder to avoid violating the rule.

See also
cost()

Definition at line 148 of file qgslabelingenginerule_impl.h.

◆ setDistance()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setDistance ( double  distance)
inline

Sets the acceptable distance threshold between labels and the features from the targetLayer().

See also
distance()
setDistanceUnit()

Definition at line 92 of file qgslabelingenginerule_impl.h.

◆ setDistanceUnit()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setDistanceUnit ( Qgis::RenderUnit  unit)
inline

Sets the unit for the distance between labels and the features from the targetLayer().

See also
distanceUnit()
setDistance()

Definition at line 110 of file qgslabelingenginerule_impl.h.

◆ setDistanceUnitScale()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setDistanceUnitScale ( const QgsMapUnitScale scale)
inline

Sets the scale for the distance between labels and the features from the targetLayer().

See also
distanceUnitScale()
setDistance()

Definition at line 128 of file qgslabelingenginerule_impl.h.

◆ setLabeledLayer()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setLabeledLayer ( QgsMapLayer layer)

Sets the layer providing the labels.

See also
labeledLayer()

Definition at line 153 of file qgslabelingenginerule_impl.cpp.

◆ setTargetLayer()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::setTargetLayer ( QgsVectorLayer layer)

Sets the layer providing the features which labels must be distant from (or close to).

See also
targetLayer()

Definition at line 163 of file qgslabelingenginerule_impl.cpp.

◆ targetLayer()

QgsVectorLayer * QgsAbstractLabelingEngineRuleDistanceFromFeature::targetLayer ( ) const

Returns the layer providing the features which labels must be distant from (or close to).

See also
setTargetLayer()

Definition at line 158 of file qgslabelingenginerule_impl.cpp.

◆ writeXml()

void QgsAbstractLabelingEngineRuleDistanceFromFeature::writeXml ( QDomDocument &  doc,
QDomElement &  element,
const QgsReadWriteContext context 
) const
overridevirtual

Writes the rule properties to an XML element.

See also
readXml()

Implements QgsAbstractLabelingEngineRule.

Definition at line 48 of file qgslabelingenginerule_impl.cpp.

Member Data Documentation

◆ mMustBeDistant

bool QgsAbstractLabelingEngineRuleDistanceFromFeature::mMustBeDistant = true
protected

true if labels must be distant from features, false if they must be close

Definition at line 155 of file qgslabelingenginerule_impl.h.


The documentation for this class was generated from the following files: