@@ -2998,6 +2998,41 @@ static QVariant fcnFormatDate( const QVariantList &values, const QgsExpressionCo
2998
2998
return dt.toString ( format );
2999
2999
}
3000
3000
3001
+ static QVariant fcnColorGrayscaleAverage ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * )
3002
+ {
3003
+ QColor color = QgsSymbolLayerUtils::decodeColor ( values.at ( 0 ).toString () );
3004
+ int avg = ( color.red () + color.green () + color.blue () ) / 3 ;
3005
+ int alpha = color.alpha ();
3006
+
3007
+ color.setRgb ( avg, avg, avg, alpha );
3008
+
3009
+ return QgsSymbolLayerUtils::encodeColor ( color );
3010
+ }
3011
+
3012
+ static QVariant fcnColorMixRgb ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
3013
+ {
3014
+ QColor color1 = QgsSymbolLayerUtils::decodeColor ( values.at ( 0 ).toString () );
3015
+ QColor color2 = QgsSymbolLayerUtils::decodeColor ( values.at ( 1 ).toString () );
3016
+ double ratio = QgsExpressionUtils::getDoubleValue ( values.at ( 2 ), parent );
3017
+ if ( ratio > 1 )
3018
+ {
3019
+ ratio = 1 ;
3020
+ }
3021
+ else if ( ratio < 0 )
3022
+ {
3023
+ ratio = 0 ;
3024
+ }
3025
+
3026
+ int red = color1.red () * ( 1 - ratio ) + color2.red () * ratio;
3027
+ int green = color1.green () * ( 1 - ratio ) + color2.green () * ratio;
3028
+ int blue = color1.blue () * ( 1 - ratio ) + color2.blue () * ratio;
3029
+ int alpha = color1.alpha () * ( 1 - ratio ) + color2.alpha () * ratio;
3030
+
3031
+ QColor newColor ( red, green, blue, alpha );
3032
+
3033
+ return QgsSymbolLayerUtils::encodeColor ( newColor );
3034
+ }
3035
+
3001
3036
static QVariant fcnColorRgb ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
3002
3037
{
3003
3038
int red = QgsExpressionUtils::getIntValue ( values.at ( 0 ), parent );
@@ -4098,6 +4133,8 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
4098
4133
<< new QgsStaticExpressionFunction ( QStringLiteral ( " format" ), -1 , fcnFormatString, QStringLiteral ( " String" ) )
4099
4134
<< new QgsStaticExpressionFunction ( QStringLiteral ( " format_number" ), 2 , fcnFormatNumber, QStringLiteral ( " String" ) )
4100
4135
<< new QgsStaticExpressionFunction ( QStringLiteral ( " format_date" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " date" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " format" ) ), fcnFormatDate, QStringList () << QStringLiteral ( " String" ) << QStringLiteral ( " Date and Time" ) )
4136
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " color_grayscale_average" ), 1 , fcnColorGrayscaleAverage, QStringLiteral ( " Color" ) )
4137
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " color_mix_rgb" ), 3 , fcnColorMixRgb, QStringLiteral ( " Color" ) )
4101
4138
<< new QgsStaticExpressionFunction ( QStringLiteral ( " color_rgb" ), 3 , fcnColorRgb, QStringLiteral ( " Color" ) )
4102
4139
<< new QgsStaticExpressionFunction ( QStringLiteral ( " color_rgba" ), 4 , fncColorRgba, QStringLiteral ( " Color" ) )
4103
4140
<< new QgsStaticExpressionFunction ( QStringLiteral ( " ramp_color" ), 2 , fcnRampColor, QStringLiteral ( " Color" ) )
0 commit comments