Skip to content

Commit 46b4f24

Browse files
committed
Allow storing multiple status in field script code
1 parent a72eea2 commit 46b4f24

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/core/processing/qgsprocessingparameters.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,9 @@ QString QgsProcessingParameterField::asScriptCode() const
22072207
break;
22082208
}
22092209

2210+
if ( mAllowMultiple )
2211+
code += QStringLiteral( "multiple " );
2212+
22102213
code += mParentLayerParameter + ' ';
22112214

22122215
code += mDefault.toString();
@@ -2283,6 +2286,13 @@ QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const
22832286
type = DateTime;
22842287
def = def.mid( 9 );
22852288
}
2289+
2290+
if ( def.startsWith( QStringLiteral( "multiple" ), Qt::CaseInsensitive ) )
2291+
{
2292+
allowMultiple = true;
2293+
def = def.mid( 8 ).trimmed();
2294+
}
2295+
22862296
QRegularExpression re( "(.*?)\\s+(.*)$" );
22872297
QRegularExpressionMatch m = re.match( def );
22882298
if ( m.hasMatch() )
@@ -2535,6 +2545,10 @@ QString QgsProcessingParameterFeatureSink::asScriptCode() const
25352545
code += QStringLiteral( "polygon " );
25362546
break;
25372547

2548+
case TypeTable:
2549+
code += QStringLiteral( "table " );
2550+
break;
2551+
25382552
default:
25392553
break;
25402554
}
@@ -2631,6 +2645,11 @@ QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScript
26312645
type = QgsProcessingParameterDefinition::TypeVectorPolygon;
26322646
def = def.mid( 8 );
26332647
}
2648+
else if ( def.startsWith( QStringLiteral( "table" ), Qt::CaseInsensitive ) )
2649+
{
2650+
type = QgsProcessingParameterDefinition::TypeTable;
2651+
def = def.mid( 6 );
2652+
}
26342653

26352654
return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
26362655
}

src/core/processing/qgsprocessingparameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class CORE_EXPORT QgsProcessingParameterDefinition
239239
TypeVectorPolygon = 2, //!< Vector polygon layers
240240
TypeRaster = 3, //!< Raster layers
241241
TypeFile = 4, //!< Files
242-
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry)
242+
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
243243
};
244244

245245
/**

tests/src/core/testqgsprocessing.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ void TestQgsProcessing::parameterField()
30513051
QCOMPARE( fromCode->allowMultiple(), def->allowMultiple() );
30523052

30533053
// multiple
3054-
def.reset( new QgsProcessingParameterField( "non_optional", QString(), QString(), QString(), QgsProcessingParameterField::Any, true, false ) );
3054+
def.reset( new QgsProcessingParameterField( "non_optional", QString(), QVariant(), QString(), QgsProcessingParameterField::Any, true, false ) );
30553055
QVERIFY( def->checkValueIsAcceptable( 1 ) );
30563056
QVERIFY( def->checkValueIsAcceptable( "test" ) );
30573057
QVERIFY( def->checkValueIsAcceptable( QStringList() << "a" << "b" ) );
@@ -3082,6 +3082,17 @@ void TestQgsProcessing::parameterField()
30823082
def.reset( dynamic_cast< QgsProcessingParameterField *>( QgsProcessingParameters::parameterFromVariantMap( map ) ) );
30833083
QVERIFY( dynamic_cast< QgsProcessingParameterField *>( def.get() ) );
30843084

3085+
code = def->asScriptCode();
3086+
fromCode.reset( dynamic_cast< QgsProcessingParameterField * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
3087+
QVERIFY( fromCode.get() );
3088+
QCOMPARE( fromCode->name(), def->name() );
3089+
QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) );
3090+
QCOMPARE( fromCode->flags(), def->flags() );
3091+
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );
3092+
QCOMPARE( fromCode->parentLayerParameter(), def->parentLayerParameter() );
3093+
QCOMPARE( fromCode->dataType(), def->dataType() );
3094+
QCOMPARE( fromCode->allowMultiple(), def->allowMultiple() );
3095+
30853096
// optional
30863097
def.reset( new QgsProcessingParameterField( "optional", QString(), QString( "def" ), QString(), QgsProcessingParameterField::Any, false, true ) );
30873098
QVERIFY( def->checkValueIsAcceptable( 1 ) );
@@ -3440,6 +3451,11 @@ void TestQgsProcessing::parameterFeatureSink()
34403451
QCOMPARE( code, QStringLiteral( "##non_optional=sink polygon" ) );
34413452
fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
34423453
QCOMPARE( fromCode->dataType(), def->dataType() );
3454+
def->setDataType( QgsProcessingParameterDefinition::TypeTable );
3455+
code = def->asScriptCode();
3456+
QCOMPARE( code, QStringLiteral( "##non_optional=sink table" ) );
3457+
fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
3458+
QCOMPARE( fromCode->dataType(), def->dataType() );
34433459

34443460
// optional
34453461
def.reset( new QgsProcessingParameterFeatureSink( "optional", QString(), QgsProcessingParameterDefinition::TypeVectorAny, QString(), true ) );

0 commit comments

Comments
 (0)