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 asImage( QSize size, QgsRenderContext* customContext = 0 );
114 
115  QImage bigSymbolPreviewImage();
116 
117  QString dump() const;
118 
119  virtual QgsSymbolV2* clone() const = 0;
120 
121  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
122 
123  QgsSymbolV2::OutputUnit outputUnit() const;
124  void setOutputUnit( QgsSymbolV2::OutputUnit u );
125 
126  QgsMapUnitScale mapUnitScale() const;
127  void setMapUnitScale( const QgsMapUnitScale& scale );
128 
130  qreal alpha() const { return mAlpha; }
132  void setAlpha( qreal alpha ) { mAlpha = alpha; }
133 
135  void setRenderHints( int hints ) { mRenderHints = hints; }
137  int renderHints() const { return mRenderHints; }
138 
139  QSet<QString> usedAttributes() const;
140 
141  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
142  const QgsVectorLayer* layer() const { return mLayer; }
143 
144  protected:
145  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
146 
147  QgsSymbolLayerV2List cloneLayers() const;
148 
152  bool isSymbolLayerCompatible( SymbolType t );
153 
156 
158  qreal mAlpha;
159 
161 
162  const QgsVectorLayer* mLayer; //current vectorlayer
163 };
164 
166 
167 class CORE_EXPORT QgsSymbolV2RenderContext
168 {
169  public:
170  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() );
172 
173  QgsRenderContext& renderContext() { return mRenderContext; }
174  const QgsRenderContext& renderContext() const { return mRenderContext; }
175  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
176 
177  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
178  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
179 
180  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
181  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
182 
184  qreal alpha() const { return mAlpha; }
186  void setAlpha( qreal alpha ) { mAlpha = alpha; }
187 
188  bool selected() const { return mSelected; }
189  void setSelected( bool selected ) { mSelected = selected; }
190 
192  int renderHints() const { return mRenderHints; }
194  void setRenderHints( int hints ) { mRenderHints = hints; }
195 
196  void setFeature( const QgsFeature* f ) { mFeature = f; }
198  const QgsFeature* feature() const { return mFeature; }
199 
204  const QgsFields* fields() const { return mFields; }
205 
206  double outputLineWidth( double width ) const;
207  double outputPixelSize( double size ) const;
208 
209  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
211 
212  private:
213  QgsRenderContext& mRenderContext;
214  QgsSymbolV2::OutputUnit mOutputUnit;
215  QgsMapUnitScale mMapUnitScale;
216  qreal mAlpha;
217  bool mSelected;
218  int mRenderHints;
219  const QgsFeature* mFeature; //current feature
220  const QgsFields* mFields;
221 };
222 
223 
224 
226 
227 
228 
229 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
230 {
231  public:
236  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
237 
239 
240  void setAngle( double angle );
241  double angle();
242 
243  void setSize( double size );
244  double size();
245 
246  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
247  ScaleMethod scaleMethod();
248 
249  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
250 
251  virtual QgsSymbolV2* clone() const;
252 };
253 
254 
255 
256 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
257 {
258  public:
263  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
264 
266 
267  void setWidth( double width );
268  double width();
269 
270  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
271 
272  virtual QgsSymbolV2* clone() const;
273 };
274 
275 
276 
277 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
278 {
279  public:
284  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
285 
287  void setAngle( double angle );
288  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
289 
290  virtual QgsSymbolV2* clone() const;
291 };
292 
293 #endif
294 
295 
296 /*
297 
298 QgsSymbolV2* ps = new QgsPointSymbol();
299 
300 // ----
301 
302 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
303 
304 // (or)
305 
306 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
307 
308 // (or)
309 
310 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
311 QgsLineSymbol* s = new LineSymbol( [ sl ] );
312 
313 // ----
314 
315 rend = QgsSingleSymbolRenderer( new LineSymbol() );
316 */
317 
318 
static unsigned index
Definition: mersenne-twister.cpp:36
OutputUnit
Definition: qgssymbolv2.h:47
int renderHints() const
Definition: qgssymbolv2.h:192
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:162
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:186
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:194
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:154
Definition: qgssymbolv2.h:277
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
Definition: qgssymbolv2.h:56
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:181
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:142
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:184
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:155
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:180
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:198
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:130
Definition: qgssymbolv2.h:256
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:141
Definition: qgssymbolv2.h:50
int symbolLayerCount()
Definition: qgssymbolv2.h:85
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:158
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:196
Definition: qgssymbolv2.h:43
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:178
RenderHint
Definition: qgssymbolv2.h:68
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:177
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:189
SymbolType
Definition: qgssymbolv2.h:54
Definition: qgssymbolv2.h:229
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:173
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:204
void setRenderHints(int hints)
Definition: qgssymbolv2.h:135
bool selected() const
Definition: qgssymbolv2.h:188
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:174
Definition: qgssymbolv2.h:63
Definition: qgssymbolv2.h:167
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:132
int mRenderHints
Definition: qgssymbolv2.h:160
int renderHints() const
Definition: qgssymbolv2.h:137