46 mDistanceMapUnitScale =
scale;
53 return mDistanceMapUnitScale;
61 if ( properties.contains( QStringLiteral(
"x_attribute" ) ) )
63 symbolLayer->
setXAttribute( properties[QStringLiteral(
"x_attribute" )] );
65 if ( properties.contains( QStringLiteral(
"y_attribute" ) ) )
67 symbolLayer->
setYAttribute( properties[QStringLiteral(
"y_attribute" )] );
69 if ( properties.contains( QStringLiteral(
"distance_unit" ) ) )
73 if ( properties.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
77 if ( properties.contains( QStringLiteral(
"scale" ) ) )
79 symbolLayer->
setScale( properties[QStringLiteral(
"scale" )].toDouble() );
81 if ( properties.contains( QStringLiteral(
"vector_field_type" ) ) )
83 symbolLayer->
setVectorFieldType( static_cast< VectorFieldType >( properties[QStringLiteral(
"vector_field_type" )].toInt() ) );
85 if ( properties.contains( QStringLiteral(
"angle_orientation" ) ) )
87 symbolLayer->
setAngleOrientation( static_cast< AngleOrientation >( properties[QStringLiteral(
"angle_orientation" )].toInt() ) );
89 if ( properties.contains( QStringLiteral(
"angle_units" ) ) )
91 symbolLayer->
setAngleUnits( static_cast< AngleUnits >( properties[QStringLiteral(
"angle_units" )].toInt() ) );
93 if ( properties.contains( QStringLiteral(
"size" ) ) )
95 symbolLayer->
setSize( properties[QStringLiteral(
"size" )].toDouble() );
97 if ( properties.contains( QStringLiteral(
"size_unit" ) ) )
101 if ( properties.contains( QStringLiteral(
"size_map_unit_scale" ) ) )
105 if ( properties.contains( QStringLiteral(
"offset" ) ) )
109 if ( properties.contains( QStringLiteral(
"offset_unit" ) ) )
113 if ( properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
124 mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
144 line << QPointF( 0, 50 );
145 line << QPointF( 100, 50 );
146 mLineSymbol->renderPolyline( line,
nullptr, context.
renderContext() );
149 double xComponent = 0;
150 double yComponent = 0;
153 if ( f && mXIndex != -1 )
155 xVal = f->
attribute( mXIndex ).toDouble();
158 if ( f && mYIndex != -1 )
160 yVal = f->
attribute( mYIndex ).toDouble();
163 switch ( mVectorFieldType )
170 convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
182 xComponent *= mScale;
183 yComponent *= mScale;
187 line << QPointF( point.x() + xComponent, point.y() - yComponent );
188 mLineSymbol->renderPolyline( line, f, context.
renderContext() );
232 properties[QStringLiteral(
"x_attribute" )] = mXAttribute;
233 properties[QStringLiteral(
"y_attribute" )] = mYAttribute;
236 properties[QStringLiteral(
"scale" )] = QString::number( mScale );
237 properties[QStringLiteral(
"vector_field_type" )] = QString::number( mVectorFieldType );
238 properties[QStringLiteral(
"angle_orientation" )] = QString::number( mAngleOrientation );
239 properties[QStringLiteral(
"angle_units" )] = QString::number( mAngleUnits );
240 properties[QStringLiteral(
"size" )] = QString::number(
mSize );
251 element.appendChild( doc.createComment( QStringLiteral(
"VectorField not implemented yet..." ) ) );
252 mLineSymbol->toSld( doc, element, props );
272 if ( !mXAttribute.isEmpty() )
274 attributes.insert( mXAttribute );
276 if ( !mYAttribute.isEmpty() )
278 attributes.insert( mYAttribute );
282 attributes.unite( mLineSymbol->usedAttributes( context ) );
287 void QgsVectorFieldSymbolLayer::convertPolarToCartesian(
double length,
double angle,
double &x,
double &y )
const 307 x = length * std::sin(
angle );
308 y = length * std::cos(
angle );
314 mLineSymbol->setColor( color );
321 return mLineSymbol ? mLineSymbol->color() :
mColor;
QgsVectorFieldSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
QgsMapUnitScale mapUnitScale() const override
QgsMapUnitScale mapUnitScale() const override
void setXAttribute(const QString &attribute)
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol's offset.
void setYAttribute(const QString &attribute)
QgsFields fields() const
Fields of the layer.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QgsVectorFieldSymbolLayer()
void setAngleUnits(AngleUnits units)
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
QgsUnitTypes::RenderUnit mSizeUnit
Marker size unit.
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
void renderPoint(QPointF point, QgsSymbolRenderContext &context) override
Renders a marker at the specified point.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Container of fields for a vector layer.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's offset.
QPointF mOffset
Marker offset.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
QMap< QString, QString > QgsStringMap
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
A symbol layer class for displaying displacement arrows based on point layer attributes.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
QgsUnitTypes::RenderUnit mOffsetUnit
Offset units.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
double size() const
Returns the symbol size.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
QgsStringMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
void setSize(double size)
Sets the symbol size.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's size.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
QgsMapUnitScale mSizeMapUnitScale
Marker size map unit scale.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QColor color() const override
The fill color.
void startRender(QgsSymbolRenderContext &context) override
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
void setColor(const QColor &color) override
The fill color.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol's size.
bool setSubSymbol(QgsSymbol *symbol) override
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.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
Struct for storing maximum and minimum scales for measurements in map units.
void setMapUnitScale(const QgsMapUnitScale &scale) override
const QgsFeature * feature() const
Current feature being rendered - may be null.
void stopRender(QgsSymbolRenderContext &context) override
bool isEmpty() const
Check whether the container is empty.
void setAngleOrientation(AngleOrientation orientation)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QgsMapUnitScale mOffsetMapUnitScale
Offset map unit scale.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setVectorFieldType(VectorFieldType type)
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
RenderUnit
Rendering size units.
static QgsSymbolLayer * createFromSld(QDomElement &element)