QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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;
33 
38 class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
39 {
40 
41  Q_DECLARE_TR_FUNCTIONS( QgsRasterRenderer )
42 
43  public:
44 
45  static const QRgb NODATA_COLOR;
46 
50  QgsRasterRenderer( QgsRasterInterface *input = nullptr, const QString &type = QString() );
51  ~QgsRasterRenderer() override;
52 
54  QgsRasterRenderer( const QgsRasterRenderer & ) = delete;
56  const QgsRasterRenderer &operator=( const QgsRasterRenderer & ) = delete;
57 
58  QgsRasterRenderer *clone() const override = 0 SIP_FACTORY;
59 
60  int bandCount() const override;
61 
62  Qgis::DataType dataType( int bandNo ) const override;
63 
64  virtual QString type() const { return mType; }
65 
66  bool setInput( QgsRasterInterface *input ) override;
67 
68  QgsRasterBlock *block( int bandNo,
69  const QgsRectangle &extent,
70  int width,
71  int height,
72  QgsRasterBlockFeedback *feedback = nullptr ) override = 0 SIP_FACTORY;
73 
74  bool usesTransparency() const;
75 
81  void setOpacity( double opacity ) { mOpacity = opacity; }
82 
88  double opacity() const { return mOpacity; }
89 
100  QColor nodataColor() const { return mNodataColor; }
101 
111  void setNodataColor( const QColor &color ) { mNodataColor = color; }
112 
113  void setRasterTransparency( QgsRasterTransparency *t SIP_TRANSFER );
114  const QgsRasterTransparency *rasterTransparency() const { return mRasterTransparency; }
115 
116  void setAlphaBand( int band ) { mAlphaBand = band; }
117  int alphaBand() const { return mAlphaBand; }
118 
120  virtual void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const { Q_UNUSED( symbolItems ) }
121 
123  void readXml( const QDomElement &rendererElem ) override;
124 
130  void copyCommonProperties( const QgsRasterRenderer *other, bool copyMinMaxOrigin = true );
131 
133  virtual QList<int> usesBands() const { return QList<int>(); }
134 
136  const QgsRasterMinMaxOrigin &minMaxOrigin() const { return mMinMaxOrigin; }
137 
139  void setMinMaxOrigin( const QgsRasterMinMaxOrigin &origin ) { mMinMaxOrigin = origin; }
140 
145  virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const;
146 
156  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
157 
158  protected:
159 
161  void _writeXml( QDomDocument &doc, QDomElement &rasterRendererElem ) const;
162 
163  QString mType;
164 
166  double mOpacity = 1.0;
168  QgsRasterTransparency *mRasterTransparency = nullptr;
169 
174  int mAlphaBand = -1;
175 
178 
187  QRgb renderColorForNodataPixel() const;
188 
189  private:
190 
191  QColor mNodataColor;
192 
193 #ifdef SIP_RUN
195  const QgsRasterRenderer &operator=( const QgsRasterRenderer & );
196 #endif
197 
198 };
199 
200 #endif // QGSRASTERRENDERER_H
qgsrasterminmaxorigin.h
QgsRasterRenderer::block
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override=0
Read block of data using given extent and size.
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
QgsRasterRenderer::minMaxOrigin
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
Definition: qgsrasterrenderer.h:136
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsRasterRenderer::nodataColor
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
Definition: qgsrasterrenderer.h:100
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsRasterRenderer::type
virtual QString type() const
Definition: qgsrasterrenderer.h:64
QgsRasterRenderer::usesBands
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
Definition: qgsrasterrenderer.h:133
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRasterRenderer::NODATA_COLOR
static const QRgb NODATA_COLOR
Definition: qgsrasterrenderer.h:45
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsRasterMinMaxOrigin
This class describes the origin of min/max values.
Definition: qgsrasterminmaxorigin.h:34
qgsrasterinterface.h
QgsRasterRenderer::mMinMaxOrigin
QgsRasterMinMaxOrigin mMinMaxOrigin
Origin of min/max values.
Definition: qgsrasterrenderer.h:177
QgsRasterInterface::setInput
virtual bool setInput(QgsRasterInterface *input)
Set input.
Definition: qgsrasterinterface.h:266
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:39
QgsRasterRenderer::rasterTransparency
const QgsRasterTransparency * rasterTransparency() const
Definition: qgsrasterrenderer.h:114
QgsRasterInterface::dataType
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
QgsRasterRenderer::setAlphaBand
void setAlphaBand(int band)
Definition: qgsrasterrenderer.h:116
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsRasterInterface::readXml
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsrasterinterface.h:463
QgsRasterTransparency
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
Definition: qgsrastertransparency.h:33
QgsRasterRenderer::clone
QgsRasterRenderer * clone() const override=0
Clone itself, create deep copy.
QgsRasterRenderer::setMinMaxOrigin
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
Definition: qgsrasterrenderer.h:139
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:117
QgsRasterRenderer::legendSymbologyItems
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
Definition: qgsrasterrenderer.h:120
QgsRasterRenderer::alphaBand
int alphaBand() const
Definition: qgsrasterrenderer.h:117
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterRenderer::QgsRasterRenderer
QgsRasterRenderer(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
QgsRasterRenderer::setNodataColor
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
Definition: qgsrasterrenderer.h:111
QgsRasterInterface::bandCount
virtual int bandCount() const =0
Gets number of bands.
QgsRasterRenderer::operator=
const QgsRasterRenderer & operator=(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
QgsRasterRenderer::mType
QString mType
Definition: qgsrasterrenderer.h:163
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:81
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:37
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:88