Skip to content

Commit

Permalink
raster filters moved to pipe node in project file to allow custom fil…
Browse files Browse the repository at this point in the history
…ters in future
  • Loading branch information
blazek committed Apr 19, 2013
1 parent d4d2625 commit 1f872ce
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion python/core/raster/qgsrasterresamplefilter.sip
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QgsRasterResampleFilter : QgsRasterInterface
void setMaxOversampling( double os );
double maxOversampling() const;

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

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& resamplefilterElem );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsbrightnesscontrastfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int QgsBrightnessContrastFilter::adjustColorComponent( int colorComponent, int a
}
}

void QgsBrightnessContrastFilter::writeXML( QDomDocument& doc, QDomElement& parentElem )
void QgsBrightnessContrastFilter::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
if ( parentElem.isNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsbrightnesscontrastfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CORE_EXPORT QgsBrightnessContrastFilter : public QgsRasterInterface
void setContrast( int contrast ) { mContrast = qBound( -100, contrast, 100 ); }
int contrast() const { return mContrast; }

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

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& filterElem );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgshuesaturationfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void QgsHueSaturationFilter::setColorizeColor( QColor colorizeColor )
mColorizeS = mColorizeColor.saturation();
}

void QgsHueSaturationFilter::writeXML( QDomDocument& doc, QDomElement& parentElem )
void QgsHueSaturationFilter::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
if ( parentElem.isNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgshuesaturationfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
void setColorizeStrength( int colorizeStrength ) { mColorizeStrength = colorizeStrength; }
int colorizeStrength() const { return mColorizeStrength; }

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

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& filterElem );
Expand Down
39 changes: 32 additions & 7 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2237,11 +2237,21 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
Q_UNUSED( errorMessage );
QDomElement rasterRendererElem;

//rasterlayerproperties element there -> old format
if ( !layer_node.firstChildElement( "rasterproperties" ).isNull() )
// pipe element was introduced in the end of 1.9 development when there were
// already many project files in use so we support 1.9 backward compatibility
// even it was never officialy released -> use pipe element if present, otherwise
// use layer node
QDomNode pipeNode = layer_node.firstChildElement( "pipe" );
if ( pipeNode.isNull() ) // old project
{
pipeNode = layer_node;
}

//rasterlayerproperties element there -> old format (1.8 and early 1.9)
if ( !pipeNode.firstChildElement( "rasterproperties" ).isNull() )
{
//copy node because layer_node is const
QDomNode layerNodeCopy = layer_node.cloneNode();
QDomNode layerNodeCopy = pipeNode.cloneNode();
QDomDocument doc = layerNodeCopy.ownerDocument();
QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( "rasterproperties" );
QgsProjectFileTransform::convertRasterProperties( doc, layerNodeCopy, rasterPropertiesElem,
Expand All @@ -2251,7 +2261,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
}
else
{
rasterRendererElem = layer_node.firstChildElement( "rasterrenderer" );
rasterRendererElem = pipeNode.firstChildElement( "rasterrenderer" );
}

if ( !rasterRendererElem.isNull() )
Expand All @@ -2270,7 +2280,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
mPipe.set( brightnessFilter );

//brightness coefficient
QDomElement brightnessElem = layer_node.firstChildElement( "brightnesscontrast" );
QDomElement brightnessElem = pipeNode.firstChildElement( "brightnesscontrast" );
if ( !brightnessElem.isNull() )
{
brightnessFilter->readXML( brightnessElem );
Expand All @@ -2281,7 +2291,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
mPipe.set( hueSaturationFilter );

//saturation coefficient
QDomElement hueSaturationElem = layer_node.firstChildElement( "huesaturation" );
QDomElement hueSaturationElem = pipeNode.firstChildElement( "huesaturation" );
if ( !hueSaturationElem.isNull() )
{
hueSaturationFilter->readXML( hueSaturationElem );
Expand All @@ -2292,7 +2302,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
mPipe.set( resampleFilter );

//max oversampling
QDomElement resampleElem = layer_node.firstChildElement( "rasterresampler" );
QDomElement resampleElem = pipeNode.firstChildElement( "rasterresampler" );
if ( !resampleElem.isNull() )
{
resampleFilter->readXML( resampleElem );
Expand Down Expand Up @@ -2472,6 +2482,20 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
Q_UNUSED( errorMessage );
QDomElement layerElem = layer_node.toElement();

// Store pipe members (except provider) into pipe element, in future, it will be
// possible to add custom filters into the pipe
QDomElement pipeElement = document.createElement( "pipe" );

for ( int i = 1; i < mPipe.size(); i++ )
{
QgsRasterInterface * interface = mPipe.at( i );
if ( !interface ) continue;
interface->writeXML( document, pipeElement );
}

layer_node.appendChild( pipeElement );

#if 0
QgsRasterRenderer *renderer = mPipe.renderer();
if ( renderer )
{
Expand All @@ -2498,6 +2522,7 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
QDomElement layerElem = layer_node.toElement();
resampleFilter->writeXML( document, layerElem );
}
#endif

// add blend mode node
QDomElement blendModeElement = document.createElement( "blendMode" );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterresamplefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ QgsRasterBlock * QgsRasterResampleFilter::block( int bandNo, QgsRectangle const
return outputBlock; // No resampling
}

void QgsRasterResampleFilter::writeXML( QDomDocument& doc, QDomElement& parentElem )
void QgsRasterResampleFilter::writeXML( QDomDocument& doc, QDomElement& parentElem ) const
{
if ( parentElem.isNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterresamplefilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CORE_EXPORT QgsRasterResampleFilter : public QgsRasterInterface
void setMaxOversampling( double os ) { mMaxOversampling = os; }
double maxOversampling() const { return mMaxOversampling; }

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

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& filterElem );
Expand Down

0 comments on commit 1f872ce

Please sign in to comment.