Skip to content
Permalink
Browse files

Add method to convert QgsProcessing::SourceType to string representation

  • Loading branch information
nyalldawson committed Jan 29, 2019
1 parent 7f7c7a9 commit d4b262cdb00483d826b4a51ebffc6781da8b80cc
@@ -39,6 +39,13 @@ and parameters.
TypeMesh
};

static QString sourceTypeToString( SourceType type );
%Docstring
Converts a source ``type`` to a string representation.

.. versionadded:: 3.6
%End

static const QString TEMPORARY_OUTPUT;
};

@@ -54,6 +54,37 @@ class CORE_EXPORT QgsProcessing
TypeMesh = 6 //!< Mesh layers \since QGIS 3.6
};

/**
* Converts a source \a type to a string representation.
*
* \since QGIS 3.6
*/
static QString sourceTypeToString( SourceType type )
{
switch ( type )
{
case QgsProcessing::TypeMapLayer:
return QStringLiteral( "TypeMapLayer" );
case QgsProcessing::TypeVectorAnyGeometry:
return QStringLiteral( "TypeVectorAnyGeometry" );
case QgsProcessing::TypeVectorPoint:
return QStringLiteral( "TypeVectorPoint" );
case QgsProcessing::TypeVectorLine:
return QStringLiteral( "TypeVectorLine" );
case QgsProcessing::TypeVectorPolygon:
return QStringLiteral( "TypeVectorPolygon" );
case QgsProcessing::TypeRaster:
return QStringLiteral( "TypeRaster" );
case QgsProcessing::TypeFile:
return QStringLiteral( "TypeFile" );
case QgsProcessing::TypeVector:
return QStringLiteral( "TypeVector" );
case QgsProcessing::TypeMesh:
return QStringLiteral( "TypeMesh" );
}
return QString();
}

/**
* Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
*
@@ -584,6 +584,8 @@ class TestQgsProcessing: public QObject
void removeParameterType();
void parameterTypes();
void parameterType();
void sourceTypeToString_data();
void sourceTypeToString();

private:

@@ -7403,5 +7405,30 @@ void TestQgsProcessing::parameterType()
QCOMPARE( reg.parameterType( QStringLiteral( "paramType" ) ), paramType );
}

void TestQgsProcessing::sourceTypeToString_data()
{
QTest::addColumn<int>( "type" );
QTest::addColumn<QString>( "expected" );

// IMPORTANT -- these must match the original enum values!
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeMapLayer ) << QStringLiteral( "TypeMapLayer" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorAnyGeometry ) << QStringLiteral( "TypeVectorAnyGeometry" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorPoint ) << QStringLiteral( "TypeVectorPoint" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorLine ) << QStringLiteral( "TypeVectorLine" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorPolygon ) << QStringLiteral( "TypeVectorPolygon" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeRaster ) << QStringLiteral( "TypeRaster" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeFile ) << QStringLiteral( "TypeFile" );
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeMesh ) << QStringLiteral( "TypeMesh" );
}

void TestQgsProcessing::sourceTypeToString()
{
QFETCH( int, type );
QFETCH( QString, expected );

const QgsProcessing::SourceType sourceType = static_cast< QgsProcessing::SourceType >( type );
QCOMPARE( QgsProcessing::sourceTypeToString( sourceType ), expected );
}

QGSTEST_MAIN( TestQgsProcessing )
#include "testqgsprocessing.moc"

0 comments on commit d4b262c

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