QGIS API Documentation
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_JOINSTYLE Qt::BevelJoin
26 #define DEFAULT_SIMPLEMARKER_SIZE DEFAULT_POINT_SIZE
27 #define DEFAULT_SIMPLEMARKER_ANGLE 0
28 
29 #include <QPen>
30 #include <QBrush>
31 #include <QPicture>
32 #include <QPolygonF>
33 #include <QFont>
34 
36 {
37  public:
38 
53  const QColor& color = DEFAULT_SIMPLEMARKER_COLOR,
54  const QColor& borderColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR,
55  double size = DEFAULT_SIMPLEMARKER_SIZE,
58  Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEMARKER_JOINSTYLE );
59 
60  // static stuff
61 
62  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
63  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
64 
65  // implemented from base classes
66 
67  QString layerType() const override;
68 
69  void startRender( QgsSymbolV2RenderContext& context ) override;
70 
71  void stopRender( QgsSymbolV2RenderContext& context ) override;
72 
73  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
74 
75  QgsStringMap properties() const override;
76 
77  QgsSimpleMarkerSymbolLayerV2* clone() const override;
78 
79  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
80 
81  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
82 
83  QString name() const { return mName; }
84  void setName( const QString& name ) { mName = name; }
85 
86  QColor borderColor() const { return mBorderColor; }
87  void setBorderColor( const QColor& color ) { mBorderColor = color; }
88 
91  Qt::PenStyle outlineStyle() const { return mOutlineStyle; }
94  void setOutlineStyle( Qt::PenStyle outlineStyle ) { mOutlineStyle = outlineStyle; }
95 
98  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
101  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
102 
105  QColor outlineColor() const override { return borderColor(); }
108  void setOutlineColor( const QColor& color ) override { setBorderColor( color ); }
109 
112  QColor fillColor() const override { return color(); }
115  void setFillColor( const QColor& color ) override { setColor( color ); }
116 
117  double outlineWidth() const { return mOutlineWidth; }
118  void setOutlineWidth( double w ) { mOutlineWidth = w; }
119 
120  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
121  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
122 
123  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
124  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
125 
126  bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
127 
128  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
129  QgsSymbolV2::OutputUnit outputUnit() const override;
130 
131  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
132  QgsMapUnitScale mapUnitScale() const override;
133 
134  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
135 
136  protected:
137  void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
138 
139  bool prepareShape( const QString& name = QString() );
140  bool prepareShape( const QString& name, QPolygonF &polygon ) const;
141  bool preparePath( QString name = QString() );
142 
145  bool prepareCache( QgsSymbolV2RenderContext& context );
146 
148  Qt::PenStyle mOutlineStyle;
152  Qt::PenJoinStyle mPenJoinStyle;
163 
164  //Maximum width/height of cache image
165  static const int mMaximumCacheWidth = 3000;
166 
167  private:
168 
169  double calculateSize( QgsSymbolV2RenderContext& context, bool& hasDataDefinedSize ) const;
170  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const;
171  bool symbolNeedsBrush( const QString& symbolName ) const;
172 };
173 
175 
176 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
177 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
178 #define DEFAULT_SVGMARKER_ANGLE 0
179 
181 {
182  public:
184  double size = DEFAULT_SVGMARKER_SIZE,
187 
188  // static stuff
189 
190  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
191  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
192 
193  // implemented from base classes
194 
195  QString layerType() const override;
196 
197  void startRender( QgsSymbolV2RenderContext& context ) override;
198 
199  void stopRender( QgsSymbolV2RenderContext& context ) override;
200 
201  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
202 
203  QgsStringMap properties() const override;
204 
205  QgsSvgMarkerSymbolLayerV2* clone() const override;
206 
207  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
208 
209  QString path() const { return mPath; }
210  void setPath( const QString& path );
211 
212  QColor fillColor() const override { return color(); }
213  void setFillColor( const QColor& color ) override { setColor( color ); }
214 
215  QColor outlineColor() const override { return mOutlineColor; }
216  void setOutlineColor( const QColor& c ) override { mOutlineColor = c; }
217 
218  double outlineWidth() const { return mOutlineWidth; }
219  void setOutlineWidth( double w ) { mOutlineWidth = w; }
220 
221  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
222  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
223 
224  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
225  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
226 
227  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
228  QgsSymbolV2::OutputUnit outputUnit() const override;
229 
230  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
231  QgsMapUnitScale mapUnitScale() const override;
232 
233  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
234 
235  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
236 
237  protected:
239 
240  //param(fill), param(outline), param(outline-width) are going
241  //to be replaced in memory
246 
247  private:
248  double calculateSize( QgsSymbolV2RenderContext& context, bool& hasDataDefinedSize ) const;
249  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, QPointF& offset, double& angle ) const;
250 
251 };
252 
253 
255 
256 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
257 #define MM2POINT(x) ( (x) * 72 / 25.4 )
258 
259 #define DEFAULT_FONTMARKER_FONT "Dingbats"
260 #define DEFAULT_FONTMARKER_CHR QChar('A')
261 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
262 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
263 #define DEFAULT_FONTMARKER_BORDERCOLOR QColor(Qt::white)
264 #define DEFAULT_FONTMARKER_JOINSTYLE Qt::MiterJoin
265 #define DEFAULT_FONTMARKER_ANGLE 0
266 
268 {
269  public:
272  double pointSize = DEFAULT_FONTMARKER_SIZE,
273  const QColor& color = DEFAULT_FONTMARKER_COLOR,
274  double angle = DEFAULT_FONTMARKER_ANGLE );
275 
277 
278  // static stuff
279 
280  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
281  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
282 
283  // implemented from base classes
284 
285  QString layerType() const override;
286 
287  void startRender( QgsSymbolV2RenderContext& context ) override;
288 
289  void stopRender( QgsSymbolV2RenderContext& context ) override;
290 
291  void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
292 
293  QgsStringMap properties() const override;
294 
295  QgsFontMarkerSymbolLayerV2* clone() const override;
296 
297  void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;
298 
299  // new methods
300 
301  QString fontFamily() const { return mFontFamily; }
302  void setFontFamily( const QString& family ) { mFontFamily = family; }
303 
304  QChar character() const { return mChr; }
305  void setCharacter( QChar ch ) { mChr = ch; }
306 
309  QColor outlineColor() const override { return mOutlineColor; }
312  void setOutlineColor( const QColor& color ) override { mOutlineColor = color; }
313 
316  double outlineWidth() const { return mOutlineWidth; }
319  void setOutlineWidth( double width ) { mOutlineWidth = width; }
320 
323  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
326  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
327 
330  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
333  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
334 
337  Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
340  void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
341 
342  QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
343 
344  protected:
345 
349 
350  double mChrWidth;
353  double mOrigSize;
354 
355  private:
356 
357  QColor mOutlineColor;
358  double mOutlineWidth;
359  QgsSymbolV2::OutputUnit mOutlineWidthUnit;
360  QgsMapUnitScale mOutlineWidthMapUnitScale;
361  Qt::PenJoinStyle mPenJoinStyle;
362 
363  QPen mPen;
364  QBrush mBrush;
365 
366  QString characterToRender( QgsSymbolV2RenderContext& context, QPointF& charOffset, double& charWidth );
367  void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const;
368  double calculateSize( QgsSymbolV2RenderContext& context );
369 };
370 
371 
372 #endif
373 
374 
virtual void renderPoint(QPointF point, QgsSymbolV2RenderContext &context)=0
void setOutlineStyle(Qt::PenStyle outlineStyle)
Set outline join style.
QgsSymbolV2::OutputUnit outlineWidthUnit() const
void setOutlineColor(const QColor &color) override
Set outline color.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set outline join style.
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.
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
Set outline width map unit scale.
#define DEFAULT_SIMPLEMARKER_ANGLE
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
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.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:451
void setMapUnitScale(const QgsMapUnitScale &scale) override
#define DEFAULT_SVGMARKER_ANGLE
#define DEFAULT_SIMPLEMARKER_NAME
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
Qt::PenJoinStyle penJoinStyle() const
Get outline join style.
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit u)
void setFontFamily(const QString &family)
#define DEFAULT_SCALE_METHOD
void setFillColor(const QColor &color) override
Set fill color.
QColor outlineColor() const override
Get outline 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)
void setOutlineWidth(double width)
Set outline width.
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)
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Get outline width map unit scale.
#define DEFAULT_SIMPLEMARKER_SIZE
Qt::PenJoinStyle penJoinStyle() const
Get outline join style.
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
Get outline join style.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set outline join style.
QColor fillColor() const override
Get fill color.
double outlineWidth() const
Get outline width.
virtual void setColor(const QColor &color)
The fill color.
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
Set outline width unit.
#define DEFAULT_SIMPLEMARKER_JOINSTYLE
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.
QgsSymbolV2::OutputUnit outlineWidthUnit() const
Get outline width unit.