35 mLineSymbol->setOutputUnit( unit );
50 mDistanceMapUnitScale =
scale;
57 return mDistanceMapUnitScale;
65 if (
properties.contains( QStringLiteral(
"x_attribute" ) ) )
69 if (
properties.contains( QStringLiteral(
"y_attribute" ) ) )
73 if (
properties.contains( QStringLiteral(
"distance_unit" ) ) )
77 if (
properties.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
81 if (
properties.contains( QStringLiteral(
"scale" ) ) )
85 if (
properties.contains( QStringLiteral(
"vector_field_type" ) ) )
89 if (
properties.contains( QStringLiteral(
"angle_orientation" ) ) )
93 if (
properties.contains( QStringLiteral(
"angle_units" ) ) )
97 if (
properties.contains( QStringLiteral(
"size" ) ) )
101 if (
properties.contains( QStringLiteral(
"size_unit" ) ) )
105 if (
properties.contains( QStringLiteral(
"size_map_unit_scale" ) ) )
109 if (
properties.contains( QStringLiteral(
"offset" ) ) )
113 if (
properties.contains( QStringLiteral(
"offset_unit" ) ) )
117 if (
properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
136 return mLineSymbol.get();
155 line << QPointF( 0, 50 );
156 line << QPointF( 100, 50 );
157 mLineSymbol->renderPolyline( line,
nullptr, context.
renderContext() );
164 double xComponent = 0;
165 double yComponent = 0;
170 xVal = f.
attribute( mXIndex ).toDouble();
175 yVal = f.
attribute( mYIndex ).toDouble();
185 switch ( mVectorFieldType )
189 destPoint = QPointF( point.x() + mScale * ctx.
convertToPainterUnits( xVal, mDistanceUnit, mDistanceMapUnitScale ),
196 convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
197 destPoint = QPointF( point.x() + mScale * ctx.
convertToPainterUnits( xComponent, mDistanceUnit, mDistanceMapUnitScale ),
198 point.y() - mScale * ctx.
convertToPainterUnits( yComponent, mDistanceUnit, mDistanceMapUnitScale ) );
204 destPoint = QPointF( point.x(), point.y() - ( mScale * ctx.
convertToPainterUnits( yVal, mDistanceUnit, mDistanceMapUnitScale ) ) );
211 const double radians = mapRotation * M_PI / 180.0;
212 destPoint = QPointF( cos( radians ) * ( destPoint.x() - point.x() ) - sin( radians ) * ( destPoint.y() - point.y() ) + point.x(),
213 sin( radians ) * ( destPoint.x() - point.x() ) + cos( radians ) * ( destPoint.y() - point.y() ) + point.y() );
218 mLineSymbol->renderPolyline( line, &f, context.
renderContext() );
263 properties[QStringLiteral(
"x_attribute" )] = mXAttribute;
264 properties[QStringLiteral(
"y_attribute" )] = mYAttribute;
267 properties[QStringLiteral(
"scale" )] = QString::number( mScale );
268 properties[QStringLiteral(
"vector_field_type" )] = QString::number( mVectorFieldType );
269 properties[QStringLiteral(
"angle_orientation" )] = QString::number( mAngleOrientation );
270 properties[QStringLiteral(
"angle_units" )] = QString::number( mAngleUnits );
289 element.appendChild( doc.createComment( QStringLiteral(
"VectorField not implemented yet..." ) ) );
290 mLineSymbol->toSld( doc, element, props );
310 if ( !mXAttribute.isEmpty() )
312 attributes.insert( mXAttribute );
314 if ( !mYAttribute.isEmpty() )
316 attributes.insert( mYAttribute );
320 attributes.unite( mLineSymbol->usedAttributes( context ) );
329 if ( mLineSymbol && mLineSymbol->hasDataDefinedProperties() )
334void QgsVectorFieldSymbolLayer::convertPolarToCartesian(
double length,
double angle,
double &x,
double &y )
const
354 x = length * std::sin(
angle );
355 y = length * std::cos(
angle );
361 mLineSymbol->setColor(
color );
368 return mLineSymbol ? mLineSymbol->color() :
mColor;
RenderUnit
Rendering size units.
@ Unknown
Mixed or unknown units.
@ MetersInMapUnits
Meters value as Map units.
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Container of fields for a vector layer.
bool isEmpty() const
Checks whether the container is empty.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A line symbol type, for rendering LineString and MultiLineString geometries.
Perform transforms between map coordinates and device coordinates.
double mapRotation() const
Returns the current map rotation in degrees (clockwise).
Struct for storing maximum and minimum scales for measurements in map units.
virtual void setSize(double size)
Sets the symbol size.
Qgis::RenderUnit mOffsetUnit
Offset units.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's offset.
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QPointF mOffset
Marker offset.
QgsMapUnitScale mapUnitScale() const override
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's size.
double size() const
Returns the symbol size.
QgsMapUnitScale mOffsetMapUnitScale
Offset map unit scale.
QgsMapUnitScale mSizeMapUnitScale
Marker size map unit scale.
Qgis::RenderUnit mSizeUnit
Marker size unit.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's size.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's offset.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
void setMapUnitScale(const QgsMapUnitScale &scale) override
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
const QgsFeature * feature() const
Returns the current feature being rendered.
QgsFields fields() const
Fields of the layer.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Abstract base class for all rendered symbols.
Qgis::SymbolType type() const
Returns the symbol's type.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
A symbol layer class for displaying displacement arrows based on point layer attributes.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
QColor color() const override
Returns the "representative" color of the symbol layer.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setYAttribute(const QString &attribute)
void setAngleUnits(AngleUnits units)
void setVectorFieldType(VectorFieldType type)
void setDistanceUnit(Qgis::RenderUnit unit)
Sets the units for the distance.
~QgsVectorFieldSymbolLayer() override
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void setAngleOrientation(AngleOrientation orientation)
Qgis::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsVectorFieldSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsVectorFieldSymbolLayer()
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
static QgsSymbolLayer * create(const QVariantMap &properties=QVariantMap())
Creates the symbol layer.
QgsMapUnitScale mapUnitScale() const override
void setXAttribute(const QString &attribute)
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
@ CounterclockwiseFromEast
static QgsSymbolLayer * createFromSld(QDomElement &element)
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props) const override
Saves the symbol layer as SLD.
void renderPoint(QPointF point, QgsSymbolRenderContext &context) override
Renders a marker at the specified point.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)