QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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() const;
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() const { 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 
191  virtual bool legendSymbolItemsCheckable() const;
192 
194  // @note added in 2.5
195  virtual bool legendSymbolItemChecked( QString key );
196 
198  // @note added in 2.5
199  virtual void checkLegendSymbolItem( QString key, bool state = true );
200 
203  virtual QString legendClassificationAttribute() const { return classAttribute(); }
204 
208  static QgsGraduatedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
209 
210  protected:
211  QString mAttrName;
214  QScopedPointer<QgsSymbolV2> mSourceSymbol;
215  QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
217  QScopedPointer<QgsExpression> mRotation;
218  QScopedPointer<QgsExpression> mSizeScale;
220  QScopedPointer<QgsExpression> mExpression;
222  int mAttrNum;
223  bool mCounting;
224 
226  QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
227 
228  QgsSymbolV2* symbolForValue( double value );
229 
230 };
231 
232 #endif // QGSGRADUATEDSYMBOLRENDERERV2_H
QList< QgsRendererRangeV2 > QgsRangeList
Definition: qgsgraduatedsymbolrendererv2.h:63
Mode mode() const
Definition: qgsgraduatedsymbolrendererv2.h:131
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
Definition: qgsrendererv2.h:190
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
Definition: qgsrendererv2.cpp:523
void setInvertedColorRamp(bool inverted)
Definition: qgsgraduatedsymbolrendererv2.h:164
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
Definition: qgsgraduatedsymbolrendererv2.h:215
virtual QString dump() const
for debugging
Definition: qgsrendererv2.cpp:367
Definition: qgsgraduatedsymbolrendererv2.h:123
QString classAttribute() const
Definition: qgsgraduatedsymbolrendererv2.h:96
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
Definition: qgsrendererv2.cpp:395
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Definition: qgsrendererv2.cpp:529
Container of fields for a vector layer.
Definition: qgsfield.h:163
QHash< QgsSymbolV2 *, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
Definition: qgsgraduatedsymbolrendererv2.h:226
Definition: qgsgraduatedsymbolrendererv2.h:126
virtual QList< QString > usedAttributes()=0
bool mInvertedColorRamp
Definition: qgsgraduatedsymbolrendererv2.h:216
Mode
Definition: qgsgraduatedsymbolrendererv2.h:121
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
Mode mMode
Definition: qgsgraduatedsymbolrendererv2.h:213
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
Definition: qgsgraduatedsymbolrendererv2.h:68
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
Definition: qgsrendererv2.cpp:505
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) ...
Definition: qgsrendererv2.h:187
QScopedPointer< QgsSymbolV2 > mSymbol
Definition: qgsgraduatedsymbolrendererv2.h:55
virtual QgsSymbolV2List symbols()=0
for symbol levels
bool mCounting
Definition: qgsgraduatedsymbolrendererv2.h:223
QgsRangeList mRanges
Definition: qgsgraduatedsymbolrendererv2.h:212
QScopedPointer< QgsExpression > mExpression
Definition: qgsgraduatedsymbolrendererv2.h:220
virtual QgsFeatureRendererV2 * clone() const =0
QgsSymbolV2::ScaleMethod scaleMethod() const
Definition: qgsgraduatedsymbolrendererv2.h:187
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Definition: qgsgraduatedsymbolrendererv2.h:92
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgsgraduatedsymbolrendererv2.h:203
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
Definition: qgsrendererv2.cpp:517
bool invertedColorRamp()
Definition: qgsgraduatedsymbolrendererv2.h:163
Definition: qgsgraduatedsymbolrendererv2.h:23
Definition: qgsgraduatedsymbolrendererv2.h:124
void setClassAttribute(QString attr)
Definition: qgsgraduatedsymbolrendererv2.h:97
QString mAttrName
Definition: qgsgraduatedsymbolrendererv2.h:211
Definition: qgssymbolv2.h:43
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgspluginlayer.h:20
Definition: qgsgraduatedsymbolrendererv2.h:127
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrendererv2.h:150
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
int mAttrNum
attribute index (derived from attribute name in startRender)
Definition: qgsgraduatedsymbolrendererv2.h:222
ScaleMethod
Definition: qgssymbolv2.h:61
Definition: qgsgraduatedsymbolrendererv2.h:125
const QgsRangeList & ranges() const
Definition: qgsgraduatedsymbolrendererv2.h:99
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
Definition: qgsrendererv2.cpp:512
double mUpperValue
Definition: qgsgraduatedsymbolrendererv2.h:54
QScopedPointer< QgsSymbolV2 > mSourceSymbol
Definition: qgsgraduatedsymbolrendererv2.h:214
void setMode(Mode mode)
Definition: qgsgraduatedsymbolrendererv2.h:132
QScopedPointer< QgsExpression > mRotation
Definition: qgsgraduatedsymbolrendererv2.h:217
Definition: qgsrendererv2.h:72
QgsSymbolV2::ScaleMethod mScaleMethod
Definition: qgsgraduatedsymbolrendererv2.h:219
QScopedPointer< QgsExpression > mSizeScale
Definition: qgsgraduatedsymbolrendererv2.h:218
Definition: qgsrendererv2.h:111
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
bool mRender
Definition: qgsgraduatedsymbolrendererv2.h:57
Definition: qgsvectorcolorrampv2.h:25
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QString mLabel
Definition: qgsgraduatedsymbolrendererv2.h:56