Skip to content

Commit e304c4d

Browse files
committedAug 29, 2016
Fix limited random color ramp always returns 1 less color than set
(cherry-picked from 1d98b10)
1 parent f23b778 commit e304c4d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,11 @@ double QgsVectorRandomColorRampV2::value( int index ) const
296296

297297
QColor QgsVectorRandomColorRampV2::color( double value ) const
298298
{
299+
if ( value < 0 || value > 1 )
300+
return QColor();
301+
299302
int colorCnt = mColors.count();
300-
int colorIdx = static_cast< int >( value * ( colorCnt - 1 ) );
303+
int colorIdx = qMin( static_cast< int >( value * colorCnt ), colorCnt - 1 );
301304

302305
if ( colorIdx >= 0 && colorIdx < colorCnt )
303306
return mColors.at( colorIdx );

0 commit comments

Comments
 (0)
Please sign in to comment.