|
46 | 46 | #include "qgsfieldformatterregistry.h"
|
47 | 47 | #include "qgsfieldformatter.h"
|
48 | 48 | #include "qgsvectorlayerfeatureiterator.h"
|
| 49 | +#include "qgsproviderregistry.h" |
49 | 50 |
|
50 | 51 | const QString QgsExpressionFunction::helpText() const
|
51 | 52 | {
|
@@ -4030,6 +4031,35 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
|
4030 | 4031 | return QVariant();
|
4031 | 4032 | }
|
4032 | 4033 |
|
| 4034 | +static QVariant fcnDecodeUri( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * ) |
| 4035 | +{ |
| 4036 | + QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent ); |
| 4037 | + if ( !layer ) |
| 4038 | + { |
| 4039 | + parent->setEvalErrorString( QObject::tr( "Cannot find layer %1" ).arg( values.at( 0 ).toString() ) ); |
| 4040 | + return QVariant(); |
| 4041 | + } |
| 4042 | + |
| 4043 | + if ( !layer->dataProvider() ) |
| 4044 | + { |
| 4045 | + parent->setEvalErrorString( QObject::tr( "Layer %1 has invalid data provider" ).arg( layer->name() ) ); |
| 4046 | + return QVariant(); |
| 4047 | + } |
| 4048 | + |
| 4049 | + const QString uriPart = values.at( 1 ).toString(); |
| 4050 | + |
| 4051 | + const QVariantMap decodedUri = QgsProviderRegistry::instance()->decodeUri( layer->providerType(), layer->dataProvider()->dataSourceUri() ); |
| 4052 | + |
| 4053 | + if ( !uriPart.isNull() ) |
| 4054 | + { |
| 4055 | + return decodedUri.value( values.at( 1 ).toString() ); |
| 4056 | + } |
| 4057 | + else |
| 4058 | + { |
| 4059 | + return decodedUri; |
| 4060 | + } |
| 4061 | +} |
| 4062 | + |
4033 | 4063 | static QVariant fcnGetRasterBandStat( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
4034 | 4064 | {
|
4035 | 4065 | QString layerIdOrName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
|
@@ -4906,6 +4936,11 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
|
4906 | 4936 | // **General** functions
|
4907 | 4937 | sFunctions
|
4908 | 4938 | << new QgsStaticExpressionFunction( QStringLiteral( "layer_property" ), 2, fcnGetLayerProperty, QStringLiteral( "General" ) )
|
| 4939 | + << new QgsStaticExpressionFunction( QStringLiteral( "decode_uri" ), |
| 4940 | + QgsExpressionFunction::ParameterList() |
| 4941 | + << QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) ) |
| 4942 | + << QgsExpressionFunction::Parameter( QStringLiteral( "part" ), true ), |
| 4943 | + fcnDecodeUri, QStringLiteral( "Map Layers" ) ) |
4909 | 4944 | << new QgsStaticExpressionFunction( QStringLiteral( "raster_statistic" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
|
4910 | 4945 | << QgsExpressionFunction::Parameter( QStringLiteral( "band" ) )
|
4911 | 4946 | << QgsExpressionFunction::Parameter( QStringLiteral( "statistic" ) ), fcnGetRasterBandStat, QStringLiteral( "Rasters" ) );
|
|
0 commit comments