@@ -597,19 +597,36 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
597
597
{
598
598
case PalettedColor:
599
599
{
600
- // create color array for renderer
600
+ // todo: go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous
601
601
int grayBand = bandNumber ( grayBandName () );
602
- QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList [ grayBand - 1 ].colorTable ;
603
- QColor* colorArray = new QColor[itemList.size ()];
604
- QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin ();
605
- for ( ; colorIt != itemList.constEnd (); ++colorIt )
602
+ QgsColorRampShader* colorRampShader = dynamic_cast <QgsColorRampShader*>( rasterShader ()->rasterShaderFunction () );
603
+ if ( colorRampShader )
606
604
{
607
- colorArray[( int )colorIt->value ] = colorIt->color ;
605
+ QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList ();
606
+ QColor* colorArray = new QColor[ colorEntries.size ()];
607
+ QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin ();
608
+ for ( ; colorIt != colorEntries.constEnd (); ++colorIt )
609
+ {
610
+ colorArray[( int )( colorIt->value )] = colorIt->color ;
611
+ }
612
+
613
+ renderer = new QgsPalettedRasterRenderer ( mDataProvider ,
614
+ grayBand,
615
+ colorArray,
616
+ colorEntries.size () );
617
+ }
618
+ else // try to get it from the color table
619
+ {
620
+ QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList [ grayBand - 1 ].colorTable ;
621
+ QColor* colorArray = new QColor[itemList.size ()];
622
+ QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin ();
623
+ for ( ; colorIt != itemList.constEnd (); ++colorIt )
624
+ {
625
+ colorArray[( int )colorIt->value ] = colorIt->color ;
626
+ }
627
+ renderer = new QgsPalettedRasterRenderer ( mDataProvider ,
628
+ grayBand, colorArray, itemList.size () );
608
629
}
609
- renderer = new QgsPalettedRasterRenderer ( mDataProvider ,
610
- grayBand,
611
- colorArray,
612
- itemList.size () );
613
630
break ;
614
631
}
615
632
case MultiBandSingleBandGray:
0 commit comments