|
QGIS API Documentation
master-3f58142
|
00001 /*************************************************************************** 00002 qgsvectorcolorrampv2.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 00016 #ifndef QGSVECTORCOLORRAMPV2_H 00017 #define QGSVECTORCOLORRAMPV2_H 00018 00019 #include <QColor> 00020 00021 #include "qgssymbollayerv2.h" // for QgsStringMap 00022 #include "qgslogger.h" 00023 00024 class CORE_EXPORT QgsVectorColorRampV2 00025 { 00026 public: 00027 virtual ~QgsVectorColorRampV2() {} 00028 00029 // Number of defined colors 00030 virtual int count() const = 0; 00031 00032 // Relative value (0,1) of color at index 00033 virtual double value( int index ) const = 0; 00034 00035 virtual QColor color( double value ) const = 0; 00036 00037 virtual QString type() const = 0; 00038 00039 virtual QgsVectorColorRampV2* clone() const = 0; 00040 00041 virtual QgsStringMap properties() const = 0; 00042 00043 }; 00044 00045 struct QgsGradientStop 00046 { 00047 double offset; // relative (0,1) 00048 QColor color; 00049 QgsGradientStop( double o, const QColor& c ) : offset( o ), color( c ) { } 00050 }; 00051 00052 typedef QList<QgsGradientStop> QgsGradientStopsList; 00053 00054 #define DEFAULT_GRADIENT_COLOR1 QColor(0,0,255) 00055 #define DEFAULT_GRADIENT_COLOR2 QColor(0,255,0) 00056 00057 class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2 00058 { 00059 public: 00060 QgsVectorGradientColorRampV2( QColor color1 = DEFAULT_GRADIENT_COLOR1, 00061 QColor color2 = DEFAULT_GRADIENT_COLOR2, 00062 bool discrete = false, 00063 QgsGradientStopsList stops = QgsGradientStopsList() ); 00064 00065 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00066 00067 virtual int count() const { return mStops.count() + 2; } 00068 00069 virtual double value( int index ) const; 00070 00071 virtual QColor color( double value ) const; 00072 00073 virtual QString type() const { return "gradient"; } 00074 00075 virtual QgsVectorColorRampV2* clone() const; 00076 00077 virtual QgsStringMap properties() const; 00078 00079 QColor color1() const { return mColor1; } 00080 QColor color2() const { return mColor2; } 00081 void setColor1( QColor color ) { mColor1 = color; } 00082 void setColor2( QColor color ) { mColor2 = color; } 00083 00084 bool isDiscrete() const { return mDiscrete; } 00085 void setDiscrete( bool discrete ) { mDiscrete = discrete; } 00086 void convertToDiscrete( bool discrete ); 00087 00088 void setStops( const QgsGradientStopsList& stops ) { mStops = stops; } 00089 const QgsGradientStopsList& stops() const { return mStops; } 00090 00091 QgsStringMap info() const { return mInfo; } 00092 void setInfo( const QgsStringMap& info ) { mInfo = info; } 00093 00094 protected: 00095 QColor mColor1, mColor2; 00096 bool mDiscrete; 00097 QgsGradientStopsList mStops; 00098 QgsStringMap mInfo; 00099 }; 00100 00101 #define DEFAULT_RANDOM_COUNT 10 00102 #define DEFAULT_RANDOM_HUE_MIN 0 00103 #define DEFAULT_RANDOM_HUE_MAX 359 00104 #define DEFAULT_RANDOM_VAL_MIN 0 00105 #define DEFAULT_RANDOM_VAL_MAX 255 00106 #define DEFAULT_RANDOM_SAT_MIN 0 00107 #define DEFAULT_RANDOM_SAT_MAX 255 00108 00109 class CORE_EXPORT QgsVectorRandomColorRampV2 : public QgsVectorColorRampV2 00110 { 00111 public: 00112 QgsVectorRandomColorRampV2( int count = DEFAULT_RANDOM_COUNT, 00113 int hueMin = DEFAULT_RANDOM_HUE_MIN, int hueMax = DEFAULT_RANDOM_HUE_MAX, 00114 int satMin = DEFAULT_RANDOM_SAT_MIN, int satMax = DEFAULT_RANDOM_SAT_MAX, 00115 int valMin = DEFAULT_RANDOM_VAL_MIN, int valMax = DEFAULT_RANDOM_VAL_MAX ); 00116 00117 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00118 00119 virtual double value( int index ) const; 00120 00121 virtual QColor color( double value ) const; 00122 00123 virtual QString type() const { return "random"; } 00124 00125 virtual QgsVectorColorRampV2* clone() const; 00126 00127 virtual QgsStringMap properties() const; 00128 00129 void updateColors(); 00130 00131 int count() const { return mCount; } 00132 int hueMin() const { return mHueMin; } 00133 int hueMax() const { return mHueMax; } 00134 int satMin() const { return mSatMin; } 00135 int satMax() const { return mSatMax; } 00136 int valMin() const { return mValMin; } 00137 int valMax() const { return mValMax; } 00138 00139 void setCount( int val ) { mCount = val; } 00140 void setHueMin( int val ) { mHueMin = val; } 00141 void setHueMax( int val ) { mHueMax = val; } 00142 void setSatMin( int val ) { mSatMin = val; } 00143 void setSatMax( int val ) { mSatMax = val; } 00144 void setValMin( int val ) { mValMin = val; } 00145 void setValMax( int val ) { mValMax = val; } 00146 00147 protected: 00148 int mCount; 00149 int mHueMin, mHueMax, mSatMin, mSatMax, mValMin, mValMax; 00150 QList<QColor> mColors; 00151 }; 00152 00153 00154 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral" 00155 #define DEFAULT_COLORBREWER_COLORS 5 00156 00157 class CORE_EXPORT QgsVectorColorBrewerColorRampV2 : public QgsVectorColorRampV2 00158 { 00159 public: 00160 QgsVectorColorBrewerColorRampV2( QString schemeName = DEFAULT_COLORBREWER_SCHEMENAME, 00161 int colors = DEFAULT_COLORBREWER_COLORS ); 00162 00163 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00164 00165 virtual double value( int index ) const; 00166 00167 virtual QColor color( double value ) const; 00168 00169 virtual QString type() const { return "colorbrewer"; } 00170 00171 virtual QgsVectorColorRampV2* clone() const; 00172 00173 virtual QgsStringMap properties() const; 00174 00175 QString schemeName() const { return mSchemeName; } 00176 virtual int count() const { return mColors; } 00177 int colors() const { return mColors; } 00178 00179 void setSchemeName( QString schemeName ) { mSchemeName = schemeName; loadPalette(); } 00180 void setColors( int colors ) { mColors = colors; loadPalette(); } 00181 00182 static QStringList listSchemeNames(); 00183 static QList<int> listSchemeVariants( QString schemeName ); 00184 00185 protected: 00186 00187 void loadPalette(); 00188 00189 QString mSchemeName; 00190 int mColors; 00191 QList<QColor> mPalette; 00192 }; 00193 00194 00195 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_" //change this 00196 #define DEFAULT_CPTCITY_VARIANTNAME "05" 00197 00198 class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorGradientColorRampV2 00199 { 00200 public: 00201 QgsCptCityColorRampV2( QString schemeName = DEFAULT_CPTCITY_SCHEMENAME, 00202 QString variantName = DEFAULT_CPTCITY_VARIANTNAME, 00203 bool doLoadFile = true ); 00204 QgsCptCityColorRampV2( QString schemeName, QStringList variantList, 00205 QString variantName = QString(), bool doLoadFile = true ); 00206 00207 static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ); 00208 00209 virtual QString type() const { return "cpt-city"; } 00210 00211 virtual QgsVectorColorRampV2* clone() const; 00212 void copy( const QgsCptCityColorRampV2* other ); 00213 QgsVectorGradientColorRampV2* cloneGradientRamp() const; 00214 00215 virtual QgsStringMap properties() const; 00216 00217 QString schemeName() const { return mSchemeName; } 00218 QString variantName() const { return mVariantName; } 00219 QStringList variantList() const { return mVariantList; } 00220 00221 /* lazy loading - have to call loadPalette() explicitly */ 00222 void setSchemeName( QString schemeName ) { mSchemeName = schemeName; mFileLoaded = false; } 00223 void setVariantName( QString variantName ) { mVariantName = variantName; mFileLoaded = false; } 00224 void setVariantList( QStringList variantList ) { mVariantList = variantList; } 00225 void setName( QString schemeName, QString variantName = "", QStringList variantList = QStringList() ) 00226 { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded = false; } 00227 00228 void loadPalette() { loadFile(); } 00229 bool hasMultiStops() const { return mMultiStops; } 00230 00231 QString fileName() const; 00232 bool loadFile(); 00233 bool fileLoaded() const { return mFileLoaded; } 00234 00235 QString copyingFileName() const; 00236 QString descFileName() const; 00237 QgsStringMap copyingInfo() const; 00238 00239 protected: 00240 00241 QString mSchemeName; 00242 QString mVariantName; 00243 QStringList mVariantList; 00244 bool mFileLoaded; 00245 bool mMultiStops; 00246 }; 00247 00248 00249 #endif