Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgscategorizedsymbolrendererv2.h 00003 --------------------- 00004 begin : November 2009 00005 copyright : (C) 2009 by Martin Dobias 00006 email : wonder.sk at gmail.com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 #ifndef QGSCATEGORIZEDSYMBOLRENDERERV2_H 00016 #define QGSCATEGORIZEDSYMBOLRENDERERV2_H 00017 00018 #include "qgssymbolv2.h" 00019 #include "qgsrendererv2.h" 00020 00021 #include <QHash> 00022 00023 class QgsVectorColorRampV2; 00024 class QgsVectorLayer; 00025 00026 /* \brief categorized renderer */ 00027 class CORE_EXPORT QgsRendererCategoryV2 00028 { 00029 public: 00030 00032 QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label ); 00033 00035 QgsRendererCategoryV2( const QgsRendererCategoryV2& cat ); 00036 00037 ~QgsRendererCategoryV2(); 00038 00039 QVariant value() const; 00040 QgsSymbolV2* symbol() const; 00041 QString label() const; 00042 00043 void setValue( const QVariant &value ); 00044 void setSymbol( QgsSymbolV2* s ); 00045 void setLabel( const QString &label ); 00046 00047 // debugging 00048 QString dump(); 00049 00050 void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const; 00051 00052 protected: 00053 QVariant mValue; 00054 QgsSymbolV2* mSymbol; 00055 QString mLabel; 00056 }; 00057 00058 typedef QList<QgsRendererCategoryV2> QgsCategoryList; 00059 00060 class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2 00061 { 00062 public: 00063 00064 QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() ); 00065 00066 virtual ~QgsCategorizedSymbolRendererV2(); 00067 00068 virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ); 00069 00070 virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ); 00071 00072 virtual void stopRender( QgsRenderContext& context ); 00073 00074 virtual QList<QString> usedAttributes(); 00075 00076 virtual QString dump(); 00077 00078 virtual QgsFeatureRendererV2* clone(); 00079 00080 virtual void toSld( QDomDocument& doc, QDomElement &element ) const; 00081 00084 virtual int capabilities() { return SymbolLevels | RotationField; } 00085 00086 virtual QgsSymbolV2List symbols(); 00087 00088 const QgsCategoryList& categories() { return mCategories; } 00089 00091 int categoryIndexForValue( QVariant val ); 00092 00093 bool updateCategoryValue( int catIndex, const QVariant &value ); 00094 bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol ); 00095 bool updateCategoryLabel( int catIndex, QString label ); 00096 00097 void addCategory( const QgsRendererCategoryV2 &category ); 00098 bool deleteCategory( int catIndex ); 00099 void deleteAllCategories(); 00100 00101 QString classAttribute() const { return mAttrName; } 00102 void setClassAttribute( QString attr ) { mAttrName = attr; } 00103 00105 static QgsFeatureRendererV2* create( QDomElement& element ); 00106 00108 virtual QDomElement save( QDomDocument& doc ); 00109 00111 virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize ); 00112 00115 virtual QgsLegendSymbolList legendSymbolItems(); 00116 00117 QgsSymbolV2* sourceSymbol(); 00118 void setSourceSymbol( QgsSymbolV2* sym ); 00119 00120 QgsVectorColorRampV2* sourceColorRamp(); 00121 void setSourceColorRamp( QgsVectorColorRampV2* ramp ); 00122 00124 void setRotationField( QString fieldName ) { mRotationField = fieldName; } 00126 QString rotationField() const { return mRotationField; } 00127 00129 void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; } 00131 QString sizeScaleField() const { return mSizeScaleField; } 00132 00133 protected: 00134 QString mAttrName; 00135 QgsCategoryList mCategories; 00136 QgsSymbolV2* mSourceSymbol; 00137 QgsVectorColorRampV2* mSourceColorRamp; 00138 QString mRotationField; 00139 QString mSizeScaleField; 00140 00142 int mAttrNum; 00143 int mRotationFieldIdx, mSizeScaleFieldIdx; 00144 00146 QHash<QString, QgsSymbolV2*> mSymbolHash; 00147 00149 QHash<QString, QgsSymbolV2*> mTempSymbols; 00150 00151 void rebuildHash(); 00152 00153 QgsSymbolV2* symbolForValue( QVariant value ); 00154 }; 00155 00156 00157 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H