Allow processing plugins to load their own parameters

This commit is contained in:
Matthias Kuhn 2018-03-01 08:04:18 -05:00
parent 88734647ce
commit ecae50f1d3
4 changed files with 45 additions and 0 deletions

View File

@ -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:

View File

@ -25,6 +25,7 @@
#include "qgssettings.h"
#include "qgsvectorfilewriter.h"
#include "qgsreferencedgeometry.h"
#include "qgsprocessingregistry.h"
#include <functional>
bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, 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<QgsProcessingProvider *> 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;

View File

@ -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 )

View File

@ -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:
/**