QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 : [email protected]
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 <QVector>
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  {
45  ColorRampItem() : value( 0 ) {}
47  ColorRampItem( double val, const QColor& col, const QString& lbl = QString() )
48  : label( lbl )
49  , value( val )
50  , color( col )
51  {}
52 
54  double value;
56 
57  // compare operator for sorting
58  bool operator<( const ColorRampItem& other ) const { return value < other.value; }
59  };
60 
63  {
66  EXACT
67  };
68 
70  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const {return mColorRampItemList.toList();}
71 
73  QgsColorRampShader::ColorRamp_TYPE colorRampType() const {return mColorRampType;}
74 
76  QString colorRampTypeAsQString();
77 
81  Q_DECL_DEPRECATED int maximumColorCacheSize() { return 0; }
82 
84  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
85 
87  void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType );
88 
90  void setColorRampType( const QString& theType );
91 
95  Q_DECL_DEPRECATED void setMaximumColorCacheSize( int theSize ) { Q_UNUSED( theSize ); }
96 
98  bool shade( double, int*, int*, int*, int* ) override;
99 
101  bool shade( double, double, double, double, int*, int*, int*, int* ) override;
102 
103  void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const override;
104 
109  void setClip( bool clip ) { mClip = clip; }
110 
114  bool clip() const { return mClip; }
115 
116  private:
123 
125  QgsColorRampShader::ColorRamp_TYPE mColorRampType;
126 
129  QVector<int> mLUT;
130  double mLUTOffset;
131  double mLUTFactor;
132  bool mLUTInitialized;
133 
135  bool mClip;
136 };
137 
138 #endif
QgsColorRampShader::ColorRamp_TYPE colorRampType() const
Get the color ramp type.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Get the custom colormap.
void setClip(bool clip)
Sets whether the shader should not render values out of range.
The raster shade function applies a shader to a pixel at render time - typically used to render grays...
ColorRampItem(double val, const QColor &col, const QString &lbl=QString())
convenience constructor
bool operator<(const ColorRampItem &other) const
Interpolates the color between two class breaks linearly.
Assigns the color of the higher class for every pixel between two class breaks.
bool clip() const
Returns whether the shader will clip values which are out of range.
Q_DECL_DEPRECATED void setMaximumColorCacheSize(int theSize)
Set the maximum size the color cache can be.
Q_DECL_DEPRECATED int maximumColorCacheSize()
Get the maximum size the color cache can be.
ColorRamp_TYPE
Supported methods for color interpolation.