QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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"
27
28class QDomElement;
29
30class QPainter;
35
40class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
41{
42
43 Q_DECLARE_TR_FUNCTIONS( QgsRasterRenderer ) // cppcheck-suppress duplInheritedMember
44
45 public:
46
47 static const QRgb NODATA_COLOR;
48
52 QgsRasterRenderer( QgsRasterInterface *input = nullptr, const QString &type = QString() );
53 ~QgsRasterRenderer() override;
54
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
69 virtual QString type() const { return mType; }
70
76 virtual Qgis::RasterRendererFlags flags() const;
77
84 virtual bool canCreateRasterAttributeTable( ) const;
85
86 bool setInput( QgsRasterInterface *input ) override;
87
100 virtual int inputBand() const;
101
114 virtual bool setInputBand( int band );
115
116 QgsRasterBlock *block( int bandNo,
117 const QgsRectangle &extent,
118 int width,
119 int height,
120 QgsRasterBlockFeedback *feedback = nullptr ) override = 0 SIP_FACTORY;
121
122 bool usesTransparency() const;
123
129 void setOpacity( double opacity ) { mOpacity = opacity; }
130
136 double opacity() const { return mOpacity; }
137
148 QColor nodataColor() const { return mNodataColor; }
149
159 void setNodataColor( const QColor &color ) { mNodataColor = color; }
160
161 void setRasterTransparency( QgsRasterTransparency *t SIP_TRANSFER );
162 const QgsRasterTransparency *rasterTransparency() const { return mRasterTransparency; }
163
164 void setAlphaBand( int band ) { mAlphaBand = band; }
165 int alphaBand() const { return mAlphaBand; }
166
172 virtual QList< QPair< QString, QColor > > legendSymbologyItems() const;
173
184 virtual QList<QgsLayerTreeModelLegendNode *> createLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY;
185
187 void readXml( const QDomElement &rendererElem ) override;
188
193 void copyCommonProperties( const QgsRasterRenderer *other, bool copyMinMaxOrigin = true );
194
200 virtual QList<int> usesBands() const { return QList<int>(); }
201
203 const QgsRasterMinMaxOrigin &minMaxOrigin() const { return mMinMaxOrigin; }
204
206 void setMinMaxOrigin( const QgsRasterMinMaxOrigin &origin ) { mMinMaxOrigin = origin; }
207
212 virtual void toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props = QVariantMap() ) const;
213
223 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
224
225 protected:
226
228 void _writeXml( QDomDocument &doc, QDomElement &rasterRendererElem ) const;
229
230 QString mType;
231
233 double mOpacity = 1.0;
235 QgsRasterTransparency *mRasterTransparency = nullptr;
236
241 int mAlphaBand = -1;
242
245
254 QRgb renderColorForNodataPixel() const;
255
256 private:
257
258 QColor mNodataColor;
259
260#ifdef SIP_RUN
262 const QgsRasterRenderer &operator=( const QgsRasterRenderer & );
263#endif
264
265};
266
267#endif // QGSRASTERRENDERER_H
QFlags< RasterRendererFlag > RasterRendererFlags
Flags which control behavior of raster renderers.
Definition qgis.h:1404
DataType
Raster data types.
Definition qgis.h:351
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Feedback object tailored for raster block reading.
Raster data container.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
virtual int bandCount() const =0
Gets number of bands.
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
virtual bool setInput(QgsRasterInterface *input)
Set input.
This class describes the origin of min/max values.
Raster renderer pipe that applies colors to a raster.
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
virtual QString type() const
Returns a unique string representation of the renderer type.
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
const QgsRasterTransparency * rasterTransparency() const
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
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.
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
void setAlphaBand(int band)
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
QgsRasterMinMaxOrigin mMinMaxOrigin
Origin of min/max values.
QgsRasterRenderer(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
static const QRgb NODATA_COLOR
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
const QgsRasterRenderer & operator=(const QgsRasterRenderer &)=delete
QgsRasterRenderer cannot be copied. Use clone() instead.
QgsRasterRenderer * clone() const override=0
Clone itself, create deep copy.
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
A rectangle specified with double values.
An interface for classes which can visit style entity (e.g.
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76