@@ -597,19 +597,36 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
597597 {
598598 case PalettedColor:
599599 {
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
601601 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 )
606604 {
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 () );
608629 }
609- renderer = new QgsPalettedRasterRenderer ( mDataProvider ,
610- grayBand,
611- colorArray,
612- itemList.size () );
613630 break ;
614631 }
615632 case MultiBandSingleBandGray:
0 commit comments