Skip to content

Commit 4ec1b4b

Browse files
committed
[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
1 parent d96a3f4 commit 4ec1b4b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/core/processing/qgsprocessingregistry.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ const QgsProcessingAlgorithm *QgsProcessingRegistry::algorithmById( const QStrin
9595
if ( alg->id() == id )
9696
return alg;
9797
}
98+
99+
// try mapping 'qgis' algs to 'native' algs - this allows us to freely move algorithms
100+
// from the python 'qgis' provider to the c++ 'native' provider without breaking API
101+
// or existing models
102+
if ( id.startsWith( QStringLiteral( "qgis:" ) ) )
103+
{
104+
QString newId = QStringLiteral( "native:" ) + id.mid( 5 );
105+
return algorithmById( newId );
106+
}
98107
return nullptr;
99108
}
100109

tests/src/core/testqgsprocessing.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@ void TestQgsProcessing::algorithm()
848848
QVERIFY( !r.algorithmById( "p1:alg3" ) );
849849
QVERIFY( !r.algorithmById( "px:alg1" ) );
850850

851+
// test that algorithmById can transparently map 'qgis' algorithms across to matching 'native' algorithms
852+
// this allows us the freedom to convert qgis python algs to c++ without breaking api or existing models
853+
QCOMPARE( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:dissolve" ) )->id(), QStringLiteral( "native:dissolve" ) );
854+
QCOMPARE( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:clip" ) )->id(), QStringLiteral( "native:clip" ) );
855+
QVERIFY( !QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "qgis:notanalg" ) ) );
856+
851857
// createAlgorithmById
852858
QVERIFY( !r.createAlgorithmById( "p1:alg3" ) );
853859
std::unique_ptr< QgsProcessingAlgorithm > creation( r.createAlgorithmById( "p1:alg1" ) );

0 commit comments

Comments
 (0)