QGIS API Documentation  3.0.2-Girona (307d082)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
QgsSymbol Class Referenceabstract

#include <qgssymbol.h>

Inheritance diagram for QgsSymbol:
Inheritance graph
[legend]

Public Types

enum  RenderHint { DynamicRotation = 2 }
 Flags controlling behavior of symbols during rendering. More...
 
enum  ScaleMethod { ScaleArea, ScaleDiameter }
 Scale method. More...
 
enum  SymbolType { Marker, Line, Fill, Hybrid }
 Type of the symbol. More...
 

Public Member Functions

virtual ~QgsSymbol ()
 
bool appendSymbolLayer (QgsSymbolLayer *layer)
 Append symbol layer at the end of the list Ownership will be transferred. More...
 
QImage asImage (QSize size, QgsRenderContext *customContext=nullptr)
 Generate symbol as image. More...
 
QImage bigSymbolPreviewImage (QgsExpressionContext *expressionContext=nullptr)
 Returns a large (roughly 100x100 pixel) preview image for the symbol. More...
 
bool changeSymbolLayer (int index, QgsSymbolLayer *layer)
 delete layer at specified index and set a new one More...
 
bool clipFeaturesToExtent () const
 Returns whether features drawn by the symbol will be clipped to the render context's extent. More...
 
virtual QgsSymbolclone () const =0
 Get a deep copy of this symbol. More...
 
QColor color () const
 
bool deleteSymbolLayer (int index)
 delete symbol layer at specified index More...
 
void drawPreviewIcon (QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr)
 Draw icon of the symbol that occupyies area given by size using the painter. More...
 
QString dump () const
 
void exportImage (const QString &path, const QString &format, QSize size)
 export symbol as image format. PNG and SVG supported More...
 
bool hasDataDefinedProperties () const
 Returns whether the symbol utilizes any data defined properties. More...
 
bool insertSymbolLayer (int index, QgsSymbolLayer *layer)
 Insert symbol layer to specified index Ownership will be transferred. More...
 
const QgsVectorLayerlayer () const
 
QgsMapUnitScale mapUnitScale () const
 
qreal opacity () const
 Returns the opacity for the symbol. More...
 
QgsUnitTypes::RenderUnit outputUnit () const
 Returns the units to use for sizes and widths within the symbol. More...
 
void renderFeature (const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, int currentVertexMarkerType=0, int currentVertexMarkerSize=0)
 Render a feature. More...
 
RenderHints renderHints () const
 Returns the rendering hint flags for the symbol. More...
 
void setClipFeaturesToExtent (bool clipFeaturesToExtent)
 Sets whether features drawn by the symbol should be clipped to the render context's extent. More...
 
void setColor (const QColor &color)
 
void setLayer (const QgsVectorLayer *layer)
 
void setMapUnitScale (const QgsMapUnitScale &scale)
 
void setOpacity (qreal opacity)
 Sets the opacity for the symbol. More...
 
void setOutputUnit (QgsUnitTypes::RenderUnit unit)
 Sets the units to use for sizes and widths within the symbol. More...
 
void setRenderHints (RenderHints hints)
 Sets rendering hint flags for the symbol. More...
 
void startRender (QgsRenderContext &context, const QgsFields &fields=QgsFields())
 Begins the rendering process for the symbol. More...
 
void stopRender (QgsRenderContext &context)
 Ends the rendering process. More...
 
QgsSymbolLayersymbolLayer (int layer)
 Returns a specific symbol layers contained in the symbol. More...
 
int symbolLayerCount () const
 Returns total number of symbol layers contained in the symbol. More...
 
QgsSymbolLayerList symbolLayers ()
 Returns list of symbol layers contained in the symbol. More...
 
QgsSymbolRenderContextsymbolRenderContext ()
 Returns the symbol render context. More...
 
QgsSymbolLayertakeSymbolLayer (int index)
 Remove symbol layer from the list and return pointer to it. More...
 
void toSld (QDomDocument &doc, QDomElement &element, QgsStringMap props) const
 
SymbolType type () const
 
QSet< QString > usedAttributes (const QgsRenderContext &context) const
 Return a list of attributes required to render this feature. More...
 

Static Public Member Functions

