QGIS API Documentation  3.6.0-Noosa (5873452)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
QgsRuleBasedRenderer Class Reference

When drawing a vector layer with rule-based renderer, it goes through the rules and draws features with symbols from rules that match. More...

#include <qgsrulebasedrenderer.h>

Inheritance diagram for QgsRuleBasedRenderer:
Inheritance graph
[legend]

Classes

struct  FeatureToRender
 Feature for rendering by a QgsRuleBasedRenderer. More...
 
struct  RenderJob
 A QgsRuleBasedRenderer rendering job, consisting of a feature to be rendered with a particular symbol. More...
 
struct  RenderLevel
 Render level: a list of jobs to be drawn at particular level for a QgsRuleBasedRenderer. More...
 
class  Rule
 This class keeps data about a rules for rule-based renderer. More...
 

Public Types

enum  FeatureFlags { FeatIsSelected = 1, FeatDrawMarkers = 2 }
 
typedef QList< QgsRuleBasedRenderer::RenderLevelRenderQueue
 Rendering queue: a list of rendering levels. More...
 
typedef QList< QgsRuleBasedRenderer::Rule * > RuleList
 
- Public Types inherited from QgsFeatureRenderer
enum  Capability { SymbolLevels = 1, MoreSymbolsPerFeature = 1 << 2, Filter = 1 << 3, ScaleDependent = 1 << 4 }
 Used to specify details about a renderer. More...
 

Public Member Functions

 QgsRuleBasedRenderer (QgsRuleBasedRenderer::Rule *root)
 Constructs the renderer from given tree of rules (takes ownership) More...
 
 QgsRuleBasedRenderer (QgsSymbol *defaultSymbol)
 Constructor for convenience. Creates a root rule and adds a default rule with symbol (takes ownership) More...
 
 ~QgsRuleBasedRenderer () override
 
QgsFeatureRenderer::Capabilities capabilities () override
 Returns details about internals of this renderer. More...
 
void checkLegendSymbolItem (const QString &key, bool state=true) override
 item in symbology was checked More...
 
QgsRuleBasedRendererclone () const override
 Create a deep copy of this renderer. More...
 
QString dump () const override
 Returns debug information about this renderer. More...
 
QString filter (const QgsFields &fields=QgsFields()) override
 If a renderer does not require all the features this method may be overridden and return an expression used as where clause. More...
 
bool filterNeedsGeometry () const override
 Returns true if this renderer requires the geometry to apply the filter. More...
 
QSet< QString > legendKeysForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns legend keys matching a specified feature. More...
 
bool legendSymbolItemChecked (const QString &key) override
 items of symbology items in legend is checked More...
 
QgsLegendSymbolList legendSymbolItems () const override
 Returns a list of symbology items for the legend. More...
 
bool legendSymbolItemsCheckable () const override
 items of symbology items in legend should be checkable More...
 
QgsSymbolList originalSymbolsForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbols per feature - similar to symbolsForFeature() More...
 
