Skip to content

Commit

Permalink
Raster shader fixes:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
wonder committed Aug 7, 2010
1 parent 4526014 commit 84003c0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
5 changes: 3 additions & 2 deletions python/core/qgsrasterlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
5 changes: 3 additions & 2 deletions python/core/qgsrastershader.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
15 changes: 15 additions & 0 deletions python/core/qgsrastershaderfunction.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
7 changes: 4 additions & 3 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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) */
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrastershader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ QgsRasterShader::QgsRasterShader( double theMinimumValue, double theMaximumValue

QgsRasterShader::~QgsRasterShader()
{
delete mRasterShaderFunction;
}

/**
Expand Down Expand Up @@ -84,6 +85,7 @@ void QgsRasterShader::setRasterShaderFunction( QgsRasterShaderFunction* theFunct

if ( 0 != theFunction )
{
delete mRasterShaderFunction;
mRasterShaderFunction = theFunction;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrastershader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 84003c0

Please sign in to comment.