Quantum GIS API Documentation  1.8
src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsgraduatedsymbolrendererv2.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 QGSGRADUATEDSYMBOLRENDERERV2_H
00016 #define QGSGRADUATEDSYMBOLRENDERERV2_H
00017 
00018 #include "qgssymbolv2.h"
00019 #include "qgsrendererv2.h"
00020 
00021 class CORE_EXPORT QgsRendererRangeV2
00022 {
00023   public:
00024     QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label );
00025     QgsRendererRangeV2( const QgsRendererRangeV2& range );
00026 
00027     ~QgsRendererRangeV2();
00028 
00029     double lowerValue() const;
00030     double upperValue() const;
00031 
00032     QgsSymbolV2* symbol() const;
00033     QString label() const;
00034 
00035     void setSymbol( QgsSymbolV2* s );
00036     void setLabel( QString label );
00037     void setLowerValue( double lowerValue );
00038     void setUpperValue( double upperValue );
00039 
00040     // debugging
00041     QString dump();
00042 
00043     void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
00044 
00045   protected:
00046     double mLowerValue, mUpperValue;
00047     QgsSymbolV2* mSymbol;
00048     QString mLabel;
00049 };
00050 
00051 typedef QList<QgsRendererRangeV2> QgsRangeList;
00052 
00053 class QgsVectorLayer;
00054 class QgsVectorColorRampV2;
00055 
00056 class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
00057 {
00058   public:
00059     QgsGraduatedSymbolRendererV2( QString attrName = QString(), QgsRangeList ranges = QgsRangeList() );
00060 
00061     virtual ~QgsGraduatedSymbolRendererV2();
00062 
00063     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
00064 
00065     virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
00066 
00067     virtual void stopRender( QgsRenderContext& context );
00068 
00069     virtual QList<QString> usedAttributes();
00070 
00071     virtual QString dump();
00072 
00073     virtual QgsFeatureRendererV2* clone();
00074 
00075     virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
00076 
00079     virtual int capabilities() { return SymbolLevels | RotationField; }
00080 
00081     virtual QgsSymbolV2List symbols();
00082 
00083     QString classAttribute() const { return mAttrName; }
00084     void setClassAttribute( QString attr ) { mAttrName = attr; }
00085 
00086     const QgsRangeList& ranges() { return mRanges; }
00087 
00088     bool updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol );
00089     bool updateRangeLabel( int rangeIndex, QString label );
00090     bool updateRangeUpperValue( int rangeIndex, double value );
00091     bool updateRangeLowerValue( int rangeIndex, double value );
00092 
00093     void addClass( QgsSymbolV2* symbol );
00094     void deleteClass( int idx );
00095 
00096     enum Mode
00097     {
00098       EqualInterval,
00099       Quantile,
00100       Jenks,
00101       StdDev,
00102       Pretty,
00103       Custom
00104     };
00105 
00106     Mode mode() const { return mMode; }
00107     void setMode( Mode mode ) { mMode = mode; }
00108 
00109     static QgsGraduatedSymbolRendererV2* createRenderer(
00110       QgsVectorLayer* vlayer,
00111       QString attrName,
00112       int classes,
00113       Mode mode,
00114       QgsSymbolV2* symbol,
00115       QgsVectorColorRampV2* ramp );
00116 
00118     static QgsFeatureRendererV2* create( QDomElement& element );
00119 
00121     virtual QDomElement save( QDomDocument& doc );
00122 
00124     virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00125 
00128     virtual QgsLegendSymbolList legendSymbolItems();
00129 
00130     QgsSymbolV2* sourceSymbol();
00131     void setSourceSymbol( QgsSymbolV2* sym );
00132 
00133     QgsVectorColorRampV2* sourceColorRamp();
00134     void setSourceColorRamp( QgsVectorColorRampV2* ramp );
00135 
00139     void updateColorRamp( QgsVectorColorRampV2* ramp );
00140 
00142     void updateSymbols( QgsSymbolV2* sym );
00143 
00145     void setRotationField( QString fieldName ) { mRotationField = fieldName; }
00147     QString rotationField() const { return mRotationField; }
00148 
00150     void setSizeScaleField( QString fieldName ) { mSizeScaleField = fieldName; }
00152     QString sizeScaleField() const { return mSizeScaleField; }
00153 
00154   protected:
00155     QString mAttrName;
00156     QgsRangeList mRanges;
00157     Mode mMode;
00158     QgsSymbolV2* mSourceSymbol;
00159     QgsVectorColorRampV2* mSourceColorRamp;
00160     QString mRotationField;
00161     QString mSizeScaleField;
00162 
00164     int mAttrNum;
00165     int mRotationFieldIdx, mSizeScaleFieldIdx;
00166 
00168 #if QT_VERSION < 0x40600
00169     QMap<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
00170 #else
00171     QHash<QgsSymbolV2*, QgsSymbolV2*> mTempSymbols;
00172 #endif
00173 
00174     QgsSymbolV2* symbolForValue( double value );
00175 };
00176 
00177 #endif // QGSGRADUATEDSYMBOLRENDERERV2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines