Skip to content
Permalink
Browse files

Only add parameter when it is new

  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 6, 2018
1 parent f22acb9 commit e3dabac78a954b0d69bb2b138b175a388c0ee093
@@ -107,7 +107,7 @@ according to some user configuration.
.. seealso:: :py:func:`algorithmById`
%End

void addParameterType( QgsProcessingParameterType *type /Transfer/ );
bool addParameterType( QgsProcessingParameterType *type /Transfer/ );
%Docstring
Register a new parameter type for processing.
Ownership is transferred to the registry.
@@ -153,10 +153,20 @@ QgsProcessingAlgorithm *QgsProcessingRegistry::createAlgorithmById( const QStrin
return creation.release();
}

void QgsProcessingRegistry::addParameterType( QgsProcessingParameterType *type )
bool QgsProcessingRegistry::addParameterType( QgsProcessingParameterType *type )
{
mParameterTypes.insert( type->id(), type );
emit parameterTypeAdded( type );
if ( !mParameterTypes.contains( type->id() ) )
{
mParameterTypes.insert( type->id(), type );
emit parameterTypeAdded( type );
return true;
}
else
{
if ( mParameterTypes.value( type->id() ) != type )
delete type;
return false;
}
}

void QgsProcessingRegistry::removeParameterType( QgsProcessingParameterType *type )
@@ -141,7 +141,7 @@ class CORE_EXPORT QgsProcessingRegistry : public QObject
*
* \since QGIS 3.2
*/
void addParameterType( QgsProcessingParameterType *type SIP_TRANSFER );
bool addParameterType( QgsProcessingParameterType *type SIP_TRANSFER );

/**
* Unregister a custom parameter type from processing.
@@ -6007,7 +6007,12 @@ void TestQgsProcessing::addParameterType()
{
QgsProcessingRegistry reg;
QSignalSpy spy( &reg, &QgsProcessingRegistry::parameterTypeAdded );
reg.addParameterType( new DummyParameterType() );
DummyParameterType *dpt = new DummyParameterType();
QVERIFY( reg.addParameterType( dpt ) );
QCOMPARE( spy.count(), 1 );
QVERIFY( !reg.addParameterType( dpt ) );
QCOMPARE( spy.count(), 1 );
QVERIFY( !reg.addParameterType( new DummyParameterType() ) );
QCOMPARE( spy.count(), 1 );
}

0 comments on commit e3dabac

Please sign in to comment.
You can’t perform that action at this time.