QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsrasterrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterrenderer.h
3  -------------------
4  begin : December 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSRASTERRENDERER_H
19 #define QGSRASTERRENDERER_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QPair>
24 
25 #include "qgsrasterinterface.h"
26 #include "qgsrasterminmaxorigin.h"
27 
28 class QDomElement;
29 
30 class QPainter;
34 class QgsLayerTreeLayer;
35 
40 class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
41 {
42 
43  Q_DECLARE_TR_FUNCTIONS( QgsRasterRenderer )
44 
45  public:
46 
47  static const QRgb NODATA_COLOR;
48 
52  QgsRasterRenderer( QgsRasterInterface *input = nullptr, const QString &type = QString() );
53  ~QgsRasterRenderer() override;
54 
56  QgsRasterRenderer( const QgsRasterRenderer & ) = delete;
58  const QgsRasterRenderer &operator=( const QgsRasterRenderer & ) = delete;
59 
60  QgsRasterRenderer *clone() const override = 0 SIP_FACTORY;
61 
62  int bandCount() const override;
63 
64  Qgis::DataType dataType( int bandNo ) const override;
65 
66  virtual QString type() const { return mType; }
67 
68  bool setInput( QgsRasterInterface *input ) override;
69 
70  QgsRasterBlock *block( int bandNo,
71  const QgsRectangle &extent,
72  int width,
73  int height,
74  QgsRasterBlockFeedback *feedback = nullptr ) override = 0 SIP_FACTORY;
75 
76  bool usesTransparency() const;
77 
83  void setOpacity( double opacity ) { mOpacity = opacity; }
84 
90  double opacity() const { return mOpacity; }
91 
102  QColor nodataColor() const { return mNodataColor; }
103 
113  void setNodataColor( const QColor &color ) { mNodataColor = color; }
114 
115  void setRasterTransparency( QgsRasterTransparency *t SIP_TRANSFER );
116  const QgsRasterTransparency *rasterTransparency() const { return mRasterTransparency; }
117 
118  void setAlphaBand( int band ) { mAlphaBand = band; }
119  int alphaBand() const { return mAlphaBand; }
120 
126  virtual QList< QPair< QString, QColor > > legendSymbologyItems() const;
127 
138  virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY;
139 
141  void readXml( const QDomElement &rendererElem ) override;
142 
148  void copyCommonProperties( const QgsRasterRenderer *other, bool copyMinMaxOrigin = true );
149 
151  virtual QList<int> usesBands() const { return QList<int>(); }
152 
154  const QgsRasterMinMaxOrigin &minMaxOrigin() const { return mMinMaxOrigin; }
155 
157  void setMinMaxOrigin( const QgsRasterMinMaxOrigin &origin ) { mMinMaxOrigin = origin; }
158 
163  virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const;
164 
174  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
175 
176  protected:
177 
179  void _writeXml( QDomDocument &doc, QDomElement &rasterRendererElem ) const;
180 
181  QString mType;
182 
184  double mOpacity = 1.0;
186  QgsRasterTransparency *mRasterTransparency = nullptr;
187 
192  int mAlphaBand = -1;
193 
196 
205  QRgb renderColorForNodataPixel() const;
206 
207  private:
208 
209  QColor mNodataColor;
210 
211 #ifdef SIP_RUN
213  const QgsRasterRenderer &operator=( const QgsRasterRenderer & );
214 #endif
215 
216 };
217 
218 #endif // QGSRASTERRENDERER_H
qgsrasterminmaxorigin.h
QgsRasterRenderer::minMaxOrigin
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
Definition: qgsrasterrenderer.h:154
QgsRasterRenderer::nodataColor
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
Definition: qgsrasterrenderer.h:102
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:128
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsRasterRenderer::type
virtual QString type() const
Definition: qgsrasterrenderer.h:66
QgsRasterRenderer::usesBands
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
Definition: qgsrasterrenderer.h:151
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRasterRenderer::NODATA_COLOR
static const QRgb NODATA_COLOR
Definition: qgsrasterrenderer.h:47
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsRasterMinMaxOrigin
This class describes the origin of min/max values. It does not store by itself the min/max values.
Definition: qgsrasterminmaxorigin.h:33
qgsrasterinterface.h
QgsRasterRenderer::mMinMaxOrigin
QgsRasterMinMaxOrigin mMinMaxOrigin
Origin of min/max values.
Definition: qgsrasterrenderer.h:195
QgsRasterInterface::setInput
virtual bool setInput(QgsRasterInterface *input)
Set input.
Definition: qgsrasterinterface.h:299
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:40
QgsRasterRenderer::rasterTransparency
const QgsRasterTransparency * rasterTransparency() const
Definition: qgsrasterrenderer.h:116
QgsRasterInterface::dataType
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
QgsRasterRenderer::setAlphaBand
void setAlphaBand(int band)
Definition: qgsrasterrenderer.h:118
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsRasterInterface::clone
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
QgsRasterInterface::readXml
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsrasterinterface.h:496
QgsRasterTransparency
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
Definition: qgsrastertransparency.h:32
QgsRasterRenderer::setMinMaxOrigin
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
Definition: qgsrasterrenderer.h:157
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:135
QgsRasterRenderer::alphaBand
int alphaBand() const
Definition: qgsrasterrenderer.h:119
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterRenderer::setNodataColor
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
Definition: qgsrasterrenderer.h:113
QgsRasterInterface::bandCount
virtual int bandCount() const =0
Gets number of bands.
QgsRasterInterface::block
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
QgsRasterRenderer::mType
QString mType
Definition: qgsrasterrenderer.h:181
QgsRasterRenderer::setOpacity
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
Definition: qgsrasterrenderer.h:83
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:36
QgsRasterRenderer::opacity
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
Definition: qgsrasterrenderer.h:90
QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:49