QgsSimpleMarkerSymbolLayer class

Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.

Base classes

class QgsSimpleMarkerSymbolLayerBase
Abstract base class for simple marker symbol layers.

Public static functions

static auto create(const QgsStringMap& properties = QgsStringMap()) -> QgsSymbolLayer*
Creates a new QgsSimpleMarkerSymbolLayer.
static auto createFromSld(QDomElement& element) -> QgsSymbolLayer*
Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.

Constructors, destructors, conversion operators

QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayerBase::Shape shape = Circle, double size = DEFAULT_SIMPLEMARKER_SIZE, double angle = DEFAULT_SIMPLEMARKER_ANGLE, QgsSymbol::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD, const QColor& color = DEFAULT_SIMPLEMARKER_COLOR, const QColor& strokeColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR, Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEMARKER_JOINSTYLE)
Constructor for QgsSimpleMarkerSymbolLayer.

Public functions

auto bounds(QPointF point, QgsSymbolRenderContext& context) -> QRectF override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined overrides and offsets which are set for the marker layer.
auto clone() const -> QgsSimpleMarkerSymbolLayer* override
Shall be reimplemented by subclasses to create a deep copy of the instance.
auto color() const -> QColor override
The fill color.
auto fillColor() const -> QColor override
Gets fill color.
auto layerType() const -> QString override
Returns a string that represents this layer type.
auto outputUnit() const -> QgsUnitTypes::RenderUnit override
Returns the units to use for sizes and widths within the symbol layer.
auto penJoinStyle() const -> Qt::PenJoinStyle
Returns the marker's stroke join style (e.g., miter, bevel, etc).
auto properties() const -> QgsStringMap override
Should be reimplemented by subclasses to return a string map that contains the configuration information for the symbol layer.
void renderPoint(QPointF point, QgsSymbolRenderContext& context) override
Renders a marker at the specified point.
void setColor(const QColor& color) override
The fill color.
void setFillColor(const QColor& color) override
Set fill color.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the marker's stroke join style (e.g., miter, bevel, etc).
void setStrokeColor(const QColor& color) override
Sets the marker's stroke color.
void setStrokeStyle(Qt::PenStyle strokeStyle)
Sets the marker's stroke style (e.g., solid, dashed, etc)
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale& scale)
Sets the map scale for the width of the marker's stroke.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)
Sets the unit for the width of the marker's stroke.
auto strokeColor() const -> QColor override
Returns the marker's stroke color.
auto strokeStyle() const -> Qt::PenStyle
Returns the marker's stroke style (e.g., solid, dashed, etc)
auto strokeWidth() const -> double
Returns the width of the marker's stroke.
auto strokeWidthMapUnitScale() const -> const QgsMapUnitScale&
Returns the map scale for the width of the marker's stroke.
auto strokeWidthUnit() const -> QgsUnitTypes::RenderUnit
Returns the unit for the width of the marker's stroke.
auto writeDxf(QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolRenderContext& context, QPointF shift = QPointF(0.0, 0.0)) const -> bool override
write as DXF
void writeSldMarker(QDomDocument& doc, QDomElement& element, const QgsStringMap& props) const override
Writes the symbol layer definition as a SLD XML element.

Protected functions

void drawMarker(QPainter* p, QgsSymbolRenderContext& context)
Draws the marker shape in the specified painter.
auto prepareCache(QgsSymbolRenderContext& context) -> bool
Prepares cache image.

Protected static variables

static const int MAXIMUM_CACHE_WIDTH
Maximum width/height of cache image.

Protected variables

QBrush mBrush
QBrush corresponding to marker's fill style.
QImage mCache
Cached image of marker, if using cached version.
QPen mPen
QPen corresponding to marker's stroke style.
Qt::PenJoinStyle mPenJoinStyle
Stroke pen join style.
QBrush mSelBrush
QBrush to use as fill of selected symbols.
QImage mSelCache
Cached image of selected marker, if using cached version.
QPen mSelPen
QPen to use as stroke of selected symbols.
QColor mStrokeColor
Stroke color.
Qt::PenStyle mStrokeStyle
Stroke style.
double mStrokeWidth
Stroke width.
QgsMapUnitScale mStrokeWidthMapUnitScale
Stroke width map unit scale.
QgsUnitTypes::RenderUnit mStrokeWidthUnit
Stroke width units.
bool mUsingCache
True if using cached images of markers for drawing.

Private functions

void draw(QgsSymbolRenderContext& context, QgsSimpleMarkerSymbolLayerBase::Shape shape, const QPolygonF& polygon, const QPainterPath& path) override SIP_FORCE virtual
Derived classes must implement draw() to handle drawing the generated shape onto the painter surface.

Function documentation

static QgsSymbolLayer* QgsSimpleMarkerSymbolLayer::create(const QgsStringMap& properties = QgsStringMap())

Creates a new QgsSimpleMarkerSymbolLayer.

Parameters
properties a property map containing symbol properties (see properties())
Returns new QgsSimpleMarkerSymbolLayer

static QgsSymbolLayer* QgsSimpleMarkerSymbolLayer::createFromSld(QDomElement& element)

Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.

Parameters
element XML element containing SLD definition of symbol
Returns new QgsSimpleMarkerSymbolLayer

QgsSimpleMarkerSymbolLayer::QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayerBase::Shape shape = Circle, double size = DEFAULT_SIMPLEMARKER_SIZE, double angle = DEFAULT_SIMPLEMARKER_ANGLE, QgsSymbol::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD, const QColor& color = DEFAULT_SIMPLEMARKER_COLOR, const QColor& strokeColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR, Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEMARKER_JOINSTYLE)

