45 mDistanceMapUnitScale =
scale;
52 return mDistanceMapUnitScale;
60 if ( properties.contains( QStringLiteral(
"x_attribute" ) ) )
62 symbolLayer->
setXAttribute( properties[QStringLiteral(
"x_attribute" )] );
64 if ( properties.contains( QStringLiteral(
"y_attribute" ) ) )
66 symbolLayer->
setYAttribute( properties[QStringLiteral(
"y_attribute" )] );
68 if ( properties.contains( QStringLiteral(
"distance_unit" ) ) )
72 if ( properties.contains( QStringLiteral(
"distance_map_unit_scale" ) ) )
76 if ( properties.contains( QStringLiteral(
"scale" ) ) )
78 symbolLayer->
setScale( properties[QStringLiteral(
"scale" )].toDouble() );
80 if ( properties.contains( QStringLiteral(
"vector_field_type" ) ) )
82 symbolLayer->
setVectorFieldType( static_cast< VectorFieldType >( properties[QStringLiteral(
"vector_field_type" )].toInt() ) );
84 if ( properties.contains( QStringLiteral(
"angle_orientation" ) ) )
86 symbolLayer->
setAngleOrientation( static_cast< AngleOrientation >( properties[QStringLiteral(
"angle_orientation" )].toInt() ) );
88 if ( properties.contains( QStringLiteral(
"angle_units" ) ) )
90 symbolLayer->
setAngleUnits( static_cast< AngleUnits >( properties[QStringLiteral(
"angle_units" )].toInt() ) );
92 if ( properties.contains( QStringLiteral(
"size" ) ) )
94 symbolLayer->
setSize( properties[QStringLiteral(
"size" )].toDouble() );
96 if ( properties.contains( QStringLiteral(
"size_unit" ) ) )
100 if ( properties.contains( QStringLiteral(
"size_map_unit_scale" ) ) )
104 if ( properties.contains( QStringLiteral(
"offset" ) ) )
108 if ( properties.contains( QStringLiteral(
"offset_unit" ) ) )
112 if ( properties.contains( QStringLiteral(
"offset_map_unit_scale" ) ) )
123 mLineSymbol.reset( static_cast<QgsLineSymbol *>( symbol ) );
143 line << QPointF( 0, 50 );
144 line << QPointF( 100, 50 );
145 mLineSymbol->renderPolyline( line,
nullptr, context.
renderContext() );
148 double xComponent = 0;
149 double yComponent = 0;
152 if ( f && mXIndex != -1 )
154 xVal = f->
attribute( mXIndex ).toDouble();
157 if ( f && mYIndex != -1 )
159 yVal = f->
attribute( mYIndex ).toDouble();
162 switch ( mVectorFieldType )
169 convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
181 xComponent *= mScale;
182 yComponent *= mScale;
186 line << QPointF( point.x() + xComponent, point.y() - yComponent );
187 mLineSymbol->renderPolyline( line, f, context.
renderContext() );
231 properties[QStringLiteral(
"x_attribute" )] = mXAttribute;
232 properties[QStringLiteral(
"y_attribute" )] = mYAttribute;
235 properties[QStringLiteral(
"scale" )] = QString::number( mScale );
236 properties[QStringLiteral(
"vector_field_type" )] = QString::number( mVectorFieldType );
237 properties[QStringLiteral(
"angle_orientation" )] = QString::number( mAngleOrientation );
238 properties[QStringLiteral(
"angle_units" )] = QString::number( mAngleUnits );
239 properties[QStringLiteral(
"size" )] = QString::number(
mSize );
250 element.appendChild( doc.createComment( QStringLiteral(
"VectorField not implemented yet..." ) ) );
251 mLineSymbol->toSld( doc, element, props );
271 if ( !mXAttribute.isEmpty() )
273 attributes.insert( mXAttribute );
275 if ( !mYAttribute.isEmpty() )
277 attributes.insert( mYAttribute );
281 attributes.unite( mLineSymbol->usedAttributes( context ) );
286 void QgsVectorFieldSymbolLayer::convertPolarToCartesian(
double length,
double angle,
double &x,
double &y )
const 306 x = length * std::sin(
angle );
307 y = length * std::cos(
angle );
313 mLineSymbol->setColor( color );
320 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)
set 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
set 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)