Skip to content
Permalink
Browse files

[processing][modeler] Fix some child algorithm vector results

are not shown as input choices for other child algorithms

(cherry-picked from 3791bac)
  • Loading branch information
nyalldawson committed May 6, 2018
1 parent 4d02041 commit c9226ce387c315a6865d442fbca99e015ab9d02b
@@ -677,9 +677,9 @@ QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSo
{
const QgsProcessingOutputVectorLayer *vectorOut = static_cast< const QgsProcessingOutputVectorLayer *>( out );

if ( !( dataTypes.contains( vectorOut->dataType() ) || vectorOut->dataType() == QgsProcessing::TypeMapLayer || vectorOut->dataType() == QgsProcessing::TypeVector
|| vectorOut->dataType() == QgsProcessing::TypeVectorAnyGeometry ) )
if ( !vectorOutputIsCompatibleType( dataTypes, vectorOut->dataType() ) )
{
//unacceptable output
continue;
}
}
@@ -866,6 +866,23 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
return true;
}

bool QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, QgsProcessing::SourceType outputType )
{
// This method is intended to be "permissive" rather than "restrictive".
// I.e. we only reject outputs which we know can NEVER be acceptable, but
// if there's doubt then we default to returning true.
return ( acceptableDataTypes.empty()
|| acceptableDataTypes.contains( outputType )
|| outputType == QgsProcessing::TypeMapLayer
|| outputType == QgsProcessing::TypeVector
|| outputType == QgsProcessing::TypeVectorAnyGeometry
|| acceptableDataTypes.contains( QgsProcessing::TypeVector )
|| acceptableDataTypes.contains( QgsProcessing::TypeMapLayer )
|| ( acceptableDataTypes.contains( QgsProcessing::TypeVectorAnyGeometry ) && ( outputType == QgsProcessing::TypeVectorPoint ||
outputType == QgsProcessing::TypeVectorLine ||
outputType == QgsProcessing::TypeVectorPolygon ) ) );
}

bool QgsProcessingModelAlgorithm::toFile( const QString &path ) const
{
QDomDocument doc = QDomDocument( QStringLiteral( "model" ) );
@@ -403,6 +403,17 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
*/
bool loadVariant( const QVariant &model );

/**
* Checks whether the output vector type given by \a outputType is compatible
* with the list of acceptable data types specified by \a acceptableDataTypes.
* Returns true if vector output is compatible.
*
* \note This method is intended to be "permissive" rather than "restrictive".
* I.e. we only reject outputs which we know can NEVER be acceptable, but
* if there's doubt then we default to returning true.
*/
static bool vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, QgsProcessing::SourceType outputType );

friend class TestQgsProcessing;
};

@@ -465,6 +465,7 @@ class TestQgsProcessing: public QObject
void asPythonCommand();
void modelerAlgorithm();
void modelExecution();
void modelVectorOutputIsCompatibleType();
void modelAcceptableValues();
void tempUtils();
void convertCompatible();
@@ -5682,6 +5683,81 @@ void TestQgsProcessing::modelExecution()
QCOMPARE( actualParts, expectedParts );
}

void TestQgsProcessing::modelVectorOutputIsCompatibleType()
{
// IMPORTANT: This method is intended to be "permissive" rather than "restrictive".
// I.e. we only reject outputs which we know can NEVER be acceptable, but
// if there's doubt then we default to returning true.

// empty acceptable type list = all are compatible
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeVectorPoint ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeVectorLine ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( QList<int>(), QgsProcessing::TypeMapLayer ) );

// accept any vector
QList< int > dataTypes;
dataTypes << QgsProcessing::TypeVector;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );

// accept any vector with geometry
dataTypes.clear();
dataTypes << QgsProcessing::TypeVectorAnyGeometry;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );

// accept any point vector
dataTypes.clear();
dataTypes << QgsProcessing::TypeVectorPoint;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );

// accept any line vector
dataTypes.clear();
dataTypes << QgsProcessing::TypeVectorLine;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );

// accept any polygon vector
dataTypes.clear();
dataTypes << QgsProcessing::TypeVectorPolygon;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( !QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );

// accept any map layer
dataTypes.clear();
dataTypes << QgsProcessing::TypeMapLayer;
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVector ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorAnyGeometry ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPoint ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorLine ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeVectorPolygon ) );
QVERIFY( QgsProcessingModelAlgorithm::vectorOutputIsCompatibleType( dataTypes, QgsProcessing::TypeMapLayer ) );
}

void TestQgsProcessing::modelAcceptableValues()
{
QgsProcessingModelAlgorithm m;

0 comments on commit c9226ce

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