Skip to content

Commit d4b262c

Browse files
committedJan 29, 2019
Add method to convert QgsProcessing::SourceType to string representation
1 parent 7f7c7a9 commit d4b262c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
 

‎python/core/auto_generated/processing/qgsprocessing.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ and parameters.
3939
TypeMesh
4040
};
4141

42+
static QString sourceTypeToString( SourceType type );
43+
%Docstring
44+
Converts a source ``type`` to a string representation.
45+
46+
.. versionadded:: 3.6
47+
%End
48+
4249
static const QString TEMPORARY_OUTPUT;
4350
};
4451

‎src/core/processing/qgsprocessing.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ class CORE_EXPORT QgsProcessing
5454
TypeMesh = 6 //!< Mesh layers \since QGIS 3.6
5555
};
5656

57+
/**
58+
* Converts a source \a type to a string representation.
59+
*
60+
* \since QGIS 3.6
61+
*/
62+
static QString sourceTypeToString( SourceType type )
63+
{
64+
switch ( type )
65+
{
66+
case QgsProcessing::TypeMapLayer:
67+
return QStringLiteral( "TypeMapLayer" );
68+
case QgsProcessing::TypeVectorAnyGeometry:
69+
return QStringLiteral( "TypeVectorAnyGeometry" );
70+
case QgsProcessing::TypeVectorPoint:
71+
return QStringLiteral( "TypeVectorPoint" );
72+
case QgsProcessing::TypeVectorLine:
73+
return QStringLiteral( "TypeVectorLine" );
74+
case QgsProcessing::TypeVectorPolygon:
75+
return QStringLiteral( "TypeVectorPolygon" );
76+
case QgsProcessing::TypeRaster:
77+
return QStringLiteral( "TypeRaster" );
78+
case QgsProcessing::TypeFile:
79+
return QStringLiteral( "TypeFile" );
80+
case QgsProcessing::TypeVector:
81+
return QStringLiteral( "TypeVector" );
82+
case QgsProcessing::TypeMesh:
83+
return QStringLiteral( "TypeMesh" );
84+
}
85+
return QString();
86+
}
87+
5788
/**
5889
* Constant used to indicate that a Processing algorithm output should be a temporary layer/file.
5990
*

‎tests/src/analysis/testqgsprocessing.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ class TestQgsProcessing: public QObject
584584
void removeParameterType();
585585
void parameterTypes();
586586
void parameterType();
587+
void sourceTypeToString_data();
588+
void sourceTypeToString();
587589

588590
private:
589591

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

7408+
void TestQgsProcessing::sourceTypeToString_data()
7409+
{
7410+
QTest::addColumn<int>( "type" );
7411+
QTest::addColumn<QString>( "expected" );
7412+
7413+
// IMPORTANT -- these must match the original enum values!
7414+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeMapLayer ) << QStringLiteral( "TypeMapLayer" );
7415+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorAnyGeometry ) << QStringLiteral( "TypeVectorAnyGeometry" );
7416+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorPoint ) << QStringLiteral( "TypeVectorPoint" );
7417+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorLine ) << QStringLiteral( "TypeVectorLine" );
7418+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeVectorPolygon ) << QStringLiteral( "TypeVectorPolygon" );
7419+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeRaster ) << QStringLiteral( "TypeRaster" );
7420+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeFile ) << QStringLiteral( "TypeFile" );
7421+
QTest::newRow( "map layer" ) << static_cast< int >( QgsProcessing::TypeMesh ) << QStringLiteral( "TypeMesh" );
7422+
}
7423+
7424+
void TestQgsProcessing::sourceTypeToString()
7425+
{
7426+
QFETCH( int, type );
7427+
QFETCH( QString, expected );
7428+
7429+
const QgsProcessing::SourceType sourceType = static_cast< QgsProcessing::SourceType >( type );
7430+
QCOMPARE( QgsProcessing::sourceTypeToString( sourceType ), expected );
7431+
}
7432+
74067433
QGSTEST_MAIN( TestQgsProcessing )
74077434
#include "testqgsprocessing.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.