Skip to content

Commit

Permalink
Allow processing plugins to load their own parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 1, 2018
1 parent 8873464 commit ecae50f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/core/processing/qgsprocessingprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/core/processing/qgsprocessingprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
11 changes: 11 additions & 0 deletions src/core/processing/qgsprocessingprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down

0 comments on commit ecae50f

Please sign in to comment.