65 , mScaleMinDenom( scaleMinDenom )
66 , mScaleMaxDenom( scaleMaxDenom )
67 , mFilterExp( filterExp )
68 , mDescription( description )
69 , mElseRule( elseRule )
186 if ( !settingsElem.
isNull() )
189 settings->
readXml( settingsElem );
197 Rule* rule =
new Rule( settings, scaleMinDenom, scaleMaxDenom, filterExp, description );
205 while ( !childRuleElem.
isNull() )
256 delete subProviders.
value(
this,
nullptr );
257 subProviders[
this] = p;
272 if ( !p->
prepare( context, attributeNames ) )
274 subProviders.
remove(
this );
288 rule->
prepare( context, attributeNames, subProviders );
298 bool registered =
false;
303 subProviders[
this]->registerFeature( feature, context, obstacleGeometry );
307 bool willRegisterSomething =
false;
318 registered |= willRegisterSomething;
323 if ( !willRegisterSomething )
333 else if ( registered )
346 return res.
toInt() != 0;
379 Q_ASSERT( origDescendants.
count() == clonedDescendants.
count() );
380 for (
int i = 0; i < origDescendants.
count(); ++i )
381 clonedDescendants[i]->setRuleKey( origDescendants[i]->ruleKey() );
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsPalLayerSettings * settings() const
Get the labeling settings.
Something was registered.
double rendererScale() const
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
Factory for label provider implementation.
bool isScaleOK(double scale) const
Check if this rule applies for a given scale.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
void updateElseRules()
Check which child rules are else rules and update the internal list of else rules.
QgsRuleBasedLabeling::RuleToProviderMap mSubProviders
label providers are owned by labeling engine
~QgsRuleBasedLabelProvider()
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames) override
Prepare for registration of features.
QDomNode appendChild(const QDomNode &newChild)
RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra...
int scaleMinDenom() const
The minimum scale at which this label rule should be applied.
QString attribute(const QString &name, const QString &defValue) const
void setTagName(const QString &name)
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool isElse() const
Check if this rule is an ELSE rule.
RegisterResult
The result of registering a rule.
QStringList referencedColumns() const
Get list of columns referenced by the expression.
Rule * clone() const
clone this rule, return new instance
const T & at(int i) const
void prepare(const QgsRenderContext &context, QStringList &attributeNames, RuleToProviderMap &subProviders)
call prepare() on sub-providers and populate attributeNames
QDomElement nextSiblingElement(const QString &tagName) const
QString description() const
A human readable description for this rule.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
A geometry is the spatial representation of a feature.
virtual QList< QgsAbstractLabelProvider * > subProviders() override
return subproviders
QString ruleKey() const
Unique rule identifier (for identification of rule within labeling, used as provider ID) ...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isFilterOK(QgsFeature &f, QgsRenderContext &context) const
Check if a given feature shall be labelled by this rule.
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames)
Prepare for registration of features.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
virtual QgsPalLayerSettings settings(QgsVectorLayer *layer, const QString &providerId=QString()) const override
Get associated label settings.
virtual QDomElement save(QDomDocument &doc) const override
Return labeling configuration as XML element.
static Rule * create(const QDomElement &ruleElem)
Create a rule from an XML definition.
virtual QString type() const override
Unique type string of the labeling configuration implementation.
int count(const T &value) const
virtual QStringList subProviders() const override
Get list of sub-providers within the layer's labeling.
void append(const T &value)
void initFilter()
Initialize filters.
int toInt(bool *ok) const
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
virtual QgsVectorLayerLabelProvider * createProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings)
create a label provider
void setSettings(QgsPalLayerSettings *settings)
set new settings (or NULL). Deletes old settings if any.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop=true, const QgsPalLayerSettings *settings=nullptr, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
void readXml(QDomElement &elem)
Read settings from a DOM element.
const QgsLabelingEngineV2 * mEngine
Associated labeling engine.
void setEngine(const QgsLabelingEngineV2 *engine)
Associate provider with a labeling engine (should be only called internally from QgsLabelingEngineV2)...
QgsRuleBasedLabeling(QgsRuleBasedLabeling::Rule *root)
Constructs the labeling from given tree of rules (takes ownership)
const Rule * findRuleByKey(const QString &key) const
Try to find a rule given its unique key.
QDomElement save(QDomDocument &doc) const
store labeling info to XML element
static QgsRuleBasedLabeling * create(const QDomElement &element)
Create the instance from a DOM element with saved configuration.
void setActive(bool state)
Sets if this rule is active.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based labeling) ...
void subProviderIds(QStringList &list) const
append rule keys of descendants that contain valid settings (i.e. they will be sub-providers) ...
QgsPalLayerSettings * mSettings
Contains information about the context of a rendering operation.
Rule(QgsPalLayerSettings *settings, int scaleMinDenom=0, int scaleMaxDenom=0, const QString &filterExp=QString(), const QString &description=QString(), bool elseRule=false)
takes ownership of settings
void insert(int i, const T &value)
QgsRuleBasedLabeling mRules
owned copy
QDomElement firstChildElement(const QString &tagName) const
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr) override
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
void insertChild(int i, Rule *rule)
add child rule, take ownership, sets this as parent
QDomElement writeXml(QDomDocument &doc)
Write settings into a DOM element.
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e...
void appendChild(Rule *rule)
add child rule, take ownership, sets this as parent
RegisterResult registerFeature(QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, QgsGeometry *obstacleGeometry=nullptr)
register individual features
const_iterator constEnd() const
int scaleMaxDenom() const
The maximum scale denominator at which this label rule should be applied.
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
void removeChildAt(int i)
delete child rule
Represents a vector layer which manages a vector based data sets.
void createSubProviders(QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider)
add providers
int compare(const QString &other) const
QgsRuleBasedLabelProvider(const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, bool withFeatureLoop=true)
const T value(const Key &key) const
int remove(const Key &key)