Skip to content

Commit 151c903

Browse files
committedApr 15, 2013
Fixed indentation in qgsexpression.cpp
1 parent 0e696a3 commit 151c903

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -979,28 +979,20 @@ static QVariant fcnFormatDate( const QVariantList& values, QgsFeature*, QgsExpre
979979
return dt.toString( format );
980980
}
981981

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-
995982
static QVariant fncColorRgb( const QVariantList &values, QgsFeature *, QgsExpression *parent )
996983
{
997984
int red = getIntValue( values.at( 0 ), parent );
998985
int green = getIntValue( values.at( 1 ), parent );
999986
int blue = getIntValue( values.at( 2 ), parent );
1000987
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+
}
1003993

994+
return color.name();
995+
}
1004996

1005997
static QVariant fncColorRgba( const QVariantList &values, QgsFeature *, QgsExpression *parent )
1006998
{
@@ -1009,20 +1001,26 @@ static QVariant fncColorRgba( const QVariantList &values, QgsFeature *, QgsExpre
10091001
int blue = getIntValue( values.at( 2 ), parent );
10101002
int alpha = getIntValue( values.at( 3 ), parent );
10111003
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+
}
10121009
return QgsSymbolLayerV2Utils::encodeColor( color );
10131010
}
10141011

1015-
QVariant fncColorFromRamp( const QVariantList &values, QgsFeature *, QgsExpression *parent )
1012+
QVariant fncRampColor( const QVariantList &values, QgsFeature *, QgsExpression *parent )
10161013
{
10171014
QString rampName = getStringValue( values.at( 0 ), parent );
10181015
const QgsVectorColorRampV2 *mRamp = QgsStyleV2::defaultStyle()->colorRampRef( rampName );
10191016
if ( ! mRamp )
10201017
{
10211018
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();
10231020
}
10241021
double value = getDoubleValue( values.at( 1 ), parent );
1025-
return QgsSymbolLayerV2Utils::encodeColor( mRamp->color( value ) );
1022+
QColor color = mRamp->color( value );
1023+
return color.name();
10261024
}
10271025

10281026
static QVariant fcnSpecialColumn( const QVariantList& values, QgsFeature* /*f*/, QgsExpression* parent )
@@ -1079,7 +1077,7 @@ const QStringList &QgsExpression::BuiltinFunctions()
10791077
<< "substr" << "concat" << "strpos" << "left"
10801078
<< "right" << "rpad" << "lpad"
10811079
<< "format_number" << "format_date"
1082-
<< "color_rgb" << "color_rgba" << "color_from_name" << "color_from_ramp"
1080+
<< "color_rgb" << "color_rgba" << "ramp_colour"
10831081
<< "xat" << "yat" << "$area"
10841082
<< "$length" << "$perimeter" << "$x" << "$y"
10851083
<< "$rownum" << "$id" << "$scale" << "_specialcol_";
@@ -1141,10 +1139,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
11411139
<< new StaticFunction( "format", -1, fcnFormatString, QObject::tr( "String" ) )
11421140
<< new StaticFunction( "format_number", 2, fcnFormatNumber, QObject::tr( "String" ) )
11431141
<< 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" ) )
11481145
<< new StaticFunction( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )
11491146
<< new StaticFunction( "yat", 1, fcnYat, QObject::tr( "Geometry" ), "", true )
11501147
<< new StaticFunction( "$area", 0, fcnGeomArea, QObject::tr( "Geometry" ), "", true )

0 commit comments

Comments
 (0)
Please sign in to comment.