QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgscolorrampshader.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorrampshader.h - description
3 -------------------
4begin : Fri Dec 28 2007
5copyright : (C) 2007 by Peter J. Ersts
7
8This class is based off of code that was originally written by Marco Hugentobler and
9originally 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 <memory>
25
26#include "qgis.h"
27#include "qgis_core.h"
28#include "qgis_sip.h"
31#include "qgsreadwritecontext.h"
32#include "qgsrectangle.h"
33
34#include <QColor>
35#include <QVector>
36
37class QgsColorRamp;
39
45{
46 public:
56 double minimumValue = 0.0,
57 double maximumValue = 255.0,
58 QgsColorRamp *colorRamp SIP_TRANSFER = nullptr,
61 );
62
64
67
68 bool operator==( const QgsColorRampShader &other ) const
69 {
70 if ( mColorRampItemList.count() != other.mColorRampItemList.count() || mClassificationMode != other.mClassificationMode || mColorRampType != other.mColorRampType )
71 {
72 return false;
73 }
74 for ( int i = 0; i < mColorRampItemList.count(); ++i )
75 {
76 if ( mColorRampItemList.at( i ) != other.mColorRampItemList.at( i ) )
77 return false;
78 }
79 return true;
80 }
81
82 bool operator!=( const QgsColorRampShader &other ) const { return !( *this == other ); }
83
84 //An entry for classification based upon value.
85 //Such a classification is typically used for
86 //single band layers where a pixel value represents
87 //not a color but a quantity, e.g. temperature or elevation
89 {
90 ColorRampItem() = default;
92 ColorRampItem( double val, const QColor &col, const QString &lbl = QString() )
93 : label( lbl )
94 , value( val )
95 , color( col )
96 {}
97
98 QString label;
99 double value = 0;
100 QColor color;
101
102 // compare operator for sorting
103 bool operator<( const QgsColorRampShader::ColorRampItem &other ) const { return value < other.value; }
104
106 {
107 return ( color != other.color ) || ( !std::isnan( value ) && !std::isnan( other.value ) && value != other.value ) || ( std::isnan( value ) != std::isnan( other.value ) );
108 }
109 };
110
116 QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const { return mColorRampItemList.toList(); }
117
123 Qgis::ShaderInterpolationMethod colorRampType() const { return mColorRampType; }
124
126 QString colorRampTypeAsQString() const;
127
133 void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
134
140 void setColorRampType( Qgis::ShaderInterpolationMethod colorRampType );
141
146 bool isEmpty() const;
147
152 QgsColorRamp *sourceColorRamp() const;
153
158 QgsColorRamp *createColorRamp() const SIP_FACTORY;
159
164 void setSourceColorRamp( QgsColorRamp *colorramp SIP_TRANSFER );
165
167 void setColorRampType( const QString &type );
168
176 void classifyColorRamp( int classes = 0, int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr );
177
184 void classifyColorRamp( int band = -1, const QgsRectangle &extent = QgsRectangle(), QgsRasterInterface *input = nullptr ) SIP_PYNAME( classifyColorRampV2 );
185
186 bool shade( double value, int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT, int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT ) const override;
187 bool shade(
188 double redValue, double greenValue, double blueValue, double alphaValue, int *returnRedValue SIP_OUT, int *returnGreenValue SIP_OUT, int *returnBlueValue SIP_OUT, int *returnAlphaValue SIP_OUT
189 ) const override;
190 void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
191
196 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
197
202 void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
203
209 void setClassificationMode( Qgis::ShaderClassificationMethod classificationMode ) { mClassificationMode = classificationMode; }
210
216 Qgis::ShaderClassificationMethod classificationMode() const { return mClassificationMode; }
217
223 void setClip( bool clip ) { mClip = clip; }
224
229 bool clip() const { return mClip; }
230
237 const QgsColorRampLegendNodeSettings *legendSettings() const;
238
247 void setLegendSettings( QgsColorRampLegendNodeSettings *settings SIP_TRANSFER );
248
249 protected:
251 std::unique_ptr<QgsColorRamp> mSourceColorRamp;
252
253 private:
261 QVector<QgsColorRampShader::ColorRampItem> mColorRampItemList;
262
265
270 mutable std::vector<int> mLUT;
271 mutable double mLUTOffset = 0.0;
272 mutable double mLUTFactor = 1.0;
273 mutable bool mLUTInitialized = false;
274
276 bool mClip = false;
277
278 std::unique_ptr< QgsColorRampLegendNodeSettings > mLegendSettings;
279};
280
281#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
ShaderInterpolationMethod
Color ramp shader interpolation methods.
Definition qgis.h:1503
@ Linear
Interpolates the color between two class breaks linearly.
Definition qgis.h:1504
ShaderClassificationMethod
Color ramp shader classification methods.
Definition qgis.h:1518
@ Continuous
Uses breaks from color palette.
Definition qgis.h:1519
Settings for a color ramp legend node.
~QgsColorRampShader() override
Qgis::ShaderClassificationMethod classificationMode() const
Returns the classification mode.
Qgis::ShaderInterpolationMethod colorRampType() const
Returns the color ramp interpolation method.
bool operator!=(const QgsColorRampShader &other) const
void setClassificationMode(Qgis::ShaderClassificationMethod classificationMode)
Sets the classification mode.
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Returns the custom color map.
bool operator==(const QgsColorRampShader &other) const
QgsColorRampShader & operator=(const QgsColorRampShader &other)
void setClip(bool clip)
Sets whether the shader should not render values out of range.
bool clip() const
Returns whether the shader will clip values which are out of range.
QgsColorRampShader(double minimumValue=0.0, double maximumValue=255.0, QgsColorRamp *colorRamp=nullptr, Qgis::ShaderInterpolationMethod type=Qgis::ShaderInterpolationMethod::Linear, Qgis::ShaderClassificationMethod classificationMode=Qgis::ShaderClassificationMethod::Continuous)
Creates a new color ramp shader.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
Source color ramp.
Abstract base class for color ramps.
Base class for processing filters like renderers, reprojector, resampler etc.
QgsRasterShaderFunction(double minimumValue=0.0, double maximumValue=255.0)
double maximumValue() const
Returns the minimum value for the raster shader.
double minimumValue() const
Returns the maximum value for the raster shader.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
ColorRampItem(double val, const QColor &col, const QString &lbl=QString())
convenience constructor
bool operator!=(const QgsColorRampShader::ColorRampItem &other) const
bool operator<(const QgsColorRampShader::ColorRampItem &other) const