Skip to content
Permalink
Browse files
Add writeXML method for renderers (needs still to be implemented for …
…most types)
  • Loading branch information
mhugent committed Mar 26, 2012
1 parent 99c7a81 commit 1e2215a9138cb3545c68e777b18f5e3aa6ac1459
@@ -273,3 +273,8 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
stopRasterRead( *bandIt );
}
}

void QgsMultiBandColorRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
//soon...
}
@@ -55,6 +55,8 @@ class QgsMultiBandColorRenderer: public QgsRasterRenderer
/**Takes ownership*/
void setBlueContrastEnhancement( QgsContrastEnhancement* ce );

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

private:
int mRedBand;
int mGreenBand;
@@ -19,6 +19,8 @@
#include "qgsrastertransparency.h"
#include "qgsrasterviewport.h"
#include <QColor>
#include <QDomDocument>
#include <QDomElement>
#include <QImage>

QgsPalettedRasterRenderer::QgsPalettedRasterRenderer( QgsRasterDataProvider* provider, int bandNumber,
@@ -155,3 +157,22 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
stopRasterRead( mAlphaBand );
}
}

void QgsPalettedRasterRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
_writeXML( doc, rasterRendererElem );

rasterRendererElem.setAttribute( "band", mBandNumber );
QDomElement colorPaletteElem = doc.createElement( "colorPalette" );
for ( int i = 0; i < mNColors; ++i )
{
QDomElement colorElem = doc.createElement( "paletteEntry" );
colorElem.setAttribute( "value", i );
colorElem.setAttribute( "color", mColors[i].name() );
colorPaletteElem.appendChild( colorElem );
}
rasterRendererElem.appendChild( colorPaletteElem );

parentElem.appendChild( rasterRendererElem );
}
@@ -38,6 +38,8 @@ class QgsPalettedRasterRenderer: public QgsRasterRenderer
/**Returns copy of color array (caller takes ownership)*/
QColor* colors() const;

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

private:
int mBandNumber;
/**Color array*/
@@ -3400,38 +3400,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
QDomElement rasterPropertiesElement = document.createElement( "rasterproperties" );
layer_node.appendChild( rasterPropertiesElement );

// resampler
if ( mRenderer )
{
//Max oversampling
QDomElement maxOversamplingElem = document.createElement( "MaxOversampling" );
QDomText maxOversamplingText = document.createTextNode( QString::number( mRenderer->maxOversampling() ) );
maxOversamplingElem.appendChild( maxOversamplingText );
rasterPropertiesElement.appendChild( maxOversamplingElem );

QString zoomedInResamplerString = "nearest";
const QgsRasterResampler* zoomedInResampler = mRenderer->zoomedInResampler();
if ( zoomedInResampler )
{
zoomedInResamplerString = zoomedInResampler->type();
}
QDomElement zoomedInResamplerElem = document.createElement( "zoomedInResampler" );
QDomText zoomedInResamplerText = document.createTextNode( zoomedInResamplerString );
zoomedInResamplerElem.appendChild( zoomedInResamplerText );
rasterPropertiesElement.appendChild( zoomedInResamplerElem );

QString zoomedOutResamplerString = "nearest";
const QgsRasterResampler* zoomedOutResampler = mRenderer->zoomedOutResampler();
if ( zoomedOutResampler )
{
zoomedOutResamplerString = zoomedOutResampler->type();
}
QDomElement zoomedOutResamplerElem = document.createElement( "zoomedOutResampler" );
QDomText zoomedOutResamplerText = document.createTextNode( zoomedOutResamplerString );
zoomedOutResamplerElem.appendChild( zoomedOutResamplerText );
rasterPropertiesElement.appendChild( zoomedOutResamplerElem );
}

QStringList sl = subLayers();
QStringList sls = mDataProvider->subLayerStyles();

@@ -3477,36 +3445,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
rasterPropertiesElement.appendChild( formatElement );
}

// <mDrawingStyle>
QDomElement drawStyleElement = document.createElement( "mDrawingStyle" );
QDomText drawStyleText = document.createTextNode( drawingStyleAsString() );

drawStyleElement.appendChild( drawStyleText );

rasterPropertiesElement.appendChild( drawStyleElement );

// <colorShadingAlgorithm>
QDomElement colorShadingAlgorithmElement = document.createElement( "mColorShadingAlgorithm" );
QDomText colorShadingAlgorithmText = document.createTextNode( colorShadingAlgorithmAsString() );

colorShadingAlgorithmElement.appendChild( colorShadingAlgorithmText );

rasterPropertiesElement.appendChild( colorShadingAlgorithmElement );

// <mInvertColor>
QDomElement mInvertColorElement = document.createElement( "mInvertColor" );

