QGIS API Documentation  2.4.0-Chugiak
 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 
28 /* \brief categorized renderer */
29 class CORE_EXPORT QgsRendererCategoryV2
30 {
31  public:
33 
35  QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label );
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  // debugging
51  QString dump() const;
52 
53  void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
54 
55  protected:
56  QVariant mValue;
57  QScopedPointer<QgsSymbolV2> mSymbol;
58  QString mLabel;
59 
60  void swap( QgsRendererCategoryV2 & other );
61 };
62 
63 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
64 
66 {
67  public:
68 
69  QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() );
70 
72 
73  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
74 
75  virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
76 
77  virtual void stopRender( QgsRenderContext& context );
78 
79  virtual QList<QString> usedAttributes();
80 
81  virtual QString dump() const;
82 
83  virtual QgsFeatureRendererV2* clone();
84 
85  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
86 
89  virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
90 
91  virtual QgsSymbolV2List symbols();
93  void updateSymbols( QgsSymbolV2 * sym );
94 
95  const QgsCategoryList& categories() const { return mCategories; }
96 
98  int categoryIndexForValue( QVariant val );
99 
100  bool updateCategoryValue( int catIndex, const QVariant &value );
101  bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
102  bool updateCategoryLabel( int catIndex, QString label );
103 
104  void addCategory( const QgsRendererCategoryV2 &category );
105  bool deleteCategory( int catIndex );
106  void deleteAllCategories();
107 
109  void moveCategory( int from, int to );
110 
111  void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
112  void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
113 
114  QString classAttribute() const { return mAttrName; }
115  void setClassAttribute( QString attr ) { mAttrName = attr; }
116 
118  static QgsFeatureRendererV2* create( QDomElement& element );
119 
121  virtual QDomElement save( QDomDocument& doc );
122 
124  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
125 
129  virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = QString() );
130 
131  QgsSymbolV2* sourceSymbol();
132  void setSourceSymbol( QgsSymbolV2* sym );
133 
134  QgsVectorColorRampV2* sourceColorRamp();
135  void setSourceColorRamp( QgsVectorColorRampV2* ramp );
136 
138  bool invertedColorRamp() { return mInvertedColorRamp; }
139  void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }
140 
142  void setRotationField( QString fieldOrExpression );
144  QString rotationField() const;
145 
147  void setSizeScaleField( QString fieldOrExpression );
149  QString sizeScaleField() const;
150 
152  void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
154  QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
155 
156  protected:
157  QString mAttrName;
159  QScopedPointer<QgsSymbolV2> mSourceSymbol;
160  QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
162  QScopedPointer<QgsExpression> mRotation;
163  QScopedPointer<QgsExpression> mSizeScale;
165  QScopedPointer<QgsExpression> mExpression;
166 
168  int mAttrNum;
169 
171  QHash<QString, QgsSymbolV2*> mSymbolHash;
172 
174  QHash<QString, QgsSymbolV2*> mTempSymbols;
175 
176  void rebuildHash();
177 
178  QgsSymbolV2* symbolForValue( QVariant value );
179 };
180 
181 
182 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
virtual void setRotationField(QString fieldName)
sets rotation field of renderer (if supported by the renderer)
const QgsCategoryList & categories() const
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
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:161
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
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
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
QList< QgsRendererCategoryV2 > QgsCategoryList
virtual QgsFeatureRendererV2 * clone()=0
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
QHash< QString, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
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)
QgsSymbolV2::ScaleMethod scaleMethod() const
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
QScopedPointer< QgsExpression > mExpression