Constructor for QgsSimpleMarkerSymbolLayer.

Parameters
shape symbol shape
size symbol size (in mm)
angle symbol rotation angle
scaleMethod scaling method for data defined scaling
color fill color for symbol
strokeColor stroke color for symbol
penJoinStyle join style for stroke pen

QRectF QgsSimpleMarkerSymbolLayer::bounds(QPointF point, QgsSymbolRenderContext& context) override

Returns the approximate bounding box of the marker symbol layer, taking into account any data defined overrides and offsets which are set for the marker layer.

Returns approximate symbol bounds, in painter units

QColor QgsSimpleMarkerSymbolLayer::fillColor() const override

Gets fill color.

Supported by marker and fill layers.

QString QgsSimpleMarkerSymbolLayer::layerType() const override

Returns a string that represents this layer type.

Used for serialization. Should match with the string used to register this symbol layer in the registry.

QgsUnitTypes::RenderUnit QgsSimpleMarkerSymbolLayer::outputUnit() const override

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

Returns output unit, or QgsUnitTypes::RenderUnknownUnit if the symbol layer contains mixed units

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

Qt::PenJoinStyle QgsSimpleMarkerSymbolLayer::penJoinStyle() const

Returns the marker's stroke join style (e.g., miter, bevel, etc).

QgsStringMap QgsSimpleMarkerSymbolLayer::properties() const override

Should be reimplemented by subclasses to return a string map that contains the configuration information for the symbol layer.

This is used to serialize a symbol layer perstistently.

void QgsSimpleMarkerSymbolLayer::renderPoint(QPointF point, QgsSymbolRenderContext& context) override

Renders a marker at the specified point.

Parameters
point position at which to render point, in painter units
context symbol render context

Derived classes must implement this to handle drawing the point.

void QgsSimpleMarkerSymbolLayer::setFillColor(const QColor& color) override

Set fill color.

Supported by marker and fill layers.

void QgsSimpleMarkerSymbolLayer::setOutputUnit(QgsUnitTypes::RenderUnit unit) override

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

Parameters
unit output units

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

void QgsSimpleMarkerSymbolLayer::setPenJoinStyle(Qt::PenJoinStyle style)

Sets the marker's stroke join style (e.g., miter, bevel, etc).

Parameters
style join style

void QgsSimpleMarkerSymbolLayer::setStrokeColor(const QColor& color) override

Sets the marker's stroke color.

Parameters
color stroke color

void QgsSimpleMarkerSymbolLayer::setStrokeStyle(Qt::PenStyle strokeStyle)

Sets the marker's stroke style (e.g., solid, dashed, etc)

Parameters
strokeStyle style

void QgsSimpleMarkerSymbolLayer::setStrokeWidth(double w)

Sets the width of the marker's stroke.

Parameters
w stroke width. See strokeWidthUnit() for units.

void QgsSimpleMarkerSymbolLayer::setStrokeWidthMapUnitScale(const QgsMapUnitScale& scale)

Sets the map scale for the width of the marker's stroke.

Parameters
scale stroke width map unit scale

void QgsSimpleMarkerSymbolLayer::setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)

Sets the unit for the width of the marker's stroke.

Parameters
u stroke width unit

QColor QgsSimpleMarkerSymbolLayer::strokeColor() const override

Returns the marker's stroke color.

Qt::PenStyle QgsSimpleMarkerSymbolLayer::strokeStyle() const

Returns the marker's stroke style (e.g., solid, dashed, etc)

double QgsSimpleMarkerSymbolLayer::strokeWidth() const

Returns the width of the marker's stroke.

const QgsMapUnitScale& QgsSimpleMarkerSymbolLayer::strokeWidthMapUnitScale() const

Returns the map scale for the width of the marker's stroke.

QgsUnitTypes::RenderUnit QgsSimpleMarkerSymbolLayer::strokeWidthUnit() const

Returns the unit for the width of the marker's stroke.

void QgsSimpleMarkerSymbolLayer::writeSldMarker(QDomDocument& doc, QDomElement& element, const QgsStringMap& props) const override

Writes the symbol layer definition as a SLD XML element.

Parameters
doc XML document
element parent XML element
props symbol layer definition (see properties())

void QgsSimpleMarkerSymbolLayer::drawMarker(QPainter* p, QgsSymbolRenderContext& context) protected

Draws the marker shape in the specified painter.

Parameters
p destination QPainter
context symbol context

bool QgsSimpleMarkerSymbolLayer::prepareCache(QgsSymbolRenderContext& context) protected

Prepares cache image.

Returns true in case of success, false if cache image size too large

void QgsSimpleMarkerSymbolLayer::draw(QgsSymbolRenderContext& context, QgsSimpleMarkerSymbolLayerBase::Shape shape, const QPolygonF& polygon, const QPainterPath& path) override SIP_FORCE virtual private

Derived classes must implement draw() to handle drawing the generated shape onto the painter surface.

Parameters
context symbol render context
shape shape to draw
polygon polygon representing transformed marker shape. May be empty, in which case the shape will be specified in the path argument.
path transformed painter path representing shape to draw

Variable documentation

bool QgsSimpleMarkerSymbolLayer::mUsingCache protected

True if using cached images of markers for drawing.

This is faster, but cannot be used when data defined properties are present