From ecae50f1d388e2eaabc9f6365b2f47a70c53a0cd Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 1 Mar 2018 08:04:18 -0500 Subject: [PATCH] Allow processing plugins to load their own parameters --- .../core/processing/qgsprocessingprovider.sip.in | 11 +++++++++++ src/core/processing/qgsprocessingparameters.cpp | 16 ++++++++++++++++ src/core/processing/qgsprocessingprovider.cpp | 7 +++++++ src/core/processing/qgsprocessingprovider.h | 11 +++++++++++ 4 files changed, 45 insertions(+) diff --git a/python/core/processing/qgsprocessingprovider.sip.in b/python/core/processing/qgsprocessingprovider.sip.in index fb4b9ce5fdd..6f9a861ca44 100644 --- a/python/core/processing/qgsprocessingprovider.sip.in +++ b/python/core/processing/qgsprocessingprovider.sip.in @@ -204,6 +204,17 @@ Returns the matching algorithm by ``name``, or a None if no matching algorithm is contained by this provider. .. seealso:: :py:func:`algorithms` +%End + + virtual QgsProcessingParameterDefinition *createParameter( const QString &type, const QString &name ) /Factory/; +%Docstring +Returns a new parameter from of the given type and name. +This should be reimplemented by providers that implement custom types. +If the provider does not implement the parameter with ``type``, a None will be returned. + +By default, this returns a None. + +.. versionadded:: 3.2 %End signals: diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 5da5e71f9a5..9fef8916723 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -25,6 +25,7 @@ #include "qgssettings.h" #include "qgsvectorfilewriter.h" #include "qgsreferencedgeometry.h" +#include "qgsprocessingregistry.h" #include bool QgsProcessingParameters::isDynamic( const QVariantMap ¶meters, const QString &name ) @@ -1079,6 +1080,21 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM def.reset( new QgsProcessingParameterFolderDestination( name ) ); else if ( type == QgsProcessingParameterBand::typeName() ) def.reset( new QgsProcessingParameterBand( name ) ); + else + { + const QList providers = QgsApplication::instance()->processingRegistry()->providers(); + + for ( QgsProcessingProvider *provider : providers ) + { + QgsProcessingParameterDefinition *param = provider->createParameter( type, name ); + + if ( param ) + { + def.reset( param ); + break; + } + } + } if ( !def ) return nullptr; diff --git a/src/core/processing/qgsprocessingprovider.cpp b/src/core/processing/qgsprocessingprovider.cpp index d50ab04cf6f..ac650a7b88e 100644 --- a/src/core/processing/qgsprocessingprovider.cpp +++ b/src/core/processing/qgsprocessingprovider.cpp @@ -74,6 +74,13 @@ const QgsProcessingAlgorithm *QgsProcessingProvider::algorithm( const QString &n return mAlgorithms.value( name ); } +QgsProcessingParameterDefinition *QgsProcessingProvider::createParameter( const QString &type, const QString &name ) +{ + Q_UNUSED( type ) + Q_UNUSED( name ) + return nullptr; +} + bool QgsProcessingProvider::addAlgorithm( QgsProcessingAlgorithm *algorithm ) { if ( !algorithm ) diff --git a/src/core/processing/qgsprocessingprovider.h b/src/core/processing/qgsprocessingprovider.h index d66f299b8a6..e5ff6375a6d 100644 --- a/src/core/processing/qgsprocessingprovider.h +++ b/src/core/processing/qgsprocessingprovider.h @@ -203,6 +203,17 @@ class CORE_EXPORT QgsProcessingProvider : public QObject */ const QgsProcessingAlgorithm *algorithm( const QString &name ) const; + /** + * Returns a new parameter from of the given type and name. + * This should be reimplemented by providers that implement custom types. + * If the provider does not implement the parameter with \a type, a nullptr will be returned. + * + * By default, this returns a nullptr. + * + * \since QGIS 3.2 + */ + virtual QgsProcessingParameterDefinition *createParameter( const QString &type, const QString &name ) SIP_FACTORY; + signals: /**