Skip to content
Permalink
Browse files

[processing] Transparently map 'qgis' algorithms to 'native' algorithms

This allows us to freely move algorithms from the qgis python library
to the c++ native provider without breaking API or existing models
  • Loading branch information
nyalldawson committed Sep 14, 2017
1 parent d96a3f4 commit 4ec1b4b348c53619a2c422421c2917bdd778c2a2
Showing with 15 additions and 0 deletions.
  1. +9 −0 src/core/processing/qgsprocessingregistry.cpp
  2. +6 −0 tests/src/core/testqgsprocessing.cpp
@@ -95,6 +95,15 @@ const QgsProcessingAlgorithm *QgsProcessingRegistry::algorithmById( const QStrin
if ( alg->id() == id )
return alg;
}

// try mapping 'qgis' algs to 'native' algs - this allows us to freely move algorithms
// from the python 'qgis' provider to the c++ 'native' provider without breaking API
// or existing models
if ( id.startsWith( QStringLiteral( "qgis:" ) ) )
{
QString newId = QStringLiteral( "native:" ) + id.mid( 5 );
return algorithmById( newId );
}
return nullptr;
}

@@ -848,6 +848,12 @@ void TestQgsProcessing::algorithm()
QVERIFY( !r.algorithmById( "p1:alg3" ) );
QVERIFY( !r.algorithmById( "px:alg1" ) );

// test that algorithmById can transparently map 'qgis' algorithms across to matching 'native' algorithms
// this allows us the freedom to convert qgis python algs to c++ without breaking api or existing models
QCOMPARE( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:dissolve" ) )->id(), QStringLiteral( "native:dissolve" ) );
QCOMPARE( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:clip" ) )->id(), QStringLiteral( "native:clip" ) );
QVERIFY( !QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:notanalg" ) ) );

// createAlgorithmById
QVERIFY( !r.createAlgorithmById( "p1:alg3" ) );
std::unique_ptr< QgsProcessingAlgorithm > creation( r.createAlgorithmById( "p1:alg1" ) );

0 comments on commit 4ec1b4b

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