QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererv2.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 QGSRENDERERV2_H
17 #define QGSRENDERERV2_H
18 
19 #include "qgis.h"
20 
21 #include <QList>
22 #include <QString>
23 #include <QVariant>
24 #include <QPair>
25 #include <QPixmap>
26 #include <QDomDocument>
27 #include <QDomElement>
28 
29 class QgsSymbolV2;
30 class QgsRenderContext;
31 class QgsFeature;
33 
34 typedef QMap<QString, QString> QgsStringMap;
35 
36 typedef QList<QgsSymbolV2*> QgsSymbolV2List;
37 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
38 
39 typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList;
40 typedef QList< QPair<QString, QgsSymbolV2*> > QgsLegendSymbolList;
41 
42 #define RENDERER_TAG_NAME "renderer-v2"
43 
45 // symbol levels
46 
47 class CORE_EXPORT QgsSymbolV2LevelItem
48 {
49  public:
50  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
51  QgsSymbolV2* symbol() { return mSymbol; }
52  int layer() { return mLayer; }
53  protected:
55  int mLayer;
56 };
57 
58 // every level has list of items: symbol + symbol layer num
59 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;
60 
61 // this is a list of levels
62 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;
63 
64 
66 // renderers
67 
68 class CORE_EXPORT QgsFeatureRendererV2
69 {
70  public:
71  // renderer takes ownership of its symbols!
72 
74  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
75 
76  QString type() const { return mType; }
77 
82  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
83 
84  virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ) = 0;
85 
86  virtual void stopRender( QgsRenderContext& context ) = 0;
87 
88  virtual QList<QString> usedAttributes() = 0;
89 
90  virtual ~QgsFeatureRendererV2() {}
91 
92  virtual QgsFeatureRendererV2* clone() = 0;
93 
94  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
95 
97  virtual QString dump() const;
98 
100  {
101  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
102  RotationField = 1 << 1, // rotate symbols by attribute value
103  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
104  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
105  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
106  };
107 
110  virtual int capabilities() { return 0; }
111 
113  virtual QgsSymbolV2List symbols() = 0;
114 
115  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
116  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
117 
119  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
120 
122  virtual QDomElement save( QDomDocument& doc );
123 
126  virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
127 
139  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
140 
143  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
144  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
145 
147  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
148 
152  virtual QgsLegendSymbolList legendSymbolItems();
153 
155  void setVertexMarkerAppearance( int type, int size );
156 
159  virtual QString rotationField() const { return ""; }
162  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
163 
168  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
169 
174  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
175 
176  protected:
177  QgsFeatureRendererV2( QString type );
178 
179  void renderFeatureWithSymbol( QgsFeature& feature,
180  QgsSymbolV2* symbol,
181  QgsRenderContext& context,
182  int layer,
183  bool selected,
184  bool drawVertexMarker );
185 
187  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
189  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
191  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
192 
193  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
194  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
195  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
196 
197  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
198 
199  QString mType;
200 
202 
207 };
208 
209 class QgsRendererV2Widget; // why does SIP fail, when this isn't here
210 
211 #endif // QGSRENDERERV2_H