QGIS API Documentation  2.10.1-Pisa
 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 #include "qgssymbolv2.h"
23 
24 #include <QList>
25 #include <QString>
26 #include <QVariant>
27 #include <QPair>
28 #include <QPixmap>
29 #include <QDomDocument>
30 #include <QDomElement>
31 
32 class QgsFeature;
33 class QgsFields;
34 class QgsVectorLayer;
36 
38 
41 
44 
45 #include "qgslegendsymbolitemv2.h"
46 
47 
48 #define RENDERER_TAG_NAME "renderer-v2"
49 
51 // symbol levels
52 
53 class CORE_EXPORT QgsSymbolV2LevelItem
54 {
55  public:
56  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
57  QgsSymbolV2* symbol() { return mSymbol; }
58  int layer() { return mLayer; }
59  protected:
61  int mLayer;
62 };
63 
64 // every level has list of items: symbol + symbol layer num
66 
67 // this is a list of levels
69 
70 
72 // renderers
73 
74 class CORE_EXPORT QgsFeatureRendererV2
75 {
76  public:
77  // renderer takes ownership of its symbols!
78 
80  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
81 
82  QString type() const { return mType; }
83 
88  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
89 
96  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature ) { return symbolForFeature( feature ); }
97 
98  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
99 
101  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
102 
103  virtual void stopRender( QgsRenderContext& context ) = 0;
104 
105  virtual QList<QString> usedAttributes() = 0;
106 
107  virtual ~QgsFeatureRendererV2();
108 
109  virtual QgsFeatureRendererV2* clone() const = 0;
110 
111  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
112 
114  virtual QString dump() const;
115 
117  {
118  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
119  RotationField = 1 << 1, // rotate symbols by attribute value
120  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
121  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
122  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
123  };
124 
126  virtual int capabilities() { return 0; }
127 
129  virtual QgsSymbolV2List symbols() = 0;
130 
131  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
132  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
133 
135  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
136 
138  virtual QDomElement save( QDomDocument& doc );
139 
142  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
145  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
146 
157  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
158 
160  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
161  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
162 
164  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
165 
168  virtual bool legendSymbolItemsCheckable() const;
169 
172  virtual bool legendSymbolItemChecked( QString key );
173 
176  virtual void checkLegendSymbolItem( QString key, bool state = true );
177 
180  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
181 
185  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
186 
189  virtual QString legendClassificationAttribute() const { return QString(); }
190 
192  void setVertexMarkerAppearance( int type, int size );
193 
195  virtual QString rotationField() const { return ""; }
197  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
198 
202  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
203 
207  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
208 
212  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
213 
220  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
221 
227  QgsPaintEffect* paintEffect() const;
228 
234  void setPaintEffect( QgsPaintEffect* effect );
235 
236  protected:
238 
239  void renderFeatureWithSymbol( QgsFeature& feature,
240  QgsSymbolV2* symbol,
241  QgsRenderContext& context,
242  int layer,
243  bool selected,
244  bool drawVertexMarker );
245 
247  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
249  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
251  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
252 
253  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
254  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
255  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
256 
257  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
258 
262  void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
263 
265 
267 
272 
274 
278  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
282  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
283 
284  private:
285  Q_DISABLE_COPY( QgsFeatureRendererV2 )
286 };
287 
288 // for some reason SIP compilation fails if these lines are not included:
289 class QgsRendererV2Widget;
291 
292 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:40
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:96
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
GeometryType
Definition: qgis.h:155
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
QDomNode appendChild(const QDomNode &newChild)
Base class for effect properties widgets.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:42
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Base class for visual effects which can be applied to QPicture drawings.
Container of fields for a vector layer.
Definition: qgsfield.h:173
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
QgsPaintEffect * mPaintEffect
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:82
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
int mCurrentVertexMarkerSize
The current size of editing marker.
int mCurrentVertexMarkerType
The current type of editing marker.
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:65
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:56
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:57
bool usingSymbolLevels() const
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:68
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:43
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:60
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:35