static QgsSymboldefaultSymbol (QgsWkbTypes::GeometryType geomType)
 return new default symbol for specified geometry type More...
 

Protected Member Functions

 QgsSymbol (SymbolType type, const QgsSymbolLayerList &layers)
 
QgsSymbolLayerList cloneLayers () const
 Retrieve a cloned list of all layers that make up this symbol. More...
 
void renderUsingLayer (QgsSymbolLayer *layer, QgsSymbolRenderContext &context)
 Renders a context using a particular symbol layer without passing in a geometry. More...
 
void renderVertexMarker (QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, int currentVertexMarkerSize)
 Render editing vertex marker at specified point. More...
 

Static Protected Member Functions

static QPolygonF _getLineString (QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent=true)
 Creates a line string in screen coordinates from a QgsCurve in map coordinates. More...
 
static QPointF _getPoint (QgsRenderContext &context, const QgsPoint &point)
 Creates a point in screen coordinates from a QgsPoint in map coordinates. More...
 
static void _getPolygon (QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent=true)
 Creates a polygon in screen coordinates from a QgsPolygonXYin map coordinates. More...
 
static QPolygonF _getPolygonRing (QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent)
 Creates a polygon ring in screen coordinates from a QgsCurve in map coordinates. More...
 

Protected Attributes

bool mClipFeaturesToExtent = true
 
const QgsVectorLayermLayer = nullptr
 
QgsSymbolLayerList mLayers
 
qreal mOpacity = 1.0
 Symbol opacity (in the range 0 - 1) More...
 
RenderHints mRenderHints = nullptr
 
SymbolType mType
 

Friends

class QgsFeatureRenderer
 

Detailed Description

Definition at line 61 of file qgssymbol.h.

Member Enumeration Documentation

◆ RenderHint

Flags controlling behavior of symbols during rendering.

Enumerator
DynamicRotation 

Rotation of symbol may be changed during rendering and symbol should not be cached.

Definition at line 102 of file qgssymbol.h.

◆ ScaleMethod

Scale method.

Enumerator
ScaleArea 

Calculate scale by the area.

ScaleDiameter 

Calculate scale by the diameter.

Definition at line 94 of file qgssymbol.h.

◆ SymbolType

Type of the symbol.

Enumerator
Marker 

Marker symbol.

Line 

Line symbol.

Fill 

Fill symbol.

Hybrid 

Hybrid symbol.

Definition at line 83 of file qgssymbol.h.

Constructor & Destructor Documentation

◆ ~QgsSymbol()

QgsSymbol::~QgsSymbol ( )
virtual

Definition at line 199 of file qgssymbol.cpp.

◆ QgsSymbol()

QgsSymbol::QgsSymbol ( SymbolType  type,
const QgsSymbolLayerList layers 
)
protected

Definition at line 80 of file qgssymbol.cpp.

Member Function Documentation

◆ _getLineString()

QPolygonF QgsSymbol::_getLineString ( QgsRenderContext context,
const QgsCurve curve,
bool  clipToExtent = true 
)
staticprotected

Creates a line string in screen coordinates from a QgsCurve in map coordinates.

Definition at line 100 of file qgssymbol.cpp.

◆ _getPoint()

static QPointF QgsSymbol::_getPoint ( QgsRenderContext context,
const QgsPoint point 
)
inlinestaticprotected

Creates a point in screen coordinates from a QgsPoint in map coordinates.

Definition at line 336 of file qgssymbol.h.

◆ _getPolygon()

void QgsSymbol::_getPolygon ( QPolygonF &  pts,
QList< QPolygonF > &  holes,
QgsRenderContext context,
const QgsPolygon polygon,
bool  clipToExtent = true 
)
staticprotected

Creates a polygon in screen coordinates from a QgsPolygonXYin map coordinates.

Definition at line 187 of file qgssymbol.cpp.

◆ _getPolygonRing()

QPolygonF QgsSymbol::_getPolygonRing ( QgsRenderContext context,
const QgsCurve curve,
bool  clipToExtent 
)
staticprotected

Creates a polygon ring in screen coordinates from a QgsCurve in map coordinates.

Definition at line 144 of file qgssymbol.cpp.

◆ appendSymbolLayer()

bool QgsSymbol::appendSymbolLayer ( QgsSymbolLayer layer)

