Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-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 committed Feb 15, 2009
1 parent ac0b428 commit 9162fc4
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -199,6 +220,10 @@ QgsRasterLayer::~QgsRasterLayer()
if ( mGdalBaseDataset )
{
GDALDereferenceDataset( mGdalBaseDataset );
}

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

mColorShadingAlgorithm = theShadingAlgorithm;

switch ( theShadingAlgorithm )
{
case PseudoColorShader:
Expand All @@ -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 ) );
}
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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 ) );
}
Expand Down

0 comments on commit 9162fc4

Please sign in to comment.