QGIS API Documentation  2.99.0-Master (6a61179)
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 
27 #include "qgscolorramp.h"
29 
33 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
34 {
35 
36  public:
37 
38  QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0 );
39 
42  virtual ~QgsColorRampShader();
43 
46  QgsColorRampShader( const QgsColorRampShader& other );
47 
50  QgsColorRampShader& operator=( const QgsColorRampShader& other );
51 
52  //An entry for classification based upon value.
53  //Such a classification is typically used for
54  //single band layers where a pixel value represents
55  //not a color but a quantity, e.g. temperature or elevation
57  {
59  ColorRampItem() : value( 0 ) {}
61  ColorRampItem( double val, const QColor& col, const QString& lbl = QString() )
62  : label( lbl )
63  , value( val )
64  , color( col )
65  {}
66 
67  QString label;
68  double value;
69  QColor color;
70 
71  // compare operator for sorting
72  bool operator<( const ColorRampItem& other ) const { return value < other.value; }
73  };
74 
77  {
80  EXACT
81  };
82 
84  QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
85 
87  QgsColorRampShader::ColorRamp_TYPE colorRampType() const { return mColorRampType; }
88 
90  QString colorRampTypeAsQString();
91 
93  void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set
94 
96  void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType );
97 
102  QgsColorRamp* sourceColorRamp() const;
103 
108  void setSourceColorRamp( QgsColorRamp* colorramp );
109 
111  void setColorRampType( const QString& theType );
112 
114  bool shade( double, int*, int*, int*, int* ) override;
115 
117  bool shade( double, double, double, double, int*, int*, int*, int* ) override;
118 
120  void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const override;
121 
126  void setClip( bool clip ) { mClip = clip; }
127 
131  bool clip() const { return mClip; }
132 
133  protected:
134 
136  QScopedPointer<QgsColorRamp> mSourceColorRamp;
137 
138  private:
139 
145  QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
146 
148  QgsColorRampShader::ColorRamp_TYPE mColorRampType;
149 
152  QVector<int> mLUT;
153  double mLUTOffset;
154  double mLUTFactor;
155  bool mLUTInitialized;
156 
158  bool mClip;
159 };
160 
161 #endif
QScopedPointer< QgsColorRamp > mSourceColorRamp
Source color ramp.
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.
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
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.
ColorRamp_TYPE
Supported methods for color interpolation.