QGIS API Documentation 3.37.0-Master (c2d15952569)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsCategorizedSymbolRenderer Class Reference

#include <qgscategorizedsymbolrenderer.h>

Inheritance diagram for QgsCategorizedSymbolRenderer:
Inheritance graph
[legend]

Public Member Functions

 QgsCategorizedSymbolRenderer (const QString &attrName=QString(), const QgsCategoryList &categories=QgsCategoryList())
 Constructor for QgsCategorizedSymbolRenderer.
 
 ~QgsCategorizedSymbolRenderer () override
 
bool accept (QgsStyleEntityVisitorInterface *visitor) const override
 Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer.
 
void addCategory (const QgsRendererCategory &category)
 Adds a new category to the renderer.
 
QgsFeatureRenderer::Capabilities capabilities () override
 Returns details about internals of this renderer.
 
const QgsCategoryListcategories () const
 Returns a list of all categories recognized by the renderer.
 
int categoryIndexForLabel (const QString &val)
 Returns the index of the category with the specified label (or -1 if the label was not found, or is not unique).
 
int categoryIndexForValue (const QVariant &val)
 Returns the index for the category with the specified value (or -1 if not found).
 
void checkLegendSymbolItem (const QString &key, bool state=true) override
 Sets whether the legend symbology item with the specified ley should be checked.
 
QString classAttribute () const
 Returns the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.
 
QgsCategorizedSymbolRendererclone () const override
 Create a deep copy of this renderer.
 
QgsDataDefinedSizeLegenddataDefinedSizeLegend () const
 Returns configuration of appearance of legend when using data-defined size for marker symbols.
 
void deleteAllCategories ()
 Deletes all existing categories from the renderer.
 
bool deleteCategory (int catIndex)
 Deletes the category with the specified index from the renderer.
 
QString dump () const override
 Returns debug information about this renderer.
 
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.
 
bool filterNeedsGeometry () const override
 Returns true if this renderer requires the geometry to apply the filter.
 
QString legendClassificationAttribute () const override
 If supported by the renderer, return classification attribute for the use in legend.
 
QSet< QString > legendKeysForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns legend keys matching a specified feature.
 
QString legendKeyToExpression (const QString &key, QgsVectorLayer *layer, bool &ok) const override
 Attempts to convert the specified legend rule key to a QGIS expression matching the features displayed using that key.
 
bool legendSymbolItemChecked (const QString &key) override
 Returns true if the legend symbology item with the specified key is checked.
 
QgsLegendSymbolList legendSymbolItems () const override
 Returns a list of symbology items for the legend.
 
bool legendSymbolItemsCheckable () const override
 Returns true if symbology items in legend are checkable.
 
int matchToSymbols (QgsStyle *style, Qgis::SymbolType type, QVariantList &unmatchedCategories, QStringList &unmatchedSymbols, bool caseSensitive=true, bool useTolerantMatch=false)
 Replaces category symbols with the symbols from a style that have a matching name and symbol type.
 
void moveCategory (int from, int to)
 Moves an existing category at index position from to index position to.
 
QgsSymboloriginalSymbolForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 Returns symbol for feature.
 
QDomElement save (QDomDocument &doc, const QgsReadWriteContext &context) override
 Stores renderer properties to an XML element.
 
void setClassAttribute (const QString &attr)
 Sets the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.
 
void setDataDefinedSizeLegend (QgsDataDefinedSizeLegend *settings)
 Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.
 
void setLegendSymbolItem (const QString &key, QgsSymbol *symbol) override
 Sets the symbol to be used for a legend symbol item.
 
void setSourceColorRamp (QgsColorRamp *ramp)
 Sets the source color ramp.
 
void setSourceSymbol (QgsSymbol *sym)
 Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbol before applying the categories' color.
 
