Skip to content

Commit

Permalink
[processing] Add createByDefault argument to destination parameter
Browse files Browse the repository at this point in the history
constructors

Allows this setting to be set for parameters created from
description text files
  • Loading branch information
nyalldawson committed Apr 27, 2018
1 parent c314639 commit c1552e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
27 changes: 22 additions & 5 deletions python/core/processing/qgsprocessingparameters.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1819,9 +1819,12 @@ which are used for the destination for layers output by an algorithm.
public:

QgsProcessingDestinationParameter( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );
%Docstring
Constructor for QgsProcessingDestinationParameter.

If ``createByDefault`` is false and the parameter is ``optional``, then the destination
output will not be created by default.
%End

virtual bool isDestination() const;
Expand Down Expand Up @@ -1900,9 +1903,12 @@ A parameter which represents the destination feature sink for features created b
public:

QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );
%Docstring
Constructor for QgsProcessingParameterFeatureSink.

If ``createByDefault`` is false and the parameter is ``optional``, then this destination
output will not be created by default.
%End

static QString typeName();
Expand Down Expand Up @@ -1978,9 +1984,12 @@ created by the algorithm.
public:

QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );
%Docstring
Constructor for QgsProcessingParameterVectorDestination.

If ``createByDefault`` is false and the parameter is ``optional``, then this destination
output will not be created by default.
%End

static QString typeName();
Expand Down Expand Up @@ -2050,9 +2059,13 @@ created by the algorithm.

QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false,
bool createByDefault = true );
%Docstring
Constructor for QgsProcessingParameterRasterDestination.

If ``createByDefault`` is false and the parameter is ``optional``, then this destination
output will not be created by default.
%End

static QString typeName();
Expand Down Expand Up @@ -2094,9 +2107,13 @@ created by the algorithm.
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false,
bool createByDefault = true );
%Docstring
Constructor for QgsProcessingParameterFileDestination.

If ``createByDefault`` is false and the parameter is ``optional``, then this destination
output will not be created by default.
%End

static QString typeName();
Expand Down
23 changes: 12 additions & 11 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3073,11 +3073,10 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc
return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional );
}

QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
, mDataType( type )
{

}

QgsProcessingParameterDefinition *QgsProcessingParameterFeatureSink::clone() const
Expand Down Expand Up @@ -3277,9 +3276,10 @@ QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScript
return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
}

QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
{}
QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
{
}

QgsProcessingParameterDefinition *QgsProcessingParameterRasterDestination::clone() const
{
Expand Down Expand Up @@ -3365,8 +3365,8 @@ QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination
}


QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional, bool createByDefault )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
, mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
{

Expand Down Expand Up @@ -3542,8 +3542,9 @@ QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination
return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
}

QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mCreateByDefault( createByDefault )
{

}
Expand Down Expand Up @@ -3579,8 +3580,8 @@ void QgsProcessingDestinationParameter::setCreateByDefault( bool createByDefault
mCreateByDefault = createByDefault;
}

QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
, mDataType( type )
{

Expand Down
27 changes: 22 additions & 5 deletions src/core/processing/qgsprocessingparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1758,9 +1758,12 @@ class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParame

/**
* Constructor for QgsProcessingDestinationParameter.
*
* If \a createByDefault is false and the parameter is \a optional, then the destination
* output will not be created by default.
*/
QgsProcessingDestinationParameter( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );

bool isDestination() const override { return true; }
QVariantMap toVariantMap() const override;
Expand Down Expand Up @@ -1835,9 +1838,12 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin

/**
* Constructor for QgsProcessingParameterFeatureSink.
*
* If \a createByDefault is false and the parameter is \a optional, then this destination
* output will not be created by default.
*/
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );

/**
* Returns the type name for the parameter class.
Expand Down Expand Up @@ -1900,9 +1906,12 @@ class CORE_EXPORT QgsProcessingParameterVectorDestination : public QgsProcessing

/**
* Constructor for QgsProcessingParameterVectorDestination.
*
* If \a createByDefault is false and the parameter is \a optional, then this destination
* output will not be created by default.
*/
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false, bool createByDefault = true );

/**
* Returns the type name for the parameter class.
Expand Down Expand Up @@ -1961,10 +1970,14 @@ class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessing

/**
* Constructor for QgsProcessingParameterRasterDestination.
*
* If \a createByDefault is false and the parameter is \a optional, then this destination
* output will not be created by default.
*/
QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false,
bool createByDefault = true );

/**
* Returns the type name for the parameter class.
Expand Down Expand Up @@ -1996,11 +2009,15 @@ class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDe

/**
* Constructor for QgsProcessingParameterFileDestination.
*
* If \a createByDefault is false and the parameter is \a optional, then this destination
* output will not be created by default.
*/
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
bool optional = false,
bool createByDefault = true );

/**
* Returns the type name for the parameter class.
Expand Down

0 comments on commit c1552e7

Please sign in to comment.