QGIS API Documentation  2.13.0-Master
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 #include "qgsfield.h"
24 #include "qgsfeaturerequest.h"
25 
26 #include <QList>
27 #include <QString>
28 #include <QVariant>
29 #include <QPair>
30 #include <QPixmap>
31 #include <QDomDocument>
32 #include <QDomElement>
33 
34 class QgsFeature;
35 class QgsVectorLayer;
37 
39 
42 
45 
46 #include "qgslegendsymbolitemv2.h"
47 
48 
49 #define RENDERER_TAG_NAME "renderer-v2"
50 
52 // symbol levels
53 
54 class CORE_EXPORT QgsSymbolV2LevelItem
55 {
56  public:
57  QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {}
58  QgsSymbolV2* symbol() { return mSymbol; }
59  int layer() { return mLayer; }
60  protected:
62  int mLayer;
63 };
64 
65 // every level has list of items: symbol + symbol layer num
67 
68 // this is a list of levels
70 
71 
73 // renderers
74 
75 class CORE_EXPORT QgsFeatureRendererV2
76 {
77  public:
78  // renderer takes ownership of its symbols!
79 
81  static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType );
82 
83  QString type() const { return mType; }
84 
92  Q_DECL_DEPRECATED virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
93 
103  // TODO - QGIS 3.0 make pure virtual when above method is removed
104  // TODO - QGIS 3.0 change PyName to symbolForFeature when deprecated method is removed
105  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
106 
114  Q_DECL_DEPRECATED virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
115 
123  //TODO - QGIS 3.0 change PyName to originalSymbolForFeature when deprecated method is removed
124  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
125 
130  virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );
131 
139  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) = 0;
140 
142  Q_DECL_DEPRECATED virtual void startRender( QgsRenderContext& context, const QgsVectorLayer* vlayer );
143 
147  virtual void stopRender( QgsRenderContext& context ) = 0;
148 
160  virtual QString filter( const QgsFields& fields = QgsFields() ) { Q_UNUSED( fields ); return QString::null; }
161 
167  virtual QList<QString> usedAttributes() = 0;
168 
169  virtual ~QgsFeatureRendererV2();
170 
171  virtual QgsFeatureRendererV2* clone() const = 0;
172 
183  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
184 
186  virtual QString dump() const;
187 
189  {
190  SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
191  RotationField = 1 << 1, // rotate symbols by attribute value
192  MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
193  Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
194  ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
195  };
196 
198  virtual int capabilities() { return 0; }
199 
203  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbols();
204 
210  //TODO - QGIS 3.0 change PyName to symbols when deprecated method is removed
211  virtual QgsSymbolV2List symbols( QgsRenderContext& context );
212 
213  bool usingSymbolLevels() const { return mUsingSymbolLevels; }
214  void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
215 
217  static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
218 
220  virtual QDomElement save( QDomDocument& doc );
221 
224  Q_DECL_DEPRECATED virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
227  virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
228 
239  static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
240 
242  virtual void toSld( QDomDocument& doc, QDomElement &element ) const
243  { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
244 
246  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
247 
250  virtual bool legendSymbolItemsCheckable() const;
251 
254  virtual bool legendSymbolItemChecked( const QString& key );
255 
258  virtual void checkLegendSymbolItem( const QString& key, bool state = true );
259 
265  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol );
266 
269  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" );
270 
274  virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;
275 
278  virtual QString legendClassificationAttribute() const { return QString(); }
279 
281  void setVertexMarkerAppearance( int type, int size );
282 
285  Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
286 
289  Q_DECL_DEPRECATED virtual void setRotationField( const QString& fieldName ) { Q_UNUSED( fieldName ); }
290 
296  Q_DECL_DEPRECATED virtual bool willRenderFeature( QgsFeature& feat );
297 
304  //TODO - QGIS 3.0 change PyName to willRenderFeature when deprecated method is removed
305  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context );
306 
312  Q_DECL_DEPRECATED virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
313 
320  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
321  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
322 
328  Q_DECL_DEPRECATED virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat );
329 
335  //TODO - QGIS 3.0 change PyName to symbolsForFeature when deprecated method is removed
336  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context );
337 
344  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) { Q_UNUSED( extent ); Q_UNUSED( context ); }
345 
351  QgsPaintEffect* paintEffect() const;
352 
358  void setPaintEffect( QgsPaintEffect* effect );
359 
364  bool forceRasterRender() const { return mForceRaster; }
365 
373  void setForceRasterRender( bool forceRaster ) { mForceRaster = forceRaster; }
374 
379  QgsFeatureRequest::OrderBy orderBy() const;
380 
385  void setOrderBy( const QgsFeatureRequest::OrderBy& orderBy );
386 
387  protected:
388  QgsFeatureRendererV2( const QString& type );
389 
390  void renderFeatureWithSymbol( QgsFeature& feature,
391  QgsSymbolV2* symbol,
392  QgsRenderContext& context,
393  int layer,
394  bool selected,
395  bool drawVertexMarker );
396 
398  void renderVertexMarker( QPointF pt, QgsRenderContext& context );
400  void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
402  void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
403 
404  static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
405  static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
406  static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
407 
408  void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
409 
418  void copyRendererData( QgsFeatureRendererV2 *destRenderer ) const;
419 
424  Q_DECL_DEPRECATED void copyPaintEffect( QgsFeatureRendererV2 *destRenderer ) const;
425 
427 
429 
434 
436 
438 
442  static void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field );
446  static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );
447 
449 
450  private:
451  Q_DISABLE_COPY( QgsFeatureRendererV2 )
452 };
453 
454 // for some reason SIP compilation fails if these lines are not included:
455 class QgsRendererV2Widget;
457 
458 #endif // QGSRENDERERV2_H
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Definition: qgsrendererv2.h:41
A rectangle specified with double values.
Definition: qgsrectangle.h:35
GeometryType
Definition: qgis.h:111
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:40
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:43
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:189
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
QgsPaintEffect * mPaintEffect
QString type() const
Definition: qgsrendererv2.h:83
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.
virtual Q_DECL_DEPRECATED QString rotationField() const
return rotation field name (or empty string if not set or not supported by renderer) ...
int mCurrentVertexMarkerType
The current type of editing marker.
QList< QgsSymbolV2LevelItem > QgsSymbolV2Level
Definition: qgsrendererv2.h:66
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:57
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:84
QgsFeatureRequest::OrderBy mOrderBy
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:58
bool usingSymbolLevels() const
QDomComment createComment(const QString &value)
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:69
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
virtual Q_DECL_DEPRECATED void setRotationField(const QString &fieldName)
sets rotation field of renderer (if supported by the renderer)
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:44
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:61
Represents a list of OrderByClauses, with the most important first and the least important last...
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:36