void sortByLabel (Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the existing categories by their label.
 
void sortByValue (Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the existing categories by their value.
 
QgsColorRampsourceColorRamp ()
 Returns the source color ramp, from which each categories' color is derived.
 
const QgsColorRampsourceColorRamp () const
 Returns the source color ramp, from which each categories' color is derived.
 
QgsSymbolsourceSymbol ()
 Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying the categories' color.
 
const QgsSymbolsourceSymbol () const
 Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying the categories' color.
 
void startRender (QgsRenderContext &context, const QgsFields &fields) override
 Must be called when a new render cycle is started.
 
void stopRender (QgsRenderContext &context) override
 Must be called when a render cycle has finished, to allow the renderer to clean up.
 
QgsSymbolsymbolForFeature (const QgsFeature &feature, QgsRenderContext &context) const override
 To be overridden.
 
QgsSymbolList symbols (QgsRenderContext &context) const override
 Returns list of symbols used by the renderer.
 
void toSld (QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const override
 used from subclasses to create SLD Rule elements following SLD v1.1 specs
 
bool updateCategoryLabel (int catIndex, const QString &label)
 Changes the label for the category with the specified index.
 
bool updateCategoryRenderState (int catIndex, bool render)
 Changes the render state for the category with the specified index.
 
bool updateCategorySymbol (int catIndex, QgsSymbol *symbol)
 Changes the symbol for the category with the specified index.
 
bool updateCategoryValue (int catIndex, const QVariant &value)
 Changes the value for the category with the specified index.
 
void updateColorRamp (QgsColorRamp *ramp)
 Update the color ramp used and all symbols colors.
 
void updateSymbols (QgsSymbol *sym)
 Update all the symbols but leave categories and colors.
 
QSet< QString > usedAttributes (const QgsRenderContext &context) const override
 Returns a list of attributes required by this renderer.
 
- Public Member Functions inherited from QgsFeatureRenderer
virtual ~QgsFeatureRenderer ()
 
virtual bool canSkipRender ()
 Returns true if the renderer can be entirely skipped, i.e.
 
void copyRendererData (QgsFeatureRenderer *destRenderer) const
 Clones generic renderer data to another renderer.
 
virtual const QgsFeatureRendererembeddedRenderer () const
 Returns the current embedded renderer (subrenderer) for this feature renderer.
 
bool forceRasterRender () const
 Returns whether the renderer must render as a raster.
 
QSet< QString > legendKeys () const
 Returns the set of all legend keys used by the renderer.
 
virtual void modifyRequestExtent (QgsRectangle &extent, QgsRenderContext &context)
 Allows for a renderer to modify the extent of a feature request prior to rendering.
 
QgsFeatureRequest::OrderBy orderBy () const
 Gets the order in which features shall be processed by this renderer.
 
bool orderByEnabled () const
 Returns whether custom ordering will be applied before features are processed by this renderer.
 
virtual QgsSymbolList originalSymbolsForFeature (const QgsFeature &feature, QgsRenderContext &context) const
 Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()
 
QgsPaintEffectpaintEffect () const
 Returns the current paint effect for the renderer.
 
double referenceScale () const
 Returns the symbology reference scale.
 
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 void setEmbeddedRenderer (QgsFeatureRenderer *subRenderer)
 Sets an embedded renderer (subrenderer) for this feature renderer.
 
void setForceRasterRender (bool forceRaster)
 Sets whether the renderer should be rendered to a raster destination.
 
void setOrderBy (const QgsFeatureRequest::OrderBy &orderBy)
 Define the order in which features shall be processed by this renderer.
 
void setOrderByEnabled (bool enabled)
 Sets whether custom ordering should be applied before features are processed by this renderer.
 
void setPaintEffect (QgsPaintEffect *effect)
 Sets the current paint effect for the renderer.
 
void setReferenceScale (double scale)
 Sets the symbology reference scale.
 
void setUsingSymbolLevels (bool usingSymbolLevels)
 
void setVertexMarkerAppearance (Qgis::VertexMarkerType type, double size)
 Sets type and size of editing vertex markers for subsequent rendering.
 
virtual QgsSymbolList symbolsForFeature (const QgsFeature &feature, QgsRenderContext &context) const
 Returns list of symbols used for rendering the feature.
 
QString type () const
 
virtual bool usesEmbeddedSymbols () const
 Returns true if the renderer uses embedded symbols for features.
 
bool usingSymbolLevels () const
 
virtual bool willRenderFeature (const QgsFeature &feature, QgsRenderContext &context) const
 Returns whether the renderer will render a feature or not.
 
virtual QDomElement writeSld (QDomDocument &doc, const QString &styleName, const QVariantMap &props=QVariantMap()) const
 create the SLD UserStyle element following the SLD v1.1 specs with the given name
 

Static Public Member Functions

static QgsCategorizedSymbolRendererconvertFromRenderer (const QgsFeatureRenderer *renderer, QgsVectorLayer *layer=nullptr)
 Creates a new QgsCategorizedSymbolRenderer from an existing renderer.
 
static QgsFeatureRenderercreate (QDomElement &element, const QgsReadWriteContext &context)
 Creates a categorized renderer from an XML element.
 
static QgsCategoryList createCategories (const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
 Create categories for a list of values.
 
static QString displayString (const QVariant &value, int precision=-1)
 Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant::toString output.
 
- Static Public Member Functions inherited from QgsFeatureRenderer
static QgsFeatureRendererdefaultRenderer (Qgis::GeometryType geomType)
 Returns a new renderer - used by default in vector layers.
 
static QgsFeatureRendererload (QDomElement &symbologyElem, const QgsReadWriteContext &context)
 create a renderer from XML element
 
static QgsFeatureRendererloadSld (const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage)
 Create a new renderer according to the information contained in the UserStyle element of a SLD style document.
 

Protected Member Functions

void rebuildHash ()
 
Q_DECL_DEPRECATED QgsSymbolskipRender ()
 
Q_DECL_DEPRECATED QgsSymbolsymbolForValue (const QVariant &value) const
 Returns the matching symbol corresponding to an attribute value.
 
QgsSymbolsymbolForValue (const QVariant &value, bool &foundMatchingSymbol) const
 Returns the matching symbol corresponding to an attribute value.
 
- Protected Member Functions inherited from QgsFeatureRenderer
 QgsFeatureRenderer (const QString &type)
 
void renderFeatureWithSymbol (const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
 Render the feature with the symbol using context.
 
void renderVertexMarker (QPointF pt, QgsRenderContext &context)
 render editing vertex marker at specified point
 
void renderVertexMarkerPolygon (QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
 render editing vertex marker for a polygon
 
void renderVertexMarkerPolyline (QPolygonF &pts, QgsRenderContext &context)
 render editing vertex marker for a polyline
 
void saveRendererData (QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
 Saves generic renderer data into the specified element.
 

Protected Attributes

QString mAttrName
 
int mAttrNum = -1
 attribute index (derived from attribute name in startRender)
 
QgsCategoryList mCategories
 
bool mCounting = false
 
std::unique_ptr< QgsDataDefinedSizeLegendmDataDefinedSizeLegend
 
std::unique_ptr< QgsExpressionmExpression
 
std::unique_ptr< QgsColorRampmSourceColorRamp
 
std::unique_ptr< QgsSymbolmSourceSymbol
 
QHash< QString, QgsSymbol * > mSymbolHash
 hashtable for faster access to symbols
 
- Protected Attributes inherited from QgsFeatureRenderer
double mCurrentVertexMarkerSize = 2
 The current size of editing marker.
 
Qgis::VertexMarkerType mCurrentVertexMarkerType = Qgis::VertexMarkerType::Cross
 The current type of editing marker.
 
bool mForceRaster = false
 
QgsFeatureRequest::OrderBy mOrderBy
 
bool mOrderByEnabled = false
 
QgsPaintEffectmPaintEffect = nullptr
 
double mReferenceScale = -1.0
 
QString mType
 
bool mUsingSymbolLevels = false
 

Additional Inherited Members

- 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...
 
- 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.
 
static void convertSymbolRotation (QgsSymbol *symbol, const QString &field)
 
static void convertSymbolSizeScale (QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
 

Detailed Description

Definition at line 171 of file qgscategorizedsymbolrenderer.h.

Constructor & Destructor Documentation

◆ QgsCategorizedSymbolRenderer()

QgsCategorizedSymbolRenderer::QgsCategorizedSymbolRenderer ( const QString &  attrName = QString(),
const QgsCategoryList categories = QgsCategoryList() 
)

Constructor for QgsCategorizedSymbolRenderer.

The attrName argument specifies the layer's field name, or expression, which the categories will be matched against.

A list of renderer categories can optionally be specified. If no categories are specified in the constructor, they can be added later by calling addCategory().

Definition at line 211 of file qgscategorizedsymbolrenderer.cpp.

◆ ~QgsCategorizedSymbolRenderer()

QgsCategorizedSymbolRenderer::~QgsCategorizedSymbolRenderer ( )
overridedefault

Member Function Documentation

◆ accept()

bool QgsCategorizedSymbolRenderer::accept ( QgsStyleEntityVisitorInterface visitor) const
overridevirtual

Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer.

Returns true if the visitor should continue visiting other objects, or false if visiting should be canceled.

Since
QGIS 3.10

Reimplemented from QgsFeatureRenderer.

Definition at line 679 of file qgscategorizedsymbolrenderer.cpp.

◆ addCategory()

void QgsCategorizedSymbolRenderer::addCategory ( const QgsRendererCategory category)

Adds a new category to the renderer.

See also
categories()

Definition at line 386 of file qgscategorizedsymbolrenderer.cpp.

◆ capabilities()

QgsFeatureRenderer::Capabilities QgsCategorizedSymbolRenderer::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 195 of file qgscategorizedsymbolrenderer.h.

◆ categories()

const QgsCategoryList & QgsCategorizedSymbolRenderer::categories ( ) const
inline

Returns a list of all categories recognized by the renderer.

Definition at line 211 of file qgscategorizedsymbolrenderer.h.

◆ categoryIndexForLabel()

int QgsCategorizedSymbolRenderer::categoryIndexForLabel ( const QString &  val)

Returns the index of the category with the specified label (or -1 if the label was not found, or is not unique).

Definition at line 338 of file qgscategorizedsymbolrenderer.cpp.

◆ categoryIndexForValue()

int QgsCategorizedSymbolRenderer::categoryIndexForValue ( const QVariant &  val)

Returns the index for the category with the specified value (or -1 if not found).

Definition at line 328 of file qgscategorizedsymbolrenderer.cpp.

◆ checkLegendSymbolItem()

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

Sets whether the legend symbology item with the specified ley should be checked.

See also
legendSymbolItemChecked()
legendKeys()

Reimplemented from QgsFeatureRenderer.

Definition at line 1356 of file qgscategorizedsymbolrenderer.cpp.

◆ classAttribute()

QString QgsCategorizedSymbolRenderer::classAttribute ( ) const
inline

Returns the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

See also
setClassAttribute()

Definition at line 317 of file qgscategorizedsymbolrenderer.h.

◆ clone()

QgsCategorizedSymbolRenderer * QgsCategorizedSymbolRenderer::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 541 of file qgscategorizedsymbolrenderer.cpp.

◆ convertFromRenderer()

QgsCategorizedSymbolRenderer * QgsCategorizedSymbolRenderer::convertFromRenderer ( const QgsFeatureRenderer renderer,
QgsVectorLayer layer = nullptr 
)
static

Creates a new QgsCategorizedSymbolRenderer from an existing renderer.

Since QGIS 3.20, the optional layer parameter is required for conversions of some renderer types.

Returns
a new renderer if the conversion was possible, otherwise nullptr.

Definition at line 1368 of file qgscategorizedsymbolrenderer.cpp.

◆ create()

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

Creates a categorized renderer from an XML element.

Definition at line 698 of file qgscategorizedsymbolrenderer.cpp.

◆ createCategories()

QgsCategoryList QgsCategorizedSymbolRenderer::createCategories ( const QVariantList &  values,
const QgsSymbol symbol,
QgsVectorLayer layer = nullptr,
const QString &  fieldName = QString() 
)
static

Create categories for a list of values.

The returned symbols in the category list will be a modification of symbol.

If layer and fieldName are specified it will try to find nicer values to represent the description for the categories based on the respective field configuration.

Since
QGIS 3.6

Definition at line 1511 of file qgscategorizedsymbolrenderer.cpp.

◆ dataDefinedSizeLegend()

QgsDataDefinedSizeLegend * QgsCategorizedSymbolRenderer::dataDefinedSizeLegend ( ) const

Returns configuration of appearance of legend when using data-defined size for marker symbols.

Will return nullptr if the functionality is disabled.

Definition at line 1444 of file qgscategorizedsymbolrenderer.cpp.

◆ deleteAllCategories()

void QgsCategorizedSymbolRenderer::deleteAllCategories ( )

Deletes all existing categories from the renderer.

See also
deleteCategory()

Definition at line 406 of file qgscategorizedsymbolrenderer.cpp.

◆ deleteCategory()

bool QgsCategorizedSymbolRenderer::deleteCategory ( int  catIndex)

Deletes the category with the specified index from the renderer.

See also
deleteAllCategories()

Definition at line 397 of file qgscategorizedsymbolrenderer.cpp.

◆ displayString()

QString QgsCategorizedSymbolRenderer::displayString ( const QVariant &  value,
int  precision = -1 
)
static

Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant::toString output.

Note
Precision is ignored for integers.
Since
QGIS 3.22.1

Definition at line 992 of file qgscategorizedsymbolrenderer.cpp.

◆ dump()

QString QgsCategorizedSymbolRenderer::dump ( ) const
overridevirtual

Returns debug information about this renderer.

Reimplemented from QgsFeatureRenderer.

Definition at line 533 of file qgscategorizedsymbolrenderer.cpp.

◆ filter()

QString QgsCategorizedSymbolRenderer::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 568 of file qgscategorizedsymbolrenderer.cpp.

◆ filterNeedsGeometry()

bool QgsCategorizedSymbolRenderer::filterNeedsGeometry ( ) const
overridevirtual

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

Reimplemented from QgsFeatureRenderer.

Definition at line 520 of file qgscategorizedsymbolrenderer.cpp.

◆ legendClassificationAttribute()

QString QgsCategorizedSymbolRenderer::legendClassificationAttribute ( ) const
inlineoverridevirtual

If supported by the renderer, return classification attribute for the use in legend.

Reimplemented from QgsFeatureRenderer.

Definition at line 397 of file qgscategorizedsymbolrenderer.h.

◆ legendKeysForFeature()

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

Returns legend keys matching a specified feature.

Reimplemented from QgsFeatureRenderer.

Definition at line 1152 of file qgscategorizedsymbolrenderer.cpp.

◆ legendKeyToExpression()

QString QgsCategorizedSymbolRenderer::legendKeyToExpression ( const QString &  key,
QgsVectorLayer layer,
bool &  ok 
) const
overridevirtual

Attempts to convert the specified legend rule key to a QGIS expression matching the features displayed using that key.

Parameters
keylegend key
layerassociated vector layer
okwill be set to true if legend key was successfully converted to a filter expression
Returns
QGIS expression string for matching features with the specified key
See also
legendKeys()
Since
QGIS 3.26

Reimplemented from QgsFeatureRenderer.

Definition at line 1198 of file qgscategorizedsymbolrenderer.cpp.

◆ legendSymbolItemChecked()

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

Returns true if the legend symbology item with the specified key is checked.

See also
checkLegendSymbolItem()
legendKeys()

Reimplemented from QgsFeatureRenderer.

Definition at line 1324 of file qgscategorizedsymbolrenderer.cpp.

◆ legendSymbolItems()

QgsLegendSymbolList QgsCategorizedSymbolRenderer::legendSymbolItems ( ) const
overridevirtual

Returns a list of symbology items for the legend.

See also
legendKeys()

Reimplemented from QgsFeatureRenderer.

Definition at line 1112 of file qgscategorizedsymbolrenderer.cpp.

◆ legendSymbolItemsCheckable()

bool QgsCategorizedSymbolRenderer::legendSymbolItemsCheckable ( ) const
overridevirtual

Returns true if symbology items in legend are checkable.

Reimplemented from QgsFeatureRenderer.

Definition at line 1319 of file qgscategorizedsymbolrenderer.cpp.

◆ matchToSymbols()

int QgsCategorizedSymbolRenderer::matchToSymbols ( QgsStyle style,
Qgis::SymbolType  type,
QVariantList &  unmatchedCategories,
QStringList &  unmatchedSymbols,
bool  caseSensitive = true,
bool  useTolerantMatch = false 
)

Replaces category symbols with the symbols from a style that have a matching name and symbol type.

The unmatchedCategories list will be filled with all existing categories which could not be matched to a symbol in style.

The unmatchedSymbols list will be filled with all symbol names from style which were not matched to an existing category.

If caseSensitive is false, then a case-insensitive match will be performed. If useTolerantMatch is true, then non-alphanumeric characters in style and category names will be ignored during the match.

Returns the count of symbols matched.

Since
QGIS 3.4

Definition at line 1449 of file qgscategorizedsymbolrenderer.cpp.

◆ moveCategory()

void QgsCategorizedSymbolRenderer::moveCategory ( int  from,
int  to 
)

Moves an existing category at index position from to index position to.

Definition at line 411 of file qgscategorizedsymbolrenderer.cpp.

◆ originalSymbolForFeature()

QgsSymbol * QgsCategorizedSymbolRenderer::originalSymbolForFeature ( const QgsFeature feature,
QgsRenderContext context 
) const
overridevirtual

Returns symbol for feature.

The difference compared to symbolForFeature() is that it returns original symbol which can be used as an identifier for renderer's rule - the former may return a temporary replacement of a symbol for use in rendering.

Reimplemented from QgsFeatureRenderer.

Definition at line 310 of file qgscategorizedsymbolrenderer.cpp.

◆ rebuildHash()

void QgsCategorizedSymbolRenderer::rebuildHash ( )
protected

Definition at line 230 of file qgscategorizedsymbolrenderer.cpp.

◆ save()

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

Stores renderer properties to an XML element.

Subclasses which override this method should call saveRendererData() as part of their implementation in order to store all common base class properties in the returned DOM element.

Reimplemented from QgsFeatureRenderer.

Definition at line 861 of file qgscategorizedsymbolrenderer.cpp.

◆ setClassAttribute()

void QgsCategorizedSymbolRenderer::setClassAttribute ( const QString &  attr)
inline

Sets the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

See also
classAttribute()

Definition at line 326 of file qgscategorizedsymbolrenderer.h.

◆ setDataDefinedSizeLegend()

void QgsCategorizedSymbolRenderer::setDataDefinedSizeLegend ( QgsDataDefinedSizeLegend settings)

Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.

This allows configuring for which values (symbol sizes) should be shown in the legend, whether to display different symbol sizes collapsed in one legend node or separated across multiple legend nodes etc.

When renderer does not use data-defined size or does not use marker symbols, these settings will be ignored. Takes ownership of the passed settings objects. nullptr is a valid input that disables data-defined size legend.

Definition at line 1439 of file qgscategorizedsymbolrenderer.cpp.

◆ setLegendSymbolItem()

void QgsCategorizedSymbolRenderer::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.
See also
legendKeys()

Reimplemented from QgsFeatureRenderer.

Definition at line 1337 of file qgscategorizedsymbolrenderer.cpp.

◆ setSourceColorRamp()

void QgsCategorizedSymbolRenderer::setSourceColorRamp ( QgsColorRamp ramp)

Sets the source color ramp.

Parameters
rampcolor ramp. Ownership is transferred to the renderer
See also
sourceColorRamp()
setSourceSymbol()

Definition at line 1279 of file qgscategorizedsymbolrenderer.cpp.

◆ setSourceSymbol()

void QgsCategorizedSymbolRenderer::setSourceSymbol ( QgsSymbol sym)

Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbol before applying the categories' color.

Parameters
symsource symbol, ownership is transferred to the renderer
See also
sourceSymbol()
setSourceColorRamp()

Definition at line 1264 of file qgscategorizedsymbolrenderer.cpp.

◆ skipRender()

QgsSymbol * QgsCategorizedSymbolRenderer::skipRender ( )
protected
Deprecated:
No longer used, will be removed in QGIS 4.0

Definition at line 252 of file qgscategorizedsymbolrenderer.cpp.

◆ sortByLabel()

void QgsCategorizedSymbolRenderer::sortByLabel ( Qt::SortOrder  order = Qt::AscendingOrder)

Sorts the existing categories by their label.

See also
sortByValue()

Definition at line 448 of file qgscategorizedsymbolrenderer.cpp.

◆ sortByValue()

void QgsCategorizedSymbolRenderer::sortByValue ( Qt::SortOrder  order = Qt::AscendingOrder)

Sorts the existing categories by their value.

See also
sortByLabel()

Definition at line 426 of file qgscategorizedsymbolrenderer.cpp.

◆ sourceColorRamp() [1/2]

QgsColorRamp * QgsCategorizedSymbolRenderer::sourceColorRamp ( )

Returns the source color ramp, from which each categories' color is derived.

See also
setSourceColorRamp()
sourceSymbol()

Definition at line 1269 of file qgscategorizedsymbolrenderer.cpp.

◆ sourceColorRamp() [2/2]

const QgsColorRamp * QgsCategorizedSymbolRenderer::sourceColorRamp ( ) const

Returns the source color ramp, from which each categories' color is derived.

See also
setSourceColorRamp()
sourceSymbol()
Note
Not available in Python bindings.

Definition at line 1274 of file qgscategorizedsymbolrenderer.cpp.

◆ sourceSymbol() [1/2]

QgsSymbol * QgsCategorizedSymbolRenderer::sourceSymbol ( )

Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying the categories' color.

See also
setSourceSymbol()
sourceColorRamp()

Definition at line 1254 of file qgscategorizedsymbolrenderer.cpp.

◆ sourceSymbol() [2/2]

const QgsSymbol * QgsCategorizedSymbolRenderer::sourceSymbol ( ) const

Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying the categories' color.

See also
setSourceSymbol()
sourceColorRamp()
Note
Not available in Python bindings.

Definition at line 1259 of file qgscategorizedsymbolrenderer.cpp.

◆ startRender()

void QgsCategorizedSymbolRenderer::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 460 of file qgscategorizedsymbolrenderer.cpp.

◆ stopRender()

void QgsCategorizedSymbolRenderer::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 483 of file qgscategorizedsymbolrenderer.cpp.

◆ symbolForFeature()

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

To be overridden.

Must be called between startRender() and stopRender() calls.

Parameters
featurefeature
contextrender context
Returns
returns pointer to symbol or 0 if symbol was not found

Implements QgsFeatureRenderer.

Definition at line 287 of file qgscategorizedsymbolrenderer.cpp.

◆ symbolForValue() [1/2]

QgsSymbol * QgsCategorizedSymbolRenderer::symbolForValue ( const QVariant &  value) const
protected

Returns the matching symbol corresponding to an attribute value.

Deprecated:
use variant which takes a second bool argument instead.

Definition at line 257 of file qgscategorizedsymbolrenderer.cpp.

◆ symbolForValue() [2/2]

QgsSymbol * QgsCategorizedSymbolRenderer::symbolForValue ( const QVariant &  value,
bool &  foundMatchingSymbol 
) const
protected

Returns the matching symbol corresponding to an attribute value.

Will return nullptr if no matching symbol was found for value, or if the category corresponding to value is currently disabled (see QgsRendererCategory::renderState()).

If foundMatchingSymbol is specified then it will be set to true if a matching category was found. This can be used to differentiate between nullptr returned as a result of no matching category vs NULLPTR as a result of disabled categories.

Note
available in Python bindings as symbolForValue2

Definition at line 263 of file qgscategorizedsymbolrenderer.cpp.

◆ symbols()

QgsSymbolList QgsCategorizedSymbolRenderer::symbols ( QgsRenderContext context) const
overridevirtual

Returns list of symbols used by the renderer.

Parameters
contextrender context

Reimplemented from QgsFeatureRenderer.

Definition at line 667 of file qgscategorizedsymbolrenderer.cpp.

◆ toSld()

void QgsCategorizedSymbolRenderer::toSld ( QDomDocument &  doc,
QDomElement &  element,
const QVariantMap &  props = QVariantMap() 
) const
overridevirtual

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

Reimplemented from QgsFeatureRenderer.

Definition at line 556 of file qgscategorizedsymbolrenderer.cpp.

◆ updateCategoryLabel()

bool QgsCategorizedSymbolRenderer::updateCategoryLabel ( int  catIndex,
const QString &  label 
)

Changes the label for the category with the specified index.

A category's label is used to represent the category within legends and the layer tree.

See also
updateCategoryValue()
updateCategoryLabel()
updateCategoryRenderState()

Definition at line 370 of file qgscategorizedsymbolrenderer.cpp.

◆ updateCategoryRenderState()

bool QgsCategorizedSymbolRenderer::updateCategoryRenderState ( int  catIndex,
bool  render 
)

Changes the render state for the category with the specified index.

The render state indicates whether or not the category will be rendered, and is reflected in whether the category is checked with the project's layer tree.

See also
updateCategoryValue()
updateCategorySymbol()
updateCategoryLabel()

Definition at line 378 of file qgscategorizedsymbolrenderer.cpp.

◆ updateCategorySymbol()

bool QgsCategorizedSymbolRenderer::updateCategorySymbol ( int  catIndex,
QgsSymbol symbol 
)

Changes the symbol for the category with the specified index.

Ownership of symbol is transferred to the renderer.

See also
updateCategoryValue()
updateCategoryLabel()
updateCategoryRenderState()

Definition at line 362 of file qgscategorizedsymbolrenderer.cpp.

◆ updateCategoryValue()

bool QgsCategorizedSymbolRenderer::updateCategoryValue ( int  catIndex,
const QVariant &  value 
)

Changes the value for the category with the specified index.

If value is a list, then the category will match any of the values from this list.

See also
updateCategorySymbol()
updateCategoryLabel()
updateCategoryRenderState()

Definition at line 354 of file qgscategorizedsymbolrenderer.cpp.

◆ updateColorRamp()

void QgsCategorizedSymbolRenderer::updateColorRamp ( QgsColorRamp ramp)

Update the color ramp used and all symbols colors.

Parameters
rampcolor ramp. Ownership is transferred to the renderer

Definition at line 1284 of file qgscategorizedsymbolrenderer.cpp.

◆ updateSymbols()

void QgsCategorizedSymbolRenderer::updateSymbols ( QgsSymbol sym)

Update all the symbols but leave categories and colors.

This method also sets the source symbol for the renderer.

Parameters
symsource symbol to use for categories. Ownership is not transferred.
See also
setSourceSymbol()

Definition at line 1306 of file qgscategorizedsymbolrenderer.cpp.

◆ usedAttributes()

QSet< QString > QgsCategorizedSymbolRenderer::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 494 of file qgscategorizedsymbolrenderer.cpp.

Member Data Documentation

◆ mAttrName

QString QgsCategorizedSymbolRenderer::mAttrName
protected

Definition at line 471 of file qgscategorizedsymbolrenderer.h.

◆ mAttrNum

int QgsCategorizedSymbolRenderer::mAttrNum = -1
protected

attribute index (derived from attribute name in startRender)

Definition at line 480 of file qgscategorizedsymbolrenderer.h.

◆ mCategories

QgsCategoryList QgsCategorizedSymbolRenderer::mCategories
protected

Definition at line 472 of file qgscategorizedsymbolrenderer.h.

◆ mCounting

bool QgsCategorizedSymbolRenderer::mCounting = false
protected

Definition at line 484 of file qgscategorizedsymbolrenderer.h.

◆ mDataDefinedSizeLegend

std::unique_ptr<QgsDataDefinedSizeLegend> QgsCategorizedSymbolRenderer::mDataDefinedSizeLegend
protected

Definition at line 477 of file qgscategorizedsymbolrenderer.h.

◆ mExpression

std::unique_ptr<QgsExpression> QgsCategorizedSymbolRenderer::mExpression
protected

Definition at line 475 of file qgscategorizedsymbolrenderer.h.

◆ mSourceColorRamp

std::unique_ptr<QgsColorRamp> QgsCategorizedSymbolRenderer::mSourceColorRamp
protected

Definition at line 474 of file qgscategorizedsymbolrenderer.h.

◆ mSourceSymbol

std::unique_ptr<QgsSymbol> QgsCategorizedSymbolRenderer::mSourceSymbol
protected

Definition at line 473 of file qgscategorizedsymbolrenderer.h.

◆ mSymbolHash

QHash<QString, QgsSymbol *> QgsCategorizedSymbolRenderer::mSymbolHash
protected

hashtable for faster access to symbols

Definition at line 483 of file qgscategorizedsymbolrenderer.h.


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