QGIS API Documentation  2.14.0-Essen
qgsmarkersymbollayerv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmarkersymbollayerv2.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMARKERSYMBOLLAYERV2_H
17 #define QGSMARKERSYMBOLLAYERV2_H
18 
19 #include "qgssymbollayerv2.h"
20 #include "qgsvectorlayer.h"
21 
22 #define DEFAULT_SIMPLEMARKER_NAME "circle"
23 #define DEFAULT_SIMPLEMARKER_COLOR QColor(255,0,0)
24 #define DEFAULT_SIMPLEMARKER_BORDERCOLOR QColor(0,0,0)
25 #define DEFAULT_SIMPLEMARKER_SIZE DEFAULT_POINT_SIZE
26 #define DEFAULT_SIMPLEMARKER_ANGLE 0
27 
28 #include <QPen>
29 #include <QBrush>
30 #include <QPicture>
31 #include <QPolygonF>
32 #include <QFont>
33 
35 {
36  public:
38  const QColor& color = DEFAULT_SIMPLEMARKER_COLOR,
39  const QColor& borderColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR,
40  double size = DEFAULT_SIMPLEMARKER_SIZE,
43 
44  // static stuff
45 
46  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
47  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
48 
49  // implemented from base classes
50 
51  QString layerType() const override;
52 
53  void startRender( QgsSymbolV2RenderContext& context ) override;
54 
55  void stopRender( QgsSymbolV2RenderContext& context ) override;
56 
57  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
58 
59  QgsStringMap properties() const override;
60 
61  QgsSimpleMarkerSymbolLayerV2* clone() const override;
62 
63  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
64 
65  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
66 
67  QString name() const { return mName; }
68  void setName( const QString& name ) { mName = name; }
69 
70  QColor borderColor() const { return mBorderColor; }
71  void setBorderColor( const QColor& color ) { mBorderColor = color; }
72 
73  Qt::PenStyle outlineStyle() const { return mOutlineStyle; }
74  void setOutlineStyle( Qt::PenStyle outlineStyle ) { mOutlineStyle = outlineStyle; }
75 
78  QColor outlineColor() const override { return borderColor(); }
81  void setOutlineColor( const QColor& color ) override { setBorderColor( color ); }
82 
85  QColor fillColor() const override { return color(); }
88  void setFillColor( const QColor& color ) override { setColor( color ); }
89 
90  double outlineWidth() const { return mOutlineWidth; }
91  void setOutlineWidth( double w ) { mOutlineWidth = w; }
92 
93  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
94  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
95 
96  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
97  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
98 
99  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
100 
101  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
102  QgsSymbolV2::OutputUnit outputUnit() const override;
103 
104  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
105  QgsMapUnitScale mapUnitScale() const override;
106 
107  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
108 
109  protected:
110  void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
111 
112  bool prepareShape( const QString& name = QString() );
113  bool prepareShape( const QString& name, QPolygonF &polygon ) const;
114  bool preparePath( QString name = QString() );
115 
118  bool prepareCache( QgsSymbolV2RenderContext& context );
119 
121  Qt::PenStyle mOutlineStyle;
135 
136  //Maximum width/height of cache image
137  static const int mMaximumCacheWidth = 3000;
138 
139  private:
140 
141  double calculateSize( QgsSymbolV2RenderContext& context, bool& hasDataDefinedSize ) const;
142  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const;
143 };
144 
146 
147 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
148 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
149 #define DEFAULT_SVGMARKER_ANGLE 0
150 
152 {
153  public:
155  double size = DEFAULT_SVGMARKER_SIZE,
158 
159  // static stuff
160 
161  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
162  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
163 
164  // implemented from base classes
165 
166  QString layerType() const override;
167 
168  void startRender( QgsSymbolV2RenderContext& context ) override;
169 
170  void stopRender( QgsSymbolV2RenderContext& context ) override;
171 
172  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
173 
174  QgsStringMap properties() const override;
175 
176  QgsSvgMarkerSymbolLayerV2* clone() const override;
177 
178  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
179 
180  QString path() const { return mPath; }
181  void setPath( const QString& path );
182 
183  QColor fillColor() const override { return color(); }
184  void setFillColor( const QColor& color ) override { setColor( color ); }
185 
186  QColor outlineColor() const override { return mOutlineColor; }
187  void setOutlineColor( const QColor& c ) override { mOutlineColor = c; }
188 
189  double outlineWidth() const { return mOutlineWidth; }
190  void setOutlineWidth( double w ) { mOutlineWidth = w; }
191 
192  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
193  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
194 
195  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
196  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
197 
198  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
199  QgsSymbolV2::OutputUnit outputUnit() const override;
200 
201  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
202  QgsMapUnitScale mapUnitScale() const override;
203 
204  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
205 
206  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
207 
208  protected:
210 
211  //param(fill), param(outline), param(outline-width) are going
212  //to be replaced in memory
217 
218  private:
219  double calculateSize( QgsSymbolV2RenderContext& context, bool& hasDataDefinedSize ) const;
220  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, QPointF& offset, double& angle ) const;
221 
222 };
223 
224 
226 
227 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
228 #define MM2POINT(x) ( (x) * 72 / 25.4 )
229 
230 #define DEFAULT_FONTMARKER_FONT "Dingbats"
231 #define DEFAULT_FONTMARKER_CHR QChar('A')
232 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
233 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
234 #define DEFAULT_FONTMARKER_ANGLE 0
235 
237 {
238  public:
241  double pointSize = DEFAULT_FONTMARKER_SIZE,
242  const QColor& color = DEFAULT_FONTMARKER_COLOR,
243  double angle = DEFAULT_FONTMARKER_ANGLE );
244 
246 
247  // static stuff
248 
249  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
250  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
251 
252  // implemented from base classes
253 
254  QString layerType() const override;
255 
256  void startRender( QgsSymbolV2RenderContext& context ) override;
257 
258  void stopRender( QgsSymbolV2RenderContext& context ) override;
259 
260  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
261 
262  QgsStringMap properties() const override;
263 
264  QgsFontMarkerSymbolLayerV2* clone() const override;
265 
266  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
267 
268  // new methods
269 
270  QString fontFamily() const { return mFontFamily; }
271  void setFontFamily( const QString& family ) { mFontFamily = family; }
272 
273  QChar character() const { return mChr; }
274  void setCharacter( QChar ch ) { mChr = ch; }
275 
276  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
277 
278  protected:
279 
283 
284  double mChrWidth;
287  double mOrigSize;
288 
289  private:
290 
291  QString characterToRender( QgsSymbolV2RenderContext& context, QPointF& charOffset, double& charWidth );
292  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const;
293  double calculateSize( QgsSymbolV2RenderContext& context );
294 };
295 
296 
297 #endif
298 
299 
virtual void renderPoint(QPointF point, QgsSymbolV2RenderContext &context)=0
void setOutlineStyle(Qt::PenStyle outlineStyle)
QgsSymbolV2::OutputUnit outlineWidthUnit() const
QgsSymbolV2::OutputUnit outputUnit() const override
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:62
virtual QgsSymbolLayerV2 * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
#define DEFAULT_FONTMARKER_COLOR
virtual QRectF bounds(QPointF point, QgsSymbolV2RenderContext &context)
Returns the approximate bounding box of the marker symbol layer, taking into account any data defined...
QgsSymbolV2::OutputUnit mOutlineWidthUnit
void setOutlineColor(const QColor &c) override
Set outline color.
#define DEFAULT_SIMPLEMARKER_ANGLE
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const
#define DEFAULT_FONTMARKER_CHR
#define DEFAULT_SIMPLEMARKER_COLOR
void setFillColor(const QColor &color) override
Set fill color.
QColor fillColor() const override
Get fill color.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QMap< QString, QString > QgsStringMap
Definition: qgis.h:384
void setMapUnitScale(const QgsMapUnitScale &scale) override
#define DEFAULT_SVGMARKER_ANGLE
#define DEFAULT_SIMPLEMARKER_NAME
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit u)
void setFontFamily(const QString &family)
#define DEFAULT_SCALE_METHOD
void setFillColor(const QColor &color) override
Set fill color.
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
#define DEFAULT_FONTMARKER_ANGLE
virtual QColor color() const
The fill color.
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolV2::OutputUnit mOutlineWidthUnit
#define DEFAULT_SVGMARKER_SIZE
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
virtual QString layerType() const =0
Returns a string that represents this layer type.
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
#define DEFAULT_FONTMARKER_SIZE
void startRender(QgsSymbolV2RenderContext &context) override
#define DEFAULT_FONTMARKER_FONT
QgsSymbolV2::OutputUnit outlineWidthUnit() const
#define DEFAULT_SVGMARKER_NAME
void setBorderColor(const QColor &color)
#define DEFAULT_SIMPLEMARKER_SIZE
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:87
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Struct for storing maximum and minimum scales for measurements in map units.
QgsMapUnitScale mapUnitScale() const override
Qt::PenStyle outlineStyle() const
QColor fillColor() const override
Get fill color.
virtual void setColor(const QColor &color)
The fill color.
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext *context, const QgsFeature *f, QPointF shift=QPointF(0.0, 0.0)) const
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
QColor outlineColor() const override
Get outline color.
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
const QgsMapUnitScale & outlineWidthMapUnitScale() const
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
QColor outlineColor() const override
Get outline color.
void setName(const QString &name)
#define DEFAULT_SIMPLEMARKER_BORDERCOLOR
void setOutlineColor(const QColor &color) override
Set outline color.