QGIS API Documentation  2.8.2-Wien
 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 #include "qgsrectangle.h"
21 #include "qgsrendercontext.h"
22 
23 #include <QList>
24 #include <QString>
25 #include <QVariant>
26 #include <QPair>
27 #include <QPixmap>
28 #include <QDomDocument>
29 #include <QDomElement>
30 
31 class QgsSymbolV2;
32 class QgsFeature;
33 class QgsFields;
35 
36 typedef QMap<QString, QString> QgsStringMap;
37 
38 typedef QList<QgsSymbolV2*> QgsSymbolV2List;
39 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
40 
41 typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList;
42 typedef QList< QPair<QString, QgsSymbolV2*> > QgsLegendSymbolList;
43 
44 #include "qgslegendsymbolitemv2.h"
45 
46 
47 #define RENDERER_TAG_NAME "renderer-v2"
48 
50 // symbol levels
51 
52 class CORE_EXPORT QgsSymbolV2LevelItem
53 {
54  public:
55  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
56  QgsSymbolV2* symbol() { return mSymbol; }
57  int layer() { return mLayer; }
58  protected:
60  int mLayer;
61 };
62 
63 // every level has list of items: symbol + symbol layer num
64 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;
65 
66 // this is a list of levels
67 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;
68 
69 
71 // renderers
72 
73 class CORE_EXPORT QgsFeatureRendererV2
74 {
75  public:
76  // renderer takes ownership of its symbols!
77 
79  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
80 
81  QString type() const { return mType; }
82 
87  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
88 
95  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature ) { return symbolForFeature( feature ); }
96 
97  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
98 
100  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
101 
102  virtual void stopRender( QgsRenderContext& context ) = 0;
103 
104  virtual QList<QString> usedAttributes() = 0;
105 
107 
108  virtual QgsFeatureRendererV2* clone() const = 0;
109 
110  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
111 
113  virtual QString dump() const;
114 
116  {
117  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
118  RotationField = 1 << 1, // rotate symbols by attribute value
119  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
120  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
121  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
122  };
123 
125  virtual int capabilities() { return 0; }
126 
128  virtual QgsSymbolV2List symbols() = 0;
129 
130  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
131  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
132 
134  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
135 
137  virtual QDomElement save( QDomDocument& doc );
138 
141  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
144  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
145 
156  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
157 
159  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
160  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
161 
163  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
164 
167  virtual bool legendSymbolItemsCheckable() const;
168 
171  virtual bool legendSymbolItemChecked( QString key );
172 
175  virtual void checkLegendSymbolItem( QString key, bool state = true );
176 
179  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
180 
184  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
185 
188  virtual QString legendClassificationAttribute() const { return QString(); }
189 
191  void setVertexMarkerAppearance( int type, int size );
192 
194  virtual QString rotationField() const { return ""; }
196  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
197 
201  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
202 
206  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
207 
211  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
212 
219  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
220 
221  protected:
222  QgsFeatureRendererV2( QString type );
223 
224  void renderFeatureWithSymbol( QgsFeature& feature,
225  QgsSymbolV2* symbol,
226  QgsRenderContext& context,
227  int layer,
228  bool selected,
229  bool drawVertexMarker );
230 
232  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
234  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
236  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
237 
238  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
239  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
240  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
241 
242  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
243 
244  QString mType;
245 
247 
252 
253  private:
254  Q_DISABLE_COPY( QgsFeatureRendererV2 )
255 };
256 
257 class QgsRendererV2Widget; // why does SIP fail, when this isn't here
258 
259 #endif // QGSRENDERERV2_H