QGIS API Documentation  2.0.1-Dufour
 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 
21 #include <QHash>
22 
24 class QgsVectorLayer;
25 
26 /* \brief categorized renderer */
27 class CORE_EXPORT QgsRendererCategoryV2
28 {
29  public:
31 
33  QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label );
34 
37 
39 
40  QgsRendererCategoryV2& operator=( const QgsRendererCategoryV2& cat );
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  // debugging
51  QString dump() const;
52 
53  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
54 
55  protected:
56  QVariant mValue;
58  QString mLabel;
59 };
60 
61 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
62 
64 {
65  public:
66 
67  QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() );
68 
70 
71  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
72 
73  virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
74 
75  virtual void stopRender( QgsRenderContext& context );
76 
77  virtual QList<QString> usedAttributes();
78 
79  virtual QString dump() const;
80 
81  virtual QgsFeatureRendererV2* clone();
82 
83  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
84 
87  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
88 
89  virtual QgsSymbolV2List symbols();
91  void updateSymbols( QgsSymbolV2 * sym );
92 
93  const QgsCategoryList& categories() { return mCategories; }
94 
96  int categoryIndexForValue( QVariant val );
97 
98  bool updateCategoryValue( int catIndex, const QVariant &value );
99  bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
100  bool updateCategoryLabel( int catIndex, QString label );
101 
102  void addCategory( const QgsRendererCategoryV2 &category );
103  bool deleteCategory( int catIndex );
104  void deleteAllCategories();
105 
107  void moveCategory( int from, int to );
108 
109  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
110  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
111 
112  QString classAttribute() const { return mAttrName; }
113  void setClassAttribute( QString attr ) { mAttrName = attr; }
114 
116  static QgsFeatureRendererV2* create( QDomElement& element );
117 
119  virtual QDomElement save( QDomDocument& doc );
120 
122  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
123 
128 
129  QgsSymbolV2* sourceSymbol();
130  void setSourceSymbol( QgsSymbolV2* sym );
131 
132  QgsVectorColorRampV2* sourceColorRamp();
133  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
134 
136  void setRotationField( QString fieldName ) { mRotationField = fieldName; }
138  QString rotationField() const { return mRotationField; }
139 
141  void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; }
143  QString sizeScaleField() const { return mSizeScaleField; }
144 
146  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
148  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
149 
150  protected:
151  QString mAttrName;
155  QString mRotationField;
158 
160  int mAttrNum;
161  int mRotationFieldIdx, mSizeScaleFieldIdx;
162 
164  QHash<QString, QgsSymbolV2*> mSymbolHash;
165 
167  QHash<QString, QgsSymbolV2*> mTempSymbols;
168 
169  void rebuildHash();
170 
171  QgsSymbolV2* symbolForValue( QVariant value );
172 };
173 
174 
175 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:36
virtual QString dump() const
for debugging
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgsrendererv2.h:39
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:114
QMap< QString, QString > QgsStringMap
Definition: qgis.h:348
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 stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
QList< QgsRendererCategoryV2 > QgsCategoryList
virtual QgsFeatureRendererV2 * clone()=0
virtual QgsLegendSymbolList legendSymbolItems()
return a list of item text / symbol
QHash< QString, 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.
int mAttrNum
attribute index (derived from attribute name in startRender)
virtual void startRender(QgsRenderContext &context, const QgsVectorLayer *vlayer)=0
QgsSymbolV2::ScaleMethod scaleMethod() const
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:40
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer