Navigation Menu

Skip to content

Commit

Permalink
[categorized renderer] When color ramp is set to random, randomize color
Browse files Browse the repository at this point in the history
of appended categories to pre-existing list when hitting the
classify button (fixes #31579)
  • Loading branch information
nirvn committed Sep 16, 2019
1 parent 7413335 commit 6db7e9e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Expand Up @@ -739,6 +739,9 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
{
QgsCategoryList prevCats = mRenderer->categories();
keepExistingColors = !prevCats.isEmpty();
QgsRandomColorRamp randomColors;
if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
randomColors.setTotalColorCount( cats.size() );
for ( int i = 0; i < cats.size(); ++i )
{
bool contains = false;
Expand All @@ -753,7 +756,14 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
}

if ( !contains )
{
if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
{
// insure that append symbols have random colors
cats.at( i ).symbol()->setColor( randomColors.color( i ) );
}
prevCats.append( cats.at( i ) );
}
}
cats = prevCats;
}
Expand Down

0 comments on commit 6db7e9e

Please sign in to comment.