diff --git a/python/core/qgsrasterlayer.sip b/python/core/qgsrasterlayer.sip index 7eb2db548eb..a292ce3cba7 100644 --- a/python/core/qgsrasterlayer.sip +++ b/python/core/qgsrasterlayer.sip @@ -426,8 +426,9 @@ public: /** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */ void setNoDataValue( double theNoData ); - /** \brief Set the raster shader function to a user defined function */ - void setRasterShaderFunction( QgsRasterShaderFunction* theFunction ); + /** \brief Set the raster shader function to a user defined function + \note ownership of the shader function is transfered to raster shader */ + void setRasterShaderFunction( QgsRasterShaderFunction* theFunction /Transfer/ ); /** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */ void setRedBandName( const QString & theBandName ); diff --git a/python/core/qgsrastershader.sip b/python/core/qgsrastershader.sip index 799be5e7fd6..f8772487423 100644 --- a/python/core/qgsrastershader.sip +++ b/python/core/qgsrastershader.sip @@ -31,8 +31,9 @@ public: bool shade(double, int* /Out/, int* /Out/, int* /Out/); /** \brief generates and new RGB value based on original RGB value */ bool shade(double, double, double, int* /Out/, int* /Out/, int* /Out/); - /** \brief A public method that allows the user to set their own shader function */ - void setRasterShaderFunction(QgsRasterShaderFunction*); + /** \brief A public method that allows the user to set their own shader function + \note Raster shader takes ownership of the shader function instance */ + void setRasterShaderFunction(QgsRasterShaderFunction* /Transfer/); /** \brief Set the maximum value */ void setMaximumValue(double); /** \brief Return the minimum value */ diff --git a/python/core/qgsrastershaderfunction.sip b/python/core/qgsrastershaderfunction.sip index 70af00d66c2..06e7f6b02ec 100644 --- a/python/core/qgsrastershaderfunction.sip +++ b/python/core/qgsrastershaderfunction.sip @@ -3,8 +3,23 @@ class QgsRasterShaderFunction { %TypeHeaderCode #include +#include +#include +#include %End +%ConvertToSubClassCode + if (dynamic_cast(sipCpp) != NULL) + sipClass = sipClass_QgsColorRampShader; + else if (dynamic_cast(sipCpp) != NULL) + sipClass = sipClass_QgsFreakOutShader; + else if (dynamic_cast(sipCpp) != NULL) + sipClass = sipClass_QgsPseudoColorShader; + else + sipClass = 0; +%End + + public: QgsRasterShaderFunction(double theMinimumValue = 0.0, double theMaximumValue = 255.0); virtual ~QgsRasterShaderFunction(); diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index e9ee586f732..74cdb49258d 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -3525,12 +3525,6 @@ void QgsRasterLayer::setNoDataValue( double theNoDataValue ) void QgsRasterLayer::setRasterShaderFunction( QgsRasterShaderFunction* theFunction ) { - //Free old shader if it is not a userdefined shader - if ( mColorShadingAlgorithm != QgsRasterLayer::UserDefinedShader && 0 != mRasterShader->rasterShaderFunction() ) - { - delete( mRasterShader->rasterShaderFunction() ); - } - if ( theFunction ) { mRasterShader->setRasterShaderFunction( theFunction ); diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index fc690a9ac1d..0df2d4990dc 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -449,8 +449,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */ void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax ); - - /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent + + /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent \note added in v1.6 */ void computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax ); @@ -592,7 +592,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */ void setNoDataValue( double theNoData ); - /** \brief Set the raster shader function to a user defined function */ + /** \brief Set the raster shader function to a user defined function + \note ownership of the shader function is transfered to raster shader */ void setRasterShaderFunction( QgsRasterShaderFunction* theFunction ); /** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */ diff --git a/src/core/raster/qgsrastershader.cpp b/src/core/raster/qgsrastershader.cpp index a97869c5d6a..7291fb16938 100644 --- a/src/core/raster/qgsrastershader.cpp +++ b/src/core/raster/qgsrastershader.cpp @@ -31,6 +31,7 @@ QgsRasterShader::QgsRasterShader( double theMinimumValue, double theMaximumValue QgsRasterShader::~QgsRasterShader() { + delete mRasterShaderFunction; } /** @@ -84,6 +85,7 @@ void QgsRasterShader::setRasterShaderFunction( QgsRasterShaderFunction* theFunct if ( 0 != theFunction ) { + delete mRasterShaderFunction; mRasterShaderFunction = theFunction; } } diff --git a/src/core/raster/qgsrastershader.h b/src/core/raster/qgsrastershader.h index 0216f059c5b..311efe58049 100644 --- a/src/core/raster/qgsrastershader.h +++ b/src/core/raster/qgsrastershader.h @@ -56,7 +56,8 @@ class CORE_EXPORT QgsRasterShader /** \brief generates and new RGB value based on original RGB value */ bool shade( double, double, double, int*, int*, int* ); - /** \brief A public method that allows the user to set their own shader function */ + /** \brief A public method that allows the user to set their own shader function + \note Raster shader takes ownership of the shader function instance */ void setRasterShaderFunction( QgsRasterShaderFunction* ); /** \brief Set the maximum value */