15#ifndef QGSRULEBASEDLABELING_H
16#define QGSRULEBASEDLABELING_H
45 typedef QList<QgsRuleBasedLabeling::Rule *>
RuleList;
48 typedef std::vector<std::pair<QgsRuleBasedLabeling::Rule *, QgsVectorLayerLabelProvider *>> RuleToProviderVec;
124 bool active()
const {
return mIsActive; }
131 bool isElse()
const {
return mElseRule; }
164 mFilterExp = filterExp;
235 void removeChildAt(
int i );
283 void subProviderIds( QStringList &list ) const
SIP_SKIP;
300 std::tuple< RegisterResult, QList<
QgsLabelFeature * > > registerFeature(
355 bool isScaleOK(
double scale )
const;
365 void updateElseRules();
368 Rule *mParent =
nullptr;
369 std::unique_ptr<QgsPalLayerSettings> mSettings;
370 double mMaximumScale = 0;
371 double mMinimumScale = 0;
373 QString mDescription;
374 bool mElseRule =
false;
377 bool mIsActive =
true;
379 QString mRuleKey = QUuid::createUuid().toString();
381 std::unique_ptr<QgsExpression> mFilter;
390 const Rule *rootRule() const
SIP_SKIP;
397 QString type() const override;
402 QStringList subProviders() const override;
414 bool requiresAdvancedEffects() const override;
415 bool hasNonDefaultCompositionMode() const override;
416 Q_DECL_DEPRECATED
void toSld( QDomNode &parent, const QVariantMap &properties ) const override
SIP_DEPRECATED;
418 void multiplyOpacity(
double opacityFactor ) override;
449 QList<QgsAbstractLabelProvider *>
subProviders()
override;
453 std::unique_ptr<QgsRuleBasedLabeling>
mRules;
455 std::vector<std::pair<QgsRuleBasedLabeling::Rule *, QgsVectorLayerLabelProvider *>>
mSubProviders;
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e....
virtual QStringList subProviders() const
Gets list of sub-providers within the layer's labeling.
virtual void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString())=0
Set pal settings for a specific provider (takes ownership).
QgsAbstractVectorLayerLabeling()=default
virtual QgsAbstractVectorLayerLabeling * clone() const =0
Returns a new copy of the object.
Handles parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
A geometry is the spatial representation of a feature.
Describes a feature that should be used within the labeling engine.
Contains settings for how a map layer will be labeled.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
Label provider for rule based labeling.
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
std::unique_ptr< QgsRuleBasedLabeling > mRules
owned copy
QList< QgsLabelFeature * > registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr) override
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
QgsRuleBasedLabelProvider(const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, bool withFeatureLoop=true)
std::vector< std::pair< QgsRuleBasedLabeling::Rule *, QgsVectorLayerLabelProvider * > > mSubProviders
label providers are owned by labeling engine
virtual QgsVectorLayerLabelProvider * createProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings)
create a label provider
A child rule for QgsRuleBasedLabeling.
QgsRuleBasedLabeling::RuleList & children()
Returns all children rules of this rule.
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based labeling).
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
Rule(const Rule &rh)=delete
double maximumScale() const
Returns the maximum map scale (i.e.
void setDescription(const QString &description)
Set a human readable description for this rule.
bool dependsOnScale() const
Determines if scale based labeling is active.
const QgsRuleBasedLabeling::RuleList & children() const
Returns all children rules of this rule.
QString filterExpression() const
A filter that will check if this rule applies.
QgsRuleBasedLabeling::Rule * parent()
The parent rule.
const QgsRuleBasedLabeling::Rule * parent() const
The parent rule.
bool active() const
Returns if this rule is active.
QgsPalLayerSettings * settings() const
Returns the labeling settings.
RegisterResult
The result of registering a rule.
@ Inactive
The rule is inactive.
@ Filtered
The rule does not apply.
@ Registered
Something was registered.
void setActive(bool state)
Sets if this rule is active.
bool isElse() const
Check if this rule is an ELSE rule.
Rule(QgsPalLayerSettings *settings, double maximumScale=0, double minimumScale=0, const QString &filterExp=QString(), const QString &description=QString(), bool elseRule=false)
takes ownership of settings, settings may be nullptr
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
Rule & operator=(const Rule &rh)=delete
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
double minimumScale() const
Returns the minimum map scale (i.e.
void setIsElse(bool iselse)
Sets if this rule is an ELSE rule.
QString ruleKey() const
Unique rule identifier (for identification of rule within labeling, used as provider ID).
QString description() const
A human readable description for this rule.
Rule based labeling for a vector layer.
QList< QgsRuleBasedLabeling::Rule * > RuleList
std::unique_ptr< Rule > mRootRule
QStringList subProviders() const override
Gets list of sub-providers within the layer's labeling.
QgsRuleBasedLabeling(QgsRuleBasedLabeling::Rule *root)
Constructs the labeling from given tree of rules (takes ownership).
QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
static QgsRuleBasedLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
bool hasNonDefaultCompositionMode() const override
Returns true the labeling requires a non-default composition mode.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Implements a label provider for vector layers.
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
const QgsPalLayerSettings & settings() const
Returns the layer's settings.
Represents a vector layer which manages a vector based dataset.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).