From 1d69939ddee92b6672b7261b13697f66b5d581fb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 22 Jun 2017 06:58:31 +1000 Subject: [PATCH] Fix build --- .../processing/qgsprocessingparameters.sip | 7 +++++-- .../processing/qgsprocessingparameters.cpp | 20 ++++++++++++++++++- src/core/processing/qgsprocessingparameters.h | 5 +++-- tests/src/core/testqgsprocessing.cpp | 4 ++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/python/core/processing/qgsprocessingparameters.sip b/python/core/processing/qgsprocessingparameters.sip index 797442c893d..6ba0d6561c1 100644 --- a/python/core/processing/qgsprocessingparameters.sip +++ b/python/core/processing/qgsprocessingparameters.sip @@ -1432,7 +1432,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter }; -class QgsProcessingParameterVectorOutput : QgsProcessingParameterDefinition +class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter { %Docstring A vector layer output parameter. Consider using the more flexible QgsProcessingParameterFeatureSink wherever @@ -1452,11 +1452,14 @@ class QgsProcessingParameterVectorOutput : QgsProcessingParameterDefinition %End virtual QString type() const; - virtual bool isDestination() const; virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const; virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const; + virtual QgsProcessingOutputDefinition *toOutputDefinition() const /Factory/; + + virtual QString defaultFileExtension() const; + QgsProcessingParameterDefinition::LayerType dataType() const; %Docstring diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index 94aed8dac87..66a211db885 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -2345,7 +2345,7 @@ QString QgsProcessingDestinationParameter::generateTemporaryDestination() const } QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional ) - : QgsProcessingParameterDefinition( name, description, defaultValue, optional ) + : QgsProcessingDestinationParameter( name, description, defaultValue, optional ) , mDataType( type ) { @@ -2398,6 +2398,24 @@ QString QgsProcessingParameterVectorOutput::valueAsPythonString( const QVariant return value.toString().prepend( '\'' ).append( '\'' ); } +QgsProcessingOutputDefinition *QgsProcessingParameterVectorOutput::toOutputDefinition() const +{ + return new QgsProcessingOutputVectorLayer( name(), description(), mDataType ); +} + +QString QgsProcessingParameterVectorOutput::defaultFileExtension() const +{ + QgsSettings settings; + if ( hasGeometry() ) + { + return settings.value( QStringLiteral( "Processing/DefaultOutputVectorLayerExt" ), QStringLiteral( "shp" ), QgsSettings::Core ).toString(); + } + else + { + return QStringLiteral( "dbf" ); + } +} + QgsProcessingParameterDefinition::LayerType QgsProcessingParameterVectorOutput::dataType() const { return mDataType; diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index b057298acf7..431afb1a7e0 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -1386,7 +1386,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin * possible. * \since QGIS 3.0 */ -class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingParameterDefinition +class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDestinationParameter { public: @@ -1397,9 +1397,10 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingParam bool optional = false ); QString type() const override { return QStringLiteral( "vectorOut" ); } - bool isDestination() const override { return true; } bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override; QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override; + QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY; + QString defaultFileExtension() const override; /** * Returns the layer type for layers associated with the parameter. diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index fb25a926f8a..95997611f4a 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -2881,6 +2881,10 @@ void TestQgsProcessing::parameterVectorOut() QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingOutputLayerDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProcessingOutputLayerDefinition(QgsProperty.fromExpression('\"abc\" || \"def\"'))" ) ); QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); + QCOMPARE( def->defaultFileExtension(), QStringLiteral( "shp" ) ); + QVERIFY( def->generateTemporaryDestination().endsWith( QStringLiteral( ".shp" ) ) ); + QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) ); + QVariantMap map = def->toVariantMap(); QgsProcessingParameterVectorOutput fromMap( "x" ); QVERIFY( fromMap.fromVariantMap( map ) );