QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #define RENDERER_TAG_NAME "renderer-v2"
44 
46 // symbol levels
47 
48 class CORE_EXPORT QgsSymbolV2LevelItem
49 {
50  public:
51  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
52  QgsSymbolV2* symbol() { return mSymbol; }
53  int layer() { return mLayer; }
54  protected:
56  int mLayer;
57 };
58 
59 // every level has list of items: symbol + symbol layer num
60 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;
61 
62 // this is a list of levels
63 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;
64 
65 
67 // renderers
68 
69 class CORE_EXPORT QgsFeatureRendererV2
70 {
71  public:
72  // renderer takes ownership of its symbols!
73 
75  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
76 
77  QString type() const { return mType; }
78 
83  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
84 
85  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
86 
88  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
89 
90  virtual void stopRender( QgsRenderContext& context ) = 0;
91 
92  virtual QList<QString> usedAttributes() = 0;
93 
94  virtual ~QgsFeatureRendererV2() {}
95 
96  virtual QgsFeatureRendererV2* clone() = 0;
97 
98  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
99 
101  virtual QString dump() const;
102 
104  {
105  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
106  RotationField = 1 << 1, // rotate symbols by attribute value
107  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
108  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
109  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
110  };
111 
114  virtual int capabilities() { return 0; }
115 
117  virtual QgsSymbolV2List symbols() = 0;
118 
119  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
120  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
121 
123  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
124 
126  virtual QDomElement save( QDomDocument& doc );
127 
130  virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
131 
143  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
144 
147  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
148  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
149 
151  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
152 
155  virtual bool legendSymbolItemsCheckable() const;
156 
159  virtual bool legendSymbolItemChecked( int index );
160 
163  virtual void checkLegendSymbolItem( int index, bool state = true );
164 
168  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
169 
171  void setVertexMarkerAppearance( int type, int size );
172 
175  virtual QString rotationField() const { return ""; }
178  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
179 
184  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
185 
190  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
191 
192  protected:
193  QgsFeatureRendererV2( QString type );
194 
195  void renderFeatureWithSymbol( QgsFeature& feature,
196  QgsSymbolV2* symbol,
197  QgsRenderContext& context,
198  int layer,
199  bool selected,
200  bool drawVertexMarker );
201 
203  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
205  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
207  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
208 
209  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
210  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb );
211  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb );
212 
213  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
214 
215  QString mType;
216 
218 
223 
224  private:
225  Q_DISABLE_COPY( QgsFeatureRendererV2 )
226 };
227 
228 class QgsRendererV2Widget; // why does SIP fail, when this isn't here
229 
230 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:38
virtual ~QgsFeatureRendererV2()
Definition: qgsrendererv2.h:94
static unsigned index
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:40
Container of fields for a vector layer.
Definition: qgsfield.h:163
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) ...
QString type() const
Definition: qgsrendererv2.h:77
int mCurrentVertexMarkerSize
The current size of editing marker.
int mCurrentVertexMarkerType
The current type of editing marker.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:60
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QgsSymbolV2LevelItem(QgsSymbolV2 *symbol, int layer)
Definition: qgsrendererv2.h:51
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:52
bool usingSymbolLevels() const
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:63
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:55
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:33