QGIS API Documentation  2.0.1-Dufour
 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 
21 class CORE_EXPORT QgsRendererRangeV2
22 {
23  public:
25  QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label );
26  QgsRendererRangeV2( const QgsRendererRangeV2& range );
27 
29 
30  QgsRendererRangeV2& operator=( const QgsRendererRangeV2& range );
31 
32  double lowerValue() const;
33  double upperValue() const;
34 
35  QgsSymbolV2* symbol() const;
36  QString label() const;
37 
38  void setSymbol( QgsSymbolV2* s );
39  void setLabel( QString label );
40  void setLowerValue( double lowerValue );
41  void setUpperValue( double upperValue );
42 
43  // debugging
44  QString dump() const;
45 
46  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
47 
48  protected:
49  double mLowerValue, mUpperValue;
51  QString mLabel;
52 };
53 
54 typedef QList<QgsRendererRangeV2> QgsRangeList;
55 
56 class QgsVectorLayer;
58 
60 {
61  public:
62  QgsGraduatedSymbolRendererV2( QString attrName = QString(), QgsRangeList ranges = QgsRangeList() );
63 
65 
66  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
67 
68  virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
69 
70  virtual void stopRender( QgsRenderContext& context );
71 
72  virtual QList<QString> usedAttributes();
73 
74  virtual QString dump() const;
75 
76  virtual QgsFeatureRendererV2* clone();
77 
78  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
79 
82  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
83 
84  virtual QgsSymbolV2List symbols();
85 
86  QString classAttribute() const { return mAttrName; }
87  void setClassAttribute( QString attr ) { mAttrName = attr; }
88 
89  const QgsRangeList& ranges() { return mRanges; }
90 
91  bool updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol );
92  bool updateRangeLabel( int rangeIndex, QString label );
93  bool updateRangeUpperValue( int rangeIndex, double value );
94  bool updateRangeLowerValue( int rangeIndex, double value );
95 
96  void addClass( QgsSymbolV2* symbol );
97  void deleteClass( int idx );
98  void deleteAllClasses();
99 
101  void moveClass( int from, int to );
102 
103  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
104  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
105 
106  enum Mode
107  {
113  Custom
114  };
115 
116  Mode mode() const { return mMode; }
117  void setMode( Mode mode ) { mMode = mode; }
118 
119  static QgsGraduatedSymbolRendererV2* createRenderer(
120  QgsVectorLayer* vlayer,
121  QString attrName,
122  int classes,
123  Mode mode,
124  QgsSymbolV2* symbol,
125  QgsVectorColorRampV2* ramp );
126 
128  static QgsFeatureRendererV2* create( QDomElement& element );
129 
131  virtual QDomElement save( QDomDocument& doc );
132 
134  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
135 
140 
141  QgsSymbolV2* sourceSymbol();
142  void setSourceSymbol( QgsSymbolV2* sym );
143 
144  QgsVectorColorRampV2* sourceColorRamp();
145  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
146 
150  void updateColorRamp( QgsVectorColorRampV2* ramp );
151 
153  void updateSymbols( QgsSymbolV2* sym );
154 
156  void setRotationField( QString fieldName ) { mRotationField = fieldName; }
158  QString rotationField() const { return mRotationField; }
159 
161  void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; }
163  QString sizeScaleField() const { return mSizeScaleField; }
164 
166  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
168  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
169 
170 
171  protected:
172  QString mAttrName;
177  QString mRotationField;
180 
182  int mAttrNum;
183  int mRotationFieldIdx, mSizeScaleFieldIdx;
184 
186 #if QT_VERSION < 0x40600
187  QMap<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
188 #else
189  QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
190 #endif
191 
192  QgsSymbolV2* symbolForValue( double value );
193 };
194 
195 #endif // QGSGRADUATEDSYMBOLRENDERERV2_H