QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsvectorfieldsymbollayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorfieldsymbollayer.h
3  -------------------------
4  begin : Octorer 25, 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSVECTORFIELDSYMBOLLAYER_H
19 #define QGSVECTORFIELDSYMBOLLAYER_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgssymbollayer.h"
24 
30 {
31  public:
33  {
34  Cartesian = 0,
36  Height
37  };
38 
40  {
41  ClockwiseFromNorth = 0,
42  CounterclockwiseFromEast
43  };
44 
46  {
47  Degrees = 0,
48  Radians
49  };
50 
52 
54  static QgsSymbolLayer *create( const QVariantMap &properties = QVariantMap() );
55  static QgsSymbolLayer *createFromSld( QDomElement &element );
56 
57  QString layerType() const override { return QStringLiteral( "VectorField" ); }
58 
59  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
60  QgsSymbol *subSymbol() override { return mLineSymbol.get(); }
61 
62  void setColor( const QColor &color ) override;
63  QColor color() const override;
64 
65  void renderPoint( QPointF point, QgsSymbolRenderContext &context ) override;
66  void startRender( QgsSymbolRenderContext &context ) override;
67  void stopRender( QgsSymbolRenderContext &context ) override;
68 
70  QVariantMap properties() const override;
71  bool usesMapUnits() const override;
72 
73  void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props ) const override;
74 
75  void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
76 
77  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
78  bool hasDataDefinedProperties() const override;
79 
80  //setters and getters
81  void setXAttribute( const QString &attribute ) { mXAttribute = attribute; }
82  QString xAttribute() const { return mXAttribute; }
83  void setYAttribute( const QString &attribute ) { mYAttribute = attribute; }
84  QString yAttribute() const { return mYAttribute; }
85  void setScale( double s ) { mScale = s; }
86  double scale() const { return mScale; }
87  void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; }
88  VectorFieldType vectorFieldType() const { return mVectorFieldType; }
89  void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; }
90  AngleOrientation angleOrientation() const { return mAngleOrientation; }
91  void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
92  AngleUnits angleUnits() const { return mAngleUnits; }
93 
94  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
95  QgsUnitTypes::RenderUnit outputUnit() const override;
96 
97  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
98  QgsMapUnitScale mapUnitScale() const override;
99 
105  void setDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mDistanceUnit = unit; }
106 
111  QgsUnitTypes::RenderUnit distanceUnit() const { return mDistanceUnit; }
112 
113  void setDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mDistanceMapUnitScale = scale; }
114  const QgsMapUnitScale &distanceMapUnitScale() const { return mDistanceMapUnitScale; }
115 
116  // TODO - implement properly
117  QRectF bounds( QPointF, QgsSymbolRenderContext & ) override { return QRectF(); }
118 
119  private:
120 #ifdef SIP_RUN
122 #endif
123 
124  QString mXAttribute;
125  QString mYAttribute;
127  QgsMapUnitScale mDistanceMapUnitScale;
128  double mScale = 1.0;
129  VectorFieldType mVectorFieldType = Cartesian;
130  AngleOrientation mAngleOrientation = ClockwiseFromNorth;
131  AngleUnits mAngleUnits = Degrees;
132 
133  std::unique_ptr< QgsLineSymbol > mLineSymbol;
134 
135  //Attribute indices are resolved in startRender method
136  int mXIndex = -1;
137  int mYIndex = -1;
138 
139  //Converts length/angle to Cartesian x/y
140  void convertPolarToCartesian( double length, double angle, double &x, double &y ) const;
141 };
142 
143 #endif // QGSVECTORFIELDSYMBOLLAYER_H
144 
145 
Struct for storing maximum and minimum scales for measurements in map units.
Abstract base class for marker symbol layers.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
QgsMapUnitScale mapUnitScale() const override
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void setMapUnitScale(const QgsMapUnitScale &scale) override
Contains information about the context of a rendering operation.
virtual QColor color() const
The fill color.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbol::SymbolType type() const
virtual void setColor(const QColor &color)
The fill color.
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
A symbol layer class for displaying displacement arrows based on point layer attributes.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
void setYAttribute(const QString &attribute)
void setAngleUnits(AngleUnits units)
void setVectorFieldType(VectorFieldType type)
const QgsMapUnitScale & distanceMapUnitScale() const
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
void setAngleOrientation(AngleOrientation orientation)
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
AngleOrientation angleOrientation() const
QRectF bounds(QPointF, QgsSymbolRenderContext &) override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
VectorFieldType vectorFieldType() const
QString layerType() const override
Returns a string that represents this layer type.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76