21 #include <QCoreApplication> 22 #include <QDomDocument> 23 #include <QDomElement> 64 if ( !input )
return false;
73 for (
int i = 1; i <= input->
bandCount(); i++ )
101 if ( rasterRendererElem.isNull() )
106 rasterRendererElem.setAttribute( QStringLiteral(
"type" ),
mType );
107 rasterRendererElem.setAttribute( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
108 rasterRendererElem.setAttribute( QStringLiteral(
"alphaBand" ),
mAlphaBand );
115 QDomElement minMaxOriginElem = doc.createElement( QStringLiteral(
"minMaxOrigin" ) );
117 rasterRendererElem.appendChild( minMaxOriginElem );
122 if ( rendererElem.isNull() )
127 mType = rendererElem.attribute( QStringLiteral(
"type" ) );
128 mOpacity = rendererElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.0" ) ).toDouble();
129 mAlphaBand = rendererElem.attribute( QStringLiteral(
"alphaBand" ), QStringLiteral(
"-1" ) ).toInt();
131 QDomElement rasterTransparencyElem = rendererElem.firstChildElement( QStringLiteral(
"rasterTransparency" ) );
132 if ( !rasterTransparencyElem.isNull() )
139 QDomElement minMaxOriginElem = rendererElem.firstChildElement( QStringLiteral(
"minMaxOrigin" ) );
140 if ( !minMaxOriginElem.isNull() )
154 if ( copyMinMaxOrigin )
virtual int bandCount() const =0
Get number of bands.
bool isEmpty() const
True if there are no entries in the pixel lists except the nodata value.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
static bool typeIsNumeric(Qgis::DataType type)
Returns true if data type is numeric.
virtual QgsRasterInterface * input() const
Current input.
QgsRasterRenderer(QgsRasterInterface *input=nullptr, const QString &type=QString())
Constructor for QgsRasterRenderer.
DataType
Raster data types.
QgsRasterMinMaxOrigin mMinMaxOrigin
Origin of min/max values.
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
const QgsRasterTransparency * rasterTransparency() const
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
static const QRgb NODATA_COLOR
bool setInput(QgsRasterInterface *input) override
Set input.
#define QgsDebugMsgLevel(str, level)
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses) ...
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
void readXml(const QDomElement &elem)
Deserialize object.
bool usesTransparency() const
Unknown or unspecified type.
void readXml(const QDomElement &elem)
Reads the transparency information from an XML document.
int mAlphaBand
Read alpha value from band.
void setAlphaBand(int band)
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
int bandCount() const override
Get number of bands.
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
~QgsRasterRenderer() override
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Writes the transparency information to an XML document.
double mOpacity
Global alpha value (0-1)
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
QgsRasterInterface * mInput
void setRasterTransparency(QgsRasterTransparency *t)
Raster renderer pipe that applies colors to a raster.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Serialize object.