Skip to content

Commit ecae50f

Browse files
committedMar 1, 2018
Allow processing plugins to load their own parameters
1 parent 8873464 commit ecae50f

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
 

‎python/core/processing/qgsprocessingprovider.sip.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ Returns the matching algorithm by ``name``, or a None if no matching
204204
algorithm is contained by this provider.
205205

206206
.. seealso:: :py:func:`algorithms`
207+
%End
208+
209+
virtual QgsProcessingParameterDefinition *createParameter( const QString &type, const QString &name ) /Factory/;
210+
%Docstring
211+
Returns a new parameter from of the given type and name.
212+
This should be reimplemented by providers that implement custom types.
213+
If the provider does not implement the parameter with ``type``, a None will be returned.
214+
215+
By default, this returns a None.
216+
217+
.. versionadded:: 3.2
207218
%End
208219

209220
signals:

‎src/core/processing/qgsprocessingparameters.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgssettings.h"
2626
#include "qgsvectorfilewriter.h"
2727
#include "qgsreferencedgeometry.h"
28+
#include "qgsprocessingregistry.h"
2829
#include <functional>
2930

3031
bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
@@ -1079,6 +1080,21 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM
10791080
def.reset( new QgsProcessingParameterFolderDestination( name ) );
10801081
else if ( type == QgsProcessingParameterBand::typeName() )
10811082
def.reset( new QgsProcessingParameterBand( name ) );
1083+
else
1084+
{
1085+
const QList<QgsProcessingProvider *> providers = QgsApplication::instance()->processingRegistry()->providers();
1086+
1087+
for ( QgsProcessingProvider *provider : providers )
1088+
{
1089+
QgsProcessingParameterDefinition *param = provider->createParameter( type, name );
1090+
1091+
if ( param )
1092+
{
1093+
def.reset( param );
1094+
break;
1095+
}
1096+
}
1097+
}
10821098

10831099
if ( !def )
10841100
return nullptr;

‎src/core/processing/qgsprocessingprovider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ const QgsProcessingAlgorithm *QgsProcessingProvider::algorithm( const QString &n
7474
return mAlgorithms.value( name );
7575
}
7676

77+
QgsProcessingParameterDefinition *QgsProcessingProvider::createParameter( const QString &type, const QString &name )
78+
{
79+
Q_UNUSED( type )
80+
Q_UNUSED( name )
81+
return nullptr;
82+
}
83+
7784
bool QgsProcessingProvider::addAlgorithm( QgsProcessingAlgorithm *algorithm )
7885
{
7986
if ( !algorithm )

‎src/core/processing/qgsprocessingprovider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ class CORE_EXPORT QgsProcessingProvider : public QObject
203203
*/
204204
const QgsProcessingAlgorithm *algorithm( const QString &name ) const;
205205

206+
/**
207+
* Returns a new parameter from of the given type and name.
208+
* This should be reimplemented by providers that implement custom types.
209+
* If the provider does not implement the parameter with \a type, a nullptr will be returned.
210+
*
211+
* By default, this returns a nullptr.
212+
*
213+
* \since QGIS 3.2
214+
*/
215+
virtual QgsProcessingParameterDefinition *createParameter( const QString &type, const QString &name ) SIP_FACTORY;
216+
206217
signals:
207218

208219
/**

0 commit comments

Comments
 (0)
Please sign in to comment.