QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
111  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
112 
113  QImage bigSymbolPreviewImage();
114 
115  QString dump() const;
116 
117  virtual QgsSymbolV2* clone() const = 0;
118 
119  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
120 
121  QgsSymbolV2::OutputUnit outputUnit() const;
122  void setOutputUnit( QgsSymbolV2::OutputUnit u );
123 
124  QgsMapUnitScale mapUnitScale() const;
125  void setMapUnitScale( const QgsMapUnitScale& scale );
126 
128  qreal alpha() const { return mAlpha; }
130  void setAlpha( qreal alpha ) { mAlpha = alpha; }
131 
133  void setRenderHints( int hints ) { mRenderHints = hints; }
135  int renderHints() const { return mRenderHints; }
136 
137  QSet<QString> usedAttributes() const;
138 
139  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
140  const QgsVectorLayer* layer() const { return mLayer; }
141 
142  protected:
143  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
144 
145  QgsSymbolLayerV2List cloneLayers() const;
146 
150  bool isSymbolLayerCompatible( SymbolType t );
151 
154 
156  qreal mAlpha;
157 
159 
160  const QgsVectorLayer* mLayer; //current vectorlayer
161 };
162 
164 
165 class CORE_EXPORT QgsSymbolV2RenderContext
166 {
167  public:
168  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() );
170 
171  QgsRenderContext& renderContext() { return mRenderContext; }
172  const QgsRenderContext& renderContext() const { return mRenderContext; }
173  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
174 
175  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
176  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
177 
178  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
179  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
180 
182  qreal alpha() const { return mAlpha; }
184  void setAlpha( qreal alpha ) { mAlpha = alpha; }
185 
186  bool selected() const { return mSelected; }
187  void setSelected( bool selected ) { mSelected = selected; }
188 
190  int renderHints() const { return mRenderHints; }
192  void setRenderHints( int hints ) { mRenderHints = hints; }
193 
194  void setFeature( const QgsFeature* f ) { mFeature = f; }
196  const QgsFeature* feature() const { return mFeature; }
197 
202  const QgsFields* fields() const { return mFields; }
203 
204  double outputLineWidth( double width ) const;
205  double outputPixelSize( double size ) const;
206 
207  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
209 
210  private:
211  QgsRenderContext& mRenderContext;
212  QgsSymbolV2::OutputUnit mOutputUnit;
213  QgsMapUnitScale mMapUnitScale;
214  qreal mAlpha;
215  bool mSelected;
216  int mRenderHints;
217  const QgsFeature* mFeature; //current feature
218  const QgsFields* mFields;
219 };
220 
221 
222 
224 
225 
226 
227 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
228 {
229  public:
234  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
235 
237 
238  void setAngle( double angle );
239  double angle();
240 
241  void setSize( double size );
242  double size();
243 
244  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
245  ScaleMethod scaleMethod();
246 
247  void renderPoint( const QPointF& point, 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 QgsLineSymbolV2 : public QgsSymbolV2
255 {
256  public:
261  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
262 
264 
265  void setWidth( double width );
266  double width();
267 
268  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
269 
270  virtual QgsSymbolV2* clone() const;
271 };
272 
273 
274 
275 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
276 {
277  public:
282  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
283 
285  void setAngle( double angle );
286  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
287 
288  virtual QgsSymbolV2* clone() const;
289 };
290 
291 #endif
292 
293 
294 /*
295 
296 QgsSymbolV2* ps = new QgsPointSymbol();
297 
298 // ----
299 
300 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
301 
302 // (or)
303 
304 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
305 
306 // (or)
307 
308 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
309 QgsLineSymbol* s = new LineSymbol( [ sl ] );
310 
311 // ----
312 
313 rend = QgsSingleSymbolRenderer( new LineSymbol() );
314 */
315 
316 
static unsigned index
Definition: mersenne-twister.cpp:36
OutputUnit
Definition: qgssymbolv2.h:47
int renderHints() const
Definition: qgssymbolv2.h:190
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:160
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:184
SymbolType type() const
Definition: qgssymbolv2.h:79
virtual QgsSymbolV2 * clone() const =0
Container of fields for a vector layer.
Definition: qgsfield.h:163
Definition: qgssymbolv2.h:57
GeometryType
Definition: qgis.h:155
void setRenderHints(int hints)
Definition: qgssymbolv2.h:192
Definition: qgssymbollayerv2.h:45
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
SymbolType mType
Definition: qgssymbolv2.h:152
Definition: qgssymbolv2.h:275
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
Definition: qgssymbolv2.h:56
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:179
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:140
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:182
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:153
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:178
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:196
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:128
Definition: qgssymbolv2.h:254
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:139
Definition: qgssymbolv2.h:50
int symbolLayerCount()
Definition: qgssymbolv2.h:85
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:156
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:194
Definition: qgssymbolv2.h:43
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:176
RenderHint
Definition: qgssymbolv2.h:68
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:175
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)
void setSelected(bool selected)
Definition: qgssymbolv2.h:187
SymbolType
Definition: qgssymbolv2.h:54
Definition: qgssymbolv2.h:227
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
ScaleMethod
Definition: qgssymbolv2.h:61
Definition: qgsmapunitscale.h:24
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:39
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:171
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:202
void setRenderHints(int hints)
Definition: qgssymbolv2.h:133
bool selected() const
Definition: qgssymbolv2.h:186
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:172
Definition: qgssymbolv2.h:63
Definition: qgssymbolv2.h:165
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
double size
Definition: qgssvgcache.cpp:77
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:130
int mRenderHints
Definition: qgssymbolv2.h:158
int renderHints() const
Definition: qgssymbolv2.h:135