Skip to content
Permalink
Browse files

Code name consistency fix and unit tests for functions

  • Loading branch information
ccrook committed Apr 15, 2013
1 parent 151c903 commit 0372e4b61b07025bdef48965f5e6ca4dcd25895d
Showing with 15 additions and 5 deletions.
  1. +5 −0 resources/function_help/ramp_color-en_US
  2. +5 −5 src/core/qgsexpression.cpp
  3. +5 −0 tests/src/core/testqgsexpression.cpp
@@ -13,3 +13,8 @@ Returns a string representing a color from a color ramp.
<p><h4>Example</h4>
<!-- Show example of function.-->
ramp_color('Spectral',0.3) &rarr; '#fdbe73'</p>

<p><h4>Note:</h4>
The color ramps available vary between QGIS installations. This function
may not give the expected results if you move your Quantum project.
</p>
@@ -979,7 +979,7 @@ static QVariant fcnFormatDate( const QVariantList& values, QgsFeature*, QgsExpre
return dt.toString( format );
}

static QVariant fncColorRgb( const QVariantList &values, QgsFeature *, QgsExpression *parent )
static QVariant fcnColorRgb( const QVariantList &values, QgsFeature *, QgsExpression *parent )
{
int red = getIntValue( values.at( 0 ), parent );
int green = getIntValue( values.at( 1 ), parent );
@@ -1009,7 +1009,7 @@ static QVariant fncColorRgba( const QVariantList &values, QgsFeature *, QgsExpre
return QgsSymbolLayerV2Utils::encodeColor( color );
}

QVariant fncRampColor( const QVariantList &values, QgsFeature *, QgsExpression *parent )
QVariant fcnRampColor( const QVariantList &values, QgsFeature *, QgsExpression *parent )
{
QString rampName = getStringValue( values.at( 0 ), parent );
const QgsVectorColorRampV2 *mRamp = QgsStyleV2::defaultStyle()->colorRampRef( rampName );
@@ -1077,7 +1077,7 @@ const QStringList &QgsExpression::BuiltinFunctions()
<< "substr" << "concat" << "strpos" << "left"
<< "right" << "rpad" << "lpad"
<< "format_number" << "format_date"
<< "color_rgb" << "color_rgba" << "ramp_colour"
<< "color_rgb" << "color_rgba" << "ramp_color"
<< "xat" << "yat" << "$area"
<< "$length" << "$perimeter" << "$x" << "$y"
<< "$rownum" << "$id" << "$scale" << "_specialcol_";
@@ -1139,9 +1139,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
<< new StaticFunction( "format", -1, fcnFormatString, QObject::tr( "String" ) )
<< new StaticFunction( "format_number", 2, fcnFormatNumber, QObject::tr( "String" ) )
<< new StaticFunction( "format_date", 2, fcnFormatDate, QObject::tr( "String" ) )
<< new StaticFunction( "color_rgb", 3, fncColorRgb, QObject::tr( "Color" ) )
<< new StaticFunction( "color_rgb", 3, fcnColorRgb, QObject::tr( "Color" ) )
<< new StaticFunction( "color_rgba", 4, fncColorRgba, QObject::tr( "Color" ) )
<< new StaticFunction( "ramp_color", 2, fncRampColor, QObject::tr( "Color" ) )
<< new StaticFunction( "ramp_color", 2, fcnRampColor, QObject::tr( "Color" ) )
<< new StaticFunction( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )
<< new StaticFunction( "yat", 1, fcnYat, QObject::tr( "Geometry" ), "", true )
<< new StaticFunction( "$area", 0, fcnGeomArea, QObject::tr( "Geometry" ), "", true )
@@ -314,6 +314,11 @@ class TestQgsExpression: public QObject
QTest::newRow( "year with interval" ) << "year(tointerval('2 years'))" << false << QVariant( 2.0 );
QTest::newRow( "age" ) << "age('2012-06-30','2012-06-28')" << false << QVariant::fromValue( QgsExpression::Interval( 172800 ) );
QTest::newRow( "negative age" ) << "age('2012-06-28','2012-06-30')" << false << QVariant::fromValue( QgsExpression::Interval( -172800 ) );

// Color functions
QTest::newRow( "ramp color" ) << "ramp_color('Spectral',0.3)" << false << QVariant( "#fdbe73" );
QTest::newRow( "color rgb" ) << "color_rgb(255,127,0)" << false << QVariant( "#ff7f00" );
QTest::newRow( "color rgba" ) << "color_rgba(255,127,0,200)" << false << QVariant( "255,127,0,200" );
}

void evaluation()

0 comments on commit 0372e4b

Please sign in to comment.
You can’t perform that action at this time.