QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
28 /* \brief categorized renderer */
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:
60  QVariant mValue;
61  QScopedPointer<QgsSymbolV2> mSymbol;
62  QString mLabel;
63  bool mRender;
64 
65  void swap( QgsRendererCategoryV2 & other );
66 };
67 
68 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
69 
71 {
72  public:
73 
74  QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() );
75 
77 
78  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
79 
80  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feature );
81 
82  virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
83 
84  virtual void stopRender( QgsRenderContext& context );
85 
86  virtual QList<QString> usedAttributes();
87 
88  virtual QString dump() const;
89 
90  virtual QgsFeatureRendererV2* clone() const;
91 
92  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
93 
96  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
97 
98  virtual QgsSymbolV2List symbols();
100  void updateSymbols( QgsSymbolV2 * sym );
101 
102  const QgsCategoryList& categories() const { return mCategories; }
103 
105  int categoryIndexForValue( QVariant val );
106 
109  int categoryIndexForLabel( QString val );
110 
111  bool updateCategoryValue( int catIndex, const QVariant &value );
112  bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
113  bool updateCategoryLabel( int catIndex, QString label );
114 
116  bool updateCategoryRenderState( int catIndex, bool render );
117 
118  void addCategory( const QgsRendererCategoryV2 &category );
119  bool deleteCategory( int catIndex );
120  void deleteAllCategories();
121 
123  void moveCategory( int from, int to );
124 
125  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
126  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
127 
128  QString classAttribute() const { return mAttrName; }
129  void setClassAttribute( QString attr ) { mAttrName = attr; }
130 
132  static QgsFeatureRendererV2* create( QDomElement& element );
133 
135  virtual QDomElement save( QDomDocument& doc );
136 
138  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
139 
143  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() );
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 
160  void setRotationField( QString fieldOrExpression );
162  QString rotationField() const;
163 
165  void setSizeScaleField( QString fieldOrExpression );
167  QString sizeScaleField() const;
168 
170  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
172  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
173 
176  virtual bool legendSymbolItemsCheckable() const;
177 
179  // @note added in 2.5
180  virtual bool legendSymbolItemChecked( QString key );
181 
183  // @note added in 2.5
184  virtual void checkLegendSymbolItem( QString key, bool state = true );
185 
188  virtual QString legendClassificationAttribute() const { return classAttribute(); }
189 
193  static QgsCategorizedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
194 
195  protected:
196  QString mAttrName;
198  QScopedPointer<QgsSymbolV2> mSourceSymbol;
199  QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
201  QScopedPointer<QgsExpression> mRotation;
202  QScopedPointer<QgsExpression> mSizeScale;
204  QScopedPointer<QgsExpression> mExpression;
205 
207  int mAttrNum;
208 
210  QHash<QString, QgsSymbolV2*> mSymbolHash;
211  bool mCounting;
212 
214  QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
215 
216  void rebuildHash();
217 
218  QgsSymbolV2* symbolForValue( QVariant value );
219 
221 };
222 
223 
224 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
QgsSymbolV2::ScaleMethod mScaleMethod
Definition: qgscategorizedsymbolrendererv2.h:203
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:94
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
Definition: qgsrendererv2.h:198
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
Definition: qgsrendererv2.cpp:523
const QgsCategoryList & categories() const
Definition: qgscategorizedsymbolrendererv2.h:102
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
virtual QString legendClassificationAttribute() const
If supported by the renderer, return classification attribute for the use in legend.
Definition: qgscategorizedsymbolrendererv2.h:188
virtual QString dump() const
for debugging
Definition: qgsrendererv2.cpp:367
Definition: qgscategorizedsymbolrendererv2.h:29
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
Definition: qgsrendererv2.cpp:395
QScopedPointer< QgsSymbolV2 > mSourceSymbol
Definition: qgscategorizedsymbolrendererv2.h:198
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Definition: qgsrendererv2.cpp:529
QScopedPointer< QgsExpression > mRotation
Definition: qgscategorizedsymbolrendererv2.h:201
Container of fields for a vector layer.
Definition: qgsfield.h:172
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
QScopedPointer< QgsSymbolV2 > mSymbol
Definition: qgscategorizedsymbolrendererv2.h:61
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
Definition: qgsrendererv2.cpp:505
QHash< QString, QgsSymbolV2 * > mSymbolHash
hashtable for faster access to symbols
Definition: qgscategorizedsymbolrendererv2.h:210
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
QScopedPointer< QgsExpression > mSizeScale
Definition: qgscategorizedsymbolrendererv2.h:202
QgsCategoryList mCategories
Definition: qgscategorizedsymbolrendererv2.h:197
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:195
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual QgsFeatureRendererV2 * clone() const =0
QList< QgsRendererCategoryV2 > QgsCategoryList
Definition: qgscategorizedsymbolrendererv2.h:68
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
Definition: qgscategorizedsymbolrendererv2.h:199
bool mCounting
Definition: qgscategorizedsymbolrendererv2.h:211
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
Definition: qgsrendererv2.cpp:517
Definition: qgscategorizedsymbolrendererv2.h:70
void setClassAttribute(QString attr)
Definition: qgscategorizedsymbolrendererv2.h:129
static QgsMarkerSymbolV2 sSkipRender
Definition: qgscategorizedsymbolrendererv2.h:220
QVariant mValue
Definition: qgscategorizedsymbolrendererv2.h:60
Definition: qgssymbolv2.h:43
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgspluginlayer.h:20
QHash< QgsSymbolV2 *, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
Definition: qgscategorizedsymbolrendererv2.h:214
bool mInvertedColorRamp
Definition: qgscategorizedsymbolrendererv2.h:200
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrendererv2.h:158
Definition: qgssymbolv2.h:229
bool invertedColorRamp()
Definition: qgscategorizedsymbolrendererv2.h:152
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
ScaleMethod
Definition: qgssymbolv2.h:61
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
Definition: qgsrendererv2.cpp:512
int mAttrNum
attribute index (derived from attribute name in startRender)
Definition: qgscategorizedsymbolrendererv2.h:207
QString classAttribute() const
Definition: qgscategorizedsymbolrendererv2.h:128
Definition: qgsrendererv2.h:72
bool mRender
Definition: qgscategorizedsymbolrendererv2.h:63
QgsSymbolV2::ScaleMethod scaleMethod() const
Definition: qgscategorizedsymbolrendererv2.h:172
Definition: qgsrendererv2.h:119
QString mLabel
Definition: qgscategorizedsymbolrendererv2.h:62
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
Definition: qgsvectorcolorrampv2.h:25
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QString mAttrName
Definition: qgscategorizedsymbolrendererv2.h:196
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
Definition: qgscategorizedsymbolrendererv2.h:96
QScopedPointer< QgsExpression > mExpression
Definition: qgscategorizedsymbolrendererv2.h:204
void setInvertedColorRamp(bool inverted)
Definition: qgscategorizedsymbolrendererv2.h:153