QGIS API Documentation  2.9.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  Pixel
53  };
54 
55  typedef QList<OutputUnit> OutputUnitList;
56 
58  {
61  Fill
62  };
63 
65  {
67  ScaleDiameter
68  };
69 
71  {
72  DataDefinedSizeScale = 1,
73  DataDefinedRotation = 2
74  };
75 
76  virtual ~QgsSymbolV2();
77 
79  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
80 
81  SymbolType type() const { return mType; }
82 
83  // symbol layers handling
84 
91  QgsSymbolLayerV2List symbolLayers() { return mLayers; }
92 
100  QgsSymbolLayerV2* symbolLayer( int layer );
101 
108  int symbolLayerCount() { return mLayers.count(); }
109 
111  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
112 
114  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
115 
117  bool deleteSymbolLayer( int index );
118 
120  QgsSymbolLayerV2* takeSymbolLayer( int index );
121 
123  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
124 
125  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
126  void stopRender( QgsRenderContext& context );
127 
128  void setColor( const QColor& color );
129  QColor color() const;
130 
134  void drawPreviewIcon( QPainter* painter, QSize size, QgsRenderContext* customContext = 0 );
135 
136  QImage asImage( QSize size, QgsRenderContext* customContext = 0 );
137 
138  QImage bigSymbolPreviewImage();
139 
140  QString dump() const;
141 
142  virtual QgsSymbolV2* clone() const = 0;
143 
144  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
145 
146  QgsSymbolV2::OutputUnit outputUnit() const;
147  void setOutputUnit( QgsSymbolV2::OutputUnit u );
148 
149  QgsMapUnitScale mapUnitScale() const;
150  void setMapUnitScale( const QgsMapUnitScale& scale );
151 
153  qreal alpha() const { return mAlpha; }
155  void setAlpha( qreal alpha ) { mAlpha = alpha; }
156 
157  void setRenderHints( int hints ) { mRenderHints = hints; }
158  int renderHints() const { return mRenderHints; }
159 
160  QSet<QString> usedAttributes() const;
161 
162  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
163  const QgsVectorLayer* layer() const { return mLayer; }
164 
165  protected:
166  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
167 
168  QgsSymbolLayerV2List cloneLayers() const;
169 
172  bool isSymbolLayerCompatible( SymbolType t );
173 
176 
178  qreal mAlpha;
179 
181 
182  const QgsVectorLayer* mLayer; //current vectorlayer
183 };
184 
186 
187 class CORE_EXPORT QgsSymbolV2RenderContext
188 {
189  public:
190  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* fields = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
192 
193  QgsRenderContext& renderContext() { return mRenderContext; }
194  const QgsRenderContext& renderContext() const { return mRenderContext; }
195 
196  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
197  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
198 
199  QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; }
200  void setMapUnitScale( const QgsMapUnitScale& scale ) { mMapUnitScale = scale; }
201 
203  qreal alpha() const { return mAlpha; }
205  void setAlpha( qreal alpha ) { mAlpha = alpha; }
206 
207  bool selected() const { return mSelected; }
208  void setSelected( bool selected ) { mSelected = selected; }
209 
210  int renderHints() const { return mRenderHints; }
211  void setRenderHints( int hints ) { mRenderHints = hints; }
212 
213  void setFeature( const QgsFeature* f ) { mFeature = f; }
215  const QgsFeature* feature() const { return mFeature; }
216 
221  const QgsFields* fields() const { return mFields; }
222 
223  double outputLineWidth( double width ) const;
224  double outputPixelSize( double size ) const;
225 
226  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
228 
229  private:
230  QgsRenderContext& mRenderContext;
231  QgsSymbolV2::OutputUnit mOutputUnit;
232  QgsMapUnitScale mMapUnitScale;
233  qreal mAlpha;
234  bool mSelected;
235  int mRenderHints;
236  const QgsFeature* mFeature; //current feature
237  const QgsFields* mFields;
238 };
239 
240 
241 
243 
244 
245 
246 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
247 {
248  public:
252  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
253 
255 
256  void setAngle( double angle );
257  double angle();
258 
259  void setSize( double size );
260  double size();
261 
262  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
263  ScaleMethod scaleMethod();
264 
265  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
266 
267  virtual QgsSymbolV2* clone() const override;
268 };
269 
270 
271 
272 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
273 {
274  public:
278  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
279 
281 
282  void setWidth( double width );
283  double width();
284 
285  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
286 
287  virtual QgsSymbolV2* clone() const override;
288 };
289 
290 
291 
292 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
293 {
294  public:
298  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
299 
301  void setAngle( double angle );
302  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
303 
304  virtual QgsSymbolV2* clone() const override;
305 };
306 
307 #endif
308 
309 
310 /*
311 
312 QgsSymbolV2* ps = new QgsPointSymbol();
313 
314 // ----
315 
316 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
317 
318 // (or)
319 
320 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
321 
322 // (or)
323 
324 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
325 QgsLineSymbol* s = new LineSymbol( [ sl ] );
326 
327 // ----
328 
329 rend = QgsSingleSymbolRenderer( new LineSymbol() );
330 */
331 
332 
static unsigned index
int renderHints() const
Definition: qgssymbolv2.h:210
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:182
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:205
SymbolType type() const
Definition: qgssymbolv2.h:81
virtual QgsSymbolV2 * clone() const =0
QList< OutputUnit > OutputUnitList
Definition: qgssymbolv2.h:55
Container of fields for a vector layer.
Definition: qgsfield.h:172
GeometryType
Definition: qgis.h:155
void setRenderHints(int hints)
Definition: qgssymbolv2.h:211
QgsSymbolLayerV2List symbolLayers()
Returns list of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:91
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:174
QMap< QString, QString > QgsStringMap
Definition: qgis.h:438
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbolv2.h:200
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:163
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:203
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:175
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.h:199
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:215
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:153
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:162
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:108
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:178
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:213
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:197
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:196
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:208
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:39
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:193
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:221
void setRenderHints(int hints)
Definition: qgssymbolv2.h:157
bool selected() const
Definition: qgssymbolv2.h:207
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:194
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:155
int mRenderHints
Definition: qgssymbolv2.h:180
int renderHints() const
Definition: qgssymbolv2.h:158