if ( invertHistogram() )
{
mInvertColorElement.setAttribute( "boolean", "true" );
}
else
{
mInvertColorElement.setAttribute( "boolean", "false" );
}

rasterPropertiesElement.appendChild( mInvertColorElement );

// <mRedBandName>
QDomElement mRedBandNameElement = document.createElement( "mRedBandName" );
QString writtenRedBandName = redBandName();
@@ -3627,37 +3565,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum

rasterPropertiesElement.appendChild( GrayMinimumMaximumEstimated );

// <contrastEnhancementAlgorithm>
QDomElement contrastEnhancementAlgorithmElement = document.createElement( "mContrastEnhancementAlgorithm" );
QDomText contrastEnhancementAlgorithmText = document.createTextNode( contrastEnhancementAlgorithmAsString() );

contrastEnhancementAlgorithmElement.appendChild( contrastEnhancementAlgorithmText );

rasterPropertiesElement.appendChild( contrastEnhancementAlgorithmElement );

// <minMaxValues>
QList<QgsContrastEnhancement>::const_iterator it;
QDomElement contrastEnhancementMinMaxValuesElement = document.createElement( "contrastEnhancementMinMaxValues" );
for ( it = mContrastEnhancementList.constBegin(); it != mContrastEnhancementList.constEnd(); ++it )
{
QDomElement minMaxEntry = document.createElement( "minMaxEntry" );
QDomElement minEntry = document.createElement( "min" );
QDomElement maxEntry = document.createElement( "max" );

QDomText minEntryText = document.createTextNode( QString::number( it->minimumValue() ) );
minEntry.appendChild( minEntryText );

QDomText maxEntryText = document.createTextNode( QString::number( it->maximumValue() ) );
maxEntry.appendChild( maxEntryText );

minMaxEntry.appendChild( minEntry );
minMaxEntry.appendChild( maxEntry );

contrastEnhancementMinMaxValuesElement.appendChild( minMaxEntry );
}

rasterPropertiesElement.appendChild( contrastEnhancementMinMaxValuesElement );

/*
* Transparency tab
*/
@@ -3677,7 +3584,7 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum

rasterPropertiesElement.appendChild( mNoDataValueElement );


#if 0
if ( mRasterTransparency.transparentSingleValuePixelList().count() > 0 )
{
QDomElement singleValuePixelListElement = document.createElement( "singleValuePixelList" );
@@ -3744,6 +3651,13 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum

rasterPropertiesElement.appendChild( customColorRampElement );
}
#endif //0

if ( mRenderer )
{
QDomElement layerElem = layer_node.toElement();
mRenderer->writeXML( document, layerElem );
}

return true;
} // bool QgsRasterLayer::writeSymbology
@@ -21,6 +21,8 @@
#include "qgsrastertransparency.h"
#include "qgsrasterviewport.h"
#include "qgsmaptopixel.h"
#include <QDomDocument>
#include <QDomElement>
#include <QImage>
#include <QPainter>

@@ -310,3 +312,31 @@ void QgsRasterRenderer::projectImage( const QImage& srcImg, QImage& dstImage, Qg
}
}
}

void QgsRasterRenderer::_writeXML( QDomDocument& doc, QDomElement& rasterRendererElem ) const
{
if ( rasterRendererElem.isNull() )
{
return;
}

rasterRendererElem.setAttribute( "type", mType );
rasterRendererElem.setAttribute( "opacity", mOpacity );
rasterRendererElem.setAttribute( "alphaBand", mAlphaBand );
rasterRendererElem.setAttribute( "maxOversampling", mMaxOversampling );
rasterRendererElem.setAttribute( "invertColor", mInvertColor );
if ( mZoomedInResampler )
{
rasterRendererElem.setAttribute( "zoomedInResampler", mZoomedInResampler->type() );
}
if ( mZoomedOutResampler )
{
rasterRendererElem.setAttribute( "zoomedOutResampler", mZoomedOutResampler->type() );
}

//todo: write raster transparency
if ( mRasterTransparency )
{
mRasterTransparency->writeXML( doc, rasterRendererElem );
}
}
@@ -27,6 +27,8 @@ class QgsRasterProjector;
class QgsRasterTransparency;
class QgsRasterViewPort;

class QDomElement;

class QgsRasterRenderer
{
public:
@@ -74,6 +76,8 @@ class QgsRasterRenderer
void setMaxOversampling( double os ) { mMaxOversampling = os; }
double maxOversampling() const { return mMaxOversampling; }

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

protected:
inline double readValue( void *data, QgsRasterDataProvider::DataType type, int index );

@@ -97,6 +101,9 @@ class QgsRasterRenderer
int nCols, int nRows, double oversamplingX, double oversamplingY ) const;
void stopRasterRead( int bandNumber );

/**Write upper class info into <rasterrenderer> element (called by writeXML method of subclasses)*/
void _writeXML( QDomDocument& doc, QDomElement& rasterRendererElem ) const;


