QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsvectorcolorrampv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorcolorrampv2.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORCOLORRAMPV2_H
17 #define QGSVECTORCOLORRAMPV2_H
18 
19 #include <QColor>
20 
21 #include "qgssymbollayerv2.h" // for QgsStringMap
22 #include "qgslogger.h"
23 
24 class CORE_EXPORT QgsVectorColorRampV2
25 {
26  public:
27  virtual ~QgsVectorColorRampV2() {}
28 
29  // Number of defined colors
30  virtual int count() const = 0;
31 
32  // Relative value (0,1) of color at index
33  virtual double value( int index ) const = 0;
34 
35  virtual QColor color( double value ) const = 0;
36 
37  virtual QString type() const = 0;
38 
39  virtual QgsVectorColorRampV2* clone() const = 0;
40 
41  virtual QgsStringMap properties() const = 0;
42 
43 };
44 
46 {
47  double offset; // relative (0,1)
48  QColor color;
49  QgsGradientStop( double o, const QColor& c ) : offset( o ), color( c ) { }
50 };
51 
52 typedef QList<QgsGradientStop> QgsGradientStopsList;
53 
54 #define DEFAULT_GRADIENT_COLOR1 QColor(0,0,255)
55 #define DEFAULT_GRADIENT_COLOR2 QColor(0,255,0)
56 
58 {
59  public:
61  QColor color2 = DEFAULT_GRADIENT_COLOR2,
62  bool discrete = false,
64 
65  static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() );
66 
67  virtual int count() const { return mStops.count() + 2; }
68 
69  virtual double value( int index ) const;
70 
71  virtual QColor color( double value ) const;
72 
73  virtual QString type() const { return "gradient"; }
74 
75  virtual QgsVectorColorRampV2* clone() const;
76 
77  virtual QgsStringMap properties() const;
78 
79  QColor color1() const { return mColor1; }
80  QColor color2() const { return mColor2; }
81  void setColor1( QColor color ) { mColor1 = color; }
82  void setColor2( QColor color ) { mColor2 = color; }
83 
84  bool isDiscrete() const { return mDiscrete; }
85  void setDiscrete( bool discrete ) { mDiscrete = discrete; }
86  void convertToDiscrete( bool discrete );
87 
88  void setStops( const QgsGradientStopsList& stops ) { mStops = stops; }
89  const QgsGradientStopsList& stops() const { return mStops; }
90 
91  QgsStringMap info() const { return mInfo; }
92  void setInfo( const QgsStringMap& info ) { mInfo = info; }
93 
94  protected:
95  QColor mColor1, mColor2;
96  bool mDiscrete;
99 };
100 
101 #define DEFAULT_RANDOM_COUNT 10
102 #define DEFAULT_RANDOM_HUE_MIN 0
103 #define DEFAULT_RANDOM_HUE_MAX 359
104 #define DEFAULT_RANDOM_VAL_MIN 200
105 #define DEFAULT_RANDOM_VAL_MAX 240
106 #define DEFAULT_RANDOM_SAT_MIN 100
107 #define DEFAULT_RANDOM_SAT_MAX 240
108 
110 {
111  public:
113  int hueMin = DEFAULT_RANDOM_HUE_MIN, int hueMax = DEFAULT_RANDOM_HUE_MAX,
114  int satMin = DEFAULT_RANDOM_SAT_MIN, int satMax = DEFAULT_RANDOM_SAT_MAX,
115  int valMin = DEFAULT_RANDOM_VAL_MIN, int valMax = DEFAULT_RANDOM_VAL_MAX );
116 
117  static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() );
118 
119  virtual double value( int index ) const;
120 
121  virtual QColor color( double value ) const;
122 
123  virtual QString type() const { return "random"; }
124 
125  virtual QgsVectorColorRampV2* clone() const;
126 
127  virtual QgsStringMap properties() const;
128 
129  void updateColors();
130 
131  int count() const { return mCount; }
132  int hueMin() const { return mHueMin; }
133  int hueMax() const { return mHueMax; }
134  int satMin() const { return mSatMin; }
135  int satMax() const { return mSatMax; }
136  int valMin() const { return mValMin; }
137  int valMax() const { return mValMax; }
138 
139  void setCount( int val ) { mCount = val; }
140  void setHueMin( int val ) { mHueMin = val; }
141  void setHueMax( int val ) { mHueMax = val; }
142  void setSatMin( int val ) { mSatMin = val; }
143  void setSatMax( int val ) { mSatMax = val; }
144  void setValMin( int val ) { mValMin = val; }
145  void setValMax( int val ) { mValMax = val; }
146 
147  protected:
148  int mCount;
149  int mHueMin, mHueMax, mSatMin, mSatMax, mValMin, mValMax;
150  QList<QColor> mColors;
151 };
152 
153 
154 #define DEFAULT_COLORBREWER_SCHEMENAME "Spectral"
155 #define DEFAULT_COLORBREWER_COLORS 5
156 
158 {
159  public:
161  int colors = DEFAULT_COLORBREWER_COLORS );
162 
163  static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() );
164 
165  virtual double value( int index ) const;
166 
167  virtual QColor color( double value ) const;
168 
169  virtual QString type() const { return "colorbrewer"; }
170 
171  virtual QgsVectorColorRampV2* clone() const;
172 
173  virtual QgsStringMap properties() const;
174 
175  QString schemeName() const { return mSchemeName; }
176  virtual int count() const { return mColors; }
177  int colors() const { return mColors; }
178 
179  void setSchemeName( QString schemeName ) { mSchemeName = schemeName; loadPalette(); }
180  void setColors( int colors ) { mColors = colors; loadPalette(); }
181 
182  static QStringList listSchemeNames();
183  static QList<int> listSchemeVariants( QString schemeName );
184 
185  protected:
186 
187  void loadPalette();
188 
189  QString mSchemeName;
190  int mColors;
191  QList<QColor> mPalette;
192 };
193 
194 
195 #define DEFAULT_CPTCITY_SCHEMENAME "cb/div/BrBG_" //change this
196 #define DEFAULT_CPTCITY_VARIANTNAME "05"
197 
199 {
200  public:
202  QString variantName = DEFAULT_CPTCITY_VARIANTNAME,
203  bool doLoadFile = true );
204  QgsCptCityColorRampV2( QString schemeName, QStringList variantList,
205  QString variantName = QString(), bool doLoadFile = true );
206 
207  static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() );
208 
209  virtual QString type() const { return "cpt-city"; }
210 
211  virtual QgsVectorColorRampV2* clone() const;
212  void copy( const QgsCptCityColorRampV2* other );
213  QgsVectorGradientColorRampV2* cloneGradientRamp() const;
214 
215  virtual QgsStringMap properties() const;
216 
217  QString schemeName() const { return mSchemeName; }
218  QString variantName() const { return mVariantName; }
219  QStringList variantList() const { return mVariantList; }
220 
221  /* lazy loading - have to call loadPalette() explicitly */
222  void setSchemeName( QString schemeName ) { mSchemeName = schemeName; mFileLoaded = false; }
223  void setVariantName( QString variantName ) { mVariantName = variantName; mFileLoaded = false; }
224  void setVariantList( QStringList variantList ) { mVariantList = variantList; }
225  void setName( QString schemeName, QString variantName = "", QStringList variantList = QStringList() )
226  { mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded = false; }
227 
228  void loadPalette() { loadFile(); }
229  bool hasMultiStops() const { return mMultiStops; }
230 
231  QString fileName() const;
232  bool loadFile();
233  bool fileLoaded() const { return mFileLoaded; }
234 
235  QString copyingFileName() const;
236  QString descFileName() const;
237  QgsStringMap copyingInfo() const;
238 
239  protected:
240 
241  QString mSchemeName;
242  QString mVariantName;
243  QStringList mVariantList;
246 };
247 
248 
249 #endif