23 , mGeometry( geometry )
24 , mPreserveAspectRatio( preserveAspectRatio )
46 return mPreserveAspectRatio;
56 return mScaleToTargetSize;
61 mScaleToTargetSize = scale;
67 if ( mScaleToTargetSize )
75 if ( mPreserveAspectRatio && bounds.height() > 0 && bounds.width() > 0 )
77 const double scaling = std::min( size.width() / bounds.width(), size.height() / bounds.height() );
78 const QSizeF scaledSize = bounds.size() * scaling;
79 dx = ( size.width() - scaledSize.width() ) / 2.0;
80 dy = ( size.height() - scaledSize.height() ) / 2.0;
85 const QPolygonF targetRectPoly = QPolygonF() << QPointF( dx, dy + size.height() )
86 << QPointF( dx + size.width(), dy + size.height() )
87 << QPointF( dx + size.width(), dy )
91 if ( bounds.width() > 0 && bounds.height() > 0 )
93 QPolygonF patchRectPoly = QPolygonF( bounds );
95 patchRectPoly.pop_back();
97 QTransform::quadToQuad( patchRectPoly, targetRectPoly, t );
99 else if ( bounds.width() > 0 )
101 t = QTransform::fromScale( size.width() / bounds.width(), 1 ).translate( -bounds.left(), size.height() / 2 - bounds.y() );
103 else if ( bounds.height() > 0 )
105 t = QTransform::fromScale( 1, size.height() / bounds.height() ).translate( size.width() / 2 - bounds.x(), -bounds.top() );
115 if (
isNull() || type != mSymbolType )
122 points << QPointF( size.width() / 2, size.height() / 2 );
123 return QList< QList<QPolygonF> >() << ( QList< QPolygonF >() << points );
132 mPreserveAspectRatio = element.attribute( QStringLiteral(
"preserveAspect" ) ).toInt();
133 mSymbolType =
static_cast< Qgis::SymbolType >( element.attribute( QStringLiteral(
"type" ) ).toInt() );
138 element.setAttribute( QStringLiteral(
"wkt" ), mGeometry.
isNull() ? QString() : mGeometry.
asWkt( ) );
139 element.setAttribute( QStringLiteral(
"preserveAspect" ), mPreserveAspectRatio ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
140 element.setAttribute( QStringLiteral(
"type" ), QString::number(
static_cast< int >( mSymbolType ) ) );
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
static Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
bool scaleToOutputSize() const
Returns true if the patch shape should by resized to the desired target size when rendering.
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type associated with this patch.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
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...
QgsGeometry scaledGeometry(QSizeF size) const
Returns the patch shape's geometry, scaled to the given size.
void setGeometry(const QgsGeometry &geometry)
Sets the geometry for the patch shape.
bool preserveAspectRatio() const
Returns true if the patch shape should preserve its aspect ratio when it is resized to fit a desired ...
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
QgsLegendPatchShape()=default
Constructor for a null QgsLegendPatchShape.
void setPreserveAspectRatio(bool preserve)
Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired leg...
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsGeometry geometry() const
Returns the geometry for the patch shape.
void setScaleToOutputSize(bool scale)
Sets whether the patch shape should by resized to the desired target size when rendering.
Qgis::SymbolType symbolType() const
Returns the symbol type associated with this patch.
The class is used as a container of context for various read/write operations on other objects.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(Qgis::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
static QList< QList< QPolygonF > > toQPolygonF(const QgsGeometry &geometry, Qgis::SymbolType type)
Converts a geometry to a set of QPolygonF objects representing how the geometry should be drawn for a...
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.