Skip to content
Permalink
Browse files

-Fixed problem when loading of default style, closes ticket #1480

-Added additional initialization of QgsRasterLayer class variables
-Plugged a memory leak when chaning shaders

git-svn-id: http://svn.osgeo.org/qgis/trunk@10172 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts
ersts committed Feb 15, 2009
1 parent ac0b428 commit 9162fc406844db6691792cb5beccdd59711a2abb
Showing with 46 additions and 12 deletions.
  1. +46 −12 src/core/raster/qgsrasterlayer.cpp
@@ -85,22 +85,31 @@ QgsRasterLayer::QgsRasterLayer(
mInvertColor( false )
{

mRasterType = QgsRasterLayer::GrayOrUndefined;

mRedBandName = TRSTRING_NOT_SET;
mGreenBandName = TRSTRING_NOT_SET;
mBlueBandName = TRSTRING_NOT_SET;
mGrayBandName = TRSTRING_NOT_SET;
mTransparencyBandName = TRSTRING_NOT_SET;


mUserDefinedRGBMinimumMaximum = false; //defaults needed to bypass enhanceContrast
mUserDefinedGrayMinimumMaximum = false;
mRGBMinimumMaximumEstimated = true;
mGrayMinimumMaximumEstimated = true;

mDrawingStyle = QgsRasterLayer::UndefinedDrawingStyle;
mContrastEnhancementAlgorithm = QgsContrastEnhancement::NoEnhancement;
mColorShadingAlgorithm = QgsRasterLayer::UndefinedShader;
mRasterShader = new QgsRasterShader();

if ( loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
if ( defaultLoadedFlag )
{
return;
}
}
mHasPyramids = false;
mNoDataValue = -9999;
mValidNoDataValue = false;

mGdalBaseDataset = 0;
mGdalDataset = 0;

// Initialise the affine transform matrix
mGeoTransform[0] = 0;
@@ -121,6 +130,18 @@ QgsRasterLayer::QgsRasterLayer(
if ( ! path.isEmpty() )
{
readFile( path ); // XXX check for failure?

//readFile() is really an extension of the constructor as many imporant fields are set in this method
//loadDefaultStyle() can not be called before the layer has actually be opened
if ( loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
if ( defaultLoadedFlag )
{
return;
}
}
}

} // QgsRasterLayer ctor
@@ -199,6 +220,10 @@ QgsRasterLayer::~QgsRasterLayer()
if ( mGdalBaseDataset )
{
GDALDereferenceDataset( mGdalBaseDataset );
}

if( mGdalDataset )
{
GDALClose( mGdalDataset );
}
}
@@ -3162,8 +3187,6 @@ void QgsRasterLayer::setColorShadingAlgorithm( ColorShadingAlgorithm theShadingA
mRasterShader = new QgsRasterShader();
}

mColorShadingAlgorithm = theShadingAlgorithm;

switch ( theShadingAlgorithm )
{
case PseudoColorShader:
@@ -3182,6 +3205,9 @@ void QgsRasterLayer::setColorShadingAlgorithm( ColorShadingAlgorithm theShadingA
mRasterShader->setRasterShaderFunction( new QgsRasterShaderFunction() );
break;
}

//Set the class variable after the call to setRasterShader(), so memory recovery can happen
mColorShadingAlgorithm = theShadingAlgorithm;
}
QgsDebugMsg( "mColorShadingAlgorithm = " + QString::number( theShadingAlgorithm ) );
}
@@ -3378,6 +3404,12 @@ 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 );
@@ -3387,7 +3419,7 @@ void QgsRasterLayer::setRasterShaderFunction( QgsRasterShaderFunction* theFuncti
{
//If NULL as passed in, set a default shader function to prevent segfaults
mRasterShader->setRasterShaderFunction( new QgsRasterShaderFunction() );
mColorShadingAlgorithm = QgsRasterLayer::UserDefinedShader;
mColorShadingAlgorithm = QgsRasterLayer::UndefinedShader;
}
}

@@ -5175,6 +5207,8 @@ bool QgsRasterLayer::readFile( QString const &theFilename )
//Set up a new color ramp shader
setColorShadingAlgorithm( ColorRampShader );
QgsColorRampShader* myColorRampShader = ( QgsColorRampShader* ) mRasterShader->rasterShaderFunction();
//TODO: Make sure the set algorithm and cast was successful,
//e.g., if ( 0 != myColorRampShader && myColorRampShader->shaderTypeAsString == "ColorRampShader" )
myColorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
myColorRampShader->setColorRampItemList( *colorTable( 1 ) );
}

0 comments on commit 9162fc4

Please sign in to comment.