QGIS API Documentation  2.3.0-Master
 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 QgsFields;
36 class QgsSymbolLayerV2;
37 class QgsRenderContext;
39 
40 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
41 
42 class CORE_EXPORT QgsSymbolV2
43 {
44  public:
45 
47  {
48  MM = 0,
50  Mixed //mixed units in symbol layers
51  };
52 
54  {
57  Fill
58  };
59 
61  {
63  ScaleDiameter
64  };
65 
68  {
69  DataDefinedSizeScale = 1,
70  DataDefinedRotation = 2
71  };
72 
73  virtual ~QgsSymbolV2();
74 
76  static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
77 
78  SymbolType type() const { return mType; }
79 
80  // symbol layers handling
81 
82  QgsSymbolLayerV2* symbolLayer( int layer );
83 
84  int symbolLayerCount() { return mLayers.count(); }
85 
87  bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
88 
90  bool appendSymbolLayer( QgsSymbolLayerV2* layer );
91 
93  bool deleteSymbolLayer( int index );
94 
96  QgsSymbolLayerV2* takeSymbolLayer( int index );
97 
99  bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
100 
101  void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
102  void stopRender( QgsRenderContext& context );
103 
104  void setColor( const QColor& color );
105  QColor color() const;
106 
107  void drawPreviewIcon( QPainter* painter, QSize size );
108 
109  QImage bigSymbolPreviewImage();
110 
111  QString dump() const;
112 
113  virtual QgsSymbolV2* clone() const = 0;
114 
115  void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
116 
117  QgsSymbolV2::OutputUnit outputUnit() const;
118  void setOutputUnit( QgsSymbolV2::OutputUnit u );
119 
121  qreal alpha() const { return mAlpha; }
123  void setAlpha( qreal alpha ) { mAlpha = alpha; }
124 
126  void setRenderHints( int hints ) { mRenderHints = hints; }
128  int renderHints() const { return mRenderHints; }
129 
130  QSet<QString> usedAttributes() const;
131 
132  void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
133  const QgsVectorLayer* layer() const { return mLayer; }
134 
135  protected:
136  QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
137 
138  QgsSymbolLayerV2List cloneLayers() const;
139 
143  bool isSymbolLayerCompatible( SymbolType t );
144 
147 
149  qreal mAlpha;
150 
152 
153  const QgsVectorLayer* mLayer; //current vectorlayer
154 };
155 
157 
158 class CORE_EXPORT QgsSymbolV2RenderContext
159 {
160  public:
161  QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* = 0 );
163 
164  QgsRenderContext& renderContext() { return mRenderContext; }
165  const QgsRenderContext& renderContext() const { return mRenderContext; }
166  //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
167 
168  QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
169  void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
170 
172  qreal alpha() const { return mAlpha; }
174  void setAlpha( qreal alpha ) { mAlpha = alpha; }
175 
176  bool selected() const { return mSelected; }
177  void setSelected( bool selected ) { mSelected = selected; }
178 
180  int renderHints() const { return mRenderHints; }
182  void setRenderHints( int hints ) { mRenderHints = hints; }
183 
184  void setFeature( const QgsFeature* f ) { mFeature = f; }
186  const QgsFeature* feature() const { return mFeature; }
187 
192  const QgsFields* fields() const { return mFields; }
193 
194  double outputLineWidth( double width ) const;
195  double outputPixelSize( double size ) const;
196 
197  // workaround for sip 4.7. Don't use assignment - will fail with assertion error
199 
200  private:
203  qreal mAlpha;
204  bool mSelected;
206  const QgsFeature* mFeature; //current feature
208 };
209 
210 
211 
213 
214 
215 
216 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
217 {
218  public:
223  static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
224 
226 
227  void setAngle( double angle );
228  double angle();
229 
230  void setSize( double size );
231  double size();
232 
233  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
234  ScaleMethod scaleMethod();
235 
236  void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
237 
238  virtual QgsSymbolV2* clone() const;
239 };
240 
241 
242 
243 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
244 {
245  public:
250  static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
251 
253 
254  void setWidth( double width );
255  double width();
256 
257  void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
258 
259  virtual QgsSymbolV2* clone() const;
260 };
261 
262 
263 
264 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
265 {
266  public:
271  static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
272 
274  void setAngle( double angle );
275  void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
276 
277  virtual QgsSymbolV2* clone() const;
278 };
279 
280 #endif
281 
282 
283 /*
284 
285 QgsSymbolV2* ps = new QgsPointSymbol();
286 
287 // ----
288 
289 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
290 
291 // (or)
292 
293 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
294 
295 // (or)
296 
297 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
298 QgsLineSymbol* s = new LineSymbol( [ sl ] );
299 
300 // ----
301 
302 rend = QgsSingleSymbolRenderer( new LineSymbol() );
303 */
static unsigned index
int renderHints() const
Definition: qgssymbolv2.h:180
GeometryType
Definition: qgis.h:155
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:153
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:174
SymbolType type() const
Definition: qgssymbolv2.h:78
virtual QgsSymbolV2 * clone() const =0
Container of fields for a vector layer.
Definition: qgsfield.h:164
void setRenderHints(int hints)
Definition: qgssymbolv2.h:182
const QgsFeature * mFeature
Definition: qgssymbolv2.h:206
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
SymbolType mType
Definition: qgssymbolv2.h:145
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:133
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:172
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:146
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:186
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:121
void setLayer(const QgsVectorLayer *layer)
Definition: qgssymbolv2.h:132
int symbolLayerCount()
Definition: qgssymbolv2.h:84
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:149
void setFeature(const QgsFeature *f)
Definition: qgssymbolv2.h:184
void setOutputUnit(QgsSymbolV2::OutputUnit u)
Definition: qgssymbolv2.h:169
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.h:168
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:177
Contains information about the context of a rendering operation.
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:38
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:164
QgsRenderContext & mRenderContext
Definition: qgssymbolv2.h:201
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:192
void setRenderHints(int hints)
Definition: qgssymbolv2.h:126
bool selected() const
Definition: qgssymbolv2.h:176
const QgsRenderContext & renderContext() const
Definition: qgssymbolv2.h:165
const QgsFields * mFields
Definition: qgssymbolv2.h:207
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
QgsSymbolV2::OutputUnit mOutputUnit
Definition: qgssymbolv2.h:202
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:123
int mRenderHints
Definition: qgssymbolv2.h:151
int renderHints() const
Definition: qgssymbolv2.h:128