QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssymbolv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolv2.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 QGSSYMBOLV2_H
17 #define QGSSYMBOLV2_H
18 
19 #include "qgis.h"
20 #include <QList>
21 #include <QMap>
22 #include "qgsmapunitscale.h"
23 
24 class QColor;
25 class QImage;
26 class QPainter;
27 class QSize;
28 class QPointF;
29 class QPolygonF;
30 
31 class QDomDocument;
32 class QDomElement;
33 //class
34 
35 class QgsFeature;
36 class QgsFields;
37 class QgsSymbolLayerV2;
38 class QgsRenderContext;
40 
41 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
42 
43 class CORE_EXPORT QgsSymbolV2
44 {
45  public:
46 
48  {
49  MM = 0,
51  Mixed //mixed units in symbol layers
52  };
53 
55  {
58  Fill
59  };
60 
62  {
64  ScaleDiameter
65  };
66 
69  {
70  DataDefinedSizeScale = 1,
71  DataDefinedRotation = 2
72  };
73 
74  virtual ~QgsSymbolV2();
75 
77  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
78 
79  SymbolType type() const { return mType; }
80 
81  // symbol layers handling
82 
83  QgsSymbolLayerV2* symbolLayer( int layer );
84 
85  int symbolLayerCount() { return mLayers.count(); }
86 
88  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
89 
91  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
92 
94  bool deleteSymbolLayer( int index );
95 
97  QgsSymbolLayerV2* takeSymbolLayer( int index );
98 
100  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
101 
102  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
103  void stopRender( QgsRenderContext& context );
104 
105  void setColor( const QColor& color );
106  QColor color() const;
107 
108  void drawPreviewIcon( QPainter* painter, QSize size );
109 
110  QImage bigSymbolPreviewImage();
111 
112  QString dump() const;
113 
114  virtual QgsSymbolV2* clone() const = 0;
115 
116  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
117 
118  QgsSymbolV2::OutputUnit outputUnit() const;
119  void setOutputUnit( QgsSymbolV2::OutputUnit u );
120 
121  QgsMapUnitScale mapUnitScale() const;
122  void setMapUnitScale( const QgsMapUnitScale& scale );
123 
125  qreal alpha() const { return mAlpha; }
127  void setAlpha( qreal alpha ) { mAlpha = alpha; }
128 
130  void setRenderHints( int hints ) { mRenderHints = hints; }
132  int renderHints() const { return mRenderHints; }
133 
134  QSet<QString> usedAttributes() const;
135 
136  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
137  const QgsVectorLayer* layer() const { return mLayer; }
138 
139  protected:
140  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
141 
142  QgsSymbolLayerV2List cloneLayers() const;
143 
147  bool isSymbolLayerCompatible( SymbolType t );
148 
151 
153  qreal mAlpha;
154 
156 
157  const QgsVectorLayer* mLayer; //current vectorlayer
158 };
159 
161 
162 class CORE_EXPORT QgsSymbolV2RenderContext
163 {
164  public:
165  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
167 
168  QgsRenderContext& renderContext() { return mRenderContext; }
169  const QgsRenderContext& renderContext() const { return mRenderContext; }
170  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
171 
172  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
173  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
174 
175  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
176  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
177 
179  qreal alpha() const { return mAlpha; }
181  void setAlpha( qreal alpha ) { mAlpha = alpha; }
182 
183  bool selected() const { return mSelected; }
184  void setSelected( bool selected ) { mSelected = selected; }
185 
187  int renderHints() const { return mRenderHints; }
189  void setRenderHints( int hints ) { mRenderHints = hints; }
190 
191  void setFeature( const QgsFeature* f ) { mFeature = f; }
193  const QgsFeature* feature() const { return mFeature; }
194 
199  const QgsFields* fields() const { return mFields; }
200 
201  double outputLineWidth( double width ) const;
202  double outputPixelSize( double size ) const;
203 
204  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
206 
207  private:
211  qreal mAlpha;
212  bool mSelected;
214  const QgsFeature* mFeature; //current feature
216 };
217 
218 
219 
221 
222 
223 
224 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
225 {
226  public:
231  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
232 
234 
235  void setAngle( double angle );
236  double angle();
237 
238  void setSize( double size );
239  double size();
240 
241  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
242  ScaleMethod scaleMethod();
243 
244  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
245 
246  virtual QgsSymbolV2* clone() const;
247 };
248 
249 
250 
251 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
252 {
253  public:
258  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
259 
261 
262  void setWidth( double width );
263  double width();
264 
265  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
266 
267  virtual QgsSymbolV2* clone() const;
268 };
269 
270 
271 
272 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
273 {
274  public:
279  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
280 
282  void setAngle( double angle );
283  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
284 
285  virtual QgsSymbolV2* clone() const;
286 };
287 
288 #endif
289 
290 
291 /*
292 
293 QgsSymbolV2* ps = new QgsPointSymbol();
294 
295 // ----
296 
297 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
298 
299 // (or)
300 
301 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
302 
303 // (or)
304 
305 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
306 QgsLineSymbol* s = new LineSymbol( [ sl ] );
307 
308 // ----
309 
310 rend = QgsSingleSymbolRenderer( new LineSymbol() );
311 */
312 
313