Append symbol layer at the end of the list Ownership will be transferred.

Parameters
layerThe layer to add
Returns
True if the layer is added, False if the layer is bad

Definition at line 355 of file qgssymbol.cpp.

◆ asImage()

QImage QgsSymbol::asImage ( QSize  size,
QgsRenderContext customContext = nullptr 
)

Generate symbol as image.

Definition at line 516 of file qgssymbol.cpp.

◆ bigSymbolPreviewImage()

QImage QgsSymbol::bigSymbolPreviewImage ( QgsExpressionContext expressionContext = nullptr)

Returns a large (roughly 100x100 pixel) preview image for the symbol.

Parameters
expressionContextoptional expression context, for evaluation of data defined symbol properties

Definition at line 530 of file qgssymbol.cpp.

◆ changeSymbolLayer()

bool QgsSymbol::changeSymbolLayer ( int  index,
QgsSymbolLayer layer 
)

delete layer at specified index and set a new one

Definition at line 385 of file qgssymbol.cpp.

◆ clipFeaturesToExtent()

bool QgsSymbol::clipFeaturesToExtent ( ) const
inline

Returns whether features drawn by the symbol will be clipped to the render context's extent.

If this option is enabled then features which are partially outside the extent will be clipped. This speeds up rendering of the feature, but may have undesirable side effects for certain symbol types.

Returns
true if features will be clipped
Since
QGIS 2.9
See also
setClipFeaturesToExtent

Definition at line 298 of file qgssymbol.h.

◆ clone()

virtual QgsSymbol* QgsSymbol::clone ( ) const
pure virtual

Get a deep copy of this symbol.

Needs to be reimplemented by subclasses. Ownership is transferred to the caller.

Implemented in QgsFillSymbol, QgsLineSymbol, and QgsMarkerSymbol.

◆ cloneLayers()

QgsSymbolLayerList QgsSymbol::cloneLayers ( ) const
protected

Retrieve a cloned list of all layers that make up this symbol.

Ownership is transferred to the caller.

Definition at line 613 of file qgssymbol.cpp.

◆ color()

QColor QgsSymbol::color ( ) const

Definition at line 454 of file qgssymbol.cpp.

◆ defaultSymbol()

QgsSymbol * QgsSymbol::defaultSymbol ( QgsWkbTypes::GeometryType  geomType)
static

return new default symbol for specified geometry type

Definition at line 266 of file qgssymbol.cpp.

◆ deleteSymbolLayer()

bool QgsSymbol::deleteSymbolLayer ( int  index)

delete symbol layer at specified index

Definition at line 365 of file qgssymbol.cpp.

◆ drawPreviewIcon()

void QgsSymbol::drawPreviewIcon ( QPainter *  painter,
QSize  size,
QgsRenderContext customContext = nullptr 
)

Draw icon of the symbol that occupyies area given by size using the painter.

Optionally custom context may be given in order to get rendering of symbols that use map units right.

Since
QGIS 2.6

Definition at line 465 of file qgssymbol.cpp.

◆ dump()

QString QgsSymbol::dump ( ) const

Definition at line 574 of file qgssymbol.cpp.

◆ exportImage()

void QgsSymbol::exportImage ( const QString &  path,
const QString &  format,
QSize  size 
)

export symbol as image format. PNG and SVG supported

Definition at line 496 of file qgssymbol.cpp.

◆ hasDataDefinedProperties()

bool QgsSymbol::hasDataDefinedProperties ( ) const

Returns whether the symbol utilizes any data defined properties.

Since
QGIS 2.12

Definition at line 662 of file qgssymbol.cpp.

◆ insertSymbolLayer()

bool QgsSymbol::insertSymbolLayer ( int  index,
QgsSymbolLayer layer 
)

Insert symbol layer to specified index Ownership will be transferred.

Parameters
indexThe index at which the layer should be added
layerThe symbol layer to add
Returns
True if the layer is added, False if the index or the layer is bad

Definition at line 342 of file qgssymbol.cpp.

◆ layer()

const QgsVectorLayer* QgsSymbol::layer ( ) const
inline

Definition at line 315 of file qgssymbol.h.

◆ mapUnitScale()

QgsMapUnitScale QgsSymbol::mapUnitScale ( ) const

