Raster shader fixes:

- memory leaks when changing shader functions
- PyQGIS: subclassing of raster shader function instances
- PyQGIS: transfer ownership of the shader function to c++


git-svn-id: http://svn.osgeo.org/qgis/trunk@14022 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2010-08-07 14:28:20 +00:00
parent 45260144ff
commit 84003c00cd
7 changed files with 29 additions and 14 deletions

View File

@ -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 );

View File

@ -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 */

View File

@ -3,8 +3,23 @@ class QgsRasterShaderFunction
{
%TypeHeaderCode
#include <qgsrastershaderfunction.h>
#include <qgscolorrampshader.h>
#include <qgsfreakoutshader.h>
#include <qgspseudocolorshader.h>
%End
%ConvertToSubClassCode
if (dynamic_cast<QgsColorRampShader*>(sipCpp) != NULL)
sipClass = sipClass_QgsColorRampShader;
else if (dynamic_cast<QgsFreakOutShader*>(sipCpp) != NULL)
sipClass = sipClass_QgsFreakOutShader;
else if (dynamic_cast<QgsPseudoColorShader*>(sipCpp) != NULL)
sipClass = sipClass_QgsPseudoColorShader;
else
sipClass = 0;
%End
public:
QgsRasterShaderFunction(double theMinimumValue = 0.0, double theMaximumValue = 255.0);
virtual ~QgsRasterShaderFunction();

View File

@ -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 );

View File

@ -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) */

View File

@ -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;
}
}

View File

@ -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 */