QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
53  static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() );
54  static QgsSymbolLayer *createFromSld( QDomElement &element );
55 
56  QString layerType() const override { return QStringLiteral( "VectorField" ); }
57 
58  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
59  QgsSymbol *subSymbol() override { return mLineSymbol.get(); }
60 
61  void setColor( const QColor &color ) override;
62  QColor color() const override;
63 
64  void renderPoint( QPointF point, QgsSymbolRenderContext &context ) override;
65  void startRender( QgsSymbolRenderContext &context ) override;
66  void stopRender( QgsSymbolRenderContext &context ) override;
67 
69  QgsStringMap properties() const override;
70 
71  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
72 
73  void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
74 
75  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
76  bool hasDataDefinedProperties() const override;
77 
78  //setters and getters
79  void setXAttribute( const QString &attribute ) { mXAttribute = attribute; }
80  QString xAttribute() const { return mXAttribute; }
81  void setYAttribute( const QString &attribute ) { mYAttribute = attribute; }
82  QString yAttribute() const { return mYAttribute; }
83  void setScale( double s ) { mScale = s; }
84  double scale() const { return mScale; }
85  void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; }
86  VectorFieldType vectorFieldType() const { return mVectorFieldType; }
87  void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; }
88  AngleOrientation angleOrientation() const { return mAngleOrientation; }
89  void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
90  AngleUnits angleUnits() const { return mAngleUnits; }
91 
92  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
93  QgsUnitTypes::RenderUnit outputUnit() const override;
94 
95  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
96  QgsMapUnitScale mapUnitScale() const override;
97 
103  void setDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mDistanceUnit = unit; }
104 
109  QgsUnitTypes::RenderUnit distanceUnit() const { return mDistanceUnit; }
110 
111  void setDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mDistanceMapUnitScale = scale; }
112  const QgsMapUnitScale &distanceMapUnitScale() const { return mDistanceMapUnitScale; }
113 
114  // TODO - implement properly
115  QRectF bounds( QPointF, QgsSymbolRenderContext & ) override { return QRectF(); }
116 
117  private:
118 #ifdef SIP_RUN
120 #endif
121 
122  QString mXAttribute;
123  QString mYAttribute;
125  QgsMapUnitScale mDistanceMapUnitScale;
126  double mScale = 1.0;
127  VectorFieldType mVectorFieldType = Cartesian;
128  AngleOrientation mAngleOrientation = ClockwiseFromNorth;
129  AngleUnits mAngleUnits = Degrees;
130 
131  std::unique_ptr< QgsLineSymbol > mLineSymbol;
132 
133  //Attribute indices are resolved in startRender method
134  int mXIndex = -1;
135  int mYIndex = -1;
136 
137  //Converts length/angle to Cartesian x/y
138  void convertPolarToCartesian( double length, double angle, double &x, double &y ) const;
139 };
140 
141 #endif // QGSVECTORFIELDSYMBOLLAYER_H
142 
143 
QgsVectorFieldSymbolLayer::AngleOrientation
AngleOrientation
Definition: qgsvectorfieldsymbollayer.h:40
QgsSymbolLayer::setSubSymbol
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Definition: qgssymbollayer.h:356
QgsVectorFieldSymbolLayer::setVectorFieldType
void setVectorFieldType(VectorFieldType type)
Definition: qgsvectorfieldsymbollayer.h:85
QgsVectorFieldSymbolLayer::setDistanceUnit
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
Definition: qgsvectorfieldsymbollayer.h:103
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsVectorFieldSymbolLayer
A symbol layer class for displaying displacement arrows based on point layer attributes.
Definition: qgsvectorfieldsymbollayer.h:30
QgsMarkerSymbolLayer::mapUnitScale
QgsMapUnitScale mapUnitScale() const override
Definition: qgssymbollayer.cpp:631
QgsVectorFieldSymbolLayer::vectorFieldType
VectorFieldType vectorFieldType() const
Definition: qgsvectorfieldsymbollayer.h:86
QgsVectorFieldSymbolLayer::yAttribute
QString yAttribute() const
Definition: qgsvectorfieldsymbollayer.h:82
QgsSymbolLayer::setColor
virtual void setColor(const QColor &color)
The fill color.
Definition: qgssymbollayer.h:232
QgsSymbolLayer::color
virtual QColor color() const
The fill color.
Definition: qgssymbollayer.h:227
QgsVectorFieldSymbolLayer::subSymbol
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
Definition: qgsvectorfieldsymbollayer.h:59
QgsVectorFieldSymbolLayer::distanceMapUnitScale
const QgsMapUnitScale & distanceMapUnitScale() const
Definition: qgsvectorfieldsymbollayer.h:112
QgsMarkerSymbolLayer::startRender
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
Definition: qgssymbollayer.cpp:447
QgsVectorFieldSymbolLayer::bounds
QRectF bounds(QPointF, QgsSymbolRenderContext &) override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
Definition: qgsvectorfieldsymbollayer.h:115
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsMarkerSymbolLayer
Abstract base class for marker symbol layers.
Definition: qgssymbollayer.h:582
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsMarkerSymbolLayer::setMapUnitScale
void setMapUnitScale(const QgsMapUnitScale &scale) override
Definition: qgssymbollayer.cpp:625
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolRenderContext
Definition: qgssymbol.h:695
QgsMarkerSymbolLayer::setOutputUnit
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.cpp:610
QgsSymbolLayer::clone
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbolLayer
Definition: qgssymbollayer.h:53
QgsVectorFieldSymbolLayer::Polar
@ Polar
Definition: qgsvectorfieldsymbollayer.h:35
QgsMarkerSymbolLayer::outputUnit
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.cpp:616
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
qgssymbollayer.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:38
QgsVectorFieldSymbolLayer::setDistanceMapUnitScale
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgsvectorfieldsymbollayer.h:111
QgsVectorFieldSymbolLayer::angleOrientation
AngleOrientation angleOrientation() const
Definition: qgsvectorfieldsymbollayer.h:88
QgsVectorFieldSymbolLayer::setScale
void setScale(double s)
Definition: qgsvectorfieldsymbollayer.h:83
QgsVectorFieldSymbolLayer::distanceUnit
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
Definition: qgsvectorfieldsymbollayer.h:109
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsVectorFieldSymbolLayer::angleUnits
AngleUnits angleUnits() const
Definition: qgsvectorfieldsymbollayer.h:90
QgsVectorFieldSymbolLayer::VectorFieldType
VectorFieldType
Definition: qgsvectorfieldsymbollayer.h:33
QgsVectorFieldSymbolLayer::setAngleOrientation
void setAngleOrientation(AngleOrientation orientation)
Definition: qgsvectorfieldsymbollayer.h:87
QgsMarkerSymbolLayer::renderPoint
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
QgsVectorFieldSymbolLayer::AngleUnits
AngleUnits
Definition: qgsvectorfieldsymbollayer.h:46
QgsSymbolLayer::type
QgsSymbol::SymbolType type() const
Definition: qgssymbollayer.h:358
QgsVectorFieldSymbolLayer::scale
double scale() const
Definition: qgsvectorfieldsymbollayer.h:84
QgsVectorFieldSymbolLayer::xAttribute
QString xAttribute() const
Definition: qgsvectorfieldsymbollayer.h:80
MathUtils::angle
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
QgsVectorFieldSymbolLayer::setYAttribute
void setYAttribute(const QString &attribute)
Definition: qgsvectorfieldsymbollayer.h:81
QgsMarkerSymbolLayer::stopRender
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Definition: qgssymbollayer.cpp:452
QgsVectorFieldSymbolLayer::layerType
QString layerType() const override
Returns a string that represents this layer type.
Definition: qgsvectorfieldsymbollayer.h:56
QgsVectorFieldSymbolLayer::setAngleUnits
void setAngleUnits(AngleUnits units)
Definition: qgsvectorfieldsymbollayer.h:89