QGIS API Documentation  3.6.0-Noosa (5873452)
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  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;
92  QgsUnitTypes::RenderUnit outputUnit() const 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 
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.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
void setAngleUnits(AngleUnits units)
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
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:587
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 bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties...
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)
Sets 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.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setAngleOrientation(AngleOrientation orientation)
void stopRender(QgsSymbolRenderContext &context) override
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
VectorFieldType vectorFieldType() const
QRectF bounds(QPointF, QgsSymbolRenderContext &) override
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
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:111
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override