Definition at line 226 of file qgssymbol.cpp.

◆ opacity()

qreal QgsSymbol::opacity ( ) const
inline

Returns the opacity for the symbol.

Returns
opacity value between 0 (fully transparent) and 1 (fully opaque)
See also
setOpacity()

Definition at line 257 of file qgssymbol.h.

◆ outputUnit()

QgsUnitTypes::RenderUnit QgsSymbol::outputUnit ( ) const

Returns the units to use for sizes and widths within the symbol.

Individual symbol layer definitions will interpret this in different ways, e.g., a marker symbol may use it to specify the units for the marker size, while a line symbol may use it to specify the units for the line width.

Returns
output unit, or QgsUnitTypes::RenderUnknownUnit if the symbol contains mixed units
See also
setOutputUnit()

Definition at line 205 of file qgssymbol.cpp.

◆ renderFeature()

PRIVATE void QgsSymbol::renderFeature ( const QgsFeature feature,
QgsRenderContext context,
int  layer = -1,
bool  selected = false,
bool  drawVertexMarker = false,
int  currentVertexMarkerType = 0,
int  currentVertexMarkerSize = 0 
)

Render a feature.

Before calling this the startRender() method should be called to initialize the rendering process. After rendering all features stopRender() must be called.

Definition at line 698 of file qgssymbol.cpp.

◆ renderHints()

RenderHints QgsSymbol::renderHints ( ) const
inline

Returns the rendering hint flags for the symbol.

See also
setRenderHints()

Definition at line 276 of file qgssymbol.h.

◆ renderUsingLayer()

void QgsSymbol::renderUsingLayer ( QgsSymbolLayer layer,
QgsSymbolRenderContext context 
)
protected

Renders a context using a particular symbol layer without passing in a geometry.

This is used as fallback, if the symbol being rendered is not compatible with the specified layer. In such a case, this method can be called and will call the layer's rendering method anyway but the geometry passed to the layer will be empty. This is required for layers that generate their own geometry from other information in the rendering context.

Definition at line 627 of file qgssymbol.cpp.

◆ renderVertexMarker()

void QgsSymbol::renderVertexMarker ( QPointF  pt,
QgsRenderContext context,
int  currentVertexMarkerType,
int  currentVertexMarkerSize 
)
protected

Render editing vertex marker at specified point.

Since
QGIS 2.16

Definition at line 1033 of file qgssymbol.cpp.

◆ setClipFeaturesToExtent()

void QgsSymbol::setClipFeaturesToExtent ( bool  clipFeaturesToExtent)
inline

Sets whether features drawn by the symbol should be clipped to the render context's extent.

If this option is enabled then features which are partially outside the extent will be clipped. This speeds up rendering of the feature, but may have undesirable side effects for certain symbol types.

Parameters
clipFeaturesToExtentset to true to enable clipping (defaults to true)
Since
QGIS 2.9
See also
clipFeaturesToExtent

Definition at line 287 of file qgssymbol.h.

◆ setColor()

void QgsSymbol::setColor ( const QColor &  color)

Definition at line 445 of file qgssymbol.cpp.

◆ setLayer()

void QgsSymbol::setLayer ( const QgsVectorLayer layer)
inline
Note
the layer will be NULL after stopRender

Definition at line 314 of file qgssymbol.h.

◆ setMapUnitScale()

void QgsSymbol::setMapUnitScale ( const QgsMapUnitScale scale)

Definition at line 258 of file qgssymbol.cpp.

◆ setOpacity()

void QgsSymbol::setOpacity ( qreal  opacity)
inline

Sets the opacity for the symbol.

Parameters
opacityopacity value between 0 (fully transparent) and 1 (fully opaque)
See also
opacity()

Definition at line 264 of file qgssymbol.h.

◆ setOutputUnit()

void QgsSymbol::setOutputUnit ( QgsUnitTypes::RenderUnit  unit)

Sets the units to use for sizes and widths within the symbol.

Individual symbol definitions will interpret this in different ways, e.g., a marker symbol may use it to specify the units for the marker size, while a line symbol may use it to specify the units for the line width.

Parameters
unitoutput units
See also
outputUnit()

Definition at line 250 of file qgssymbol.cpp.

◆ setRenderHints()

