QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsgraduatedsymbolrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraduatedsymbolrendererv2.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 #ifndef QGSGRADUATEDSYMBOLRENDERERV2_H
16 #define QGSGRADUATEDSYMBOLRENDERERV2_H
17 
18 #include "qgssymbolv2.h"
19 #include "qgsrendererv2.h"
20 #include "qgsexpression.h"
21 #include <QScopedPointer>
22 
23 class CORE_EXPORT QgsRendererRangeV2
24 {
25  public:
27  QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label, bool render = true );
28  QgsRendererRangeV2( const QgsRendererRangeV2& range );
29 
30  // default dtor is ok
31  QgsRendererRangeV2& operator=( QgsRendererRangeV2 range );
32 
33  double lowerValue() const;
34  double upperValue() const;
35 
36  QgsSymbolV2* symbol() const;
37  QString label() const;
38 
39  void setSymbol( QgsSymbolV2* s );
40  void setLabel( QString label );
41  void setLowerValue( double lowerValue );
42  void setUpperValue( double upperValue );
43 
44  // @note added in 2.5
45  bool renderState() const;
46  void setRenderState( bool render );
47 
48  // debugging
49  QString dump() const;
50 
51  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
52 
53  protected:
54  double mLowerValue, mUpperValue;
55  QScopedPointer<QgsSymbolV2> mSymbol;
56  QString mLabel;
57  bool mRender;
58 
59  // for cpy+swap idiom
60  void swap( QgsRendererRangeV2 & other );
61 };
62 
63 typedef QList<QgsRendererRangeV2> QgsRangeList;
64 
65 class QgsVectorLayer;
67 
69 {
70  public:
71  QgsGraduatedSymbolRendererV2( QString attrName = QString(), QgsRangeList ranges = QgsRangeList() );
73 
75 
76  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
77 
78  virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
79 
80  virtual void stopRender( QgsRenderContext& context );
81 
82  virtual QList<QString> usedAttributes();
83 
84  virtual QString dump() const;
85 
86  virtual QgsFeatureRendererV2* clone();
87 
88  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
89 
92  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
93 
94  virtual QgsSymbolV2List symbols();
95 
96  QString classAttribute() const { return mAttrName; }
97  void setClassAttribute( QString attr ) { mAttrName = attr; }
98 
99  const QgsRangeList& ranges() { return mRanges; }
100 
101  bool updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol );
102  bool updateRangeLabel( int rangeIndex, QString label );
103  bool updateRangeUpperValue( int rangeIndex, double value );
104  bool updateRangeLowerValue( int rangeIndex, double value );
106  bool updateRangeRenderState( int rangeIndex, bool render );
107 
108 
109  void addClass( QgsSymbolV2* symbol );
111  void addClass( QgsRendererRangeV2 range );
112  void deleteClass( int idx );
113  void deleteAllClasses();
114 
116  void moveClass( int from, int to );
117 
118  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
119  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
120 
121  enum Mode
122  {
128  Custom
129  };
130 
131  Mode mode() const { return mMode; }
132  void setMode( Mode mode ) { mMode = mode; }
133 
134  static QgsGraduatedSymbolRendererV2* createRenderer(
135  QgsVectorLayer* vlayer,
136  QString attrName,
137  int classes,
138  Mode mode,
139  QgsSymbolV2* symbol,
140  QgsVectorColorRampV2* ramp,
141  bool inverted = false );
142 
144  static QgsFeatureRendererV2* create( QDomElement& element );
145 
147  virtual QDomElement save( QDomDocument& doc );
148 
150  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
151 
155  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() );
156 
157  QgsSymbolV2* sourceSymbol();
158  void setSourceSymbol( QgsSymbolV2* sym );
159 
160  QgsVectorColorRampV2* sourceColorRamp();
161  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
163  bool invertedColorRamp() { return mInvertedColorRamp; }
164  void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }
165 
169  void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );
170 
172  void updateSymbols( QgsSymbolV2* sym );
173 
175  void setRotationField( QString fieldOrExpression );
177  QString rotationField() const;
178 
180  void setSizeScaleField( QString fieldOrExpression );
182  QString sizeScaleField() const;
183 
185  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
187  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
188 
190  // @note added in 2.5
191  virtual bool legendSymbolItemsCheckable() const;
192 
194  // @note added in 2.5
195  virtual bool legendSymbolItemChecked( int index );
196 
198  // @note added in 2.5
199  virtual void checkLegendSymbolItem( int index, bool state = true );
200 
201  protected:
202  QString mAttrName;
205  QScopedPointer<QgsSymbolV2> mSourceSymbol;
206  QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
208  QScopedPointer<QgsExpression> mRotation;
209  QScopedPointer<QgsExpression> mSizeScale;
211  QScopedPointer<QgsExpression> mExpression;
213  int mAttrNum;
214  bool mCounting;
215 
217  QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
218 
219  QgsSymbolV2* symbolForValue( double value );
220 
221 };
222 
223 #endif // QGSGRADUATEDSYMBOLRENDERERV2_H
QList< QgsRendererRangeV2 > QgsRangeList
static unsigned index
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
virtual QString dump() const
for debugging
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Container of fields for a vector layer.
Definition: qgsfield.h:161
QHash< QgsSymbolV2 *, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
virtual QList< QString > usedAttributes()=0
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
virtual QString rotationField() const
return rotation field name (or empty string if not set or not supported by renderer) ...
QScopedPointer< QgsSymbolV2 > mSymbol
virtual QgsSymbolV2List symbols()=0
for symbol levels
QScopedPointer< QgsExpression > mExpression
virtual QgsFeatureRendererV2 * clone()=0
QgsSymbolV2::ScaleMethod scaleMethod() const
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
virtual bool legendSymbolItemChecked(int index)
items of symbology items in legend is checked
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Contains information about the context of a rendering operation.
int mAttrNum
attribute index (derived from attribute name in startRender)
virtual void checkLegendSymbolItem(int index, bool state=true)
item in symbology was checked
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
QScopedPointer< QgsSymbolV2 > mSourceSymbol
QScopedPointer< QgsExpression > mRotation
QScopedPointer< QgsExpression > mSizeScale
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden