Skip to content

Commit

Permalink
Insure that QgsColorUtils::colorFromString handle hex color strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 4, 2024
1 parent 58ff964 commit e3c5359
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/core/qgscolorutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,17 @@ QColor QgsColorUtils::colorFromString( const QString &string )
const QRegularExpressionMatch match = rx.match( string );
if ( !match.hasMatch() )
{
// try reading older color format
const thread_local QRegularExpression rgbArx( QStringLiteral( "^(\\d+),(\\d+),(\\d+),(\\d+)$" ) );
const QRegularExpressionMatch match = rgbArx.match( string );
if ( !match.hasMatch() )
return QColor();

const int red = match.captured( 1 ).toInt();
const int green = match.captured( 2 ).toInt();
const int blue = match.captured( 3 ).toInt();
const int alpha = match.captured( 4 ).toInt();
// try reading older color format and hex strings
const QStringList lst = string.split( ',' );
if ( lst.count() < 3 )
{
return QColor( string );
}
int red, green, blue, alpha;
red = lst[0].toInt();
green = lst[1].toInt();
blue = lst[2].toInt();
alpha = lst.count() > 3 ? lst[3].toInt() : 255;
return QColor( red, green, blue, alpha );
}

Expand Down

0 comments on commit e3c5359

Please sign in to comment.