QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgscolorrampshader.h
Go to the documentation of this file.
1 /* **************************************************************************
2  qgscolorrampshader.h - description
3  -------------------
4 begin : Fri Dec 28 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : ersts@amnh.org
7 
8 This class is based off of code that was originally written by Marco Hugentobler and
9 originally part of the larger QgsRasterLayer class
10 ****************************************************************************/
11 
12 /* **************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 #ifndef QGSCOLORRAMPSHADER_H
22 #define QGSCOLORRAMPSHADER_H
23 
24 #include <QColor>
25 #include <QMap>
26 
28 
32 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
33 {
34 
35  public:
36  QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0 );
37 
38  //An entry for classification based upon value.
39  //Such a classification is typically used for
40  //single band layers where a pixel value represents
41  //not a color but a quantity, e.g. temperature or elevation
43  {
47  ColorRampItem( double val, QColor col, QString lbl = QString() ) : label( lbl ), value( val ), color( col ) {}
48 
49  QString label;
50  double value;
51  QColor color;
52 
53  // compare operator for sorting
54  bool operator<( const ColorRampItem& other ) const { return value < other.value; }
55  };
56 
58  {
61  EXACT
62  };
63 
65  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const {return mColorRampItemList;}
66 
68  QgsColorRampShader::ColorRamp_TYPE colorRampType() const {return mColorRampType;}
69 
71  QString colorRampTypeAsQString();
72 
74  int maximumColorCacheSize() { return mMaximumColorCacheSize; }
75 
77  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
78 
80  void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType );
81 
83  void setColorRampType( QString );
84 
86  void setMaximumColorCacheSize( int theSize ) { mMaximumColorCacheSize = theSize; }
87 
89  bool shade( double, int*, int*, int*, int* );
90 
92  bool shade( double, double, double, double, int*, int*, int*, int* );
93 
94  void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
95 
96  void setClip( bool clip ) { mClip = clip; }
97  bool clip() const { return mClip; }
98 
99  private:
101  int mCurrentColorRampItemIndex;
102 
103  //TODO: Consider pulling this out as a separate class and internally storing as a QMap rather than a QList
109  QList<QgsColorRampShader::ColorRampItem> mColorRampItemList;
110 
112  QgsColorRampShader::ColorRamp_TYPE mColorRampType;
113 
115  QMap<double, QColor> mColorCache;
116 
119  int mMaximumColorCacheSize;
120 
124  bool discreteColor( double, int*, int*, int*, int* );
125 
129  bool exactColor( double, int*, int*, int*, int* );
130 
134  bool interpolatedColor( double, int*, int*, int*, int* );
135 
137  bool mClip;
138 };
139 
140 #endif
ColorRampItem(double val, QColor col, QString lbl=QString())
convenience constructor
Definition: qgscolorrampshader.h:47
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:32
bool operator<(const ColorRampItem &other) const
Definition: qgscolorrampshader.h:54
QColor color
Definition: qgscolorrampshader.h:51
virtual bool shade(double, int *, int *, int *, int *)
generates and new RGBA value based on one input value
Definition: qgsrastershaderfunction.cpp:67
void setClip(bool clip)
Definition: qgscolorrampshader.h:96
Definition: qgscolorrampshader.h:60
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Get the custom colormap.
Definition: qgscolorrampshader.h:65
QgsColorRampShader::ColorRamp_TYPE colorRampType() const
Get the color ramp type.
Definition: qgscolorrampshader.h:68
ColorRampItem()
default constructor
Definition: qgscolorrampshader.h:45
bool clip() const
Definition: qgscolorrampshader.h:97
The raster shade function applies a shader to a pixel at render time - typically used to render grays...
Definition: qgsrastershaderfunction.h:30
QString label
Definition: qgscolorrampshader.h:49
Definition: qgscolorrampshader.h:59
void setMaximumColorCacheSize(int theSize)
Set the maximum size the color cache can be.
Definition: qgscolorrampshader.h:86
Definition: qgscolorrampshader.h:42
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Definition: qgsrastershaderfunction.h:54
int maximumColorCacheSize()
Get the maximum size the color cache can be.
Definition: qgscolorrampshader.h:74
ColorRamp_TYPE
Definition: qgscolorrampshader.h:57
double value
Definition: qgscolorrampshader.h:50