Skip to content
Permalink
Browse files
Implement readXML for multiband color renderer
  • Loading branch information
mhugent committed Apr 3, 2012
1 parent 7a43e45 commit f1a742c151b36b66d0f8a266f47b02739fc45e3e
Showing with 63 additions and 1 deletion.
  1. +19 −0 src/core/raster/qgscontrastenhancement.cpp
  2. +2 −0 src/core/raster/qgscontrastenhancement.h
  3. +42 −1 src/core/raster/qgsmultibandcolorrenderer.cpp
@@ -376,3 +376,22 @@ void QgsContrastEnhancement::writeXML( QDomDocument& doc, QDomElement& parentEle
algorithmElem.appendChild( algorithmText );
parentElem.appendChild( algorithmElem );
}

void QgsContrastEnhancement::readXML( const QDomElement& elem )
{
QDomElement minValueElem = elem.firstChildElement( "minValue" );
if ( !minValueElem.isNull() )
{
mMinimumValue = minValueElem.text().toInt();
}
QDomElement maxValueElem = elem.firstChildElement( "maxValue" );
if ( !maxValueElem.isNull() )
{
mMaximumValue = maxValueElem.text().toInt();
}
QDomElement algorithmElem = elem.firstChildElement( "algorithm" );
if ( !algorithmElem.isNull() )
{
setContrastEnhancementAlgorithm(( ContrastEnhancementAlgorithm )( algorithmElem.text().toInt() ) );
}
}
@@ -123,6 +123,8 @@ class CORE_EXPORT QgsContrastEnhancement

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

void readXML( const QDomElement& elem );

private:
/** \brief Current contrast enhancement algorithm */
ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm;
@@ -57,7 +57,48 @@ void QgsMultiBandColorRenderer::setBlueContrastEnhancement( QgsContrastEnhanceme

QgsRasterRenderer* QgsMultiBandColorRenderer::create( const QDomElement& elem, QgsRasterDataProvider* provider )
{
return 0;
if ( elem.isNull() )
{
return 0;
}

//red band, green band, blue band
int redBand = elem.attribute( "redBand", "-1" ).toInt();
int greenBand = elem.attribute( "greenBand", "-1" ).toInt();
int blueBand = elem.attribute( "blueBand", "-1" ).toInt();

//contrast enhancements
QgsContrastEnhancement* redContrastEnhancement = 0;
QDomElement redContrastElem = elem.firstChildElement( "redContrastEnhancement" );
if ( !redContrastElem.isNull() )
{
redContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( redBand ) ) );
redContrastEnhancement->readXML( redContrastElem );
}

QgsContrastEnhancement* greenContrastEnhancement = 0;
QDomElement greenContrastElem = elem.firstChildElement( "greenContrastEnhancement" );
if ( !greenContrastElem.isNull() )
{
greenContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( greenBand ) ) );
greenContrastEnhancement->readXML( greenContrastElem );
}

QgsContrastEnhancement* blueContrastEnhancement = 0;
QDomElement blueContrastElem = elem.firstChildElement( "blueContrastEnhancement" );
if ( !blueContrastElem.isNull() )
{
blueContrastEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( blueBand ) ) );
blueContrastEnhancement->readXML( blueContrastElem );
}

QgsRasterRenderer* r = new QgsMultiBandColorRenderer( provider, redBand, greenBand, blueBand, redContrastEnhancement,
greenContrastEnhancement, blueContrastEnhancement );
r->readXML( elem );
return r;
}

void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )

0 comments on commit f1a742c

Please sign in to comment.