Skip to content

Commit 732a899

Browse files
committed
Use color name to compare colors when adding new recent color, prevents
duplicate colors in recent color list
1 parent 344eccd commit 732a899

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/gui/qgscolorbuttonv2.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,21 @@ void QgsColorButtonV2::addRecentColor( const QColor& color )
519519

520520
QSettings settings;
521521
QList< QVariant > recentColorVariants = settings.value( QString( "/colors/recent" ) ).toList();
522-
QVariant colorVariant = QVariant( opaqueColor );
523-
recentColorVariants.removeAll( colorVariant );
524522

523+
//remove colors by name
524+
for ( int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
525+
{
526+
if (( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
527+
{
528+
recentColorVariants.removeAt( colorIdx );
529+
}
530+
}
531+
532+
//add color
533+
QVariant colorVariant = QVariant( opaqueColor );
525534
recentColorVariants.prepend( colorVariant );
526535

536+
//trim to 20 colors
527537
while ( recentColorVariants.count() > 20 )
528538
{
529539
recentColorVariants.pop_back();

0 commit comments

Comments
 (0)