QGIS API Documentation  2.11.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 #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 
105  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
106 
108  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
109 
110  virtual void stopRender( QgsRenderContext& context ) = 0;
111 
123  virtual QString filter() { return QString::null; }
124 
125  virtual QList<QString> usedAttributes() = 0;
126 
127  virtual ~QgsFeatureRendererV2();
128 
129  virtual QgsFeatureRendererV2* clone() const = 0;
130 
131  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
132 
134  virtual QString dump() const;
135 
137  {
138  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
139  RotationField = 1 << 1, // rotate symbols by attribute value
140  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
141  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
142  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
143  };
144 
146  virtual int capabilities() { return 0; }
147 
149  virtual QgsSymbolV2List symbols() = 0;
150 
151  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
152  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
153 
155  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
156 
158  virtual QDomElement save( QDomDocument& doc );
159 
162  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
165  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
166 
177  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
178 
180  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
181  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
182 
184  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
185 
188  virtual bool legendSymbolItemsCheckable() const;
189 
192  virtual bool legendSymbolItemChecked( QString key );
193 
196  virtual void checkLegendSymbolItem( QString key, bool state = true );
197 
200  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
201 
205  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
206 
209  virtual QString legendClassificationAttribute() const { return QString(); }
210 
212  void setVertexMarkerAppearance( int type, int size );
213 
215  virtual QString rotationField() const { return ""; }
217  virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
218 
222  virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
223 
227  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
228 
232  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
233 
240  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
241 
247  QgsPaintEffect* paintEffect() const;
248 
254  void setPaintEffect( QgsPaintEffect* effect );
255 
260  bool forceRasterRender() const { return mForceRaster; }
261 
269  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
270 
271  protected:
273 
274  void renderFeatureWithSymbol( QgsFeature& feature,
275  QgsSymbolV2* symbol,
276  QgsRenderContext& context,
277  int layer,
278  bool selected,
279  bool drawVertexMarker );
280 
282  void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
284  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
286  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
287 
288  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
289  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
290  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
291 
292  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
293 
297  void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
298 
300 
302 
307 
309 
311 
315  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
319  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
320 
321  private:
322  Q_DISABLE_COPY( QgsFeatureRendererV2 )
323 };
324 
325 // for some reason SIP compilation fails if these lines are not included:
326 class QgsRendererV2Widget;
328 
329 #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)
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
QDomNode appendChild(const QDomNode &newChild)
Base class for effect properties widgets.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:42
virtual QString filter()
If a renderer does not require all the features this method may be overridden and return an expressio...
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
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: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
bool forceRasterRender() const
Returns whether the renderer must render as a raster.
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