mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Add string format() function to expression
This commit is contained in:
parent
f2029b4ec4
commit
3c29cd25a0
@ -569,6 +569,23 @@ static QVariant fcnLPad( const QVariantList& values, QgsFeature* , QgsExpression
|
||||
return string.leftJustified( length, fill.at( 0 ), true );
|
||||
}
|
||||
|
||||
static QVariant fcnFormatString( const QVariantList& values, QgsFeature* , QgsExpression *parent )
|
||||
{
|
||||
QString string = getStringValue( values.at( 0 ), parent );
|
||||
for ( int n = 1; n <= values.length() - 1; n++ )
|
||||
{
|
||||
QString arg = getStringValue( values.at( n ), parent );
|
||||
QString place = '%' + QString::number( n );
|
||||
if ( string.indexOf( place ) == -1 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string.replace( place, arg );
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
static QVariant fcnNow( const QVariantList&, QgsFeature* , QgsExpression * )
|
||||
{
|
||||
return QVariant( QDateTime::currentDateTime() );
|
||||
@ -1100,6 +1117,7 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
|
||||
<< new StaticFunction( "right", 2, fcnRight, QObject::tr( "String" ) )
|
||||
<< new StaticFunction( "rpad", 3, fcnRPad, QObject::tr( "String" ) )
|
||||
<< new StaticFunction( "lpad", 3, fcnLPad, QObject::tr( "String" ) )
|
||||
<< 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( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )
|
||||
|
Loading…
x
Reference in New Issue
Block a user