Quantum GIS API Documentation  1.7.4
src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Go to the documentation of this file.
00001 #ifndef QGSCATEGORIZEDSYMBOLRENDERERV2_H
00002 #define QGSCATEGORIZEDSYMBOLRENDERERV2_H
00003 
00004 #include "qgsrendererv2.h"
00005 
00006 #include <QHash>
00007 
00008 class QgsVectorColorRampV2;
00009 class QgsVectorLayer;
00010 
00011 /* \brief categorized renderer */
00012 class CORE_EXPORT QgsRendererCategoryV2
00013 {
00014   public:
00015 
00017     QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label );
00018 
00020     QgsRendererCategoryV2( const QgsRendererCategoryV2& cat );
00021 
00022     ~QgsRendererCategoryV2();
00023 
00024     QVariant value() const;
00025     QgsSymbolV2* symbol() const;
00026     QString label() const;
00027 
00028     void setValue( const QVariant &value );
00029     void setSymbol( QgsSymbolV2* s );
00030     void setLabel( const QString &label );
00031 
00032     // debugging
00033     QString dump();
00034 
00035   protected:
00036     QVariant mValue;
00037     QgsSymbolV2* mSymbol;
00038     QString mLabel;
00039 };
00040 
00041 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
00042 
00043 class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
00044 {
00045   public:
00046 
00047     QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() );
00048 
00049     virtual ~QgsCategorizedSymbolRendererV2();
00050 
00051     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
00052 
00053     virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
00054 
00055     virtual void stopRender( QgsRenderContext& context );
00056 
00057     virtual QList<QString> usedAttributes();
00058 
00059     virtual QString dump();
00060 
00061     virtual QgsFeatureRendererV2* clone();
00062 
00063     virtual QgsSymbolV2List symbols();
00064 
00065     const QgsCategoryList& categories() { return mCategories; }
00066 
00068     int categoryIndexForValue( QVariant val );
00069 
00070     bool updateCategoryValue( int catIndex, const QVariant &value );
00071     bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
00072     bool updateCategoryLabel( int catIndex, QString label );
00073 
00074     void addCategory( const QgsRendererCategoryV2 &category );
00075     bool deleteCategory( int catIndex );
00076     void deleteAllCategories();
00077 
00078     QString classAttribute() const { return mAttrName; }
00079     void setClassAttribute( QString attr ) { mAttrName = attr; }
00080 
00082     static QgsFeatureRendererV2* create( QDomElement& element );
00083 
00085     virtual QDomElement save( QDomDocument& doc );
00086 
00088     virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00089 
00092     virtual QgsLegendSymbolList legendSymbolItems();
00093 
00094     QgsSymbolV2* sourceSymbol();
00095     void setSourceSymbol( QgsSymbolV2* sym );
00096 
00097     QgsVectorColorRampV2* sourceColorRamp();
00098     void setSourceColorRamp( QgsVectorColorRampV2* ramp );
00099 
00101     void setRotationField( QString fieldName ) { mRotationField = fieldName; }
00103     QString rotationField() const { return mRotationField; }
00104 
00106     void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; }
00108     QString sizeScaleField() const { return mSizeScaleField; }
00109 
00110   protected:
00111     QString mAttrName;
00112     QgsCategoryList mCategories;
00113     QgsSymbolV2* mSourceSymbol;
00114     QgsVectorColorRampV2* mSourceColorRamp;
00115     QString mRotationField;
00116     QString mSizeScaleField;
00117 
00119     int mAttrNum;
00120     int mRotationFieldIdx, mSizeScaleFieldIdx;
00121 
00123     QHash<QString, QgsSymbolV2*> mSymbolHash;
00124 
00126     QHash<QString, QgsSymbolV2*> mTempSymbols;
00127 
00128     void rebuildHash();
00129 
00130     QgsSymbolV2* symbolForValue( QVariant value );
00131 };
00132 
00133 
00134 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines