63 : mParent( nullptr ), mSettings( settings )
64 , mScaleMinDenom( scaleMinDenom ), mScaleMaxDenom( scaleMaxDenom )
65 , mFilterExp( filterExp ), mDescription( description )
66 , mElseRule( elseRule )
77 qDeleteAll( mChildren );
83 if ( mSettings == settings )
92 if ( mElseRule || mFilterExp.compare(
"ELSE", Qt::CaseInsensitive ) == 0 )
97 else if ( !mFilterExp.isEmpty() )
111 Q_FOREACH (
Rule* rule, mChildren )
121 mChildren.append( rule );
128 mChildren.insert( i, rule );
135 delete mChildren.at( i );
136 mChildren.removeAt( i );
143 Rule* newrule =
new Rule( s, mScaleMinDenom, mScaleMaxDenom, mFilterExp, mDescription );
146 Q_FOREACH (
Rule* rule, mChildren )
155 if ( !settingsElem.
isNull() )
158 settings->
readXml( settingsElem );
163 int scaleMinDenom = ruleElem.
attribute(
"scalemindenom",
"0" ).
toInt();
164 int scaleMaxDenom = ruleElem.
attribute(
"scalemaxdenom",
"0" ).
toInt();
166 Rule* rule =
new Rule( settings, scaleMinDenom, scaleMaxDenom, filterExp, description );
174 while ( !childRuleElem.
isNull() )
197 ruleElem.
appendChild( mSettings->writeXml( doc ) );
199 if ( !mFilterExp.isEmpty() )
201 if ( mScaleMinDenom != 0 )
202 ruleElem.
setAttribute(
"scalemindenom", mScaleMinDenom );
203 if ( mScaleMaxDenom != 0 )
204 ruleElem.
setAttribute(
"scalemaxdenom", mScaleMaxDenom );
205 if ( !mDescription.isEmpty() )
211 for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it )
225 delete subProviders.
value(
this,
nullptr );
226 subProviders[
this] = p;
230 Q_FOREACH (
Rule* rule, mChildren )
241 if ( !p->
prepare( context, attributeNames ) )
243 subProviders.
remove(
this );
250 attributeNames << mFilter->referencedColumns();
255 Q_FOREACH (
Rule* rule, mChildren )
257 rule->
prepare( context, attributeNames, subProviders );
263 if ( !isFilterOK( feature, context )
267 bool registered =
false;
270 if ( subProviders.
contains(
this ) && mIsActive )
272 subProviders[
this]->registerFeature( feature, context, obstacleGeometry );
276 bool willRegisterSomething =
false;
279 Q_FOREACH (
Rule* rule, mChildren )
286 willRegisterSomething |= ( res == Registered || res == Inactive );
287 registered |= willRegisterSomething;
292 if ( !willRegisterSomething )
294 Q_FOREACH (
Rule* rule, mElseRules )
296 registered |= rule->
registerFeature( feature, context, subProviders, obstacleGeometry ) != Filtered;
302 else if ( registered )
310 if ( ! mFilter || mElseRule )
315 return res.
toInt() != 0;
322 if ( mScaleMinDenom == 0 && mScaleMaxDenom == 0 )
324 if ( mScaleMinDenom != 0 && mScaleMinDenom > scale )
326 if ( mScaleMaxDenom != 0 && mScaleMaxDenom < scale )
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
Factory for label provider implementation.
bool isElse() const
Check if this rule is an ELSE rule.
bool contains(const Key &key) const
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)
bool isFilterOK(QgsFeature &f, QgsRenderContext &context) const
Check if a given feature shall be labelled by this rule.
QString attribute(const QString &name, const QString &defValue) const
void setTagName(const QString &name)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QDomElement save(QDomDocument &doc) const
store labeling info to XML element
RegisterResult
The result of registering a rule.
double rendererScale() 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
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...
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 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.
bool isScaleOK(double scale) const
Check if this rule applies for a given scale.
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)
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.
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
Rule * clone() const
clone this rule, return new instance
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
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
QDomElement createElement(const QString &tagName)
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
QgsRuleBasedLabelProvider(const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, bool withFeatureLoop=true)
const T value(const Key &key) const
int remove(const Key &key)