Skip to content
Permalink
Browse files

[processing] Fix use of models as child algorithms in other models

Fixes #19857
  • Loading branch information
nyalldawson committed Sep 18, 2018
1 parent 1732654 commit cdd72e51e5c177093a9060b450599ef5efe7a9fd
@@ -930,6 +930,16 @@ bool QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( const QList<int>
outputType == QgsProcessing::TypeVectorPolygon ) ) );
}

void QgsProcessingModelAlgorithm::reattachAlgorithms() const
{
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( !childIt->algorithm() )
childIt->reattach();
}
}

bool QgsProcessingModelAlgorithm::toFile( const QString &path ) const
{
QDomDocument doc = QDomDocument( QStringLiteral( "model" ) );
@@ -1182,6 +1192,7 @@ QSet< QString > QgsProcessingModelAlgorithm::dependsOnChildAlgorithms( const QSt

bool QgsProcessingModelAlgorithm::canExecute( QString *errorMessage ) const
{
reattachAlgorithms();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
@@ -416,6 +416,11 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
*/
static bool vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, QgsProcessing::SourceType outputType );

/**
* Tries to reattach all child algorithms to their linked algorithms.
*/
void reattachAlgorithms() const;

friend class TestQgsProcessing;
};

@@ -5750,7 +5750,14 @@ void TestQgsProcessing::modelerAlgorithm()
alg2.addChildAlgorithm( c6 );
QVERIFY( !alg2.canExecute() );


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

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

0 comments on commit cdd72e5

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