QgsRasterDataProvider* mProvider;
QString mType;
@@ -15,11 +15,13 @@ email : ersts@amnh.org
* (at your option) any later version. *
* *
***************************************************************************/
#include <QList>

#include "qgsrastertransparency.h"
#include "qgis.h"

#include <QDomDocument>
#include <QDomElement>

QgsRasterTransparency::QgsRasterTransparency()
{

@@ -180,3 +182,38 @@ bool QgsRasterTransparency::isEmpty( double nodataValue ) const
( mTransparentThreeValuePixelList.size() < 4 && doubleNear( mTransparentThreeValuePixelList.at( 0 ).red, nodataValue ) &&
doubleNear( mTransparentThreeValuePixelList.at( 0 ).green, nodataValue ) && doubleNear( mTransparentThreeValuePixelList.at( 0 ).blue, nodataValue ) ) ) );
}

void QgsRasterTransparency::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
QDomElement rasterTransparencyElem = doc.createElement( "rasterTransparency" );
if ( mTransparentSingleValuePixelList.count() > 0 )
{
QDomElement singleValuePixelListElement = doc.createElement( "singleValuePixelList" );
QList<QgsRasterTransparency::TransparentSingleValuePixel>::const_iterator it = mTransparentSingleValuePixelList.constBegin();
for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
{
QDomElement pixelListElement = doc.createElement( "pixelListEntry" );
pixelListElement.setAttribute( "pixelValue", QString::number( it->pixelValue, 'f' ) );
pixelListElement.setAttribute( "percentTransparent", QString::number( it->percentTransparent ) );
singleValuePixelListElement.appendChild( pixelListElement );
}
rasterTransparencyElem.appendChild( singleValuePixelListElement );

}
if ( mTransparentThreeValuePixelList.count() > 0 )
{
QDomElement threeValuePixelListElement = doc.createElement( "threeValuePixelList" );
QList<QgsRasterTransparency::TransparentThreeValuePixel>::const_iterator it = mTransparentThreeValuePixelList.constBegin();
for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
{
QDomElement pixelListElement = doc.createElement( "pixelListEntry" );
pixelListElement.setAttribute( "red", QString::number( it->red, 'f' ) );
pixelListElement.setAttribute( "green", QString::number( it->green, 'f' ) );
pixelListElement.setAttribute( "blue", QString::number( it->blue, 'f' ) );
pixelListElement.setAttribute( "percentTransparent", QString::number( it->percentTransparent ) );
threeValuePixelListElement.appendChild( pixelListElement );
}
rasterTransparencyElem.appendChild( threeValuePixelListElement );
}
parentElem.appendChild( rasterTransparencyElem );
}
@@ -18,6 +18,10 @@ email : ersts@amnh.org
#ifndef QGSRASTERTRANSPARENCY_H
#define QGSRASTERTRANSPARENCY_H

#include <QList>
class QDomDocument;
class QDomElement;

/** \ingroup core
* Defines the list of pixel values to be considered as transparent or semi
* transparent when rendering rasters.
@@ -75,6 +79,8 @@ class CORE_EXPORT QgsRasterTransparency
/**True if there are no entries in the pixel lists except the nodata value*/
bool isEmpty( double nodataValue ) const;

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

private:
/** \brief The list to hold transparency values for RGB layers */
QList<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList;
@@ -87,3 +87,8 @@ void QgsSingleBandColorDataRenderer::draw( QPainter* p, QgsRasterViewPort* viewP

stopRasterRead( mBand );
}

void QgsSingleBandColorDataRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
//soon...
}
@@ -32,6 +32,8 @@ class QgsSingleBandColorDataRenderer: public QgsRasterRenderer

virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

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

private:
int mBand;
};
@@ -151,3 +151,8 @@ void QgsSingleBandGrayRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
stopRasterRead( mAlphaBand );
}
}

void QgsSingleBandGrayRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
//soon...
}
@@ -39,6 +39,8 @@ class QgsSingleBandGrayRenderer: public QgsRasterRenderer
/**Takes ownership*/
void setContrastEnhancement( QgsContrastEnhancement* ce );

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

private:
int mGrayBand;
QgsContrastEnhancement* mContrastEnhancement;
@@ -145,3 +145,8 @@ void QgsSingleBandPseudoColorRenderer::draw( QPainter* p, QgsRasterViewPort* vie
stopRasterRead( mAlphaBand );
}
}

void QgsSingleBandPseudoColorRenderer::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
//soon...
}
@@ -38,6 +38,8 @@ class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
void setShader( QgsRasterShader* shader );
QgsRasterShader* shader() { return mShader; }

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

private:
QgsRasterShader* mShader;
int mBand;

0 comments on commit 1e2215a

Please sign in to comment.