QGIS API Documentation  2.99.0-Master (b058df7)
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:
32  {
33  Cartesian = 0,
35  Height
36  };
37 
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  virtual 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 
76  //setters and getters
77  void setXAttribute( const QString &attribute ) { mXAttribute = attribute; }
78  QString xAttribute() const { return mXAttribute; }
79  void setYAttribute( const QString &attribute ) { mYAttribute = attribute; }
80  QString yAttribute() const { return mYAttribute; }
81  void setScale( double s ) { mScale = s; }
82  double scale() const { return mScale; }
83  void setVectorFieldType( VectorFieldType type ) { mVectorFieldType = type; }
84  VectorFieldType vectorFieldType() const { return mVectorFieldType; }
85  void setAngleOrientation( AngleOrientation orientation ) { mAngleOrientation = orientation; }
86  AngleOrientation angleOrientation() const { return mAngleOrientation; }
87  void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
88  AngleUnits angleUnits() const { return mAngleUnits; }
89 
90  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
91  QgsUnitTypes::RenderUnit outputUnit() const override;
92 
93  void setMapUnitScale( const QgsMapUnitScale &scale ) override;
94  QgsMapUnitScale mapUnitScale() const override;
95 
101  void setDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mDistanceUnit = unit; }
102 
107  QgsUnitTypes::RenderUnit distanceUnit() const { return mDistanceUnit; }
108 
109  void setDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mDistanceMapUnitScale = scale; }
110  const QgsMapUnitScale &distanceMapUnitScale() const { return mDistanceMapUnitScale; }
111 
112  // TODO - implement properly
113  virtual QRectF bounds( QPointF, QgsSymbolRenderContext & ) override { return QRectF(); }
114 
115  private:
116 #ifdef SIP_RUN
118 #endif
119 
120  QString mXAttribute;
121  QString mYAttribute;
123  QgsMapUnitScale mDistanceMapUnitScale;
124  double mScale = 1.0;
125  VectorFieldType mVectorFieldType = Cartesian;
126  AngleOrientation mAngleOrientation = ClockwiseFromNorth;
127  AngleUnits mAngleUnits = Degrees;
128 
129  std::unique_ptr< QgsLineSymbol > mLineSymbol;
130 
131  //Attribute indices are resolved in startRender method
132  int mXIndex = -1;
133  int mYIndex = -1;
134 
135  //Converts length/angle to Cartesian x/y
136  void convertPolarToCartesian( double length, double angle, double &x, double &y ) const;
137 };
138 
139 #endif // QGSVECTORFIELDSYMBOLLAYER_H
140 
141 
QgsMapUnitScale mapUnitScale() const override
void setXAttribute(const QString &attribute)
void setYAttribute(const QString &attribute)
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
void setAngleUnits(AngleUnits units)
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
virtual QRectF bounds(QPointF, QgsSymbolRenderContext &) override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
AngleOrientation angleOrientation() const
void startRender(QgsSymbolRenderContext &context) override
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QMap< QString, QString > QgsStringMap
Definition: qgis.h:443
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
QString layerType() const override
Returns a string that represents this layer type.
virtual void setColor(const QColor &color)
The fill color.
A symbol layer class for displaying displacement arrows based on point layer attributes.
virtual bool setSubSymbol(QgsSymbol *symbol)
set layer&#39;s subsymbol. takes ownership of the passed symbol
const QgsMapUnitScale & distanceMapUnitScale() const
QgsSymbol * subSymbol() override
Returns the symbol&#39;s sub symbol, if present.
virtual void renderPoint(QPointF point, QgsSymbolRenderContext &context)=0
Renders a marker at the specified point.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual QColor color() const
The fill color.
QgsSymbol::SymbolType type() const
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
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.
Abstract base class for marker symbol layers.
Struct for storing maximum and minimum scales for measurements in map units.
virtual void stopRender(QgsSymbolRenderContext &context)=0
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setAngleOrientation(AngleOrientation orientation)
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
VectorFieldType vectorFieldType() const
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.
Definition: qgsunittypes.h:100
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override