QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
QgsSymbolV2 Class Referenceabstract

#include <qgssymbolv2.h>

Inheritance diagram for QgsSymbolV2:
Inheritance graph
[legend]

Public Types

enum  OutputUnit {
  MM = 0, MapUnit, Mixed, Pixel,
  Percentage
}
 The unit of the output. More...
 
typedef QList< OutputUnitOutputUnitList
 
enum  RenderHint { DataDefinedSizeScale = 1, DataDefinedRotation = 2 }
 
enum  ScaleMethod { ScaleArea, ScaleDiameter }
 Scale method. More...
 
enum  SymbolType { Marker, Line, Fill, Hybrid }
 Type of the symbol. More...
 

Public Member Functions

virtual ~QgsSymbolV2 ()
 
qreal alpha () const
 Get alpha transparency 1 for opaque, 0 for invisible. More...
 
bool appendSymbolLayer (QgsSymbolLayerV2 *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, QgsSymbolLayerV2 *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 QgsSymbolV2clone () const =0
 
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 utilises any data defined properties. More...
 
bool insertSymbolLayer (int index, QgsSymbolLayerV2 *layer)
 Insert symbol layer to specified index Ownership will be transferred. More...
 
const QgsVectorLayerlayer () const
 
QgsMapUnitScale mapUnitScale () const
 
QgsSymbolV2::OutputUnit outputUnit () const
 
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...
 
int renderHints () const
 
void setAlpha (qreal alpha)
 Set alpha transparency 1 for opaque, 0 for invisible. 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 setOutputUnit (QgsSymbolV2::OutputUnit u)
 
void setRenderHints (int hints)
 
void startRender (QgsRenderContext &context, const QgsFields *fields=nullptr)
 
void stopRender (QgsRenderContext &context)
 
QgsSymbolLayerV2symbolLayer (int layer)
 Returns a specific symbol layers contained in the symbol. More...
 
int symbolLayerCount ()
 Returns total number of symbol layers contained in the symbol. More...
 
QgsSymbolLayerV2List symbolLayers ()
 Returns list of symbol layers contained in the symbol. More...
 
QgsSymbolV2RenderContextsymbolRenderContext ()
 Returns the symbol render context. More...
 
QgsSymbolLayerV2takeSymbolLayer (int index)
 Remove symbol layer from the list and return pointer to it. More...
 
void toSld (QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
 Writes the SLD element following the SLD v1.1 specs. More...
 
SymbolType type () const
 
QSet< QStringusedAttributes () const
 Return a list of attributes required to render this feature. More...
 

Static Public Member Functions

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

Protected Member Functions

 QgsSymbolV2 (SymbolType type, const QgsSymbolLayerV2List &layers)
 
QgsSymbolLayerV2List cloneLayers () const
 Retrieve a cloned list of all layers that make up this symbol. More...
 
Q_DECL_DEPRECATED bool isSymbolLayerCompatible (SymbolType layerType)
 check whether a symbol layer type can be used within the symbol (marker-marker, line-line, fill-fill/line) More...
 
void renderUsingLayer (QgsSymbolLayerV2 *layer, QgsSymbolV2RenderContext &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 QgsConstWkbPtr _getLineString (QPolygonF &pts, QgsRenderContext &context, QgsConstWkbPtr &wkb, bool clipToExtent=true)
 Creates a line string in screen coordinates from a wkb string in map coordinates. More...
 
static void _getPoint (QPointF &pt, QgsRenderContext &context, const QgsPointV2 *point)
 Creates a point in screen coordinates from a QgsPointV2 in map coordinates. More...
 
static QgsConstWkbPtr _getPoint (QPointF &pt, QgsRenderContext &context, QgsConstWkbPtr &wkb)
 Creates a point in screen coordinates from a wkb string in map coordinates. More...
 
static QgsConstWkbPtr _getPolygon (QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, QgsConstWkbPtr &wkb, bool clipToExtent=true)
 Creates a polygon in screen coordinates from a wkb string in map coordinates. More...
 

Protected Attributes

qreal mAlpha
 Symbol opacity (in the range 0 - 1) More...
 
bool mClipFeaturesToExtent
 
const QgsVectorLayermLayer
 
QgsSymbolLayerV2List mLayers
 
int mRenderHints
 
SymbolType mType
 

Friends

class QgsFeatureRendererV2
 

Detailed Description

Definition at line 55 of file qgssymbolv2.h.

Member Typedef Documentation

◆ OutputUnitList

Definition at line 74 of file qgssymbolv2.h.

Member Enumeration Documentation

◆ OutputUnit

The unit of the output.

Enumerator
MM 

The output shall be in millimeters.

MapUnit 

The output shall be in map unitx.

Mixed 

Mixed units in symbol layers.

Pixel 

The output shall be in pixels.

Percentage 

The ouput shall be a percentage of another measurement (eg canvas size, feature size)

Definition at line 65 of file qgssymbolv2.h.

◆ RenderHint

Enumerator
DataDefinedSizeScale 
DataDefinedRotation 

Definition at line 96 of file qgssymbolv2.h.

◆ ScaleMethod

Scale method.

Enumerator
ScaleArea 

Calculate scale by the area.

ScaleDiameter 

Calculate scale by the diameter.

Definition at line 90 of file qgssymbolv2.h.

◆ SymbolType

Type of the symbol.

Enumerator
Marker 

Marker symbol.

Line 

Line symbol.

Fill 

Fill symbol.

Hybrid 

Hybrid symbol.

Definition at line 79 of file qgssymbolv2.h.

Constructor & Destructor Documentation

◆ ~QgsSymbolV2()

QgsSymbolV2::~QgsSymbolV2 ( )
virtual

Definition at line 245 of file qgssymbolv2.cpp.

◆ QgsSymbolV2()

QgsSymbolV2::QgsSymbolV2 ( SymbolType  type,
const QgsSymbolLayerV2List layers 
)
protected

Definition at line 85 of file qgssymbolv2.cpp.

Member Function Documentation

◆ _getLineString()

QgsConstWkbPtr QgsSymbolV2::_getLineString ( QPolygonF pts,
QgsRenderContext context,
QgsConstWkbPtr wkb,
bool  clipToExtent = true 
)
staticprotected

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

Definition at line 127 of file qgssymbolv2.cpp.

◆ _getPoint() [1/2]

static void QgsSymbolV2::_getPoint ( QPointF pt,
QgsRenderContext context,
const QgsPointV2 point 
)
inlinestaticprotected

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

Definition at line 265 of file qgssymbolv2.h.

◆ _getPoint() [2/2]

QgsConstWkbPtr QgsSymbolV2::_getPoint ( QPointF pt,
QgsRenderContext context,
QgsConstWkbPtr wkb 
)
staticprotected

Creates a point in screen coordinates from a wkb string in map coordinates.

Definition at line 110 of file qgssymbolv2.cpp.

◆ _getPolygon()

QgsConstWkbPtr QgsSymbolV2::_getPolygon ( QPolygonF pts,
QList< QPolygonF > &  holes,
QgsRenderContext context,
QgsConstWkbPtr wkb,
bool  clipToExtent = true 
)
staticprotected

Creates a polygon in screen coordinates from a wkb string in map coordinates.

Definition at line 177 of file qgssymbolv2.cpp.

◆ alpha()

qreal QgsSymbolV2::alpha ( ) const
inline

Get alpha transparency 1 for opaque, 0 for invisible.

Definition at line 204 of file qgssymbolv2.h.

◆ appendSymbolLayer()

bool QgsSymbolV2::appendSymbolLayer ( QgsSymbolLayerV2 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 399 of file qgssymbolv2.cpp.

◆ asImage()

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

Generate symbol as image.

Definition at line 549 of file qgssymbolv2.cpp.

◆ bigSymbolPreviewImage()

QImage QgsSymbolV2::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 563 of file qgssymbolv2.cpp.

◆ changeSymbolLayer()

bool QgsSymbolV2::changeSymbolLayer ( int  index,
QgsSymbolLayerV2 layer 
)

delete layer at specified index and set a new one

Definition at line 429 of file qgssymbolv2.cpp.

◆ clipFeaturesToExtent()

bool QgsSymbolV2::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
Note
added in QGIS 2.9
See also
setClipFeaturesToExtent

Definition at line 229 of file qgssymbolv2.h.

◆ clone()

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

◆ cloneLayers()

QgsSymbolLayerV2List QgsSymbolV2::cloneLayers ( ) const
protected

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

Ownership is transferred to the caller.

Definition at line 647 of file qgssymbolv2.cpp.

◆ color()

QColor QgsSymbolV2::color ( ) const

Definition at line 490 of file qgssymbolv2.cpp.

◆ defaultSymbol()

QgsSymbolV2 * QgsSymbolV2::defaultSymbol ( QGis::GeometryType  geomType)
static

return new default symbol for specified geometry type

Definition at line 313 of file qgssymbolv2.cpp.

◆ deleteSymbolLayer()

bool QgsSymbolV2::deleteSymbolLayer ( int  index)

delete symbol layer at specified index

Definition at line 409 of file qgssymbolv2.cpp.

◆ drawPreviewIcon()

void QgsSymbolV2::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.

Note
customContext parameter added in 2.6

Definition at line 501 of file qgssymbolv2.cpp.

◆ dump()

QString QgsSymbolV2::dump ( ) const

Definition at line 607 of file qgssymbolv2.cpp.

◆ exportImage()

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

export symbol as image format. PNG and SVG supported

Definition at line 529 of file qgssymbolv2.cpp.

◆ hasDataDefinedProperties()

bool QgsSymbolV2::hasDataDefinedProperties ( ) const

Returns whether the symbol utilises any data defined properties.

Note
added in QGIS 2.12

Definition at line 698 of file qgssymbolv2.cpp.

◆ insertSymbolLayer()

bool QgsSymbolV2::insertSymbolLayer ( int  index,
QgsSymbolLayerV2 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 386 of file qgssymbolv2.cpp.

◆ isSymbolLayerCompatible()

bool QgsSymbolV2::isSymbolLayerCompatible ( SymbolType  layerType)
protected

check whether a symbol layer type can be used within the symbol (marker-marker, line-line, fill-fill/line)

Deprecated:
since 2.14, use QgsSymbolLayerV2::isCompatibleWithSymbol instead

Definition at line 376 of file qgssymbolv2.cpp.

◆ layer()

const QgsVectorLayer* QgsSymbolV2::layer ( ) const
inline

Definition at line 245 of file qgssymbolv2.h.

◆ mapUnitScale()

QgsMapUnitScale QgsSymbolV2::mapUnitScale ( ) const

Definition at line 273 of file qgssymbolv2.cpp.

◆ outputUnit()

QgsSymbolV2::OutputUnit QgsSymbolV2::outputUnit ( ) const

Definition at line 252 of file qgssymbolv2.cpp.

◆ renderFeature()

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

Render a feature.

Definition at line 730 of file qgssymbolv2.cpp.

◆ renderHints()

int QgsSymbolV2::renderHints ( ) const
inline

Definition at line 209 of file qgssymbolv2.h.

◆ renderUsingLayer()

void QgsSymbolV2::renderUsingLayer ( QgsSymbolLayerV2 layer,
QgsSymbolV2RenderContext 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 660 of file qgssymbolv2.cpp.

◆ renderVertexMarker()

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

Render editing vertex marker at specified point.

Note
added in QGIS 2.16

Definition at line 1069 of file qgssymbolv2.cpp.

◆ setAlpha()

void QgsSymbolV2::setAlpha ( qreal  alpha)
inline

Set alpha transparency 1 for opaque, 0 for invisible.

Definition at line 206 of file qgssymbolv2.h.

◆ setClipFeaturesToExtent()

void QgsSymbolV2::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)
Note
added in QGIS 2.9
See also
clipFeaturesToExtent

Definition at line 219 of file qgssymbolv2.h.

◆ setColor()

void QgsSymbolV2::setColor ( const QColor color)

Definition at line 481 of file qgssymbolv2.cpp.

◆ setLayer()

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

Definition at line 244 of file qgssymbolv2.h.

◆ setMapUnitScale()

void QgsSymbolV2::setMapUnitScale ( const QgsMapUnitScale scale)

Definition at line 305 of file qgssymbolv2.cpp.

◆ setOutputUnit()

void QgsSymbolV2::setOutputUnit ( QgsSymbolV2::OutputUnit  u)

Definition at line 297 of file qgssymbolv2.cpp.

◆ setRenderHints()

void QgsSymbolV2::setRenderHints ( int  hints)
inline

Definition at line 208 of file qgssymbolv2.h.

◆ startRender()

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

Definition at line 445 of file qgssymbolv2.cpp.

◆ stopRender()

void QgsSymbolV2::stopRender ( QgsRenderContext context)

Definition at line 463 of file qgssymbolv2.cpp.

◆ symbolLayer()

QgsSymbolLayerV2 * QgsSymbolV2::symbolLayer ( int  layer)

Returns a specific symbol layers contained in the symbol.

Parameters
layerlayer number
Returns
corresponding symbol layer
Note
added in QGIS 2.7
See also
symbolLayers
symbolLayerCount

Definition at line 370 of file qgssymbolv2.cpp.

◆ symbolLayerCount()

int QgsSymbolV2::symbolLayerCount ( )
inline

Returns total number of symbol layers contained in the symbol.

Returns
count of symbol layers
Note
added in QGIS 2.7
See also
symbolLayers
symbolLayer

Definition at line 134 of file qgssymbolv2.h.

◆ symbolLayers()

QgsSymbolLayerV2List QgsSymbolV2::symbolLayers ( )
inline

Returns list of symbol layers contained in the symbol.

Returns
symbol layers list
Note
added in QGIS 2.7
See also
symbolLayer
symbolLayerCount

Definition at line 117 of file qgssymbolv2.h.

◆ symbolRenderContext()

QgsSymbolV2RenderContext * QgsSymbolV2::symbolRenderContext ( )

Returns the symbol render context.

Only valid between startRender and stopRender calls.

Returns
The symbol render context

Definition at line 1064 of file qgssymbolv2.cpp.

◆ takeSymbolLayer()

QgsSymbolLayerV2 * QgsSymbolV2::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 420 of file qgssymbolv2.cpp.

◆ toSld()

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

Writes the SLD element following the SLD v1.1 specs.

Definition at line 633 of file qgssymbolv2.cpp.

◆ type()

SymbolType QgsSymbolV2::type ( ) const
inline

Definition at line 107 of file qgssymbolv2.h.

◆ usedAttributes()

QSet< QString > QgsSymbolV2::usedAttributes ( ) 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 684 of file qgssymbolv2.cpp.

Friends And Related Function Documentation

◆ QgsFeatureRendererV2

friend class QgsFeatureRendererV2
friend

Definition at line 57 of file qgssymbolv2.h.

Member Data Documentation

◆ mAlpha

qreal QgsSymbolV2::mAlpha
protected

Symbol opacity (in the range 0 - 1)

Definition at line 330 of file qgssymbolv2.h.

◆ mClipFeaturesToExtent

bool QgsSymbolV2::mClipFeaturesToExtent
protected

Definition at line 333 of file qgssymbolv2.h.

◆ mLayer

const QgsVectorLayer* QgsSymbolV2::mLayer
protected

Definition at line 335 of file qgssymbolv2.h.

◆ mLayers

QgsSymbolLayerV2List QgsSymbolV2::mLayers
protected

Definition at line 327 of file qgssymbolv2.h.

◆ mRenderHints

int QgsSymbolV2::mRenderHints
protected

Definition at line 332 of file qgssymbolv2.h.

◆ mType

SymbolType QgsSymbolV2::mType
protected

Definition at line 326 of file qgssymbolv2.h.


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