diff --git a/src/core/symbology/qgssymbollayerutils.cpp b/src/core/symbology/qgssymbollayerutils.cpp index 6d04614cca28..c5048924df95 100644 --- a/src/core/symbology/qgssymbollayerutils.cpp +++ b/src/core/symbology/qgssymbollayerutils.cpp @@ -3921,14 +3921,29 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in (rrr,ggg,bbb) format, brackets and rgb prefix optional - const thread_local QRegularExpression rgbFormatRx( "^\\s*(?:rgb)?\\(?\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression rgbFormatRx( "^\\s*(?:rgb)?\\(?\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*,\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*,\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*\\)?\\s*;?\\s*$" ); match = rgbFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int r = match.captured( 1 ).toInt(); - const int g = match.captured( 2 ).toInt(); - const int b = match.captured( 3 ).toInt(); - parsedColor.setRgb( r, g, b ); + bool rOk = false; + bool gOk = false; + bool bOk = false; + const int r = match.captured( 1 ).toInt( &rOk ); + const int g = match.captured( 2 ).toInt( &gOk ); + const int b = match.captured( 3 ).toInt( &bOk ); + + if ( !rOk || !gOk || !bOk ) + { + const float rFloat = match.captured( 1 ).toFloat(); + const float gFloat = match.captured( 2 ).toFloat(); + const float bFloat = match.captured( 3 ).toFloat(); + parsedColor.setRgbF( rFloat / 255.0, gFloat / 255.0, bFloat / 255.0 ); + } + else + { + parsedColor.setRgb( r, g, b ); + } + if ( parsedColor.isValid() ) { containsAlpha = false; @@ -3937,14 +3952,28 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in hsl(h,s,l) format, brackets optional - const thread_local QRegularExpression hslFormatRx( "^\\s*hsl\\(?\\s*(\\d+)\\s*,\\s*(\\d+)\\s*%\\s*,\\s*(\\d+)\\s*%\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression hslFormatRx( "^\\s*hsl\\(?\\s*(\\d+(?:\\.\\d*)?)\\s*,\\s*(\\d+(?:\\.\\d*)?)\\s*%\\s*,\\s*(\\d+(?:\\.\\d*)?)\\s*%\\s*\\)?\\s*;?\\s*$" ); match = hslFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int h = match.captured( 1 ).toInt(); - const int s = match.captured( 2 ).toInt(); - const int l = match.captured( 3 ).toInt(); - parsedColor.setHsl( h, s / 100.0 * 255.0, l / 100.0 * 255.0 ); + bool hOk = false; + bool sOk = false; + bool lOk = false; + const int h = match.captured( 1 ).toInt( &hOk ); + const int s = match.captured( 2 ).toInt( &sOk ); + const int l = match.captured( 3 ).toInt( &lOk ); + + if ( !hOk || !sOk || !lOk ) + { + const float hFloat = match.captured( 1 ).toFloat(); + const float sFloat = match.captured( 2 ).toFloat(); + const float lFloat = match.captured( 3 ).toFloat(); + parsedColor.setHslF( hFloat / 360.0, sFloat / 100.0, lFloat / 100.0 ); + } + else + { + parsedColor.setHsl( h, s / 100.0 * 255.0, l / 100.0 * 255.0 ); + } if ( parsedColor.isValid() ) { containsAlpha = false; @@ -3953,14 +3982,14 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in (r%,g%,b%) format, brackets and rgb prefix optional - const thread_local QRegularExpression rgbPercentFormatRx( "^\\s*(?:rgb)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression rgbPercentFormatRx( "^\\s*(?:rgb)?\\(?\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*,\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*,\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*\\)?\\s*;?\\s*$" ); match = rgbPercentFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int r = std::round( match.captured( 1 ).toDouble() * 2.55 ); - const int g = std::round( match.captured( 2 ).toDouble() * 2.55 ); - const int b = std::round( match.captured( 3 ).toDouble() * 2.55 ); - parsedColor.setRgb( r, g, b ); + const double r = match.captured( 1 ).toDouble() / 100; + const double g = match.captured( 2 ).toDouble() / 100; + const double b = match.captured( 3 ).toDouble() / 100; + parsedColor.setRgbF( r, g, b ); if ( parsedColor.isValid() ) { containsAlpha = false; @@ -3969,15 +3998,30 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in (r,g,b,a) format, brackets and rgba prefix optional - const thread_local QRegularExpression rgbaFormatRx( "^\\s*(?:rgba)?\\(?\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression rgbaFormatRx( "^\\s*(?:rgba)?\\(?\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*,\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*,\\s*((?:[01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\\.\\d*)?)\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" ); match = rgbaFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int r = match.captured( 1 ).toInt(); - const int g = match.captured( 2 ).toInt(); - const int b = match.captured( 3 ).toInt(); - const int a = std::round( match.captured( 4 ).toDouble() * 255.0 ); - parsedColor.setRgb( r, g, b, a ); + bool rOk = false; + bool gOk = false; + bool bOk = false; + const int r = match.captured( 1 ).toInt( &rOk ); + const int g = match.captured( 2 ).toInt( &gOk ); + const int b = match.captured( 3 ).toInt( &bOk ); + const double aDouble = match.captured( 4 ).toDouble(); + + if ( !rOk || !gOk || !bOk ) + { + const float rFloat = match.captured( 1 ).toFloat(); + const float gFloat = match.captured( 2 ).toFloat(); + const float bFloat = match.captured( 3 ).toFloat(); + parsedColor.setRgbF( rFloat / 255.0, gFloat / 255.0, bFloat / 255.0, aDouble ); + } + else + { + const int a = static_cast< int >( std::round( match.captured( 4 ).toDouble() * 255.0 ) ); + parsedColor.setRgb( r, g, b, a ); + } if ( parsedColor.isValid() ) { containsAlpha = true; @@ -3986,15 +4030,15 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in (r%,g%,b%,a) format, brackets and rgba prefix optional - const thread_local QRegularExpression rgbaPercentFormatRx( "^\\s*(?:rgba)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression rgbaPercentFormatRx( "^\\s*(?:rgba)?\\(?\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*,\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*,\\s*(100|0*\\d{1,2}(?:\\.\\d*)?)\\s*%\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" ); match = rgbaPercentFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int r = std::round( match.captured( 1 ).toDouble() * 2.55 ); - const int g = std::round( match.captured( 2 ).toDouble() * 2.55 ); - const int b = std::round( match.captured( 3 ).toDouble() * 2.55 ); - const int a = std::round( match.captured( 4 ).toDouble() * 255.0 ); - parsedColor.setRgb( r, g, b, a ); + const double r = match.captured( 1 ).toDouble() / 100; + const double g = match.captured( 2 ).toDouble() / 100; + const double b = match.captured( 3 ).toDouble() / 100; + const double a = match.captured( 4 ).toDouble(); + parsedColor.setRgbF( r, g, b, a ); if ( parsedColor.isValid() ) { containsAlpha = true; @@ -4003,15 +4047,31 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & } //color in hsla(h,s%,l%,a) format, brackets optional - const thread_local QRegularExpression hslaPercentFormatRx( "^\\s*hsla\\(?\\s*(\\d+)\\s*,\\s*(\\d+)\\s*%\\s*,\\s*(\\d+)\\s*%\\s*,\\s*([\\d\\.]+)\\s*\\)?\\s*;?\\s*$" ); + const thread_local QRegularExpression hslaPercentFormatRx( "^\\s*hsla\\(?\\s*(\\d+(?:\\.\\d*)?)\\s*,\\s*(\\d+(?:\\.\\d*)?)\\s*%\\s*,\\s*(\\d+(?:\\.\\d*)?)\\s*%\\s*,\\s*([\\d\\.]+)\\s*\\)?\\s*;?\\s*$" ); match = hslaPercentFormatRx.match( colorStr ); if ( match.hasMatch() ) { - const int h = match.captured( 1 ).toInt(); - const int s = match.captured( 2 ).toInt(); - const int l = match.captured( 3 ).toInt(); - const int a = std::round( match.captured( 4 ).toDouble() * 255.0 ); - parsedColor.setHsl( h, s / 100.0 * 255.0, l / 100.0 * 255.0, a ); + bool hOk = false; + bool sOk = false; + bool lOk = false; + const int h = match.captured( 1 ).toInt( &hOk ); + const int s = match.captured( 2 ).toInt( &sOk ); + const int l = match.captured( 3 ).toInt( &lOk ); + const double aDouble = match.captured( 4 ).toDouble(); + + if ( !hOk || !sOk || !lOk ) + { + const float hFloat = match.captured( 1 ).toFloat(); + const float sFloat = match.captured( 2 ).toFloat(); + const float lFloat = match.captured( 3 ).toFloat(); + parsedColor.setHslF( hFloat / 360.0, sFloat / 100.0, lFloat / 100.0, aDouble ); + } + else + { + const int a = std::round( aDouble * 255.0 ); + parsedColor.setHsl( h, s / 100.0 * 255.0, l / 100.0 * 255.0, a ); + } + if ( parsedColor.isValid() ) { containsAlpha = true; diff --git a/tests/src/core/testqgssymbol.cpp b/tests/src/core/testqgssymbol.cpp index 281332e18181..f5de049fe791 100644 --- a/tests/src/core/testqgssymbol.cpp +++ b/tests/src/core/testqgssymbol.cpp @@ -204,6 +204,7 @@ void TestQgsSymbol::testParseColor() { // values for color tests QMap< QString, QPair< QColor, bool> > colorTests; + colorTests.insert( QStringLiteral( "bad color" ), qMakePair( QColor(), false ) ); colorTests.insert( QStringLiteral( "red" ), qMakePair( QColor( 255, 0, 0 ), false ) ); colorTests.insert( QStringLiteral( "#ff00ff" ), qMakePair( QColor( 255, 0, 255 ), false ) ); @@ -230,6 +231,7 @@ void TestQgsSymbol::testParseColor() colorTests.insert( QStringLiteral( "255,255,255" ), qMakePair( QColor( 255, 255, 255 ), false ) ); colorTests.insert( QStringLiteral( "256,60,0" ), qMakePair( QColor(), false ) ); colorTests.insert( QStringLiteral( "rgb(127,60,0)" ), qMakePair( QColor( 127, 60, 0 ), false ) ); + colorTests.insert( QStringLiteral( "rgb(127.5,60.5,0.5)" ), qMakePair( QColor::fromRgbF( 127.5 / 255.0, 60.5 / 255.0, 0.5 / 255.0 ), false ) ); colorTests.insert( QStringLiteral( "rgb(255,255,255)" ), qMakePair( QColor( 255, 255, 255 ), false ) ); colorTests.insert( QStringLiteral( "rgb(256,60,0)" ), qMakePair( QColor(), false ) ); colorTests.insert( QStringLiteral( " rgb( 127, 60 , 0 ) " ), qMakePair( QColor( 127, 60, 0 ), false ) ); @@ -238,10 +240,13 @@ void TestQgsSymbol::testParseColor() colorTests.insert( QStringLiteral( "hsl( 30 , 19 % , 90 % )" ), qMakePair( QColor::fromHsl( 30, 48, 229 ), false ) ); colorTests.insert( QStringLiteral( " hsl( 30, 19%, 90% ) " ), qMakePair( QColor::fromHsl( 30, 48, 229 ), false ) ); colorTests.insert( QStringLiteral( "hsl(30,19%,90%);" ), qMakePair( QColor::fromHsl( 30, 48, 229 ), false ) ); + colorTests.insert( QStringLiteral( "hsl(30,19%,90%);" ), qMakePair( QColor::fromHsl( 30, 48, 229 ), false ) ); + colorTests.insert( QStringLiteral( "hsl(74.5, 15.6%, 77.1%)" ), qMakePair( QColor::fromHslF( 0.206944444, 0.156, 0.771 ), false ) ); colorTests.insert( QStringLiteral( "hsla(30,19%,90%,0.4)" ), qMakePair( QColor::fromHsl( 30, 48, 229, 102 ), true ) ); colorTests.insert( QStringLiteral( "hsla( 30 , 19 % , 90 % , 0.4 )" ), qMakePair( QColor::fromHsl( 30, 48, 229, 102 ), true ) ); colorTests.insert( QStringLiteral( " hsla( 30, 19%, 90%, 0.4 ) " ), qMakePair( QColor::fromHsl( 30, 48, 229, 102 ), true ) ); colorTests.insert( QStringLiteral( "hsla(30,19%,90%,0.4);" ), qMakePair( QColor::fromHsl( 30, 48, 229, 102 ), true ) ); + colorTests.insert( QStringLiteral( "hsla(74.5, 15.6%, 77.1%, 0.44)" ), qMakePair( QColor::fromHslF( 0.206944444, 0.156, 0.771, 0.44 ), true ) ); colorTests.insert( QStringLiteral( "(127,60,0);" ), qMakePair( QColor( 127, 60, 0 ), false ) ); colorTests.insert( QStringLiteral( "(127,60,0)" ), qMakePair( QColor( 127, 60, 0 ), false ) ); colorTests.insert( QStringLiteral( "127,060,000" ), qMakePair( QColor( 127, 60, 0 ), false ) ); @@ -252,29 +257,32 @@ void TestQgsSymbol::testParseColor() colorTests.insert( QStringLiteral( "rgba(255,255,255,0.0)" ), qMakePair( QColor( 255, 255, 255, 0 ), true ) ); colorTests.insert( QStringLiteral( " rgba( 127, 60 , 0 , 0.2 ) " ), qMakePair( QColor( 127, 60, 0, 51 ), true ) ); colorTests.insert( QStringLiteral( "rgba(127,60,0,0.1);" ), qMakePair( QColor( 127, 60, 0, 26 ), true ) ); + colorTests.insert( QStringLiteral( "rgba(127.5,60.5,0.5,0.1)" ), qMakePair( QColor::fromRgbF( 127.5 / 255.0, 60.5 / 255.0, 0.5 / 255.0, 0.1 ), true ) ); colorTests.insert( QStringLiteral( "(127,60,0,1);" ), qMakePair( QColor( 127, 60, 0, 255 ), true ) ); colorTests.insert( QStringLiteral( "(127,60,0,1.0)" ), qMakePair( QColor( 127, 60, 0, 255 ), true ) ); colorTests.insert( QStringLiteral( "127,060,000,1" ), qMakePair( QColor( 127, 60, 0, 255 ), true ) ); colorTests.insert( QStringLiteral( "0%,0%,0%" ), qMakePair( QColor( 0, 0, 0 ), false ) ); - colorTests.insert( QStringLiteral( "50 %,60 %,0 %" ), qMakePair( QColor( 127, 153, 0 ), false ) ); + colorTests.insert( QStringLiteral( "50 %,60 %,0 %" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); colorTests.insert( QStringLiteral( "100%, 100%, 100%" ), qMakePair( QColor( 255, 255, 255 ), false ) ); - colorTests.insert( QStringLiteral( "rgb(50%,60%,0%)" ), qMakePair( QColor( 127, 153, 0 ), false ) ); + colorTests.insert( QStringLiteral( "rgb(50%,60%,0%)" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); colorTests.insert( QStringLiteral( "rgb(100%, 100%, 100%)" ), qMakePair( QColor( 255, 255, 255 ), false ) ); - colorTests.insert( QStringLiteral( " rgb( 50 % , 60 % , 0 % ) " ), qMakePair( QColor( 127, 153, 0 ), false ) ); - colorTests.insert( QStringLiteral( "rgb(50%,60%,0%);" ), qMakePair( QColor( 127, 153, 0 ), false ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%);" ), qMakePair( QColor( 127, 153, 0 ), false ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%)" ), qMakePair( QColor( 127, 153, 0 ), false ) ); - colorTests.insert( QStringLiteral( "050%,060%,000%" ), qMakePair( QColor( 127, 153, 0 ), false ) ); + colorTests.insert( QStringLiteral( " rgb( 50 % , 60 % , 0 % ) " ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); + colorTests.insert( QStringLiteral( "rgb(50%,60%,0%);" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); + colorTests.insert( QStringLiteral( "rgb(50.5%,60.6%,0.8%)" ), qMakePair( QColor::fromRgbF( 0.505, 0.606, 0.008 ), false ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%);" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%)" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); + colorTests.insert( QStringLiteral( "050%,060%,000%" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0 ), false ) ); colorTests.insert( QStringLiteral( "0%,0%,0%,0" ), qMakePair( QColor( 0, 0, 0, 0 ), true ) ); - colorTests.insert( QStringLiteral( "50 %,60 %,0 %,0.5" ), qMakePair( QColor( 127, 153, 0, 128 ), true ) ); + colorTests.insert( QStringLiteral( "50 %,60 %,0 %,0.5" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 0.5 ), true ) ); colorTests.insert( QStringLiteral( "100%, 100%, 100%, 1.0" ), qMakePair( QColor( 255, 255, 255, 255 ), true ) ); - colorTests.insert( QStringLiteral( "rgba(50%,60%,0%, 1.0)" ), qMakePair( QColor( 127, 153, 0, 255 ), true ) ); + colorTests.insert( QStringLiteral( "rgba(50%,60%,0%, 1.0)" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 1.0 ), true ) ); colorTests.insert( QStringLiteral( "rgba(100%, 100%, 100%, 0.0)" ), qMakePair( QColor( 255, 255, 255, 0 ), true ) ); - colorTests.insert( QStringLiteral( " rgba( 50 % , 60 % , 0 %, 0.5 ) " ), qMakePair( QColor( 127, 153, 0, 128 ), true ) ); - colorTests.insert( QStringLiteral( "rgba(50%,60%,0%,0);" ), qMakePair( QColor( 127, 153, 0, 0 ), true ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%,1);" ), qMakePair( QColor( 127, 153, 0, 255 ), true ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%,1.0)" ), qMakePair( QColor( 127, 153, 0, 255 ), true ) ); - colorTests.insert( QStringLiteral( "050%,060%,000%,0" ), qMakePair( QColor( 127, 153, 0, 0 ), true ) ); + colorTests.insert( QStringLiteral( " rgba( 50 % , 60 % , 0 %, 0.5 ) " ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 0.5 ), true ) ); + colorTests.insert( QStringLiteral( "rgba(50%,60%,0%,0);" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 0 ), true ) ); + colorTests.insert( QStringLiteral( "rgba(50.5%,60.6%,0.8%, 0.5)" ), qMakePair( QColor::fromRgbF( 0.505, 0.606, 0.008, 0.5 ), true ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%,1);" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 1.0 ), true ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%,1.0)" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 1.0 ), true ) ); + colorTests.insert( QStringLiteral( "050%,060%,000%,0" ), qMakePair( QColor::fromRgbF( 0.5, 0.6, 0, 0 ), true ) ); QMap >::const_iterator i = colorTests.constBegin(); while ( i != colorTests.constEnd() ) @@ -282,8 +290,8 @@ void TestQgsSymbol::testParseColor() QgsDebugMsgLevel( "color string: " + i.key(), 1 ); bool hasAlpha = false; const QColor result = QgsSymbolLayerUtils::parseColorWithAlpha( i.key(), hasAlpha ); - QVERIFY( result == i.value().first ); - QVERIFY( hasAlpha == i.value().second ); + QCOMPARE( result, i.value().first ); + QCOMPARE( hasAlpha, i.value().second ); ++i; } } @@ -337,25 +345,25 @@ void TestQgsSymbol::testParseColorList() colorTests.insert( QStringLiteral( "(127,60,0,1.0)" ), QColor( 127, 60, 0, 255 ) ); colorTests.insert( QStringLiteral( "127,060,000,1" ), QColor( 127, 60, 0, 255 ) ); colorTests.insert( QStringLiteral( "0%,0%,0%" ), QColor( 0, 0, 0 ) ); - colorTests.insert( QStringLiteral( "50 %,60 %,0 %" ), QColor( 127, 153, 0 ) ); + colorTests.insert( QStringLiteral( "50 %,60 %,0 %" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); colorTests.insert( QStringLiteral( "100%, 100%, 100%" ), QColor( 255, 255, 255 ) ); - colorTests.insert( QStringLiteral( "rgb(50%,60%,0%)" ), QColor( 127, 153, 0 ) ); + colorTests.insert( QStringLiteral( "rgb(50%,60%,0%)" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); colorTests.insert( QStringLiteral( "rgb(100%, 100%, 100%)" ), QColor( 255, 255, 255 ) ); - colorTests.insert( QStringLiteral( " rgb( 50 % , 60 % , 0 % ) " ), QColor( 127, 153, 0 ) ); - colorTests.insert( QStringLiteral( "rgb(50%,60%,0%);" ), QColor( 127, 153, 0 ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%);" ), QColor( 127, 153, 0 ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%)" ), QColor( 127, 153, 0 ) ); - colorTests.insert( QStringLiteral( "050%,060%,000%" ), QColor( 127, 153, 0 ) ); + colorTests.insert( QStringLiteral( " rgb( 50 % , 60 % , 0 % ) " ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); + colorTests.insert( QStringLiteral( "rgb(50%,60%,0%);" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%);" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%)" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); + colorTests.insert( QStringLiteral( "050%,060%,000%" ), QColor::fromRgbF( 0.5, 0.6, 0 ) ); colorTests.insert( QStringLiteral( "0%,0%,0%,0" ), QColor( 0, 0, 0, 0 ) ); - colorTests.insert( QStringLiteral( "50 %,60 %,0 %,0.5" ), QColor( 127, 153, 0, 128 ) ); + colorTests.insert( QStringLiteral( "50 %,60 %,0 %,0.5" ), QColor::fromRgbF( 0.5, 0.6, 0, 0.5 ) ); colorTests.insert( QStringLiteral( "100%, 100%, 100%, 1.0" ), QColor( 255, 255, 255, 255 ) ); - colorTests.insert( QStringLiteral( "rgba(50%,60%,0%, 1.0)" ), QColor( 127, 153, 0, 255 ) ); + colorTests.insert( QStringLiteral( "rgba(50%,60%,0%, 1.0)" ), QColor::fromRgbF( 0.5, 0.6, 0, 1.0 ) ); colorTests.insert( QStringLiteral( "rgba(100%, 100%, 100%, 0.0)" ), QColor( 255, 255, 255, 0 ) ); - colorTests.insert( QStringLiteral( " rgba( 50 % , 60 % , 0 %, 0.5 ) " ), QColor( 127, 153, 0, 128 ) ); - colorTests.insert( QStringLiteral( "rgba(50%,60%,0%,0);" ), QColor( 127, 153, 0, 0 ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%,1);" ), QColor( 127, 153, 0, 255 ) ); - colorTests.insert( QStringLiteral( "(50%,60%,0%,1.0)" ), QColor( 127, 153, 0, 255 ) ); - colorTests.insert( QStringLiteral( "050%,060%,000%,0" ), QColor( 127, 153, 0, 0 ) ); + colorTests.insert( QStringLiteral( " rgba( 50 % , 60 % , 0 %, 0.5 ) " ), QColor::fromRgbF( 0.5, 0.6, 0, 0.5 ) ); + colorTests.insert( QStringLiteral( "rgba(50%,60%,0%,0);" ), QColor::fromRgbF( 0.5, 0.6, 0, 0 ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%,1);" ), QColor::fromRgbF( 0.5, 0.6, 0, 1 ) ); + colorTests.insert( QStringLiteral( "(50%,60%,0%,1.0)" ), QColor::fromRgbF( 0.5, 0.6, 0, 1 ) ); + colorTests.insert( QStringLiteral( "050%,060%,000%,0" ), QColor::fromRgbF( 0.5, 0.6, 0, 0 ) ); QMap::const_iterator i = colorTests.constBegin(); while ( i != colorTests.constEnd() )