16#ifndef QGSRULEBASEDRENDERER_H
17#define QGSRULEBASEDRENDERER_H
106 QList<QgsRuleBasedRenderer::RenderJob *>
jobs;
116 for (
auto it = rh.
jobs.constBegin(); it != rh.
jobs.constEnd(); ++it )
127 for (
auto it = other.
jobs.constBegin(); it != other.
jobs.constEnd(); ++it )
129 jobs << new RenderJob( *( *it ) );
138 typedef QList<QgsRuleBasedRenderer::Rule *>
RuleList;
164 int maximumScale = 0,
165 int minimumScale = 0,
166 const QString &filterExp = QString(),
167 const QString &label = QString(),
168 const QString &description = QString(),
169 bool elseRule =
false
181 QString
dump(
int indent = 0 )
const;
228 QString
label()
const {
return mLabel; }
273 bool active()
const {
return mIsActive; }
312 void setFilterExpression(
const QString &filterExp );
328 std::unique_ptr<QgsRuleBasedRenderer::Rule>
clone()
const;
335 Q_DECL_DEPRECATED
void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props )
const SIP_DEPRECATED;
361 bool hasActiveChildren()
const;
364 QSet<int> collectZLevels();
370 void setNormZLevels(
const QMap<int, int> &zLevelsToNormLevels )
SIP_SKIP;
454 void removeChildAt(
int i );
472 void setIsElse(
bool iselse );
479 bool isElse()
const {
return mElseRule; }
500 Rule *mParent =
nullptr;
501 std::unique_ptr< QgsSymbol > mSymbol;
502 double mMaximumScale = 0;
503 double mMinimumScale = 0;
504 QString mFilterExp, mLabel, mDescription;
505 bool mElseRule =
false;
508 bool mIsActive =
true;
513 std::unique_ptr< QgsExpression >
mFilter;
515 QSet<int> mSymbolNormZLevels;
522 void updateElseRules();
528 static std::unique_ptr<QgsFeatureRenderer> create( QDomElement &element,
const QgsReadWriteContext &context );
544 bool canSkipRender() override;
549 QSet<QString> usedAttributes( const
QgsRenderContext &context ) const override;
551 bool filterNeedsGeometry() const override;
555 Q_DECL_DEPRECATED
void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const override
SIP_DEPRECATED;
556 bool toSld( QDomDocument &doc, QDomElement &element,
QgsSldExportContext &context ) const override;
561 static std::unique_ptr<
QgsFeatureRenderer> createFromSld( QDomElement &element,
Qgis::GeometryType geomType );
566 bool legendSymbolItemsCheckable() const override;
567 bool legendSymbolItemChecked( const QString &key ) override;
568 void checkLegendSymbolItem( const QString &key,
bool state = true ) override;
569 QString legendKeyToExpression( const QString &key,
QgsVectorLayer *layer,
bool &ok ) const override;
572 void setLegendSymbolItemLabel( const QString &key, const QString &label ) override;
574 QString dump() const override;
615 static void convertToDataDefinedSymbology(
QgsSymbol *symbol,
const QString &sizeScaleField,
const QString &rotationField = QString() );
Provides global constants and enumerations for use throughout the application.
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
A feature renderer which represents features using a list of renderer categories.
Custom exception class for Coordinate Reference System related exceptions.
Handles parsing and evaluation of expressions (formerly called "search strings").
Abstract base class for all 2D vector feature renderers.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
QgsFeatureRenderer(const QString &type)
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual Qgis::FeatureRendererFlags flags() const
Returns flags associated with the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QFlags< Capability > Capabilities
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
Stores renderer properties to an XML element.
virtual QString dump() const
Returns debug information about this renderer.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
@ ScaleDependent
Depends on scale if feature will be rendered (rule based ).
@ Filter
Features may be filtered, i.e. some features may not be rendered (categorized, rule based ....
virtual Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
A vector feature renderer which uses numeric attributes to classify features into different ranges.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
Represents an individual rule for a rule-based renderer.
QString ruleKey() const
Unique rule identifier (for identification of rule within renderer).
void setDescription(const QString &description)
Set a human readable description for this rule.
bool dependsOnScale() const
bool needsGeometry() const
Returns true if this rule or one of its children needs the geometry to be applied.
const QgsRuleBasedRenderer::RuleList & children() const
Returns all children rules of this rule.
RenderResult
The result of rendering a rule.
@ Inactive
The rule is inactive.
@ Filtered
The rule does not apply.
@ Rendered
Something was rendered.
double maximumScale() const
Returns the maximum map scale (i.e.
QgsRuleBasedRenderer::Rule * parent()
The parent rule.
bool isElse() const
Check if this rule is an ELSE rule.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
void setActive(bool state)
Sets if this rule is active.
Rule(QgsSymbol *symbol, int maximumScale=0, int minimumScale=0, const QString &filterExp=QString(), const QString &label=QString(), const QString &description=QString(), bool elseRule=false)
Constructor takes ownership of the symbol.
Rule(const Rule &rh)=delete
Rule & operator=(const Rule &rh)=delete
bool isFilterOK(const QgsFeature &f, QgsRenderContext *context=nullptr) const
Check if a given feature shall be rendered by this rule.
bool isScaleOK(double scale) const
Check if this rule applies for a given scale.
QgsExpression * filter() const
A filter that will check if this rule applies.
double minimumScale() const
Returns the minimum map scale (i.e.
QString description() const
A human readable description for this rule.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
void setLabel(const QString &label)
const QgsSymbol * symbol() const
Returns the symbol associated with the rule.
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer).
QString filterExpression() const
A filter that will check if this rule applies.
bool active() const
Returns if this rule is active.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
QList< QgsRuleBasedRenderer::RenderLevel > RenderQueue
Rendering queue: a list of rendering levels.
const QgsRuleBasedRenderer::Rule * rootRule() const
Returns the root rule of the rule-based renderer.
static std::unique_ptr< QgsFeatureRenderer > create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
QString filter(const QgsFields &fields=QgsFields()) override
If a renderer does not require all the features this method may be overridden and return an expressio...
std::unique_ptr< Rule > mRootRule
the root node with hierarchical list of rules
static std::unique_ptr< QgsFeatureRenderer > createFromSld(QDomElement &element, Qgis::GeometryType geomType)
Creates a new rule based renderer from an SLD XML element.
QList< QgsRuleBasedRenderer::Rule * > RuleList
QgsRuleBasedRenderer::Rule * rootRule()
QList< FeatureToRender > mCurrentFeatures
QgsRuleBasedRenderer(QgsRuleBasedRenderer::Rule *root)
Constructs the renderer from given tree of rules (takes ownership).
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.
Represents a vector layer which manages a vector based dataset.
#define SIP_THROW(name,...)
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QMap< QString, QgsSymbol * > QgsSymbolMap
QList< QgsSymbol * > QgsSymbolList
Feature for rendering by a QgsRuleBasedRenderer.
FeatureToRender(const QgsFeature &_f, int _flags)
A QgsRuleBasedRenderer rendering job, consisting of a feature to be rendered with a particular symbol...
RenderJob(const QgsRuleBasedRenderer::FeatureToRender &_ftr, QgsSymbol *_s)
Constructor for a render job, with the specified feature to render and symbol.
QgsRuleBasedRenderer::FeatureToRender ftr
Feature to render.
QgsSymbol * symbol
Symbol to render feature with (not owned by this object).
Render level: a list of jobs to be drawn at particular level for a QgsRuleBasedRenderer.
QList< QgsRuleBasedRenderer::RenderJob * > jobs
List of jobs to render, owned by this object.
QgsRuleBasedRenderer::RenderLevel & operator=(const QgsRuleBasedRenderer::RenderLevel &rh)
RenderLevel(const QgsRuleBasedRenderer::RenderLevel &other)