Skip to content
Permalink
Browse files

QgsColorRampShader can have color ramp legend node settings

  • Loading branch information
nyalldawson committed Dec 18, 2020
1 parent e48286c commit 45d2edda161e764818f7f47e9c824016122a02eb
@@ -11,7 +11,6 @@




class QgsColorRampShader : QgsRasterShaderFunction
{
%Docstring
@@ -206,6 +205,22 @@ Sets whether the shader should not render values out of range.
Returns whether the shader will clip values which are out of range.

.. seealso:: :py:func:`setClip`
%End

const QgsColorRampLegendNodeSettings *legendSettings() const;
%Docstring
Returns the color ramp shader legend settings.

.. seealso:: :py:func:`setLegendSettings`
%End

void setLegendSettings( QgsColorRampLegendNodeSettings *settings /Transfer/ );
%Docstring
Sets the color ramp shader legend ``settings``.

Ownership of ``settings`` is transferred.

.. seealso:: :py:func:`legendSettings`
%End

protected:
@@ -54,6 +54,7 @@ QgsColorRampShader::QgsColorRampShader( const QgsColorRampShader &other )
, mLUTFactor( other.mLUTFactor )
, mLUTInitialized( other.mLUTInitialized )
, mClip( other.mClip )
, mLegendSettings( other.legendSettings() ? new QgsColorRampLegendNodeSettings( *other.legendSettings() ) : new QgsColorRampLegendNodeSettings() )
{
if ( auto *lSourceColorRamp = other.sourceColorRamp() )
mSourceColorRamp.reset( lSourceColorRamp->clone() );
@@ -76,6 +77,7 @@ QgsColorRampShader &QgsColorRampShader::operator=( const QgsColorRampShader &oth
mLUTInitialized = other.mLUTInitialized;
mClip = other.mClip;
mColorRampItemList = other.mColorRampItemList;
mLegendSettings.reset( other.legendSettings() ? new QgsColorRampLegendNodeSettings( *other.legendSettings() ) : new QgsColorRampLegendNodeSettings() );
return *this;
}

@@ -533,6 +535,10 @@ QDomElement QgsColorRampShader::writeXml( QDomDocument &doc, const QgsReadWriteC
itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
colorRampShaderElem.appendChild( itemElem );
}

if ( mLegendSettings )
mLegendSettings->writeXml( doc, colorRampShaderElem, context );

return colorRampShaderElem;
}

@@ -571,4 +577,21 @@ void QgsColorRampShader::readXml( const QDomElement &colorRampShaderElem, const
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
}
setColorRampItemList( itemList );

if ( !mLegendSettings )
mLegendSettings = qgis::make_unique< QgsColorRampLegendNodeSettings >();

mLegendSettings->readXml( colorRampShaderElem, context );
}

const QgsColorRampLegendNodeSettings *QgsColorRampShader::legendSettings() const
{
return mLegendSettings.get();
}

void QgsColorRampShader::setLegendSettings( QgsColorRampLegendNodeSettings *settings )
{
if ( settings == mLegendSettings.get() )
return;
mLegendSettings.reset( settings );
}
@@ -33,7 +33,7 @@ originally part of the larger QgsRasterLayer class

class QgsColorRamp;
class QgsRasterInterface;

class QgsColorRampLegendNodeSettings;

/**
* \ingroup core
@@ -226,6 +226,22 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
*/
bool clip() const { return mClip; }

/**
* Returns the color ramp shader legend settings.
*
* \see setLegendSettings()
*/
const QgsColorRampLegendNodeSettings *legendSettings() const;

/**
* Sets the color ramp shader legend \a settings.
*
* Ownership of \a settings is transferred.
*
* \see legendSettings()
*/
void setLegendSettings( QgsColorRampLegendNodeSettings *settings SIP_TRANSFER );

protected:

//! Source color ramp
@@ -257,6 +273,8 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
//! Do not render values out of range
bool mClip = false;

std::unique_ptr< QgsColorRampLegendNodeSettings > mLegendSettings;

};

#endif

0 comments on commit 45d2edd

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