QGIS API Documentation  2.9.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 #include "qgsrectangle.h"
21 #include "qgsrendercontext.h"
22 
23 #include <QList>
24 #include <QString>
25 #include <QVariant>
26 #include <QPair>
27 #include <QPixmap>
28 #include <QDomDocument>
29 #include <QDomElement>
30 
31 class QgsSymbolV2;
32 class QgsFeature;
33 class QgsFields;
34 class QgsVectorLayer;
36 
37 typedef QMap<QString, QString> QgsStringMap;
38 
39 typedef QList<QgsSymbolV2*> QgsSymbolV2List;
40 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
41 
42 typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList;
43 typedef QList< QPair<QString, QgsSymbolV2*> > QgsLegendSymbolList;
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
65 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;
66 
67 // this is a list of levels
68 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;
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:
237  QgsFeatureRendererV2( QString type );
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 
264  QString mType;
265 
267 
272 
274 
275  private:
276  Q_DISABLE_COPY( QgsFeatureRendererV2 )
277 };
278 
279 // for some reason SIP compilation fails if these lines are not included:
280 class QgsRendererV2Widget;
282 
283 #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
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: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
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< QPair< QString, QPixmap > > QgsLegendSymbologyList
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
Base class for renderer settings widgets.
QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder
Definition: qgsrendererv2.h:68
QList< QgsLegendSymbolItemV2 > QgsLegendSymbolListV2
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:43
QgsSymbolV2 * mSymbol
Definition: qgsrendererv2.h:60
QMap< QString, QString > QgsStringMap
Definition: qgsrendererv2.h:35