QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscategorizedsymbolrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscategorizedsymbolrendererv2.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 QGSCATEGORIZEDSYMBOLRENDERERV2_H
16 #define QGSCATEGORIZEDSYMBOLRENDERERV2_H
17 
18 #include "qgssymbolv2.h"
19 #include "qgsrendererv2.h"
20 #include "qgsexpression.h"
21 
22 #include <QHash>
23 #include <QScopedPointer>
24 
26 class QgsVectorLayer;
27 
29 class CORE_EXPORT QgsRendererCategoryV2
30 {
31  public:
33 
35  QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label, bool render = true );
36 
39 
41 
42  QVariant value() const;
43  QgsSymbolV2* symbol() const;
44  QString label() const;
45 
46  void setValue( const QVariant &value );
47  void setSymbol( QgsSymbolV2* s );
48  void setLabel( const QString &label );
49 
50  // @note added in 2.5
51  bool renderState() const;
52  void setRenderState( bool render );
53 
54  // debugging
55  QString dump() const;
56 
57  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
58 
59  protected:
63  bool mRender;
64 
65  void swap( QgsRendererCategoryV2 & other );
66 };
67 
69 
71 {
72  public:
73 
75 
77 
78  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) override;
79 
80  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature ) override;
81 
82  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) override;
83 
84  virtual void stopRender( QgsRenderContext& context ) override;
85 
86  virtual QList<QString> usedAttributes() override;
87 
88  virtual QString dump() const override;
89 
90  virtual QgsFeatureRendererV2* clone() const override;
91 
92  virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
93 
95  virtual int capabilities() override { return SymbolLevels | RotationField | Filter; }
96 
97  virtual QgsSymbolV2List symbols() override;
98  void updateSymbols( QgsSymbolV2 * sym );
99 
100  const QgsCategoryList& categories() const { return mCategories; }
101 
103  int categoryIndexForValue( QVariant val );
104 
107  int categoryIndexForLabel( QString val );
108 
109  bool updateCategoryValue( int catIndex, const QVariant &value );
110  bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
111  bool updateCategoryLabel( int catIndex, QString label );
112 
114  bool updateCategoryRenderState( int catIndex, bool render );
115 
116  void addCategory( const QgsRendererCategoryV2 &category );
117  bool deleteCategory( int catIndex );
118  void deleteAllCategories();
119 
121  void moveCategory( int from, int to );
122 
123  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
124  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
125 
126  QString classAttribute() const { return mAttrName; }
127  void setClassAttribute( QString attr ) { mAttrName = attr; }
128 
130  static QgsFeatureRendererV2* create( QDomElement& element );
131 
133  virtual QDomElement save( QDomDocument& doc ) override;
134 
136  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize ) override;
137 
140  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() ) override;
141 
144 
145  QgsSymbolV2* sourceSymbol();
146  void setSourceSymbol( QgsSymbolV2* sym );
147 
148  QgsVectorColorRampV2* sourceColorRamp();
149  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
150 
152  bool invertedColorRamp() { return mInvertedColorRamp; }
153  void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }
154 
155  // Update the color ramp used and all symbols colors.
157  void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );
158 
159  void setRotationField( QString fieldOrExpression ) override;
160  QString rotationField() const override;
161 
162  void setSizeScaleField( QString fieldOrExpression );
163  QString sizeScaleField() const;
164 
165  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
166  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
167 
170  virtual bool legendSymbolItemsCheckable() const override;
171 
173  // @note added in 2.5
174  virtual bool legendSymbolItemChecked( QString key ) override;
175 
177  // @note added in 2.5
178  virtual void checkLegendSymbolItem( QString key, bool state = true ) override;
179 
182  virtual QString legendClassificationAttribute() const override { return classAttribute(); }
183 
187  static QgsCategorizedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
188 
189  protected:
199 
201  int mAttrNum;
202 
205  bool mCounting;
206 
209 
210  void rebuildHash();
211 
212  QgsSymbolV2* symbolForValue( QVariant value );
213 
215 };
216 
217 
218 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
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)
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
const QgsCategoryList & categories() const
virtual QString dump() const
for debugging
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
QScopedPointer< QgsSymbolV2 > mSourceSymbol
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
QScopedPointer< QgsExpression > mRotation
Container of fields for a vector layer.
Definition: qgsfield.h:173
virtual int capabilities() override
returns bitwise OR-ed capabilities of the renderer
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:162
QScopedPointer< QgsSymbolV2 > mSymbol
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
QHash< QString, QgsSymbolV2 * > mSymbolHash
hashtable for faster access to symbols
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
QScopedPointer< QgsExpression > mSizeScale
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) ...
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual QgsFeatureRendererV2 * clone() const =0
QList< QgsRendererCategoryV2 > QgsCategoryList
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
QHash< QgsSymbolV2 *, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
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.
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const
Return a list of symbology items for the legend.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
int mAttrNum
attribute index (derived from attribute name in startRender)
QgsSymbolV2::ScaleMethod scaleMethod() const
Represents a vector layer which manages a vector based data sets.
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QScopedPointer< QgsExpression > mExpression
virtual QString legendClassificationAttribute() const override
If supported by the renderer, return classification attribute for the use in legend.