QGIS API Documentation  2.2.0-Valmiera
 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 );
28  QgsRendererRangeV2( const QgsRendererRangeV2& range );
29 
30  // default dtor is ok
31 
32  QgsRendererRangeV2& operator=( QgsRendererRangeV2 range );
33 
34  double lowerValue() const;
35  double upperValue() const;
36 
37  QgsSymbolV2* symbol() const;
38  QString label() const;
39 
40  void setSymbol( QgsSymbolV2* s );
41  void setLabel( QString label );
42  void setLowerValue( double lowerValue );
43  void setUpperValue( double upperValue );
44 
45  // debugging
46  QString dump() const;
47 
48  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
49 
50  protected:
51  double mLowerValue, mUpperValue;
52  QScopedPointer<QgsSymbolV2> mSymbol;
53  QString mLabel;
54 
55  // for cpy+swap idiom
56  void swap( QgsRendererRangeV2 & other );
57 };
58 
59 typedef QList<QgsRendererRangeV2> QgsRangeList;
60 
61 class QgsVectorLayer;
63 
65 {
66  public:
67  QgsGraduatedSymbolRendererV2( QString attrName = QString(), QgsRangeList ranges = QgsRangeList() );
69 
71 
72  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
73 
74  virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
75 
76  virtual void stopRender( QgsRenderContext& context );
77 
78  virtual QList<QString> usedAttributes();
79 
80  virtual QString dump() const;
81 
82  virtual QgsFeatureRendererV2* clone();
83 
84  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
85 
88  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
89 
90  virtual QgsSymbolV2List symbols();
91 
92  QString classAttribute() const { return mAttrName; }
93  void setClassAttribute( QString attr ) { mAttrName = attr; }
94 
95  const QgsRangeList& ranges() { return mRanges; }
96 
97  bool updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol );
98  bool updateRangeLabel( int rangeIndex, QString label );
99  bool updateRangeUpperValue( int rangeIndex, double value );
100  bool updateRangeLowerValue( int rangeIndex, double value );
101 
102  void addClass( QgsSymbolV2* symbol );
104  void addClass( QgsRendererRangeV2 range );
105  void deleteClass( int idx );
106  void deleteAllClasses();
107 
109  void moveClass( int from, int to );
110 
111  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
112  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
113 
114  enum Mode
115  {
121  Custom
122  };
123 
124  Mode mode() const { return mMode; }
125  void setMode( Mode mode ) { mMode = mode; }
126 
127  static QgsGraduatedSymbolRendererV2* createRenderer(
128  QgsVectorLayer* vlayer,
129  QString attrName,
130  int classes,
131  Mode mode,
132  QgsSymbolV2* symbol,
133  QgsVectorColorRampV2* ramp,
134  bool inverted = false );
135 
137  static QgsFeatureRendererV2* create( QDomElement& element );
138 
140  virtual QDomElement save( QDomDocument& doc );
141 
143  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
144 
148  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() );
149 
150  QgsSymbolV2* sourceSymbol();
151  void setSourceSymbol( QgsSymbolV2* sym );
152 
153  QgsVectorColorRampV2* sourceColorRamp();
154  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
156  bool invertedColorRamp() { return mInvertedColorRamp; }
157  void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }
158 
162  void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );
163 
165  void updateSymbols( QgsSymbolV2* sym );
166 
168  void setRotationField( QString fieldOrExpression );
170  QString rotationField() const;
171 
173  void setSizeScaleField( QString fieldOrExpression );
175  QString sizeScaleField() const;
176 
178  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
180  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
181 
182 
183  protected:
184  QString mAttrName;
187  QScopedPointer<QgsSymbolV2> mSourceSymbol;
188  QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
190  QScopedPointer<QgsExpression> mRotation;
191  QScopedPointer<QgsExpression> mSizeScale;
193  QScopedPointer<QgsExpression> mExpression;
195  int mAttrNum;
196 
198  QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
199 
200  QgsSymbolV2* symbolForValue( double value );
201 
202 };
203 
204 #endif // QGSGRADUATEDSYMBOLRENDERERV2_H