46 : mParent( 0 ), mSettings( settings )
47 , mScaleMinDenom( scaleMinDenom ), mScaleMaxDenom( scaleMaxDenom )
48 , mFilterExp( filterExp ), mDescription( description )
49 , mElseRule( elseRule )
60 qDeleteAll( mChildren );
66 if ( mSettings == settings )
75 if ( mElseRule || mFilterExp.compare(
"ELSE", Qt::CaseInsensitive ) == 0 )
80 else if ( !mFilterExp.isEmpty() )
94 Q_FOREACH (
Rule* rule, mChildren )
104 mChildren.append( rule );
111 mChildren.insert( i, rule );
118 Rule* rule = mChildren[i];
119 mChildren.removeAt( i );
127 Rule* newrule =
new Rule( s, mScaleMinDenom, mScaleMaxDenom, mFilterExp, mDescription );
130 Q_FOREACH (
Rule* rule, mChildren )
139 if ( !settingsElem.
isNull() )
142 settings->
readXml( settingsElem );
147 int scaleMinDenom = ruleElem.
attribute(
"scalemindenom",
"0" ).
toInt();
148 int scaleMaxDenom = ruleElem.
attribute(
"scalemaxdenom",
"0" ).
toInt();
150 Rule* rule =
new Rule( settings, scaleMinDenom, scaleMaxDenom, filterExp, description );
158 while ( !childRuleElem.
isNull() )
181 ruleElem.
appendChild( mSettings->writeXml( doc ) );
183 if ( !mFilterExp.isEmpty() )
185 if ( mScaleMinDenom != 0 )
186 ruleElem.
setAttribute(
"scalemindenom", mScaleMinDenom );
187 if ( mScaleMaxDenom != 0 )
188 ruleElem.
setAttribute(
"scalemaxdenom", mScaleMaxDenom );
189 if ( !mDescription.isEmpty() )
195 for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it )
209 subProviders[
this] = p;
213 Q_FOREACH (
Rule* rule, mChildren )
224 if ( !p->
prepare( context, attributeNames ) )
226 subProviders.
remove(
this );
233 attributeNames << mFilter->referencedColumns();
238 Q_FOREACH (
Rule* rule, mChildren )
240 rule->
prepare( context, attributeNames, subProviders );
246 if ( !isFilterOK( feature, context )
250 bool registered =
false;
253 if ( subProviders.
contains(
this ) && mIsActive )
255 subProviders[
this]->registerFeature( feature, context );
259 bool willRegisterSomething =
false;
262 Q_FOREACH (
Rule* rule, mChildren )
269 willRegisterSomething |= ( res == Registered || res == Inactive );
270 registered |= willRegisterSomething;
275 if ( !willRegisterSomething )
277 Q_FOREACH (
Rule* rule, mElseRules )
279 registered |= rule->
registerFeature( feature, context, subProviders ) != Filtered;
285 else if ( registered )
293 if ( ! mFilter || mElseRule )
298 return res.
toInt() != 0;
305 if ( mScaleMinDenom == 0 && mScaleMaxDenom == 0 )
307 if ( mScaleMinDenom != 0 && mScaleMinDenom > scale )
309 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.
QList< T > values() const
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
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.
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.
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 createSubProviders(QgsVectorLayer *layer, RuleToProviderMap &subProviders)
add providers
int toInt(bool *ok) const
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)
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context) override
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
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
RegisterResult registerFeature(QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders)
register individual features
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
QDomElement createElement(const QString &tagName)
void removeChildAt(int i)
delete child rule
Represents a vector layer which manages a vector based data sets.
QgsRuleBasedLabelProvider(const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, bool withFeatureLoop=true)
int remove(const Key &key)