Skip to content
Permalink
Browse files

[FEATURE] save and restore color ramp used for singleband pseudocolor…

… rendering
  • Loading branch information
alexbruy committed Nov 2, 2016
1 parent 1c44d74 commit 2497375ee95c5eb3046a8316793adf75c4ef1768
@@ -35,6 +35,7 @@ QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximu
, mLUTFactor( 1.0 )
, mLUTInitialized( false )
, mClip( false )
, mColorRampName( "" )
{
QgsDebugMsgLevel( "called.", 4 );
}
@@ -82,6 +83,12 @@ void QgsColorRampShader::setColorRampType( const QString& theType )
}
}

void QgsColorRampShader::setColorRampName( const QString& theName )
{
mColorRampName = theName;
}


bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue, int *theReturnAlphaValue )
{
if ( mColorRampItemList.isEmpty() )
@@ -75,6 +75,9 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
//! \brief Get the color ramp type as a string
QString colorRampTypeAsQString();

//! \brief Get the original color ramp name
QString colorRampName() const {return mColorRampName;}

//! \brief Set custom colormap
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set

@@ -84,6 +87,9 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
//! \brief Set the color ramp type
void setColorRampType( const QString& theType );

//! \brief Set the source color ramp name
void setColorRampName( const QString& theName );

//! \brief Generates and new RGB value based on one input value
bool shade( double, int*, int*, int*, int* ) override;

@@ -121,6 +127,9 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
double mLUTFactor;
bool mLUTInitialized;

/** Colorramp name*/
QString mColorRampName;

//! Do not render values out of range
bool mClip;
};
@@ -143,7 +143,8 @@ void QgsRasterShader::writeXml( QDomDocument& doc, QDomElement& parent ) const
if ( colorRampShader )
{
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampShader->colorRampTypeAsQString() );
colorRampShaderElem.setAttribute( "colorRampName", colorRampShader->colorRampName() );
colorRampShaderElem.setAttribute( "colorRampType", colorRampShader->colorRampTypeAsQString() );
colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), colorRampShader->clip() );
//items
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
@@ -169,6 +170,7 @@ void QgsRasterShader::readXml( const QDomElement& elem )
if ( !colorRampShaderElem.isNull() )
{
QgsColorRampShader* colorRampShader = new QgsColorRampShader();
colorRampShader->setColorRampName( colorRampShaderElem.attribute( "colorRampName", "" ) );
colorRampShader->setColorRampType( colorRampShaderElem.attribute( QStringLiteral( "colorRampType" ), QStringLiteral( "INTERPOLATED" ) ) );
colorRampShader->setClip( colorRampShaderElem.attribute( QStringLiteral( "clip" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );

@@ -63,6 +63,7 @@ QgsSingleBandPseudoColorRenderer* QgsSingleBandPseudoColorRenderer::clone() cons
{
QgsColorRampShader * colorRampShader = new QgsColorRampShader( mShader->minimumValue(), mShader->maximumValue() );

colorRampShader->setColorRampName( origColorRampShader->colorRampName() );
colorRampShader->setColorRampType( origColorRampShader->colorRampType() );
colorRampShader->setClip( origColorRampShader->clip() );
colorRampShader->setColorRampItemList( origColorRampShader->colorRampItemList() );
@@ -152,6 +152,7 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()

QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->currentData().toInt() );
colorRampShader->setColorRampType( interpolation );
colorRampShader->setColorRampName( mColorRampComboBox->currentText() );
rasterShader->setRasterShaderFunction( colorRampShader );

int bandNumber = mBandComboBox->currentData().toInt();
@@ -792,6 +793,14 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
if ( colorRampShader )
{
int idx = mColorRampComboBox->findText( colorRampShader->colorRampName() );
if ( idx == -1 )
{
QSettings settings;
QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString();
idx = mColorRampComboBox->findText( defaultPalette );
}
mColorRampComboBox->setCurrentIndex( idx );
mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader->colorRampType() ) );

const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();

0 comments on commit 2497375

Please sign in to comment.
You can’t perform that action at this time.