QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  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;
100 
103 
104  void setMapUnitScale( const QgsMapUnitScale& scale );
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  static const QString EXPR_SIZE;
137 
138  private:
139  QgsExpression *mAngleExpression;
140  QgsExpression *mNameExpression;
141 };
142 
144 
145 #define DEFAULT_SVGMARKER_NAME "/crosses/Star1.svg"
146 #define DEFAULT_SVGMARKER_SIZE 2*DEFAULT_POINT_SIZE
147 #define DEFAULT_SVGMARKER_ANGLE 0
148 
150 {
151  public:
153  double size = DEFAULT_SVGMARKER_SIZE,
156 
157  // static stuff
158 
159  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
160  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
161 
162  // implemented from base classes
163 
164  QString layerType() const;
165 
166  void startRender( QgsSymbolV2RenderContext& context );
167 
168  void stopRender( QgsSymbolV2RenderContext& context );
169 
170  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
171 
172  QgsStringMap properties() const;
173 
174  QgsSymbolLayerV2* clone() const;
175 
176  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
177 
178  QString path() const { return mPath; }
179  void setPath( QString path );
180 
181  QColor fillColor() const { return mFillColor; }
182  void setFillColor( const QColor& c ) { mFillColor = c; }
183 
184  QColor outlineColor() const { return mOutlineColor; }
185  void setOutlineColor( const QColor& c ) { mOutlineColor = c; }
186 
187  double outlineWidth() const { return mOutlineWidth; }
188  void setOutlineWidth( double w ) { mOutlineWidth = w; }
189 
190  void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
191  QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
192 
193  void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
194  const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
195 
198 
199  void setMapUnitScale( const QgsMapUnitScale& scale );
201 
202  bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
203 
204  protected:
205  QString mPath;
206 
207  //param(fill), param(outline), param(outline-width) are going
208  //to be replaced in memory
209  QColor mFillColor;
214  double mOrigSize;
215 };
216 
217 
219 
220 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
221 #define MM2POINT(x) ( (x) * 72 / 25.4 )
222 
223 #define DEFAULT_FONTMARKER_FONT "Dingbats"
224 #define DEFAULT_FONTMARKER_CHR QChar('A')
225 #define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
226 #define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
227 #define DEFAULT_FONTMARKER_ANGLE 0
228 
230 {
231  public:
233  QChar chr = DEFAULT_FONTMARKER_CHR,
234  double pointSize = DEFAULT_FONTMARKER_SIZE,
235  QColor color = DEFAULT_FONTMARKER_COLOR,
236  double angle = DEFAULT_FONTMARKER_ANGLE );
237 
238  // static stuff
239 
240  static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
241  static QgsSymbolLayerV2* createFromSld( QDomElement &element );
242 
243  // implemented from base classes
244 
245  QString layerType() const;
246 
247  void startRender( QgsSymbolV2RenderContext& context );
248 
249  void stopRender( QgsSymbolV2RenderContext& context );
250 
251  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
252 
253  QgsStringMap properties() const;
254 
255  QgsSymbolLayerV2* clone() const;
256 
257  void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
258 
259  // new methods
260 
261  QString fontFamily() const { return mFontFamily; }
262  void setFontFamily( QString family ) { mFontFamily = family; }
263 
264  QChar character() const { return mChr; }
265  void setCharacter( QChar ch ) { mChr = ch; }
266 
267  protected:
268 
269  QString mFontFamily;
270  QChar mChr;
271 
272  QPointF mChrOffset;
273  QFont mFont;
274  double mOrigSize;
275 };
276 
277 
278 #endif
279 
280 
QColor borderColor() const
Definition: qgsmarkersymbollayerv2.h:70
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QChar character() const
Definition: qgsmarkersymbollayerv2.h:264
void setOutlineStyle(Qt::PenStyle outlineStyle)
Definition: qgsmarkersymbollayerv2.h:74
QgsSymbolV2::OutputUnit outlineWidthUnit() const
Definition: qgsmarkersymbollayerv2.h:191
double outlineWidth() const
Definition: qgsmarkersymbollayerv2.h:187
OutputUnit
Definition: qgssymbolv2.h:47
QgsMapUnitScale mOutlineWidthMapUnitScale
Definition: qgsmarkersymbollayerv2.h:121
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbollayerv2.cpp:356
virtual QgsSymbolLayerV2 * clone() const =0
QChar mChr
Definition: qgsmarkersymbollayerv2.h:270
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbollayerv2.cpp:365
#define DEFAULT_FONTMARKER_COLOR
Definition: qgsmarkersymbollayerv2.h:226
QgsSymbolV2::OutputUnit mOutlineWidthUnit
Definition: qgsmarkersymbollayerv2.h:212
#define DEFAULT_SIMPLEMARKER_ANGLE
Definition: qgsmarkersymbollayerv2.h:26
void startRender(QgsSymbolV2RenderContext &context)
Definition: qgssymbollayerv2.cpp:230
void setFillColor(const QColor &c)
Set fill color.
Definition: qgsmarkersymbollayerv2.h:182
#define DEFAULT_FONTMARKER_CHR
Definition: qgsmarkersymbollayerv2.h:224
void setOutlineWidth(double w)
Definition: qgsmarkersymbollayerv2.h:91
#define DEFAULT_SIMPLEMARKER_COLOR
Definition: qgsmarkersymbollayerv2.h:23
QImage mCache
Definition: qgsmarkersymbollayerv2.h:127
bool mUsingCache
Definition: qgsmarkersymbollayerv2.h:131
Definition: qgssymbollayerv2.h:45
void setOutlineWidth(double w)
Definition: qgsmarkersymbollayerv2.h:188
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
double mOutlineWidth
Definition: qgsmarkersymbollayerv2.h:119
void setOutputUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgssymbollayerv2.cpp:350
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
#define DEFAULT_SVGMARKER_ANGLE
Definition: qgsmarkersymbollayerv2.h:147
void setFontFamily(QString family)
Definition: qgsmarkersymbollayerv2.h:262
#define DEFAULT_SIMPLEMARKER_NAME
Definition: qgsmarkersymbollayerv2.h:22
Definition: qgsmarkersymbollayerv2.h:149
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
Definition: qgsmarkersymbollayerv2.h:190
QString name() const
Definition: qgsmarkersymbollayerv2.h:67
virtual void writeSldMarker(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Definition: qgssymbollayerv2.h:198
double mOutlineWidth
Definition: qgsmarkersymbollayerv2.h:211
QString mName
Definition: qgsmarkersymbollayerv2.h:126
QPolygonF mPolygon
Definition: qgsmarkersymbollayerv2.h:124
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit u)
Definition: qgsmarkersymbollayerv2.h:93
QString mPath
Definition: qgsmarkersymbollayerv2.h:205
QString mFontFamily
Definition: qgsmarkersymbollayerv2.h:269
virtual void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context)=0
double mOrigSize
Definition: qgsmarkersymbollayerv2.h:274
QColor mBorderColor
Definition: qgsmarkersymbollayerv2.h:117
double mOrigSize
Definition: qgsmarkersymbollayerv2.h:214
QColor fillColor() const
Get fill color.
Definition: qgsmarkersymbollayerv2.h:181
#define DEFAULT_SCALE_METHOD
Definition: qgssymbollayerv2.h:24
Qt::PenStyle mOutlineStyle
Definition: qgsmarkersymbollayerv2.h:118
QColor outlineColor() const
Get outline color.
Definition: qgsmarkersymbollayerv2.h:78
QString fontFamily() const
Definition: qgsmarkersymbollayerv2.h:261
QPointF mChrOffset
Definition: qgsmarkersymbollayerv2.h:272
double outlineWidth() const
Definition: qgsmarkersymbollayerv2.h:90
void setFillColor(const QColor &color)
Set fill color.
Definition: qgsmarkersymbollayerv2.h:88
virtual QgsStringMap properties() const =0
#define DEFAULT_FONTMARKER_ANGLE
Definition: qgsmarkersymbollayerv2.h:227
QgsMapUnitScale mOutlineWidthMapUnitScale
Definition: qgsmarkersymbollayerv2.h:213
virtual QColor color() const
Definition: qgssymbollayerv2.h:50
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgsmarkersymbollayerv2.h:193
QColor fillColor() const
Get fill color.
Definition: qgsmarkersymbollayerv2.h:85
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbollayerv2.cpp:371
QgsSymbolV2::OutputUnit mOutlineWidthUnit
Definition: qgsmarkersymbollayerv2.h:120
#define DEFAULT_SVGMARKER_SIZE
Definition: qgsmarkersymbollayerv2.h:146
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, const QgsSymbolV2RenderContext *context, const QgsFeature *f, const QPointF &shift=QPointF(0.0, 0.0)) const
Definition: qgssymbollayerv2.cpp:81
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)
QBrush mBrush
Definition: qgsmarkersymbollayerv2.h:123
virtual QString layerType() const =0
QPainterPath mPath
Definition: qgsmarkersymbollayerv2.h:125
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgsmarkersymbollayerv2.h:96
QColor outlineColor() const
Get outline color.
Definition: qgsmarkersymbollayerv2.h:184
#define DEFAULT_FONTMARKER_SIZE
Definition: qgsmarkersymbollayerv2.h:225
QFont mFont
Definition: qgsmarkersymbollayerv2.h:273
#define DEFAULT_FONTMARKER_FONT
Definition: qgsmarkersymbollayerv2.h:223
QgsSymbolV2::OutputUnit outlineWidthUnit() const
Definition: qgsmarkersymbollayerv2.h:94
#define DEFAULT_SVGMARKER_NAME
Definition: qgsmarkersymbollayerv2.h:145
#define DEFAULT_SIMPLEMARKER_SIZE
Definition: qgsmarkersymbollayerv2.h:25
QColor mOutlineColor
Definition: qgsmarkersymbollayerv2.h:210
ScaleMethod
Definition: qgssymbolv2.h:61
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Definition: qgsmarkersymbollayerv2.h:97
Definition: qgsmapunitscale.h:24
Qt::PenStyle outlineStyle() const
Definition: qgsmarkersymbollayerv2.h:73
void setOutlineColor(const QColor &color)
Set outline color.
Definition: qgsmarkersymbollayerv2.h:81
QImage mSelCache
Definition: qgsmarkersymbollayerv2.h:130
QColor mFillColor
Definition: qgsmarkersymbollayerv2.h:209
static const QString EXPR_SIZE
Definition: qgsmarkersymbollayerv2.h:136
QPen mSelPen
Definition: qgsmarkersymbollayerv2.h:128
QPen mPen
Definition: qgsmarkersymbollayerv2.h:122
void setName(QString name)
Definition: qgsmarkersymbollayerv2.h:68
virtual void setColor(const QColor &color)
Definition: qgssymbollayerv2.h:51
Definition: qgsmarkersymbollayerv2.h:229
void setBorderColor(QColor color)
Definition: qgsmarkersymbollayerv2.h:71
Definition: qgssymbollayerv2.h:160
Definition: qgssymbolv2.h:167
void setOutlineColor(const QColor &c)
Set outline color.
Definition: qgsmarkersymbollayerv2.h:185
QString path() const
Definition: qgsmarkersymbollayerv2.h:178
double size
Definition: qgssvgcache.cpp:77
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Definition: qgsmarkersymbollayerv2.h:194
virtual QString ogrFeatureStyle(double mmScaleFactor, double mapUnitScaleFactor) const
Definition: qgssymbollayerv2.h:77
void setCharacter(QChar ch)
Definition: qgsmarkersymbollayerv2.h:265
Definition: qgsmarkersymbollayerv2.h:34
Definition: qgsdxfexport.h:32
#define DEFAULT_SIMPLEMARKER_BORDERCOLOR
Definition: qgsmarkersymbollayerv2.h:24
QBrush mSelBrush
Definition: qgsmarkersymbollayerv2.h:129