|
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 | {
|
@@ -4024,12 +4025,49 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
|
4024 | 4025 | return QgsWkbTypes::geometryDisplayString( vLayer->geometryType() );
|
4025 | 4026 | else if ( QString::compare( layerProperty, QStringLiteral( "feature_count" ), Qt::CaseInsensitive ) == 0 )
|
4026 | 4027 | return QVariant::fromValue( vLayer->featureCount() );
|
| 4028 | + else if ( QString::compare( layerProperty, QStringLiteral( "path" ), Qt::CaseInsensitive ) == 0 ) |
| 4029 | + { |
| 4030 | + if ( vLayer->dataProvider() ) |
| 4031 | + { |
| 4032 | + const QVariantMap decodedUri = QgsProviderRegistry::instance()->decodeUri( layer->providerType(), layer->dataProvider()->dataSourceUri() ); |
| 4033 | + return decodedUri.value( QStringLiteral( "path" ) ); |
| 4034 | + } |
| 4035 | + } |
4027 | 4036 | }
|
4028 | 4037 | }
|
4029 | 4038 |
|
4030 | 4039 | return QVariant();
|
4031 | 4040 | }
|
4032 | 4041 |
|
| 4042 | +static QVariant fcnDecodeUri( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * ) |
| 4043 | +{ |
| 4044 | + QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent ); |
| 4045 | + if ( !layer ) |
| 4046 | + { |
| 4047 | + parent->setEvalErrorString( QObject::tr( "Cannot find layer %1" ).arg( values.at( 0 ).toString() ) ); |
| 4048 | + return QVariant(); |
| 4049 | + } |
| 4050 | + |
| 4051 | + if ( !layer->dataProvider() ) |
| 4052 | + { |
| 4053 | + parent->setEvalErrorString( QObject::tr( "Layer %1 has invalid data provider" ).arg( layer->name() ) ); |
| 4054 | + return QVariant(); |
| 4055 | + } |
| 4056 | + |
| 4057 | + const QString uriPart = values.at( 1 ).toString(); |
| 4058 | + |
| 4059 | + const QVariantMap decodedUri = QgsProviderRegistry::instance()->decodeUri( layer->providerType(), layer->dataProvider()->dataSourceUri() ); |
| 4060 | + |
| 4061 | + if ( !uriPart.isNull() ) |
| 4062 | + { |
| 4063 | + return decodedUri.value( values.at( 1 ).toString() ); |
| 4064 | + } |
| 4065 | + else |
| 4066 | + { |
| 4067 | + return decodedUri; |
| 4068 | + } |
| 4069 | +} |
| 4070 | + |
4033 | 4071 | static QVariant fcnGetRasterBandStat( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
4034 | 4072 | {
|
4035 | 4073 | QString layerIdOrName = QgsExpressionUtils::getStringValue( values.at( 0 ), parent );
|
@@ -4906,6 +4944,11 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
|
4906 | 4944 | // **General** functions
|
4907 | 4945 | sFunctions
|
4908 | 4946 | << new QgsStaticExpressionFunction( QStringLiteral( "layer_property" ), 2, fcnGetLayerProperty, QStringLiteral( "General" ) )
|
| 4947 | + << new QgsStaticExpressionFunction( QStringLiteral( "decode_uri" ), |
| 4948 | + QgsExpressionFunction::ParameterList() |
| 4949 | + << QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) ) |
| 4950 | + << QgsExpressionFunction::Parameter( QStringLiteral( "part" ), true ), |
| 4951 | + fcnDecodeUri, QStringLiteral( "Map Layers" ) ) |
4909 | 4952 | << new QgsStaticExpressionFunction( QStringLiteral( "raster_statistic" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "layer" ) )
|
4910 | 4953 | << QgsExpressionFunction::Parameter( QStringLiteral( "band" ) )
|
4911 | 4954 | << QgsExpressionFunction::Parameter( QStringLiteral( "statistic" ) ), fcnGetRasterBandStat, QStringLiteral( "Rasters" ) );
|
|
0 commit comments