QGIS API Documentation  2.0.1-Dufour
 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 
23 class QColor;
24 class QImage;
25 class QPainter;
26 class QSize;
27 class QPointF;
28 class QPolygonF;
29 
30 class QDomDocument;
31 class QDomElement;
32 //class
33 
34 class QgsFeature;
35 class QgsSymbolLayerV2;
36 class QgsRenderContext;
38 
39 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
40 
41 class CORE_EXPORT QgsSymbolV2
42 {
43  public:
44 
46  {
47  MM = 0,
49  Mixed //mixed units in symbol layers
50  };
51 
53  {
56  Fill
57  };
58 
60  {
62  ScaleDiameter
63  };
64 
67  {
68  DataDefinedSizeScale = 1,
69  DataDefinedRotation = 2
70  };
71 
72  virtual ~QgsSymbolV2();
73 
75  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
76 
77  SymbolType type() const { return mType; }
78 
79  // symbol layers handling
80 
81  QgsSymbolLayerV2* symbolLayer( int layer );
82 
83  int symbolLayerCount() { return mLayers.count(); }
84 
86  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
87 
89  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
90 
92  bool deleteSymbolLayer( int index );
93 
95  QgsSymbolLayerV2* takeSymbolLayer( int index );
96 
98  bool changeSymbolLayer( int index, QgsSymbolLayerV2* layer );
99 
100  void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 );
101  void stopRender( QgsRenderContext& context );
102 
103  void setColor( const QColor& color );
104  QColor color() const;
105 
106  void drawPreviewIcon( QPainter* painter, QSize size );
107 
108  QImage bigSymbolPreviewImage();
109 
110  QString dump() const;
111 
112  virtual QgsSymbolV2* clone() const = 0;
113 
114  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
115 
116  QgsSymbolV2::OutputUnit outputUnit() const;
117  void setOutputUnit( QgsSymbolV2::OutputUnit u );
118 
120  qreal alpha() const { return mAlpha; }
122  void setAlpha( qreal alpha ) { mAlpha = alpha; }
123 
125  void setRenderHints( int hints ) { mRenderHints = hints; }
127  int renderHints() const { return mRenderHints; }
128 
129  QSet<QString> usedAttributes() const;
130 
131  protected:
132  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
133 
134  QgsSymbolLayerV2List cloneLayers() const;
135 
139  bool isSymbolLayerCompatible( SymbolType t );
140 
143 
145  qreal mAlpha;
146 
148 };
149 
151 
152 class CORE_EXPORT QgsSymbolV2RenderContext
153 {
154  public:
155  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 );
157 
158  QgsRenderContext& renderContext() { return mRenderContext; }
159  const QgsRenderContext& renderContext() const { return mRenderContext; }
160  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
161 
162  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
163  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
164 
166  qreal alpha() const { return mAlpha; }
168  void setAlpha( qreal alpha ) { mAlpha = alpha; }
169 
170  bool selected() const { return mSelected; }
171  void setSelected( bool selected ) { mSelected = selected; }
172 
174  int renderHints() const { return mRenderHints; }
176  void setRenderHints( int hints ) { mRenderHints = hints; }
177 
178  void setFeature( const QgsFeature* f ) { mFeature = f; }
179  const QgsFeature* feature() const { return mFeature; }
180 
181  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
182  const QgsVectorLayer* layer() const { return mLayer; }
183 
184  double outputLineWidth( double width ) const;
185  double outputPixelSize( double size ) const;
186 
187  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
189 
190  private:
193  qreal mAlpha;
194  bool mSelected;
196  const QgsFeature* mFeature; //current feature
197  const QgsVectorLayer* mLayer; //current vectorlayer
198 };
199 
200 
201 
203 
204 
205 
206 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
207 {
208  public:
213  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
214 
216 
217  void setAngle( double angle );
218  double angle();
219 
220  void setSize( double size );
221  double size();
222 
223  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
224  ScaleMethod scaleMethod();
225 
226  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
227 
228  virtual QgsSymbolV2* clone() const;
229 };
230 
231 
232 
233 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
234 {
235  public:
240  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
241 
243 
244  void setWidth( double width );
245  double width();
246 
247  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
248 
249  virtual QgsSymbolV2* clone() const;
250 };
251 
252 
253 
254 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
255 {
256  public:
261  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
262 
264  void setAngle( double angle );
265  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
266 
267  virtual QgsSymbolV2* clone() const;
268 };
269 
270 #endif
271 
272 
273 /*
274 
275 QgsSymbolV2* ps = new QgsPointSymbol();
276 
277 // ----
278 
279 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
280 
281 // (or)
282 
283 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
284 
285 // (or)
286 
287 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
288 QgsLineSymbol* s = new LineSymbol( [ sl ] );
289 
290 // ----
291 
292 rend = QgsSingleSymbolRenderer( new LineSymbol() );
293 */