QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  QColor color = DEFAULT_SIMPLEMARKER_COLOR,
39  QColor borderColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR,
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( const QPointF& point, QgsSymbolV2RenderContext& context ) override;
58 
59  QgsStringMap properties() const override;
60 
61  QgsSymbolLayerV2* clone() const override;
62 
63  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
64 
65  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const override;
66 
67  QString name() const { return mName; }
68  void setName( QString name ) { mName = name; }
69 
70  QColor borderColor() const { return mBorderColor; }
71  void setBorderColor( 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, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const 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  protected:
108  void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
109 
110  bool prepareShape( QString name = QString() );
111  bool preparePath( QString name = QString() );
112 
115  bool prepareCache( QgsSymbolV2RenderContext& context );
116 
117  QColor mBorderColor;
118  Qt::PenStyle mOutlineStyle;
122  QPen mPen;
123  QBrush mBrush;
124  QPolygonF mPolygon;
125  QPainterPath mPath;
126  QString mName;
127  QImage mCache;
128  QPen mSelPen;
129  QBrush mSelBrush;
130  QImage mSelCache;
132 
133  //Maximum width/height of cache image
134  static const int mMaximumCacheWidth = 3000;
135 
136 };
137 
139 
140 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
141 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
142 #define DEFAULT_SVGMARKER_ANGLE 0
143 
145 {
146  public:
148  double size = DEFAULT_SVGMARKER_SIZE,
151 
152  // static stuff
153 
154  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
155  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
156 
157  // implemented from base classes
158 
159  QString layerType() const override;
160 
161  void startRender( QgsSymbolV2RenderContext& context ) override;
162 
163  void stopRender( QgsSymbolV2RenderContext& context ) override;
164 
165  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) override;
166 
167  QgsStringMap properties() const override;
168 
169  QgsSymbolLayerV2* clone() const override;
170 
171  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
172 
173  QString path() const { return mPath; }
174  void setPath( QString path );
175 
176  QColor fillColor() const override { return mFillColor; }
177  void setFillColor( const QColor& c ) override { mFillColor = c; }
178 
179  QColor outlineColor() const override { return mOutlineColor; }
180  void setOutlineColor( const QColor& c ) override { mOutlineColor = c; }
181 
182  double outlineWidth() const { return mOutlineWidth; }
183  void setOutlineWidth( double w ) { mOutlineWidth = w; }
184 
185  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
186  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
187 
188  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
189  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
190 
191  void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
192  QgsSymbolV2::OutputUnit outputUnit() const override;
193 
194  void setMapUnitScale( const QgsMapUnitScale& scale ) override;
195  QgsMapUnitScale mapUnitScale() const override;
196 
197  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const override;
198 
199  protected:
200  QString mPath;
201 
202  //param(fill), param(outline), param(outline-width) are going
203  //to be replaced in memory
204  QColor mFillColor;
209 };
210 
211 
213 
214 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
215 #define MM2POINT(x) ( (x) * 72 / 25.4 )
216 
217 #define DEFAULT_FONTMARKER_FONT "Dingbats"
218 #define DEFAULT_FONTMARKER_CHR QChar('A')
219 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
220 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
221 #define DEFAULT_FONTMARKER_ANGLE 0
222 
224 {
225  public:
227  QChar chr = DEFAULT_FONTMARKER_CHR,
228  double pointSize = DEFAULT_FONTMARKER_SIZE,
229  QColor color = DEFAULT_FONTMARKER_COLOR,
230  double angle = DEFAULT_FONTMARKER_ANGLE );
231 
233 
234  // static stuff
235 
236  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
237  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
238 
239  // implemented from base classes
240 
241  QString layerType() const override;
242 
243  void startRender( QgsSymbolV2RenderContext& context ) override;
244 
245  void stopRender( QgsSymbolV2RenderContext& context ) override;
246 
247  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) override;
248 
249  QgsStringMap properties() const override;
250 
251  QgsSymbolLayerV2* clone() const override;
252 
253  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const override;
254 
255  // new methods
256 
257  QString fontFamily() const { return mFontFamily; }
258  void setFontFamily( QString family ) { mFontFamily = family; }
259 
260  QChar character() const { return mChr; }
261  void setCharacter( QChar ch ) { mChr = ch; }
262 
263  protected:
264 
265  QString mFontFamily;
266  QFontMetrics* mFontMetrics;
267  QChar mChr;
268 
269  QPointF mChrOffset;
270  QFont mFont;
271  double mOrigSize;
272 
273 };
274 
275 
276 #endif
277 
278