QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
29 {
30  public:
31  enum VectorFieldType
32  {
33  Cartesian = 0,
34  Polar,
35  Height
36  };
37 
38  enum AngleOrientation
39  {
40  ClockwiseFromNorth = 0,
41  CounterclockwiseFromEast
42  };
43 
45  {
46  Degrees = 0,
47  Radians
48  };
49 
51 
52  static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() );
53  static QgsSymbolLayer *createFromSld( QDomElement &element );
54 
55  QString layerType() const override { return QStringLiteral( "VectorField" ); }
56 
57  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
58  QgsSymbol *subSymbol() override { return mLineSymbol.get(); }
59 
60  void setColor( const QColor &color ) override;
61  QColor color() const override;
62 
63  void renderPoint( QPointF point, QgsSymbolRenderContext &context ) override;
64  void startRender( QgsSymbolRenderContext &context ) override;
65  void stopRender( QgsSymbolRenderContext &context ) override;
66 
68  QgsStringMap properties() const override;
69 
70  void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
71 
72  void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
73 
74  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
75  bool hasDataDefinedProperties() const override;
76 
77  //setters and getters
78  void setXAttribute( const QString &attribute ) { mXAttribute = attribute; }
79  QString xAttribute() const { return mXAttribute; }
80  void setYAttribute( const QString &attribute ) { mYAttribute = attribute; }
81  QString yAttribute() const { return mYAttribute; }
82  void setScale( double s ) { mScale = s; }
83  double scale() const { return mScale; }
84  void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; }
85  VectorFieldType vectorFieldType() const { return mVectorFieldType; }
86  void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; }
87  AngleOrientation angleOrientation() const { return mAngleOrientation; }
88  void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
89  AngleUnits angleUnits() const { return mAngleUnits; }
90 
91  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
93 
94  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
95  QgsMapUnitScale mapUnitScale() const override;
96 
102  void setDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mDistanceUnit = unit; }
103 
108  QgsUnitTypes::RenderUnit distanceUnit() const { return mDistanceUnit; }
109 
110  void setDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mDistanceMapUnitScale = scale; }
111  const QgsMapUnitScale &distanceMapUnitScale() const { return mDistanceMapUnitScale; }
112 
113  // TODO - implement properly
114  QRectF bounds( QPointF, QgsSymbolRenderContext & ) override { return QRectF(); }
115 
116  private:
117 #ifdef SIP_RUN
119 #endif
120 
121  QString mXAttribute;
122  QString mYAttribute;
124  QgsMapUnitScale mDistanceMapUnitScale;
125  double mScale = 1.0;
126  VectorFieldType mVectorFieldType = Cartesian;
127  AngleOrientation mAngleOrientation = ClockwiseFromNorth;
128  AngleUnits mAngleUnits = Degrees;
129 
130  std::unique_ptr< QgsLineSymbol > mLineSymbol;
131 
132  //Attribute indices are resolved in startRender method
133  int mXIndex = -1;
134  int mYIndex = -1;
135 
136  //Converts length/angle to Cartesian x/y
137  void convertPolarToCartesian( double length, double angle, double &x, double &y ) const;
138 };
139 
140 #endif // QGSVECTORFIELDSYMBOLLAYER_H
141 
142 
QgsVectorFieldSymbolLayer::AngleOrientation
AngleOrientation
Definition: qgsvectorfieldsymbollayer.h:51
QgsSymbolLayer::setSubSymbol
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Definition: qgssymbollayer.h:351
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsVectorFieldSymbolLayer
Definition: qgsvectorfieldsymbollayer.h:28
QgsMarkerSymbolLayer::mapUnitScale
QgsMapUnitScale mapUnitScale() const override
Definition: qgssymbollayer.cpp:627
QgsSymbolLayer::setColor
virtual void setColor(const QColor &color)
The fill color.
Definition: qgssymbollayer.h:231
QgsSymbolLayer::color
virtual QColor color() const
The fill color.
Definition: qgssymbollayer.h:226
QgsMarkerSymbolLayer::startRender
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
Definition: qgssymbollayer.cpp:443
qgis.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsMarkerSymbolLayer
Abstract base class for marker symbol layers.
Definition: qgssymbollayer.h:575
QgsSymbol
Definition: qgssymbol.h:63
QgsMarkerSymbolLayer::setMapUnitScale
void setMapUnitScale(const QgsMapUnitScale &scale) override
Definition: qgssymbollayer.cpp:621
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolRenderContext
Definition: qgssymbol.h:681
QgsMarkerSymbolLayer::setOutputUnit
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.cpp:606
QgsSymbolLayer::clone
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbolLayer
Definition: qgssymbollayer.h:52
QgsMarkerSymbolLayer::outputUnit
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.cpp:612
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:37
QgsSymbolLayer::subSymbol
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
Definition: qgssymbollayer.h:348
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsVectorFieldSymbolLayer::VectorFieldType
VectorFieldType
Definition: qgsvectorfieldsymbollayer.h:44
QgsMarkerSymbolLayer::renderPoint
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
QgsVectorFieldSymbolLayer::AngleUnits
AngleUnits
Definition: qgsvectorfieldsymbollayer.h:57
QgsMarkerSymbolLayer::bounds
virtual QRectF bounds(QPointF point, QgsSymbolRenderContext &context)=0
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
QgsSymbolLayer::type
QgsSymbol::SymbolType type() const
Definition: qgssymbollayer.h:353
QgsSymbolLayer::layerType
virtual QString layerType() const =0
Returns a string that represents this layer type.
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
QgsMarkerSymbolLayer::stopRender
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Definition: qgssymbollayer.cpp:448