Class: QgsLegendPatchShape¶
- class qgis.core.QgsLegendPatchShape¶
Bases:
sip.wrapper
Represents a patch shape for use in map legends.
New in version 3.14.
QgsLegendPatchShape() Constructor for a null QgsLegendPatchShape.
A null
QgsLegendPatchShape
indicates that the default legend patch shape should be used instead.QgsLegendPatchShape(type: Qgis.SymbolType, geometry:
QgsGeometry
, preserveAspectRatio: bool = 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. SeesetGeometry()
for further details on the geometry requirements.If
preserveAspectRatio
isTrue
, then the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.QgsLegendPatchShape(
QgsLegendPatchShape
)Methods
Returns the geometry for the patch shape.
Returns
True
if the patch shape is a nullQgsLegendPatchShape
, which indicates that the default legend patch shape should be used instead.Returns
True
if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.Read settings from a DOM
element
.Returns
True
if the patch shape should by resized to the desired target size when rendering.Returns the patch shape's geometry, scaled to the given size.
Sets the
geometry
for the patch shape.Sets whether the patch shape should
preserve
its aspect ratio when it is resized to fit a desired legend patch size.Sets whether the patch shape should by resized to the desired target size when rendering.
Sets the symbol
type
associated with this patch.Returns the symbol type associated with this patch.
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 specifiedsize
(as geometry parts and rings).Write settings into a DOM
element
.- geometry(self) QgsGeometry ¶
Returns the geometry for the patch shape.
See also
- Return type:
- isNull(self) bool ¶
Returns
True
if the patch shape is a nullQgsLegendPatchShape
, which indicates that the default legend patch shape should be used instead.- Return type:
bool
- preserveAspectRatio(self) bool ¶
Returns
True
if the patch shape should preserve its aspect ratio when it is resized to fit a desired legend patch size.See also
- Return type:
bool
- readXml(self, element: QDomElement, context: QgsReadWriteContext)¶
Read settings from a DOM
element
.See also
- Parameters:
element (QDomElement) –
context (QgsReadWriteContext) –
- scaleToOutputSize(self) bool ¶
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
New in version 3.22.
- Return type:
bool
- scaledGeometry(self, size: QSizeF) QgsGeometry ¶
Returns the patch shape’s geometry, scaled to the given size.
Note that if
scaleToOutputSize()
isFalse
then no scaling will be applied.New in version 3.22.
- Parameters:
size (QSizeF) –
- Return type:
- setGeometry(self, geometry: QgsGeometry)¶
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
- Parameters:
geometry (QgsGeometry) –
- setPreserveAspectRatio(self, preserve: bool)¶
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
- Parameters:
preserve (bool) –
- setScaleToOutputSize(self, scale: bool)¶
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
New in version 3.22.
- Parameters:
scale (bool) –
- setSymbolType(self, type: Qgis.SymbolType)¶
Sets the symbol
type
associated with this patch.See also
- Parameters:
type (Qgis.SymbolType) –
- symbolType(self) Qgis.SymbolType ¶
Returns the symbol type associated with this patch.
See also
- Return type:
- toQPolygonF(self, type: Qgis.SymbolType, size: QSizeF) object ¶
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 specifiedsize
(as geometry parts and rings).- Parameters:
type (Qgis.SymbolType) –
size (QSizeF) –
- Return type:
object
- writeXml(self, element: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)¶
Write settings into a DOM
element
.See also
- Parameters:
element (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –