Skip to content
Permalink
Browse files

Allow storing multiple status in field script code

  • Loading branch information
nyalldawson committed Jun 26, 2017
1 parent a72eea2 commit 46b4f2468c9f15a9240dea87c3d66c85207f6bde
@@ -2207,6 +2207,9 @@ QString QgsProcessingParameterField::asScriptCode() const
break;
}

if ( mAllowMultiple )
code += QStringLiteral( "multiple " );

code += mParentLayerParameter + ' ';

code += mDefault.toString();
@@ -2283,6 +2286,13 @@ QgsProcessingParameterField *QgsProcessingParameterField::fromScriptCode( const
type = DateTime;
def = def.mid( 9 );
}

if ( def.startsWith( QStringLiteral( "multiple" ), Qt::CaseInsensitive ) )
{
allowMultiple = true;
def = def.mid( 8 ).trimmed();
}

QRegularExpression re( "(.*?)\\s+(.*)$" );
QRegularExpressionMatch m = re.match( def );
if ( m.hasMatch() )
@@ -2535,6 +2545,10 @@ QString QgsProcessingParameterFeatureSink::asScriptCode() const
code += QStringLiteral( "polygon " );
break;

case TypeTable:
code += QStringLiteral( "table " );
break;

default:
break;
}
@@ -2631,6 +2645,11 @@ QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScript
type = QgsProcessingParameterDefinition::TypeVectorPolygon;
def = def.mid( 8 );
}
else if ( def.startsWith( QStringLiteral( "table" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeTable;
def = def.mid( 6 );
}

return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
}
@@ -239,7 +239,7 @@ class CORE_EXPORT QgsProcessingParameterDefinition
TypeVectorPolygon = 2, //!< Vector polygon layers
TypeRaster = 3, //!< Raster layers
TypeFile = 4, //!< Files
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry)
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
};

/**
@@ -3051,7 +3051,7 @@ void TestQgsProcessing::parameterField()
QCOMPARE( fromCode->allowMultiple(), def->allowMultiple() );

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

code = def->asScriptCode();
fromCode.reset( dynamic_cast< QgsProcessingParameterField * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
QVERIFY( fromCode.get() );
QCOMPARE( fromCode->name(), def->name() );
QCOMPARE( fromCode->description(), QStringLiteral( "non optional" ) );
QCOMPARE( fromCode->flags(), def->flags() );
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );
QCOMPARE( fromCode->parentLayerParameter(), def->parentLayerParameter() );
QCOMPARE( fromCode->dataType(), def->dataType() );
QCOMPARE( fromCode->allowMultiple(), def->allowMultiple() );

// optional
def.reset( new QgsProcessingParameterField( "optional", QString(), QString( "def" ), QString(), QgsProcessingParameterField::Any, false, true ) );
QVERIFY( def->checkValueIsAcceptable( 1 ) );
@@ -3440,6 +3451,11 @@ void TestQgsProcessing::parameterFeatureSink()
QCOMPARE( code, QStringLiteral( "##non_optional=sink polygon" ) );
fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
QCOMPARE( fromCode->dataType(), def->dataType() );
def->setDataType( QgsProcessingParameterDefinition::TypeTable );
code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##non_optional=sink table" ) );
fromCode.reset( dynamic_cast< QgsProcessingParameterFeatureSink * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );
QCOMPARE( fromCode->dataType(), def->dataType() );

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

0 comments on commit 46b4f24

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