Skip to content

Commit

Permalink
Only add parameter when it is new
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nyalldawson committed Mar 6, 2018
1 parent f22acb9 commit e3dabac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/core/processing/qgsprocessingregistry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions src/core/processing/qgsprocessingregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/processing/qgsprocessingregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion tests/src/analysis/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit e3dabac

Please sign in to comment.