QGIS API Documentation  2.99.0-Master (69af2f5)
qgspalettedrasterrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspalettedrasterrenderer.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 QGSPALETTEDRASTERRENDERER_H
19 #define QGSPALETTEDRASTERRENDERER_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include <QVector>
24 
25 #include "qgsrasterrenderer.h"
26 #include "qgscolorrampshader.h"
27 
28 class QColor;
29 class QDomElement;
30 
35 {
36  public:
37 
39  struct Class
40  {
42  Class( int value, const QColor &color = QColor(), const QString &label = QString() )
43  : value( value )
44  , color( color )
45  , label( label )
46  {}
47 
49  int value;
50 
52  QColor color;
54  QString label;
55  };
56 
58  typedef QList< QgsPalettedRasterRenderer::Class > ClassData;
59 
63  QgsPalettedRasterRenderer( QgsRasterInterface *input, int bandNumber, const ClassData &classes );
64 
68  const QgsPalettedRasterRenderer &operator=( const QgsPalettedRasterRenderer & ) = delete;
69 
70  QgsPalettedRasterRenderer *clone() const override SIP_FACTORY;
71  static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input ) SIP_FACTORY;
72 
73  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
74 
76  int nColors() const { return mClassData.size(); }
77 
81  ClassData classes() const;
82 
85  QString label( int idx ) const;
86 
89  void setLabel( int idx, const QString &label );
90 
95  int band() const { return mBand; }
96 
97  void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
98 
99  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
100 
101  QList<int> usesBands() const override;
102 
108  void setSourceColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
109 
114  QgsColorRamp *sourceColorRamp() const;
115 
120  static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
121 
128  static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
129 
135  static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
136 
142  static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
143 
149  static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
150  QgsRasterBlockFeedback *feedback = nullptr );
151 
152  private:
153 #ifdef SIP_RUN
155  const QgsPalettedRasterRenderer &operator=( const QgsPalettedRasterRenderer & );
156 #endif
157 
158 
159  int mBand;
160  ClassData mClassData;
161 
163  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
164 
166  QMap< int, QRgb > mColors;
167  void updateArrays();
168 };
169 
170 #endif // QGSPALETTEDRASTERRENDERER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
QColor color
Color to render value.
Renderer for paletted raster images.
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
Properties of a single value class.
Raster data container.
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
#define SIP_TRANSFER
Definition: qgis_sip.h:24
#define SIP_FACTORY
Definition: qgis_sip.h:57
Base class for processing filters like renderers, reprojector, resampler etc.
#define SIP_OUT
Definition: qgis_sip.h:39
int band() const
Returns the raster band used for rendering the raster.
Class(int value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.