QGIS API Documentation  master-6227475
src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgscategorizedsymbolrendererv2.h
00003     ---------------------
00004     begin                : November 2009
00005     copyright            : (C) 2009 by Martin Dobias
00006     email                : wonder dot sk at gmail dot 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     QgsRendererCategoryV2( );
00031 
00033     QgsRendererCategoryV2( QVariant value, QgsSymbolV2* symbol, QString label );
00034 
00036     QgsRendererCategoryV2( const QgsRendererCategoryV2& cat );
00037 
00038 
00039     ~QgsRendererCategoryV2();
00040 
00041     QgsRendererCategoryV2& operator=( const QgsRendererCategoryV2& cat );
00042 
00043     QVariant value() const;
00044     QgsSymbolV2* symbol() const;
00045     QString label() const;
00046 
00047     void setValue( const QVariant &value );
00048     void setSymbol( QgsSymbolV2* s );
00049     void setLabel( const QString &label );
00050 
00051     // debugging
00052     QString dump();
00053 
00054     void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
00055 
00056   protected:
00057     QVariant mValue;
00058     QgsSymbolV2* mSymbol;
00059     QString mLabel;
00060 };
00061 
00062 typedef QList<QgsRendererCategoryV2> QgsCategoryList;
00063 
00064 class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
00065 {
00066   public:
00067 
00068     QgsCategorizedSymbolRendererV2( QString attrName = QString(), QgsCategoryList categories = QgsCategoryList() );
00069 
00070     virtual ~QgsCategorizedSymbolRendererV2();
00071 
00072     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
00073 
00074     virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
00075 
00076     virtual void stopRender( QgsRenderContext& context );
00077 
00078     virtual QList<QString> usedAttributes();
00079 
00080     virtual QString dump();
00081 
00082     virtual QgsFeatureRendererV2* clone();
00083 
00084     virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
00085 
00088     virtual int capabilities() { return SymbolLevels | RotationField | Filter; }
00089 
00090     virtual QgsSymbolV2List symbols();
00092     void updateSymbols( QgsSymbolV2 * sym );
00093 
00094     const QgsCategoryList& categories() { return mCategories; }
00095 
00097     int categoryIndexForValue( QVariant val );
00098 
00099     bool updateCategoryValue( int catIndex, const QVariant &value );
00100     bool updateCategorySymbol( int catIndex, QgsSymbolV2* symbol );
00101     bool updateCategoryLabel( int catIndex, QString label );
00102 
00103     void addCategory( const QgsRendererCategoryV2 &category );
00104     bool deleteCategory( int catIndex );
00105     void deleteAllCategories();
00106 
00108     void moveCategory( int from, int to );
00109 
00110     void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
00111     void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
00112 
00113     QString classAttribute() const { return mAttrName; }
00114     void setClassAttribute( QString attr ) { mAttrName = attr; }
00115 
00117     static QgsFeatureRendererV2* create( QDomElement& element );
00118 
00120     virtual QDomElement save( QDomDocument& doc );
00121 
00123     virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00124 
00128     virtual QgsLegendSymbolList legendSymbolItems();
00129 
00130     QgsSymbolV2* sourceSymbol();
00131     void setSourceSymbol( QgsSymbolV2* sym );
00132 
00133     QgsVectorColorRampV2* sourceColorRamp();
00134     void setSourceColorRamp( QgsVectorColorRampV2* ramp );
00135 
00137     void setRotationField( QString fieldName ) { mRotationField = fieldName; }
00139     QString rotationField() const { return mRotationField; }
00140 
00142     void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; }
00144     QString sizeScaleField() const { return mSizeScaleField; }
00145 
00147     void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
00149     QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }
00150 
00151   protected:
00152     QString mAttrName;
00153     QgsCategoryList mCategories;
00154     QgsSymbolV2* mSourceSymbol;
00155     QgsVectorColorRampV2* mSourceColorRamp;
00156     QString mRotationField;
00157     QString mSizeScaleField;
00158     QgsSymbolV2::ScaleMethod mScaleMethod;
00159 
00161     int mAttrNum;
00162     int mRotationFieldIdx, mSizeScaleFieldIdx;
00163 
00165     QHash<QString, QgsSymbolV2*> mSymbolHash;
00166 
00168     QHash<QString, QgsSymbolV2*> mTempSymbols;
00169 
00170     void rebuildHash();
00171 
00172     QgsSymbolV2* symbolForValue( QVariant value );
00173 };
00174 
00175 
00176 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines