Skip to content

Commit 38e5d59

Browse files
author
wonder
committed
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/qgis@14022 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a92f86a commit 38e5d59

7 files changed

+29
-14
lines changed

python/core/qgsrasterlayer.sip

+3-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ public:
426426
/** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */
427427
void setNoDataValue( double theNoData );
428428

429-
/** \brief Set the raster shader function to a user defined function */
430-
void setRasterShaderFunction( QgsRasterShaderFunction* theFunction );
429+
/** \brief Set the raster shader function to a user defined function
430+
\note ownership of the shader function is transfered to raster shader */
431+
void setRasterShaderFunction( QgsRasterShaderFunction* theFunction /Transfer/ );
431432

432433
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */
433434
void setRedBandName( const QString & theBandName );

python/core/qgsrastershader.sip

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public:
3131
bool shade(double, int* /Out/, int* /Out/, int* /Out/);
3232
/** \brief generates and new RGB value based on original RGB value */
3333
bool shade(double, double, double, int* /Out/, int* /Out/, int* /Out/);
34-
/** \brief A public method that allows the user to set their own shader function */
35-
void setRasterShaderFunction(QgsRasterShaderFunction*);
34+
/** \brief A public method that allows the user to set their own shader function
35+
\note Raster shader takes ownership of the shader function instance */
36+
void setRasterShaderFunction(QgsRasterShaderFunction* /Transfer/);
3637
/** \brief Set the maximum value */
3738
void setMaximumValue(double);
3839
/** \brief Return the minimum value */

python/core/qgsrastershaderfunction.sip

+15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@ class QgsRasterShaderFunction
33
{
44
%TypeHeaderCode
55
#include <qgsrastershaderfunction.h>
6+
#include <qgscolorrampshader.h>
7+
#include <qgsfreakoutshader.h>
8+
#include <qgspseudocolorshader.h>
69
%End
710

11+
%ConvertToSubClassCode
12+
if (dynamic_cast<QgsColorRampShader*>(sipCpp) != NULL)
13+
sipClass = sipClass_QgsColorRampShader;
14+
else if (dynamic_cast<QgsFreakOutShader*>(sipCpp) != NULL)
15+
sipClass = sipClass_QgsFreakOutShader;
16+
else if (dynamic_cast<QgsPseudoColorShader*>(sipCpp) != NULL)
17+
sipClass = sipClass_QgsPseudoColorShader;
18+
else
19+
sipClass = 0;
20+
%End
21+
22+
823
public:
924
QgsRasterShaderFunction(double theMinimumValue = 0.0, double theMaximumValue = 255.0);
1025
virtual ~QgsRasterShaderFunction();

src/core/raster/qgsrasterlayer.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -3525,12 +3525,6 @@ void QgsRasterLayer::setNoDataValue( double theNoDataValue )
35253525

35263526
void QgsRasterLayer::setRasterShaderFunction( QgsRasterShaderFunction* theFunction )
35273527
{
3528-
//Free old shader if it is not a userdefined shader
3529-
if ( mColorShadingAlgorithm != QgsRasterLayer::UserDefinedShader && 0 != mRasterShader->rasterShaderFunction() )
3530-
{
3531-
delete( mRasterShader->rasterShaderFunction() );
3532-
}
3533-
35343528
if ( theFunction )
35353529
{
35363530
mRasterShader->setRasterShaderFunction( theFunction );

src/core/raster/qgsrasterlayer.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
449449

450450
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
451451
void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );
452-
453-
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
452+
453+
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
454454
\note added in v1.6 */
455455
void computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax );
456456

@@ -592,7 +592,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
592592
/** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */
593593
void setNoDataValue( double theNoData );
594594

595-
/** \brief Set the raster shader function to a user defined function */
595+
/** \brief Set the raster shader function to a user defined function
596+
\note ownership of the shader function is transfered to raster shader */
596597
void setRasterShaderFunction( QgsRasterShaderFunction* theFunction );
597598

598599
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */

src/core/raster/qgsrastershader.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ QgsRasterShader::QgsRasterShader( double theMinimumValue, double theMaximumValue
3131

3232
QgsRasterShader::~QgsRasterShader()
3333
{
34+
delete mRasterShaderFunction;
3435
}
3536

3637
/**
@@ -84,6 +85,7 @@ void QgsRasterShader::setRasterShaderFunction( QgsRasterShaderFunction* theFunct
8485

8586
if ( 0 != theFunction )
8687
{
88+
delete mRasterShaderFunction;
8789
mRasterShaderFunction = theFunction;
8890
}
8991
}

src/core/raster/qgsrastershader.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class CORE_EXPORT QgsRasterShader
5656
/** \brief generates and new RGB value based on original RGB value */
5757
bool shade( double, double, double, int*, int*, int* );
5858

59-
/** \brief A public method that allows the user to set their own shader function */
59+
/** \brief A public method that allows the user to set their own shader function
60+
\note Raster shader takes ownership of the shader function instance */
6061
void setRasterShaderFunction( QgsRasterShaderFunction* );
6162

6263
/** \brief Set the maximum value */

0 commit comments

Comments
 (0)