QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
26 , mGeometry( geometry )
27 , mPreserveAspectRatio( preserveAspectRatio )
49 return mPreserveAspectRatio;
59 const double *srcX = line->
xData();
60 const double *srcY = line->
yData();
62 QPolygonF thisRes( count );
63 QPointF *dest = thisRes.data();
64 for (
int i = 0; i < count; ++i )
66 *dest++ = QPointF( *srcX++, *srcY++ );
73 if (
const QgsLineString *line = qgsgeometry_cast< const QgsLineString * >( curve ) )
79 std::unique_ptr< QgsLineString > straightened( curve->
curveToLine() );
86 if (
isNull() || type != mSymbolType )
95 if ( mPreserveAspectRatio && bounds.height() > 0 && bounds.width() > 0 )
97 const double scaling = std::min( size.width() / bounds.width(), size.height() / bounds.height() );
98 const QSizeF scaledSize = bounds.size() * scaling;
99 dx = ( size.width() - scaledSize.width() ) / 2.0;
100 dy = ( size.height() - scaledSize.height() ) / 2.0;
105 QPolygonF targetRectPoly = QPolygonF() << QPointF( dx, dy + size.height() )
106 << QPointF( dx + size.width(), dy + size.height() )
107 << QPointF( dx + size.width(), dy )
108 << QPointF( dx, dy );
111 if ( bounds.width() > 0 && bounds.height() > 0 )
113 QPolygonF patchRectPoly = QPolygonF( bounds );
115 patchRectPoly.pop_back();
117 QTransform::quadToQuad( patchRectPoly, targetRectPoly, t );
119 else if ( bounds.width() > 0 )
121 t = QTransform::fromScale( size.width() / bounds.width(), 1 ).translate( -bounds.left(), size.height() / 2 - bounds.y() );
123 else if ( bounds.height() > 0 )
125 t = QTransform::fromScale( 1, size.height() / bounds.height() ).translate( size.width() / 2 - bounds.x(), -bounds.top() );
131 switch ( mSymbolType )
141 points << QPointF( ( *it ).x(), ( *it ).y() );
145 points << QPointF( static_cast< int >( size.width() ) / 2,
static_cast< int >( size.height() ) / 2 );
147 return QList< QList<QPolygonF> >() << ( QList< QPolygonF >() << points );
152 QList< QList<QPolygonF> > res;
156 res << ( QList< QPolygonF >() <<
curveToPolygonF( qgsgeometry_cast< const QgsCurve * >( *it ) ) );
163 QList< QList<QPolygonF> > res;
168 QList<QPolygonF> thisPart;
169 const QgsCurvePolygon *surface = qgsgeometry_cast< const QgsCurvePolygon * >( *it );
187 return QList< QList<QPolygonF> >();
190 return QList< QList<QPolygonF> >();
196 mPreserveAspectRatio = element.attribute( QStringLiteral(
"preserveAspect" ) ).toInt();
197 mSymbolType =
static_cast< QgsSymbol::SymbolType >( element.attribute( QStringLiteral(
"type" ) ).toInt() );
202 element.setAttribute( QStringLiteral(
"wkt" ), mGeometry.
isNull() ? QString() : mGeometry.
asWkt( ) );
203 element.setAttribute( QStringLiteral(
"preserveAspect" ), mPreserveAspectRatio ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
204 element.setAttribute( QStringLiteral(
"type" ), QString::number( mSymbolType ) );
Abstract base class for curved geometry type.
QList< QList< QPolygonF > > toQPolygonF(QgsSymbol::SymbolType type, QSizeF size) const
Converts the patch shape to a set of QPolygonF objects representing how the patch should be drawn for...
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsGeometry geometry() const
Returns the geometry for the patch shape.
QPolygonF lineStringToQPolygonF(const QgsLineString *line)
void setPreserveAspectRatio(bool preserve)
Sets whether the patch shape should preserve its aspect ratio when it is resized to fit a desired leg...
The class is used as a container of context for various read/write operations on other objects.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
QgsLegendPatchShape()=default
Constructor for a null QgsLegendPatchShape.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Curve polygon geometry type.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
const double * yData() const
Returns a const pointer to the y vertex data.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
QPolygonF curveToPolygonF(const QgsCurve *curve)
Line string geometry type, with support for z-dimension and m-values.
QgsSymbol::SymbolType symbolType() const
Returns the symbol type associated with this patch.
const double * xData() const
Returns a const pointer to the x vertex data.
static QgsStyle * defaultStyle()
Returns default application-wide style.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
bool preserveAspectRatio() const
Returns true if the patch shape should preserve its aspect ratio when it is resized to fit a desired ...
void setGeometry(const QgsGeometry &geometry)
Sets the geometry for the patch shape.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
QList< QList< QPolygonF > > defaultPatchAsQPolygonF(QgsSymbol::SymbolType type, QSizeF size) const
Returns the default patch geometry for the given symbol type and size as a set of QPolygonF objects (...
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type associated with this patch.
A geometry is the spatial representation of a feature.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
SymbolType
Type of the symbol.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
int numPoints() const override SIP_HOLDGIL
Returns the number of points in the curve.
void writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
virtual QgsLineString * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...