Skip to content

Commit d443bb3

Browse files
committed
Expose compatible vector layer parameter evaluation to QgsProcessingAlgorithm
1 parent 9e184fe commit d443bb3

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class QgsProcessingAlgorithm
514514

515515
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
516516
%Docstring
517-
Evaluates the parameter with matching ``definition`` to a feature source.
517+
Evaluates the parameter with matching ``name`` to a feature source.
518518

519519
Sources will either be taken from ``context``'s active project, or loaded from external
520520
sources and stored temporarily in the ``context``.
@@ -523,6 +523,22 @@ class QgsProcessingAlgorithm
523523
:rtype: QgsProcessingFeatureSource
524524
%End
525525

526+
QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
527+
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 );
528+
%Docstring
529+
Evaluates the parameter with matching ``name`` to a source vector layer file path of compatible format.
530+
531+
If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
532+
``compatibleFormats`` argument, then the layer will first be exported to a compatible format
533+
in a temporary location. The function will then return the path to that temporary file.
534+
535+
``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'.
536+
537+
The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary
538+
layer export is required.
539+
:rtype: str
540+
%End
541+
526542
QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
527543
%Docstring
528544
Evaluates the parameter with matching ``name`` to a map layer.

src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVa
503503
return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
504504
}
505505

506+
QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
507+
{
508+
return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
509+
}
510+
506511
QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
507512
{
508513
return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );

src/core/processing/qgsprocessingalgorithm.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
class QgsProcessingProvider;
3131
class QgsProcessingFeedback;
3232
class QgsFeatureSink;
33+
class QgsProcessingFeedback;
3334

3435

3536
/**
@@ -485,7 +486,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
485486
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const SIP_FACTORY;
486487

487488
/**
488-
* Evaluates the parameter with matching \a definition to a feature source.
489+
* Evaluates the parameter with matching \a name to a feature source.
489490
*
490491
* Sources will either be taken from \a context's active project, or loaded from external
491492
* sources and stored temporarily in the \a context.
@@ -494,6 +495,21 @@ class CORE_EXPORT QgsProcessingAlgorithm
494495
*/
495496
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;
496497

498+
/**
499+
* Evaluates the parameter with matching \a name to a source vector layer file path of compatible format.
500+
*
501+
* If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
502+
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
503+
* in a temporary location. The function will then return the path to that temporary file.
504+
*
505+
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
506+
*
507+
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
508+
* layer export is required.
509+
*/
510+
QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
511+
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
512+
497513
/**
498514
* Evaluates the parameter with matching \a name to a map layer.
499515
*

0 commit comments

Comments
 (0)