Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgsvectorcolorrampv2.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 00016 #ifndef QGSVECTORCOLORRAMPV2_H 00017 #define QGSVECTORCOLORRAMPV2_H 00018 00019 #include <QColor> 00020 00021 #include "qgssymbollayerv2.h" // for QgsStringMap 00022 00023 class CORE_EXPORT QgsVectorColorRampV2 00024 { 00025 public: 00026 virtual ~QgsVectorColorRampV2() {} 00027 00028 virtual QColor color( double value ) const = 0; 00029 00030 virtual QString type() const = 0; 00031 00032 virtual QgsVectorColorRampV2* clone() const = 0; 00033 00034 virtual QgsStringMap properties() const = 0; 00035 00036 }; 00037 00038 #define DEFAULT_GRADIENT_COLOR1 QColor(0,0,255) 00039 #define DEFAULT_GRADIENT_COLOR2 QColor(0,255,0) 00040 00041 class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2 00042 { 00043 public: 00044 QgsVectorGradientColorRampV2( QColor color1 = DEFAULT_GRADIENT_COLOR1, 00045 QColor color2 = DEFAULT_GRADIENT_COLOR2 ); 00046 00047 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00048 00049 virtual QColor color( double value ) const; 00050 00051 virtual QString type() const { return "gradient"; } 00052 00053 virtual QgsVectorColorRampV2* clone() const; 00054 00055 virtual QgsStringMap properties() const; 00056 00057 QColor color1() const { return mColor1; } 00058 QColor color2() const { return mColor2; } 00059 00060 void setColor1( QColor color ) { mColor1 = color; } 00061 void setColor2( QColor color ) { mColor2 = color; } 00062 00063 typedef QMap<double, QColor> StopsMap; 00064 00065 void setStops( const StopsMap& stops ) { mStops = stops; } 00066 const StopsMap& stops() const { return mStops; } 00067 00068 protected: 00069 QColor mColor1, mColor2; 00070 StopsMap mStops; 00071 }; 00072 00073 #define DEFAULT_RANDOM_COUNT 10 00074 #define DEFAULT_RANDOM_HUE_MIN 0 00075 #define DEFAULT_RANDOM_HUE_MAX 359 00076 #define DEFAULT_RANDOM_VAL_MIN 0 00077 #define DEFAULT_RANDOM_VAL_MAX 255 00078 #define DEFAULT_RANDOM_SAT_MIN 0 00079 #define DEFAULT_RANDOM_SAT_MAX 255 00080 00081 class CORE_EXPORT QgsVectorRandomColorRampV2 : public QgsVectorColorRampV2 00082 { 00083 public: 00084 QgsVectorRandomColorRampV2( int count = DEFAULT_RANDOM_COUNT, 00085 int hueMin = DEFAULT_RANDOM_HUE_MIN, int hueMax = DEFAULT_RANDOM_HUE_MAX, 00086 int satMin = DEFAULT_RANDOM_SAT_MIN, int satMax = DEFAULT_RANDOM_SAT_MAX, 00087 int valMin = DEFAULT_RANDOM_VAL_MIN, int valMax = DEFAULT_RANDOM_VAL_MAX ); 00088 00089 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00090 00091 virtual QColor color( double value ) const; 00092 00093 virtual QString type() const { return "random"; } 00094 00095 virtual QgsVectorColorRampV2* clone() const; 00096 00097 virtual QgsStringMap properties() const; 00098 00099 void updateColors(); 00100 00101 int count() const { return mCount; } 00102 int hueMin() const { return mHueMin; } 00103 int hueMax() const { return mHueMax; } 00104 int satMin() const { return mSatMin; } 00105 int satMax() const { return mSatMax; } 00106 int valMin() const { return mValMin; } 00107 int valMax() const { return mValMax; } 00108 00109 void setCount( int val ) { mCount = val; } 00110 void setHueMin( int val ) { mHueMin = val; } 00111 void setHueMax( int val ) { mHueMax = val; } 00112 void setSatMin( int val ) { mSatMin = val; } 00113 void setSatMax( int val ) { mSatMax = val; } 00114 void setValMin( int val ) { mValMin = val; } 00115 void setValMax( int val ) { mValMax = val; } 00116 00117 protected: 00118 int mCount; 00119 int mHueMin, mHueMax, mSatMin, mSatMax, mValMin, mValMax; 00120 QList<QColor> mColors; 00121 }; 00122 00123 00124 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral" 00125 #define DEFAULT_COLORBREWER_COLORS 5 00126 00127 class CORE_EXPORT QgsVectorColorBrewerColorRampV2 : public QgsVectorColorRampV2 00128 { 00129 public: 00130 QgsVectorColorBrewerColorRampV2( QString schemeName = DEFAULT_COLORBREWER_SCHEMENAME, 00131 int colors = DEFAULT_COLORBREWER_COLORS ); 00132 00133 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00134 00135 virtual QColor color( double value ) const; 00136 00137 virtual QString type() const { return "colorbrewer"; } 00138 00139 virtual QgsVectorColorRampV2* clone() const; 00140 00141 virtual QgsStringMap properties() const; 00142 00143 QString schemeName() const { return mSchemeName; } 00144 int colors() const { return mColors; } 00145 00146 void setSchemeName( QString schemeName ) { mSchemeName = schemeName; loadPalette(); } 00147 void setColors( int colors ) { mColors = colors; loadPalette(); } 00148 00149 static QStringList listSchemeNames(); 00150 static QList<int> listSchemeVariants( QString schemeName ); 00151 00152 protected: 00153 00154 void loadPalette(); 00155 00156 QString mSchemeName; 00157 int mColors; 00158 QList<QColor> mPalette; 00159 }; 00160 00161 #endif