QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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;
32 class QgsFields;
34 
35 typedef QMap<QString, QString> QgsStringMap;
36 
37 typedef QList<QgsSymbolV2*> QgsSymbolV2List;
38 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
39 
40 typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList;
41 typedef QList< QPair<QString, QgsSymbolV2*> > QgsLegendSymbolList;
42 
43 #include "qgslegendsymbolitemv2.h"
44 
45 
46 #define RENDERER_TAG_NAME "renderer-v2"
47 
49 // symbol levels
50 
51 class CORE_EXPORT QgsSymbolV2LevelItem
52 {
53  public:
54  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
55  QgsSymbolV2* symbol() { return mSymbol; }
56  int layer() { return mLayer; }
57  protected:
59  int mLayer;
60 };
61 
62 // every level has list of items: symbol + symbol layer num
63 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;
64 
65 // this is a list of levels
66 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;
67 
68 
70 // renderers
71 
72 class CORE_EXPORT QgsFeatureRendererV2
73 {
74  public:
75  // renderer takes ownership of its symbols!
76 
78  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
79 
80  QString type() const { return mType; }
81 
86  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
87 
94  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature ) { return symbolForFeature( feature ); }
95 
96  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
97 
99  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
100 
101  virtual void stopRender( QgsRenderContext& context ) = 0;
102 
103  virtual QList<QString> usedAttributes() = 0;
104 
106 
107  virtual QgsFeatureRendererV2* clone() const = 0;
108 
109  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
110 
112  virtual QString dump() const;
113 
115  {
116  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
117  RotationField = 1 << 1, // rotate symbols by attribute value
118  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
119  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
120  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
121  };
122 
124  virtual int capabilities() { return 0; }
125 
127  virtual QgsSymbolV2List symbols() = 0;
128 
129  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
130  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
131 
133  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
134 
136  virtual QDomElement save( QDomDocument& doc );
137 
139  virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
140 
151  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
152 
154  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
155  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
156 
158  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
159 
162  virtual bool legendSymbolItemsCheckable() const;
163 
166  virtual bool legendSymbolItemChecked( QString key );
167 
170  virtual void checkLegendSymbolItem( QString key, bool state = true );
171 
174  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
175 
179  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
180 
183  virtual QString legendClassificationAttribute() const { return QString(); }
184 
186  void setVertexMarkerAppearance( int type, int size );
187 
189  virtual QString rotationField() const { return ""; }
191  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
192 
196  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
197 
201  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
202 
206  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
207 
208  protected:
209  QgsFeatureRendererV2( QString type );
210 
211  void renderFeatureWithSymbol( QgsFeature& feature,
212  QgsSymbolV2* symbol,
213  QgsRenderContext& context,
214  int layer,
215  bool selected,
216  bool drawVertexMarker );
217 
219  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
221  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
223  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
224 
225  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
226  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
227  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
228 
229  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
230 
231  QString mType;
232 
234 
239 
240  private:
241  Q_DISABLE_COPY( QgsFeatureRendererV2 )
242 };
243 
244 class QgsRendererV2Widget; // why does SIP fail, when this isn't here
245 
246 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:38
virtual ~QgsFeatureRendererV2()
Definition: qgsrendererv2.h:105
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
Definition: qgsrendererv2.h:196
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:94
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
Definition: qgsrendererv2.h:191
QString mType
Definition: qgsrendererv2.h:231
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
int mLayer
Definition: qgsrendererv2.h:59
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:40
Container of fields for a vector layer.
Definition: qgsfield.h:172
GeometryType
Definition: qgis.h:155
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
virtual QString rotationField() const
return rotation field name (or empty string if not set or not supported by renderer) ...
Definition: qgsrendererv2.h:189
QString type() const
Definition: qgsrendererv2.h:80
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsrendererv2.h:183
int mCurrentVertexMarkerSize
The current size of editing marker.
Definition: qgsrendererv2.h:238
int mCurrentVertexMarkerType
The current type of editing marker.
Definition: qgsrendererv2.h:236
Capabilities
Definition: qgsrendererv2.h:114
Definition: qgssymbolv2.h:43
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgspluginlayer.h:20
Definition: qgsrendererv2.h:51
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:63
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrendererv2.h:154
QgsSymbolV2LevelItem(QgsSymbolV2 *symbol, int layer)
Definition: qgsrendererv2.h:54
void setUsingSymbolLevels(bool usingSymbolLevels)
Definition: qgsrendererv2.h:130
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:55
bool usingSymbolLevels() const
Definition: qgsrendererv2.h:129
Base class for renderer settings widgets.
Definition: qgsrendererv2widget.h:38
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:66
Definition: qgsrendererv2.h:72
QList< QgsLegendSymbolItemV2 > QgsLegendSymbolListV2
Definition: qgslegendsymbolitemv2.h:90
int layer()
Definition: qgsrendererv2.h:56
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Definition: qgsrendererv2.h:124
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:468
double size
Definition: qgssvgcache.cpp:77
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
bool mUsingSymbolLevels
Definition: qgsrendererv2.h:233
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:58
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:33