void QgsSymbol::setRenderHints ( RenderHints  hints)
inline

Sets rendering hint flags for the symbol.

See also
renderHints()

Definition at line 270 of file qgssymbol.h.

◆ startRender()

void QgsSymbol::startRender ( QgsRenderContext context,
const QgsFields fields = QgsFields() 
)

Begins the rendering process for the symbol.

This must be called before renderFeature(), and should be followed by a call to stopRender().

Parameters
contextrender context which symbol will be drawn using
fieldsfields for features to be rendered (usually the associated vector layer's fields). Required for correct calculation of data defined overrides.
See also
stopRender()

Definition at line 401 of file qgssymbol.cpp.

◆ stopRender()

void QgsSymbol::stopRender ( QgsRenderContext context)

Ends the rendering process.

This should be called after rendering all desired features.

Parameters
contextrender context, must match the context specified when startRender() was called.
See also
startRender()

Definition at line 423 of file qgssymbol.cpp.

◆ symbolLayer()

QgsSymbolLayer * QgsSymbol::symbolLayer ( int  layer)

Returns a specific symbol layers contained in the symbol.

Parameters
layerlayer number
Returns
corresponding symbol layer
Since
QGIS 2.7
See also
symbolLayers
symbolLayerCount

Definition at line 337 of file qgssymbol.cpp.

◆ symbolLayerCount()

int QgsSymbol::symbolLayerCount ( ) const
inline

Returns total number of symbol layers contained in the symbol.

Returns
count of symbol layers
Since
QGIS 2.7
See also
symbolLayers
symbolLayer

Definition at line 143 of file qgssymbol.h.

◆ symbolLayers()

QgsSymbolLayerList QgsSymbol::symbolLayers ( )
inline

Returns list of symbol layers contained in the symbol.

Returns
symbol layers list
Since
QGIS 2.7
See also
symbolLayer
symbolLayerCount

Definition at line 124 of file qgssymbol.h.

◆ symbolRenderContext()

QgsSymbolRenderContext * QgsSymbol::symbolRenderContext ( )

Returns the symbol render context.

Only valid between startRender and stopRender calls.

Returns
The symbol render context

Definition at line 1028 of file qgssymbol.cpp.

◆ takeSymbolLayer()

QgsSymbolLayer * QgsSymbol::takeSymbolLayer ( int  index)

Remove symbol layer from the list and return pointer to it.

Ownership is handed to the caller.

Parameters
indexThe index of the layer to remove
Returns
A pointer to the removed layer

Definition at line 376 of file qgssymbol.cpp.

◆ toSld()

void QgsSymbol::toSld ( QDomDocument &  doc,
QDomElement &  element,
QgsStringMap  props 
) const

Definition at line 600 of file qgssymbol.cpp.

◆ type()

SymbolType QgsSymbol::type ( ) const
inline

Definition at line 113 of file qgssymbol.h.

◆ usedAttributes()

QSet< QString > QgsSymbol::usedAttributes ( const QgsRenderContext context) const

Return a list of attributes required to render this feature.

This should include any attributes required by the symbology including the ones required by expressions.

Definition at line 648 of file qgssymbol.cpp.

Friends And Related Function Documentation

◆ QgsFeatureRenderer

friend class QgsFeatureRenderer
friend

Definition at line 76 of file qgssymbol.h.

Member Data Documentation

◆ mClipFeaturesToExtent

bool QgsSymbol::mClipFeaturesToExtent = true
protected

Definition at line 400 of file qgssymbol.h.

◆ mLayer

const QgsVectorLayer* QgsSymbol::mLayer = nullptr
protected

Definition at line 402 of file qgssymbol.h.

◆ mLayers

QgsSymbolLayerList QgsSymbol::mLayers
protected

Definition at line 394 of file qgssymbol.h.

◆ mOpacity

qreal QgsSymbol::mOpacity = 1.0
protected

Symbol opacity (in the range 0 - 1)

Definition at line 397 of file qgssymbol.h.

◆ mRenderHints

RenderHints QgsSymbol::mRenderHints = nullptr
protected

Definition at line 399 of file qgssymbol.h.

◆ mType

SymbolType QgsSymbol::mType
protected

Definition at line 393 of file qgssymbol.h.


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