QGIS API Documentation  2.2.0-Valmiera
 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;
52 
53  void startRender( QgsSymbolV2RenderContext& context );
54 
55  void stopRender( QgsSymbolV2RenderContext& context );
56 
57  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
58 
59  QgsStringMap properties() const;
60 
61  QgsSymbolLayerV2* clone() const;
62 
63  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
64 
65  QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
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 { return borderColor(); }
81  void setOutlineColor( const QColor& color ) { setBorderColor( color ); }
82 
85  QColor fillColor() const { return color(); }
88  void setFillColor( const QColor& color ) { setColor( color ); }
89 
90  double outlineWidth() const { return mOutlineWidth; }
91  void setOutlineWidth( double w ) { mOutlineWidth = w; }
92 
93  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
94  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
95 
96  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
97 
98  protected:
99 
100  void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
101 
102  bool prepareShape( QString name = QString() );
103  bool preparePath( QString name = QString() );
104 
107  bool prepareCache( QgsSymbolV2RenderContext& context );
108 
109  QColor mBorderColor;
110  Qt::PenStyle mOutlineStyle;
113  QPen mPen;
114  QBrush mBrush;
115  QPolygonF mPolygon;
116  QPainterPath mPath;
117  QString mName;
118  QImage mCache;
119  QPen mSelPen;
120  QBrush mSelBrush;
121  QImage mSelCache;
123 
124  //Maximum width/height of cache image
125  static const int mMaximumCacheWidth = 3000;
126 
127  private:
130 };
131 
133 
134 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
135 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
136 #define DEFAULT_SVGMARKER_ANGLE 0
137 
139 {
140  public:
142  double size = DEFAULT_SVGMARKER_SIZE,
143  double angle = DEFAULT_SVGMARKER_ANGLE );
144 
145  // static stuff
146 
147  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
148  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
149 
150  // implemented from base classes
151 
152  QString layerType() const;
153 
154  void startRender( QgsSymbolV2RenderContext& context );
155 
156  void stopRender( QgsSymbolV2RenderContext& context );
157 
158  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
159 
160  QgsStringMap properties() const;
161 
162  QgsSymbolLayerV2* clone() const;
163 
164  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
165 
166  QString path() const { return mPath; }
167  void setPath( QString path );
168 
169  QColor fillColor() const { return mFillColor; }
170  void setFillColor( const QColor& c ) { mFillColor = c; }
171 
172  QColor outlineColor() const { return mOutlineColor; }
173  void setOutlineColor( const QColor& c ) { mOutlineColor = c; }
174 
175  double outlineWidth() const { return mOutlineWidth; }
176  void setOutlineWidth( double w ) { mOutlineWidth = w; }
177 
178  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
179  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
180 
183 
184  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
185 
186  protected:
187  QString mPath;
188 
189  //param(fill), param(outline), param(outline-width) are going
190  //to be replaced in memory
191  QColor mFillColor;
195  double mOrigSize;
196 };
197 
198 
200 
201 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
202 #define MM2POINT(x) ( (x) * 72 / 25.4 )
203 
204 #define DEFAULT_FONTMARKER_FONT "Dingbats"
205 #define DEFAULT_FONTMARKER_CHR QChar('A')
206 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
207 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
208 #define DEFAULT_FONTMARKER_ANGLE 0
209 
211 {
212  public:
214  QChar chr = DEFAULT_FONTMARKER_CHR,
215  double pointSize = DEFAULT_FONTMARKER_SIZE,
216  QColor color = DEFAULT_FONTMARKER_COLOR,
217  double angle = DEFAULT_FONTMARKER_ANGLE );
218 
219  // static stuff
220 
221  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
222  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
223 
224  // implemented from base classes
225 
226  QString layerType() const;
227 
228  void startRender( QgsSymbolV2RenderContext& context );
229 
230  void stopRender( QgsSymbolV2RenderContext& context );
231 
232  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
233 
234  QgsStringMap properties() const;
235 
236  QgsSymbolLayerV2* clone() const;
237 
238  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
239 
240  // new methods
241 
242  QString fontFamily() const { return mFontFamily; }
243  void setFontFamily( QString family ) { mFontFamily = family; }
244 
245  QChar character() const { return mChr; }
246  void setCharacter( QChar ch ) { mChr = ch; }
247 
248  protected:
249 
250  QString mFontFamily;
251  QChar mChr;
252 
253  QPointF mChrOffset;
254  QFont mFont;
255  double mOrigSize;
256 };
257 
258 
259 #endif