63 : mParent( nullptr ),
mSettings( settings )
64 , mScaleMinDenom( scaleMinDenom ), mScaleMaxDenom( scaleMaxDenom )
65 , mFilterExp( filterExp ), mDescription( description )
66 , mElseRule( elseRule )
155 if ( !settingsElem.
isNull() )
158 settings->
readXml( settingsElem );
166 Rule* rule =
new Rule( settings, scaleMinDenom, scaleMaxDenom, filterExp, description );
174 while ( !childRuleElem.
isNull() )
225 delete subProviders.
value(
this,
nullptr );
226 subProviders[
this] = p;
241 if ( !p->
prepare( context, attributeNames ) )
243 subProviders.
remove(
this );
257 rule->
prepare( context, attributeNames, subProviders );
267 bool registered =
false;
272 subProviders[
this]->registerFeature( feature, context, obstacleGeometry );
276 bool willRegisterSomething =
false;
287 registered |= willRegisterSomething;
292 if ( !willRegisterSomething )
302 else if ( registered )
315 return res.
toInt() != 0;
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)
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
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, bool withFeatureLoop=true, const QgsPalLayerSettings *settings=nullptr, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
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 list of child providers - useful if the provider needs to put labels into more layers with dif...
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)
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.
void append(const T &value)
void initFilter()
Initialize filters.
int toInt(bool *ok) const
virtual QgsVectorLayerLabelProvider * createProvider(QgsVectorLayer *layer, bool withFeatureLoop, const QgsPalLayerSettings *settings)
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
void setSettings(QgsPalLayerSettings *settings)
set new settings (or NULL). Deletes old settings if any.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
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)
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.
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.
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)