Skip to content
Permalink
Browse files

Use color name to compare colors when adding new recent color, prevents

duplicate colors in recent color list
  • Loading branch information
nyalldawson committed Oct 8, 2014
1 parent 344eccd commit 732a8994d2ae3143d1afa88bb81286ccf6f37f72
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/gui/qgscolorbuttonv2.cpp
@@ -519,11 +519,21 @@ void QgsColorButtonV2::addRecentColor( const QColor& color )

QSettings settings;
QList< QVariant > recentColorVariants = settings.value( QString( "/colors/recent" ) ).toList();
QVariant colorVariant = QVariant( opaqueColor );
recentColorVariants.removeAll( colorVariant );

//remove colors by name
for ( int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
{
if (( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
{
recentColorVariants.removeAt( colorIdx );
}
}

//add color
QVariant colorVariant = QVariant( opaqueColor );
recentColorVariants.prepend( colorVariant );

//trim to 20 colors
while ( recentColorVariants.count() > 20 )
{
recentColorVariants.pop_back();

0 comments on commit 732a899

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