QGIS API Documentation  2.2.0-Valmiera
 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  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
132  const QgsVectorLayer* layer() const { return mLayer; }
133 
134  protected:
135  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
136 
137  QgsSymbolLayerV2List cloneLayers() const;
138 
142  bool isSymbolLayerCompatible( SymbolType t );
143 
146 
148  qreal mAlpha;
149 
151 
152  const QgsVectorLayer* mLayer; //current vectorlayer
153 };
154 
156 
157 class CORE_EXPORT QgsSymbolV2RenderContext
158 {
159  public:
160  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 );
162 
163  QgsRenderContext& renderContext() { return mRenderContext; }
164  const QgsRenderContext& renderContext() const { return mRenderContext; }
165  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
166 
167  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
168  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
169 
171  qreal alpha() const { return mAlpha; }
173  void setAlpha( qreal alpha ) { mAlpha = alpha; }
174 
175  bool selected() const { return mSelected; }
176  void setSelected( bool selected ) { mSelected = selected; }
177 
179  int renderHints() const { return mRenderHints; }
181  void setRenderHints( int hints ) { mRenderHints = hints; }
182 
183  void setFeature( const QgsFeature* f ) { mFeature = f; }
184  const QgsFeature* feature() const { return mFeature; }
185 
186  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
187  const QgsVectorLayer* layer() const { return mLayer; }
188 
189  double outputLineWidth( double width ) const;
190  double outputPixelSize( double size ) const;
191 
192  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
194 
195  private:
198  qreal mAlpha;
199  bool mSelected;
201  const QgsFeature* mFeature; //current feature
202  const QgsVectorLayer* mLayer; //current vectorlayer
203 };
204 
205 
206 
208 
209 
210 
211 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
212 {
213  public:
218  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
219 
221 
222  void setAngle( double angle );
223  double angle();
224 
225  void setSize( double size );
226  double size();
227 
228  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
229  ScaleMethod scaleMethod();
230 
231  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
232 
233  virtual QgsSymbolV2* clone() const;
234 };
235 
236 
237 
238 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
239 {
240  public:
245  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
246 
248 
249  void setWidth( double width );
250  double width();
251 
252  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
253 
254  virtual QgsSymbolV2* clone() const;
255 };
256 
257 
258 
259 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
260 {
261  public:
266  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
267 
269  void setAngle( double angle );
270  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
271 
272  virtual QgsSymbolV2* clone() const;
273 };
274 
275 #endif
276 
277 
278 /*
279 
280 QgsSymbolV2* ps = new QgsPointSymbol();
281 
282 // ----
283 
284 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
285 
286 // (or)
287 
288 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
289 
290 // (or)
291 
292 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
293 QgsLineSymbol* s = new LineSymbol( [ sl ] );
294 
295 // ----
296 
297 rend = QgsSingleSymbolRenderer( new LineSymbol() );
298 */