@@ -979,28 +979,20 @@ static QVariant fcnFormatDate( const QVariantList& values, QgsFeature*, QgsExpre
979
979
return dt.toString ( format );
980
980
}
981
981
982
-
983
- static QVariant fncColorFromName ( const QVariantList &values, QgsFeature *, QgsExpression *parent )
984
- {
985
- QString name = getStringValue ( values.at ( 0 ), parent );
986
- QColor color = QColor ( name );
987
- if ( ! color.isValid () )
988
- {
989
- parent->setEvalErrorString ( QObject::tr ( " Cannot convert '%1' to double" ).arg ( name ) );
990
- color = QColor ( 0 , 0 , 0 );
991
- }
992
- return QgsSymbolLayerV2Utils::encodeColor ( color );
993
- }
994
-
995
982
static QVariant fncColorRgb ( const QVariantList &values, QgsFeature *, QgsExpression *parent )
996
983
{
997
984
int red = getIntValue ( values.at ( 0 ), parent );
998
985
int green = getIntValue ( values.at ( 1 ), parent );
999
986
int blue = getIntValue ( values.at ( 2 ), parent );
1000
987
QColor color = QColor ( red, green, blue );
1001
- return QgsSymbolLayerV2Utils::encodeColor ( color );
1002
- }
988
+ if ( ! color.isValid () )
989
+ {
990
+ parent->setEvalErrorString ( QObject::tr ( " Cannot convert '%1:%2:%3' to color" ).arg ( red ).arg ( green ).arg ( blue ) );
991
+ color = QColor ( 0 , 0 , 0 );
992
+ }
1003
993
994
+ return color.name ();
995
+ }
1004
996
1005
997
static QVariant fncColorRgba ( const QVariantList &values, QgsFeature *, QgsExpression *parent )
1006
998
{
@@ -1009,20 +1001,26 @@ static QVariant fncColorRgba( const QVariantList &values, QgsFeature *, QgsExpre
1009
1001
int blue = getIntValue ( values.at ( 2 ), parent );
1010
1002
int alpha = getIntValue ( values.at ( 3 ), parent );
1011
1003
QColor color = QColor ( red, green, blue, alpha );
1004
+ if ( ! color.isValid () )
1005
+ {
1006
+ parent->setEvalErrorString ( QObject::tr ( " Cannot convert '%1:%2:%3:%4' to color" ).arg ( red ).arg ( green ).arg ( blue ).arg ( alpha ) );
1007
+ color = QColor ( 0 , 0 , 0 );
1008
+ }
1012
1009
return QgsSymbolLayerV2Utils::encodeColor ( color );
1013
1010
}
1014
1011
1015
- QVariant fncColorFromRamp ( const QVariantList &values, QgsFeature *, QgsExpression *parent )
1012
+ QVariant fncRampColor ( const QVariantList &values, QgsFeature *, QgsExpression *parent )
1016
1013
{
1017
1014
QString rampName = getStringValue ( values.at ( 0 ), parent );
1018
1015
const QgsVectorColorRampV2 *mRamp = QgsStyleV2::defaultStyle ()->colorRampRef ( rampName );
1019
1016
if ( ! mRamp )
1020
1017
{
1021
1018
parent->setEvalErrorString ( QObject::tr ( " \" %1\" is not a valid color ramp" ).arg ( rampName ) );
1022
- return QgsSymbolLayerV2Utils::encodeColor ( QColor ( 0 , 0 , 0 ) );
1019
+ return QColor ( 0 , 0 , 0 ). name ( );
1023
1020
}
1024
1021
double value = getDoubleValue ( values.at ( 1 ), parent );
1025
- return QgsSymbolLayerV2Utils::encodeColor ( mRamp ->color ( value ) );
1022
+ QColor color = mRamp ->color ( value );
1023
+ return color.name ();
1026
1024
}
1027
1025
1028
1026
static QVariant fcnSpecialColumn ( const QVariantList& values, QgsFeature* /* f*/ , QgsExpression* parent )
@@ -1079,7 +1077,7 @@ const QStringList &QgsExpression::BuiltinFunctions()
1079
1077
<< " substr" << " concat" << " strpos" << " left"
1080
1078
<< " right" << " rpad" << " lpad"
1081
1079
<< " format_number" << " format_date"
1082
- << " color_rgb" << " color_rgba" << " color_from_name " << " color_from_ramp "
1080
+ << " color_rgb" << " color_rgba" << " ramp_colour "
1083
1081
<< " xat" << " yat" << " $area"
1084
1082
<< " $length" << " $perimeter" << " $x" << " $y"
1085
1083
<< " $rownum" << " $id" << " $scale" << " _specialcol_" ;
@@ -1141,10 +1139,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
1141
1139
<< new StaticFunction ( " format" , -1 , fcnFormatString, QObject::tr ( " String" ) )
1142
1140
<< new StaticFunction ( " format_number" , 2 , fcnFormatNumber, QObject::tr ( " String" ) )
1143
1141
<< new StaticFunction ( " format_date" , 2 , fcnFormatDate, QObject::tr ( " String" ) )
1144
- << new StaticFunction ( " color_rgb" , 3 , fncColorRgb, QObject::tr ( " Color" ), QObject::tr ( " Usage: color_rgb(red,green,blue) - rgb values from 0 to 255" ) )
1145
- << new StaticFunction ( " color_rgba" , 4 , fncColorRgba, QObject::tr ( " Color" ), QObject::tr ( " Usage: color_rgba(red,green,blue,alpha) - rgba values from 0 to 255\" " ) )
1146
- << new StaticFunction ( " color_from_name" , 1 , fncColorFromName, QObject::tr ( " Color" ), QObject::tr ( " Usage: color_from_name(name) - examples \" #FF0000\" , \" red\" " ) )
1147
- << new StaticFunction ( " color_from_ramp" , 1 , fncColorFromRamp, QObject::tr ( " Color" ), QObject::tr ( " Usage: color_from_ramp(name) - type=ramp name, value=0..1" ) )
1142
+ << new StaticFunction ( " color_rgb" , 3 , fncColorRgb, QObject::tr ( " Color" ) )
1143
+ << new StaticFunction ( " color_rgba" , 4 , fncColorRgba, QObject::tr ( " Color" ) )
1144
+ << new StaticFunction ( " ramp_color" , 2 , fncRampColor, QObject::tr ( " Color" ) )
1148
1145
<< new StaticFunction ( " xat" , 1 , fcnXat, QObject::tr ( " Geometry" ), " " , true )
1149
1146
<< new StaticFunction ( " yat" , 1 , fcnYat, QObject::tr ( " Geometry" ), " " , true )
1150
1147
<< new StaticFunction ( " $area" , 0 , fcnGeomArea, QObject::tr ( " Geometry" ), " " , true )
0 commit comments