QGIS API Documentation  2.0.1-Dufour
 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  double outlineWidth() const { return mOutlineWidth; }
74  void setOutlineWidth( double w ) { mOutlineWidth = w; }
75 
76  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
77  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
78 
79  protected:
80 
81  void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
82 
83  bool prepareShape( QString name = QString() );
84  bool preparePath( QString name = QString() );
85 
88  bool prepareCache( QgsSymbolV2RenderContext& context );
89 
90  QColor mBorderColor;
91  double mOutlineWidth;
93  QPen mPen;
94  QBrush mBrush;
95  QPolygonF mPolygon;
96  QPainterPath mPath;
97  QString mName;
98  QImage mCache;
99  QPen mSelPen;
100  QBrush mSelBrush;
101  QImage mSelCache;
103 
104  //Maximum width/height of cache image
105  static const int mMaximumCacheWidth = 3000;
106 };
107 
109 
110 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
111 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
112 #define DEFAULT_SVGMARKER_ANGLE 0
113 
115 {
116  public:
118  double size = DEFAULT_SVGMARKER_SIZE,
119  double angle = DEFAULT_SVGMARKER_ANGLE );
120 
121  // static stuff
122 
123  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
124  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
125 
126  // implemented from base classes
127 
128  QString layerType() const;
129 
130  void startRender( QgsSymbolV2RenderContext& context );
131 
132  void stopRender( QgsSymbolV2RenderContext& context );
133 
134  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
135 
136  QgsStringMap properties() const;
137 
138  QgsSymbolLayerV2* clone() const;
139 
140  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
141 
142  QString path() const { return mPath; }
143  void setPath( QString path );
144 
145  QColor fillColor() const { return mFillColor; }
146  void setFillColor( const QColor& c ) { mFillColor = c; }
147 
148  QColor outlineColor() const { return mOutlineColor; }
149  void setOutlineColor( const QColor& c ) { mOutlineColor = c; }
150 
151  double outlineWidth() const { return mOutlineWidth; }
152  void setOutlineWidth( double w ) { mOutlineWidth = w; }
153 
154  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
155  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
156 
159 
160  protected:
161  QString mPath;
162 
163  //param(fill), param(outline), param(outline-width) are going
164  //to be replaced in memory
165  QColor mFillColor;
169  double mOrigSize;
170 };
171 
172 
174 
175 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
176 #define MM2POINT(x) ( (x) * 72 / 25.4 )
177 
178 #define DEFAULT_FONTMARKER_FONT "Dingbats"
179 #define DEFAULT_FONTMARKER_CHR QChar('A')
180 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
181 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
182 #define DEFAULT_FONTMARKER_ANGLE 0
183 
185 {
186  public:
188  QChar chr = DEFAULT_FONTMARKER_CHR,
189  double pointSize = DEFAULT_FONTMARKER_SIZE,
190  QColor color = DEFAULT_FONTMARKER_COLOR,
191  double angle = DEFAULT_FONTMARKER_ANGLE );
192 
193  // static stuff
194 
195  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
196  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
197 
198  // implemented from base classes
199 
200  QString layerType() const;
201 
202  void startRender( QgsSymbolV2RenderContext& context );
203 
204  void stopRender( QgsSymbolV2RenderContext& context );
205 
206  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
207 
208  QgsStringMap properties() const;
209 
210  QgsSymbolLayerV2* clone() const;
211 
212  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
213 
214  // new methods
215 
216  QString fontFamily() const { return mFontFamily; }
217  void setFontFamily( QString family ) { mFontFamily = family; }
218 
219  QChar character() const { return mChr; }
220  void setCharacter( QChar ch ) { mChr = ch; }
221 
222  protected:
223 
224  QString mFontFamily;
225  QChar mChr;
226 
227  QPointF mChrOffset;
228  QFont mFont;
229  double mOrigSize;
230 };
231 
232 
233 #endif