Skip to content

Commit cdd72e5

Browse files
committedSep 18, 2018
[processing] Fix use of models as child algorithms in other models
Fixes #19857
1 parent 1732654 commit cdd72e5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
 

‎src/core/processing/models/qgsprocessingmodelalgorithm.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,16 @@ bool QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( const QList<int>
930930
outputType == QgsProcessing::TypeVectorPolygon ) ) );
931931
}
932932

933+
void QgsProcessingModelAlgorithm::reattachAlgorithms() const
934+
{
935+
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
936+
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
937+
{
938+
if ( !childIt->algorithm() )
939+
childIt->reattach();
940+
}
941+
}
942+
933943
bool QgsProcessingModelAlgorithm::toFile( const QString &path ) const
934944
{
935945
QDomDocument doc = QDomDocument( QStringLiteral( "model" ) );
@@ -1182,6 +1192,7 @@ QSet< QString > QgsProcessingModelAlgorithm::dependsOnChildAlgorithms( const QSt
11821192

11831193
bool QgsProcessingModelAlgorithm::canExecute( QString *errorMessage ) const
11841194
{
1195+
reattachAlgorithms();
11851196
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
11861197
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
11871198
{

‎src/core/processing/models/qgsprocessingmodelalgorithm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
416416
*/
417417
static bool vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, QgsProcessing::SourceType outputType );
418418

419+
/**
420+
* Tries to reattach all child algorithms to their linked algorithms.
421+
*/
422+
void reattachAlgorithms() const;
423+
419424
friend class TestQgsProcessing;
420425
};
421426

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5750,7 +5750,14 @@ void TestQgsProcessing::modelerAlgorithm()
57505750
alg2.addChildAlgorithm( c6 );
57515751
QVERIFY( !alg2.canExecute() );
57525752

5753-
5753+
// test that children are re-attached before testing for canExecute
5754+
QgsProcessingModelAlgorithm alg2a( "test", "testGroup" );
5755+
QgsProcessingModelChildAlgorithm c5a;
5756+
c5a.setAlgorithmId( "native:centroids" );
5757+
alg2a.addChildAlgorithm( c5a );
5758+
// simulate initially missing provider or algorithm (e.g. another model as a child algorithm)
5759+
alg2a.mChildAlgorithms.begin().value().mAlgorithm.reset();
5760+
QVERIFY( alg2a.canExecute() );
57545761

57555762
// dependencies
57565763
QgsProcessingModelAlgorithm alg3( "test", "testGroup" );

0 commit comments

Comments
 (0)
Please sign in to comment.