Skip to content
Permalink
Browse files

Also use ramp based legend nodes for mesh layers

  • Loading branch information
nyalldawson committed Dec 16, 2020
1 parent bffd8eb commit 7fac0484231e788b08628033fd80c3e1b414ace0
Showing with 22 additions and 4 deletions.
  1. +22 −4 src/core/qgsmaplayerlegend.cpp
@@ -28,6 +28,7 @@
#include "qgssymbollayerutils.h"
#include "qgspointcloudrenderer.h"
#include "qgsrasterrenderer.h"
#include "qgscolorramplegendnode.h"

QgsMapLayerLegend::QgsMapLayerLegend( QObject *parent )
: QObject( parent )
@@ -471,11 +472,28 @@ QList<QgsLayerTreeModelLegendNode *> QgsDefaultMeshLayerLegend::createLayerTreeM
if ( indexScalar > -1 )
{
QgsMeshRendererScalarSettings settings = rendererSettings.scalarSettings( indexScalar );
QgsLegendColorList items;
settings.colorRampShader().legendSymbologyItems( items );
for ( const QPair< QString, QColor > &item : qgis::as_const( items ) )
const QgsColorRampShader shader = settings.colorRampShader();
switch ( shader.colorRampType() )
{
nodes << new QgsRasterSymbolLegendNode( nodeLayer, item.second, item.first );
case QgsColorRampShader::Interpolated:
// for interpolated shaders we use a ramp legend node
nodes << new QgsColorRampLegendNode( nodeLayer, shader.sourceColorRamp()->clone(),
QString::number( shader.minimumValue() ),
QString::number( shader.maximumValue() ) );
break;

case QgsColorRampShader::Discrete:
case QgsColorRampShader::Exact:
{
// for all others we use itemised lists
QgsLegendColorList items;
settings.colorRampShader().legendSymbologyItems( items );
for ( const QPair< QString, QColor > &item : items )
{
nodes << new QgsRasterSymbolLegendNode( nodeLayer, item.second, item.first );
}
break;
}
}
}

0 comments on commit 7fac048

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