bool renderFeature (const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
 Render a feature using this renderer in the given context. More...
 
QgsRuleBasedRenderer::RulerootRule ()
 
QDomElement save (QDomDocument &doc, const QgsReadWriteContext &context) override
 store renderer info to XML element More...
 
void setLegendSymbolItem (const QString &key, QgsSymbol *symbol) override
 Sets the symbol to be used for a legend symbol item. More...
 
void startRender (QgsRenderContext &context, const QgsFields &fields) override
 Must be called when a new render cycle is started. More...
 
void stopRender (QgsRenderContext &context) override
 Must be called when a render cycle has finished, to allow the renderer to clean up. More...
 
QgsSymbolsymbolForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns symbol for current feature. Should not be used individually: there could be more symbols for a feature. More...
 
QgsSymbolList symbols (QgsRenderContext &context) const override
 Returns list of symbols used by the renderer. More...
 
QgsSymbolList symbolsForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns list of symbols used for rendering the feature. More...
 
void toSld (QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
 used from subclasses to create SLD Rule elements following SLD v1.1 specs More...
 
QSet< QString > usedAttributes (const QgsRenderContext &context) const override
 Returns a list of attributes required by this renderer. More...
 
bool willRenderFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns whether the renderer will render a feature or not. More...
 
- Public Member Functions inherited from QgsFeatureRenderer
virtual ~QgsFeatureRenderer ()
 
virtual const QgsFeatureRendererembeddedRenderer () const
 Returns the current embedded renderer (subrenderer) for this feature renderer. More...
 
bool forceRasterRender () const
 Returns whether the renderer must render as a raster. More...
 
virtual QString legendClassificationAttribute () const
 If supported by the renderer, return classification attribute for the use in legend. More...
 
virtual void modifyRequestExtent (QgsRectangle &extent, QgsRenderContext &context)
 Allows for a renderer to modify the extent of a feature request prior to rendering. More...
 
QgsFeatureRequest::OrderBy orderBy () const
 Gets the order in which features shall be processed by this renderer. More...
 
bool orderByEnabled () const
 Returns whether custom ordering will be applied before features are processed by this renderer. More...
 
virtual QgsSymboloriginalSymbolForFeature (const QgsFeature &feature, QgsRenderContext &context) const
 Returns symbol for feature. More...
 
QgsPaintEffectpaintEffect () const
 Returns the current paint effect for the renderer. More...
 
virtual void setEmbeddedRenderer (QgsFeatureRenderer *subRenderer)
 Sets an embedded renderer (subrenderer) for this feature renderer. More...
 
void setForceRasterRender (bool forceRaster)
 Sets whether the renderer should be rendered to a raster destination. More...
 
void setOrderBy (const QgsFeatureRequest::OrderBy &orderBy)
 Define the order in which features shall be processed by this renderer. More...
 
void setOrderByEnabled (bool enabled)
 Sets whether custom ordering should be applied before features are processed by this renderer. More...
 
void setPaintEffect (QgsPaintEffect *effect)
 Sets the current paint effect for the renderer. More...
 
void setUsingSymbolLevels (bool usingSymbolLevels)
 
void setVertexMarkerAppearance (int type, double size)
 Sets type and size of editing vertex markers for subsequent rendering. More...
 
QString type () const
 
bool usingSymbolLevels () const
 
virtual QDomElement writeSld (QDomDocument &doc, const QString &styleName, const QgsStringMap &props=QgsStringMap()) const
 create the SLD UserStyle element following the SLD v1.1 specs with the given name More...
 

Static Public Member Functions

static QgsRuleBasedRendererconvertFromRenderer (const QgsFeatureRenderer *renderer)
 creates a QgsRuleBasedRenderer from an existing renderer. More...
 
static void convertToDataDefinedSymbology (QgsSymbol *symbol, const QString &sizeScaleField, const QString &rotationField=QString())
 helper function to convert the size scale and rotation fields present in some other renderers to data defined symbology More...
 
static QgsFeatureRenderercreate (QDomElement &element, const QgsReadWriteContext &context)
 Creates a new rule-based renderer instance from XML. More...
 
static QgsFeatureRenderercreateFromSld (QDomElement &element, QgsWkbTypes::GeometryType geomType)
 
static void refineRuleCategories (QgsRuleBasedRenderer::Rule *initialRule, QgsCategorizedSymbolRenderer *r)
 take a rule and create a list of new rules based on the categories from categorized symbol renderer More...
 
static void refineRuleRanges (QgsRuleBasedRenderer::Rule *initialRule, QgsGraduatedSymbolRenderer *r)
 take a rule and create a list of new rules based on the ranges from graduated symbol renderer More...
 
static void refineRuleScales (QgsRuleBasedRenderer::Rule *initialRule, QList< int > scales)
 take a rule and create a list of new rules with intervals of scales given by the passed scale denominators More...
 
- Static Public Member Functions inherited from QgsFeatureRenderer
static QgsFeatureRendererdefaultRenderer (QgsWkbTypes::GeometryType geomType)
 Returns a new renderer - used by default in vector layers. More...
 
static QgsFeatureRendererload (QDomElement &symbologyElem, const QgsReadWriteContext &context)
 create a renderer from XML element More...
 
static QgsFeatureRendererloadSld (const QDomNode &node, QgsWkbTypes::GeometryType geomType, QString &errorMessage)
 Create a new renderer according to the information contained in the UserStyle element of a SLD style document. More...
 

Protected Attributes

QList< FeatureToRendermCurrentFeatures
 
QString mFilter
 
RenderQueue mRenderQueue
 
RulemRootRule = nullptr
 the root node with hierarchical list of rules More...
 
- Protected Attributes inherited from QgsFeatureRenderer
double mCurrentVertexMarkerSize
 The current size of editing marker. More...
 
int mCurrentVertexMarkerType
 The current type of editing marker. More...
 
bool mForceRaster
 
QgsFeatureRequest::OrderBy mOrderBy
 
bool mOrderByEnabled
 
QgsPaintEffectmPaintEffect = nullptr
 
QString mType
 
bool mUsingSymbolLevels
 

Additional Inherited Members

- Protected Member Functions inherited from QgsFeatureRenderer
 QgsFeatureRenderer (const QString &type)
 
void copyRendererData (QgsFeatureRenderer *destRenderer) const
 Clones generic renderer data to another renderer. More...
 
void renderFeatureWithSymbol (const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
 Render the feature with the symbol using context. More...
 
void renderVertexMarker (QPointF pt, QgsRenderContext &context)
 render editing vertex marker at specified point More...
 
void renderVertexMarkerPolygon (QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
 render editing vertex marker for a polygon More...
 
void renderVertexMarkerPolyline (QPolygonF &pts, QgsRenderContext &context)
 render editing vertex marker for a polyline More...
 
- Static Protected Member Functions inherited from QgsFeatureRenderer
static QPointF _getPoint (QgsRenderContext &context, const QgsPoint &point)
 Creates a point in screen coordinates from a wkb string in map coordinates. More...
 
static void convertSymbolRotation (QgsSymbol *symbol, const QString &field)
 
static void convertSymbolSizeScale (QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
 

Detailed Description

When drawing a vector layer with rule-based renderer, it goes through the rules and draws features with symbols from rules that match.

Definition at line 37 of file qgsrulebasedrenderer.h.

Member Typedef Documentation

◆ RenderQueue

Rendering queue: a list of rendering levels.

Definition at line 117 of file qgsrulebasedrenderer.h.

◆ RuleList

Definition at line 119 of file qgsrulebasedrenderer.h.

Member Enumeration Documentation

◆ FeatureFlags

Enumerator
FeatIsSelected 
FeatDrawMarkers 

Definition at line 42 of file qgsrulebasedrenderer.h.

Constructor & Destructor Documentation

◆ QgsRuleBasedRenderer() [1/2]

QgsRuleBasedRenderer::QgsRuleBasedRenderer ( QgsRuleBasedRenderer::Rule root)

Constructs the renderer from given tree of rules (takes ownership)

Definition at line 857 of file qgsrulebasedrenderer.cpp.

◆ QgsRuleBasedRenderer() [2/2]

QgsRuleBasedRenderer::QgsRuleBasedRenderer ( QgsSymbol defaultSymbol)

Constructor for convenience. Creates a root rule and adds a default rule with symbol (takes ownership)

Definition at line 863 of file qgsrulebasedrenderer.cpp.

◆ ~QgsRuleBasedRenderer()

QgsRuleBasedRenderer::~QgsRuleBasedRenderer ( )
override

Definition at line 870 of file qgsrulebasedrenderer.cpp.

Member Function Documentation

◆ capabilities()

QgsFeatureRenderer::Capabilities QgsRuleBasedRenderer::capabilities ( )
inlineoverridevirtual

Returns details about internals of this renderer.

E.g. if you only want to deal with visible features:

if not renderer.capabilities().testFlag(QgsFeatureRenderer.Filter) or renderer.willRenderFeature(feature, context):
deal_with_my_feature()
else:
skip_the_curren_feature()

Reimplemented from QgsFeatureRenderer.

Definition at line 511 of file qgsrulebasedrenderer.h.

◆ checkLegendSymbolItem()

void QgsRuleBasedRenderer::checkLegendSymbolItem ( const QString &  key,
bool  state = true 
)
overridevirtual

item in symbology was checked

Since
QGIS 2.5

Reimplemented from QgsFeatureRenderer.

Definition at line 1054 of file qgsrulebasedrenderer.cpp.

◆ clone()

QgsRuleBasedRenderer * QgsRuleBasedRenderer::clone ( ) const
overridevirtual

Create a deep copy of this renderer.

Should be implemented by all subclasses and generate a proper subclass.

Returns
A copy of this renderer

Implements QgsFeatureRenderer.

Definition at line 982 of file qgsrulebasedrenderer.cpp.

◆ convertFromRenderer()

QgsRuleBasedRenderer * QgsRuleBasedRenderer::convertFromRenderer ( const QgsFeatureRenderer renderer)
static

creates a QgsRuleBasedRenderer from an existing renderer.

Returns
a new renderer if the conversion was possible, otherwise 0.
Since
QGIS 2.5

Definition at line 1240 of file qgsrulebasedrenderer.cpp.

◆ convertToDataDefinedSymbology()

void QgsRuleBasedRenderer::convertToDataDefinedSymbology ( QgsSymbol symbol,
const QString &  sizeScaleField,
const QString &  rotationField = QString() 
)
static

helper function to convert the size scale and rotation fields present in some other renderers to data defined symbology

Definition at line 1422 of file qgsrulebasedrenderer.cpp.

◆ create()

QgsFeatureRenderer * QgsRuleBasedRenderer::create ( QDomElement &  element,
const QgsReadWriteContext context 
)
static

Creates a new rule-based renderer instance from XML.

Definition at line 1076 of file qgsrulebasedrenderer.cpp.

◆ createFromSld()

QgsFeatureRenderer * QgsRuleBasedRenderer::createFromSld ( QDomElement &  element,
QgsWkbTypes::GeometryType  geomType 
)
static

Definition at line 1099 of file qgsrulebasedrenderer.cpp.

◆ dump()

QString QgsRuleBasedRenderer::dump ( ) const
overridevirtual

Returns debug information about this renderer.

Reimplemented from QgsFeatureRenderer.

Definition at line 1213 of file qgsrulebasedrenderer.cpp.

◆ filter()

QString QgsRuleBasedRenderer::filter ( const QgsFields fields = QgsFields())
overridevirtual

If a renderer does not require all the features this method may be overridden and return an expression used as where clause.

This will be called once after startRender() and before the first call to renderFeature(). By default this returns a null string and all features will be requested. You do not need to specify the extent in here, this is taken care of separately and will be combined with a filter returned from this method.

Returns
An expression used as where clause

Reimplemented from QgsFeatureRenderer.

Definition at line 967 of file qgsrulebasedrenderer.cpp.

◆ filterNeedsGeometry()

bool QgsRuleBasedRenderer::filterNeedsGeometry ( ) const
overridevirtual

Returns true if this renderer requires the geometry to apply the filter.

Reimplemented from QgsFeatureRenderer.

Definition at line 977 of file qgsrulebasedrenderer.cpp.

◆ legendKeysForFeature()

QSet< QString > QgsRuleBasedRenderer::legendKeysForFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Returns legend keys matching a specified feature.

Since
QGIS 2.14

Reimplemented from QgsFeatureRenderer.

Definition at line 1235 of file qgsrulebasedrenderer.cpp.

◆ legendSymbolItemChecked()

bool QgsRuleBasedRenderer::legendSymbolItemChecked ( const QString &  key)
overridevirtual

items of symbology items in legend is checked

Since
QGIS 2.5

Reimplemented from QgsFeatureRenderer.

Definition at line 1048 of file qgsrulebasedrenderer.cpp.

◆ legendSymbolItems()

QgsLegendSymbolList QgsRuleBasedRenderer::legendSymbolItems ( ) const
overridevirtual

Returns a list of symbology items for the legend.

Since
QGIS 2.6

Reimplemented from QgsFeatureRenderer.

Definition at line 1070 of file qgsrulebasedrenderer.cpp.

◆ legendSymbolItemsCheckable()

bool QgsRuleBasedRenderer::legendSymbolItemsCheckable ( ) const
overridevirtual

items of symbology items in legend should be checkable

Since
QGIS 2.5

Reimplemented from QgsFeatureRenderer.

Definition at line 1043 of file qgsrulebasedrenderer.cpp.

◆ originalSymbolsForFeature()

QgsSymbolList QgsRuleBasedRenderer::originalSymbolsForFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()

Since
QGIS 2.12

Reimplemented from QgsFeatureRenderer.

Definition at line 1230 of file qgsrulebasedrenderer.cpp.

◆ refineRuleCategories()

void QgsRuleBasedRenderer::refineRuleCategories ( QgsRuleBasedRenderer::Rule initialRule,
QgsCategorizedSymbolRenderer r 
)
static

take a rule and create a list of new rules based on the categories from categorized symbol renderer

Definition at line 1133 of file qgsrulebasedrenderer.cpp.

◆ refineRuleRanges()

void QgsRuleBasedRenderer::refineRuleRanges ( QgsRuleBasedRenderer::Rule initialRule,
QgsGraduatedSymbolRenderer r 
)
static

take a rule and create a list of new rules based on the ranges from graduated symbol renderer

Definition at line 1163 of file qgsrulebasedrenderer.cpp.

◆ refineRuleScales()

void QgsRuleBasedRenderer::refineRuleScales ( QgsRuleBasedRenderer::Rule initialRule,
QList< int >  scales 
)
static

take a rule and create a list of new rules with intervals of scales given by the passed scale denominators

Definition at line 1194 of file qgsrulebasedrenderer.cpp.

◆ renderFeature()

bool QgsRuleBasedRenderer::renderFeature ( const QgsFeature feature,
QgsRenderContext context,
int  layer = -1,
bool  selected = false,
bool  drawVertexMarker = false 
)
overridevirtual

Render a feature using this renderer in the given context.

Must be called between startRender() and stopRender() calls. Default implementation renders a symbol as determined by symbolForFeature() call. Returns true if the feature has been returned (this is used for example to determine whether the feature may be labelled).

If layer is not -1, the renderer should draw only a particula layer from symbols (in order to support symbol level rendering).

See also
startRender()
stopRender()

Reimplemented from QgsFeatureRenderer.

Definition at line 882 of file qgsrulebasedrenderer.cpp.

◆ rootRule()

QgsRuleBasedRenderer::Rule* QgsRuleBasedRenderer::rootRule ( )
inline

Definition at line 515 of file qgsrulebasedrenderer.h.

◆ save()

QDomElement QgsRuleBasedRenderer::save ( QDomDocument &  doc,
const QgsReadWriteContext context 
)
overridevirtual

store renderer info to XML element

Reimplemented from QgsFeatureRenderer.

Definition at line 1013 of file qgsrulebasedrenderer.cpp.

◆ setLegendSymbolItem()

void QgsRuleBasedRenderer::setLegendSymbolItem ( const QString &  key,
QgsSymbol symbol 
)
overridevirtual

Sets the symbol to be used for a legend symbol item.

Parameters
keyrule key for legend symbol
symbolnew symbol for legend item. Ownership is transferred to renderer.
Since
QGIS 2.14

Reimplemented from QgsFeatureRenderer.

Definition at line 1061 of file qgsrulebasedrenderer.cpp.

◆ startRender()

void QgsRuleBasedRenderer::startRender ( QgsRenderContext context,
const QgsFields fields 
)
overridevirtual

Must be called when a new render cycle is started.

A call to startRender() must always be followed by a corresponding call to stopRender() after all features have been rendered.

Parameters
contextAdditional information passed to the renderer about the job which will be rendered
fieldsThe fields available for rendering
See also
stopRender()
Warning
This method is not thread safe. Before calling startRender() in a non-main thread, the renderer should instead be cloned and startRender()/stopRender() called on the clone.

Reimplemented from QgsFeatureRenderer.

Definition at line 898 of file qgsrulebasedrenderer.cpp.

◆ stopRender()

void QgsRuleBasedRenderer::stopRender ( QgsRenderContext context)
overridevirtual

Must be called when a render cycle has finished, to allow the renderer to clean up.

Calls to stopRender() must always be preceded by a call to startRender().

Warning
This method is not thread safe. Before calling startRender() in a non-main thread, the renderer should instead be cloned and startRender()/stopRender() called on the clone.
See also
startRender()

Reimplemented from QgsFeatureRenderer.

Definition at line 923 of file qgsrulebasedrenderer.cpp.

◆ symbolForFeature()

QgsSymbol * QgsRuleBasedRenderer::symbolForFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Returns symbol for current feature. Should not be used individually: there could be more symbols for a feature.

Implements QgsFeatureRenderer.

Definition at line 876 of file qgsrulebasedrenderer.cpp.

◆ symbols()

QgsSymbolList QgsRuleBasedRenderer::symbols ( QgsRenderContext context) const
overridevirtual

Returns list of symbols used by the renderer.

Parameters
contextrender context
Since
QGIS 2.12

Reimplemented from QgsFeatureRenderer.

Definition at line 1008 of file qgsrulebasedrenderer.cpp.

◆ symbolsForFeature()

QgsSymbolList QgsRuleBasedRenderer::symbolsForFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Returns list of symbols used for rendering the feature.

For renderers that do not support MoreSymbolsPerFeature it is more efficient to use symbolForFeature()

Since
QGIS 2.12

Reimplemented from QgsFeatureRenderer.

Definition at line 1225 of file qgsrulebasedrenderer.cpp.

◆ toSld()

void QgsRuleBasedRenderer::toSld ( QDomDocument &  doc,
QDomElement &  element,
const QgsStringMap props = QgsStringMap() 
) const
overridevirtual

used from subclasses to create SLD Rule elements following SLD v1.1 specs

Reimplemented from QgsFeatureRenderer.

Definition at line 1002 of file qgsrulebasedrenderer.cpp.

◆ usedAttributes()

QSet< QString > QgsRuleBasedRenderer::usedAttributes ( const QgsRenderContext context) const
overridevirtual

Returns a list of attributes required by this renderer.

Attributes not listed in here may not have been requested from the provider at rendering time.

Returns
A set of attributes

Implements QgsFeatureRenderer.

Definition at line 972 of file qgsrulebasedrenderer.cpp.

◆ willRenderFeature()

bool QgsRuleBasedRenderer::willRenderFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Returns whether the renderer will render a feature or not.

Must be called between startRender() and stopRender() calls. Default implementation uses symbolForFeature().

Since
QGIS 2.12

Reimplemented from QgsFeatureRenderer.

Definition at line 1220 of file qgsrulebasedrenderer.cpp.

Member Data Documentation

◆ mCurrentFeatures

QList<FeatureToRender> QgsRuleBasedRenderer::mCurrentFeatures
protected

Definition at line 542 of file qgsrulebasedrenderer.h.

◆ mFilter

QString QgsRuleBasedRenderer::mFilter
protected

Definition at line 544 of file qgsrulebasedrenderer.h.

◆ mRenderQueue

RenderQueue QgsRuleBasedRenderer::mRenderQueue
protected

Definition at line 541 of file qgsrulebasedrenderer.h.

◆ mRootRule

Rule* QgsRuleBasedRenderer::mRootRule = nullptr
protected

the root node with hierarchical list of rules

Definition at line 538 of file qgsrulebasedrenderer.h.


The documentation for this class was generated from the following files: