QGIS API Documentation  2.99.0-Master (cb63e82)
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 <QVector>
23 
24 #include "qgsrasterrenderer.h"
25 #include "qgscolorrampshader.h"
26 
27 class QColor;
28 class QDomElement;
29 
34 {
35  public:
36 
38  struct Class
39  {
41  Class( int value, const QColor &color = QColor(), const QString &label = QString() )
42  : value( value )
43  , color( color )
44  , label( label )
45  {}
46 
48  int value;
49 
51  QColor color;
53  QString label;
54  };
55 
57  typedef QList< Class > ClassData;
58 
62  QgsPalettedRasterRenderer( QgsRasterInterface *input, int bandNumber, const ClassData &classes );
63 
67  const QgsPalettedRasterRenderer &operator=( const QgsPalettedRasterRenderer & ) = delete;
68 
69  QgsPalettedRasterRenderer *clone() const override;
70  static QgsRasterRenderer *create( const QDomElement &elem, QgsRasterInterface *input );
71 
72  QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
73 
75  int nColors() const { return mClassData.size(); }
76 
80  ClassData classes() const;
81 
84  QString label( int idx ) const;
85 
88  void setLabel( int idx, const QString &label );
89 
90  void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
91 
92  void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems ) const override;
93 
94  QList<int> usesBands() const override;
95 
101  void setSourceColorRamp( QgsColorRamp *ramp );
102 
107  QgsColorRamp *sourceColorRamp() const;
108 
113  static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
114 
121  static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
122 
128  static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
129 
135  static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
136 
142  static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = nullptr,
143  QgsRasterBlockFeedback *feedback = nullptr );
144 
145  private:
146 
147  int mBand;
148  ClassData mClassData;
149 
151  std::unique_ptr<QgsColorRamp> mSourceColorRamp;
152 
154  QMap< int, QRgb > mColors;
155  void updateArrays();
156 };
157 
158 #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.
int nColors() const
Returns number of colors.
Raster data container.
Base class for processing filters like renderers, reprojector, resampler etc.
Class(int value, const QColor &color=QColor(), const QString &label=QString())
Constructor for Class.
QList< Class > ClassData
Map of value to class properties.
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.