QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
Public Member Functions | List of all members
QgsLegendPatchShape Class Reference

Represents a patch shape for use in map legends. More...

#include <qgslegendpatchshape.h>

Public Member Functions

 QgsLegendPatchShape ()=default
 Constructor for a null QgsLegendPatchShape. More...
 
 QgsLegendPatchShape (Qgis::SymbolType type, const QgsGeometry &geometry, bool preserveAspectRatio=true)
 Constructor for QgsLegendPatchShape. More...
 
QgsGeometry geometry () const
 Returns the geometry for the patch shape. More...
 
bool isNull () const
 Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legend patch shape should be used instead. More...
 
bool preserveAspectRatio () const
 Returns true if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size. More...
 
void readXml (const QDomElement &element, const QgsReadWriteContext &context)
 Read settings from a DOM element. More...
 
QgsGeometry scaledGeometry (QSizeF size) const
 Returns the patch shape's geometry, scaled to the given size. More...
 
bool scaleToOutputSize () const
 Returns true if the patch shape should by resized to the desired target size when rendering. More...
 
void setGeometry (const QgsGeometry &geometry)
 Sets the geometry for the patch shape. More...
 
void setPreserveAspectRatio (bool preserve)
 Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size. More...
 
void setScaleToOutputSize (bool scale)
 Sets whether the patch shape should by resized to the desired target size when rendering. More...
 
void setSymbolType (Qgis::SymbolType type)
 Sets the symbol type associated with this patch. More...
 
Qgis::SymbolType symbolType () const
 Returns the symbol type associated with this patch. More...
 
QList< QList< QPolygonF > > toQPolygonF (Qgis::SymbolType type, QSizeF size) const
 Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for a symbol of the given type at the specified size (as geometry parts and rings). More...
 
void writeXml (QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
 Write settings into a DOM element. More...
 

Detailed Description

Represents a patch shape for use in map legends.

Since
QGIS 3.14

Definition at line 33 of file qgslegendpatchshape.h.

Constructor & Destructor Documentation

◆ QgsLegendPatchShape() [1/2]

QgsLegendPatchShape::QgsLegendPatchShape ( )
default

Constructor for a null QgsLegendPatchShape.

A null QgsLegendPatchShape indicates that the default legend patch shape should be used instead.

◆ QgsLegendPatchShape() [2/2]

QgsLegendPatchShape::QgsLegendPatchShape ( Qgis::SymbolType  type,
const QgsGeometry geometry,
bool  preserveAspectRatio = true 
)

Constructor for QgsLegendPatchShape.

The type argument specifies the symbol type associated with this patch.

The geometry argument gives the shape of the patch to render. See setGeometry() for further details on the geometry requirements.

If preserveAspectRatio is true, then the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

Definition at line 24 of file qgslegendpatchshape.cpp.

Member Function Documentation

◆ geometry()

QgsGeometry QgsLegendPatchShape::geometry ( ) const

Returns the geometry for the patch shape.

See also
setGeometry()

Definition at line 37 of file qgslegendpatchshape.cpp.

◆ isNull()

bool QgsLegendPatchShape::isNull ( ) const

Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legend patch shape should be used instead.

Definition at line 32 of file qgslegendpatchshape.cpp.

◆ preserveAspectRatio()

bool QgsLegendPatchShape::preserveAspectRatio ( ) const

Returns true if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

See also
setPreserveAspectRatio()

Definition at line 47 of file qgslegendpatchshape.cpp.

◆ readXml()

void QgsLegendPatchShape::readXml ( const QDomElement &  element,
const QgsReadWriteContext context 
)

Read settings from a DOM element.

See also
writeXml()

Definition at line 215 of file qgslegendpatchshape.cpp.

◆ scaledGeometry()

QgsGeometry QgsLegendPatchShape::scaledGeometry ( QSizeF  size) const

Returns the patch shape's geometry, scaled to the given size.

Note that if scaleToOutputSize() is false then no scaling will be applied.

Since
QGIS 3.22

Definition at line 94 of file qgslegendpatchshape.cpp.

◆ scaleToOutputSize()

bool QgsLegendPatchShape::scaleToOutputSize ( ) const

Returns true if the patch shape should by resized to the desired target size when rendering.

Resizing to the target size is the default behavior.

See also
setScaleToOutputSize()
Since
QGIS 3.22

Definition at line 57 of file qgslegendpatchshape.cpp.

◆ setGeometry()

void QgsLegendPatchShape::setGeometry ( const QgsGeometry geometry)

Sets the geometry for the patch shape.

The origin and size of the geometry is not important, as the legend renderer will automatically scale and transform the geometry to match the desired overall patch bounds.

Geometries for legend patches are rendered respecting the traditional "y values increase toward the top of the map" convention, as opposed to the standard computer graphics convention of "y values increase toward the bottom of the display".

Warning
The geometry type should match the patch shape's symbolType(), e.g. a fill symbol type should only have Polygon or MultiPolygon geometries set, while a line symbol type must have LineString or MultiLineString geometries.
See also
geometry()

Definition at line 42 of file qgslegendpatchshape.cpp.

◆ setPreserveAspectRatio()

void QgsLegendPatchShape::setPreserveAspectRatio ( bool  preserve)

Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.

The default behavior is to respect the geometry()'s aspect ratio.

See also
setPreserveAspectRatio()

Definition at line 52 of file qgslegendpatchshape.cpp.

◆ setScaleToOutputSize()

void QgsLegendPatchShape::setScaleToOutputSize ( bool  scale)

Sets whether the patch shape should by resized to the desired target size when rendering.

Resizing to the target size is the default behavior.

See also
scaleToOutputSize()
Since
QGIS 3.22

Definition at line 62 of file qgslegendpatchshape.cpp.

◆ setSymbolType()

void QgsLegendPatchShape::setSymbolType ( Qgis::SymbolType  type)

Sets the symbol type associated with this patch.

See also
symbolType()

Definition at line 234 of file qgslegendpatchshape.cpp.

◆ symbolType()

Qgis::SymbolType QgsLegendPatchShape::symbolType ( ) const

Returns the symbol type associated with this patch.

See also
setSymbolType()

Definition at line 229 of file qgslegendpatchshape.cpp.

◆ toQPolygonF()

QList< QList< QPolygonF > > QgsLegendPatchShape::toQPolygonF ( Qgis::SymbolType  type,
QSizeF  size 
) const

Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for a symbol of the given type at the specified size (as geometry parts and rings).

Definition at line 143 of file qgslegendpatchshape.cpp.

◆ writeXml()

void QgsLegendPatchShape::writeXml ( QDomElement &  element,
QDomDocument &  doc,
const QgsReadWriteContext context 
) const

Write settings into a DOM element.

See also
readXml()

Definition at line 222 of file qgslegendpatchshape.cpp.


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