Skip to content

Commit c1552e7

Browse files
committed
[processing] Add createByDefault argument to destination parameter
constructors Allows this setting to be set for parameters created from description text files
1 parent c314639 commit c1552e7

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

python/core/processing/qgsprocessingparameters.sip.in

+22-5
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,12 @@ which are used for the destination for layers output by an algorithm.
18191819
public:
18201820

18211821
QgsProcessingDestinationParameter( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1822-
bool optional = false );
1822+
bool optional = false, bool createByDefault = true );
18231823
%Docstring
18241824
Constructor for QgsProcessingDestinationParameter.
1825+
1826+
If ``createByDefault`` is false and the parameter is ``optional``, then the destination
1827+
output will not be created by default.
18251828
%End
18261829

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

19021905
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
1903-
bool optional = false );
1906+
bool optional = false, bool createByDefault = true );
19041907
%Docstring
19051908
Constructor for QgsProcessingParameterFeatureSink.
1909+
1910+
If ``createByDefault`` is false and the parameter is ``optional``, then this destination
1911+
output will not be created by default.
19061912
%End
19071913

19081914
static QString typeName();
@@ -1978,9 +1984,12 @@ created by the algorithm.
19781984
public:
19791985

19801986
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
1981-
bool optional = false );
1987+
bool optional = false, bool createByDefault = true );
19821988
%Docstring
19831989
Constructor for QgsProcessingParameterVectorDestination.
1990+
1991+
If ``createByDefault`` is false and the parameter is ``optional``, then this destination
1992+
output will not be created by default.
19841993
%End
19851994

19861995
static QString typeName();
@@ -2050,9 +2059,13 @@ created by the algorithm.
20502059

20512060
QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
20522061
const QVariant &defaultValue = QVariant(),
2053-
bool optional = false );
2062+
bool optional = false,
2063+
bool createByDefault = true );
20542064
%Docstring
20552065
Constructor for QgsProcessingParameterRasterDestination.
2066+
2067+
If ``createByDefault`` is false and the parameter is ``optional``, then this destination
2068+
output will not be created by default.
20562069
%End
20572070

20582071
static QString typeName();
@@ -2094,9 +2107,13 @@ created by the algorithm.
20942107
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
20952108
const QString &fileFilter = QString(),
20962109
const QVariant &defaultValue = QVariant(),
2097-
bool optional = false );
2110+
bool optional = false,
2111+
bool createByDefault = true );
20982112
%Docstring
20992113
Constructor for QgsProcessingParameterFileDestination.
2114+
2115+
If ``createByDefault`` is false and the parameter is ``optional``, then this destination
2116+
output will not be created by default.
21002117
%End
21012118

21022119
static QString typeName();

src/core/processing/qgsprocessingparameters.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -3073,11 +3073,10 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc
30733073
return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional );
30743074
}
30753075

3076-
QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional )
3077-
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
3076+
QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
3077+
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
30783078
, mDataType( type )
30793079
{
3080-
30813080
}
30823081

30833082
QgsProcessingParameterDefinition *QgsProcessingParameterFeatureSink::clone() const
@@ -3277,9 +3276,10 @@ QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScript
32773276
return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
32783277
}
32793278

3280-
QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3281-
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
3282-
{}
3279+
QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
3280+
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
3281+
{
3282+
}
32833283

32843284
QgsProcessingParameterDefinition *QgsProcessingParameterRasterDestination::clone() const
32853285
{
@@ -3365,8 +3365,8 @@ QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination
33653365
}
33663366

33673367

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

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

3545-
QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
3545+
QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, bool createByDefault )
35463546
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
3547+
, mCreateByDefault( createByDefault )
35473548
{
35483549

35493550
}
@@ -3579,8 +3580,8 @@ void QgsProcessingDestinationParameter::setCreateByDefault( bool createByDefault
35793580
mCreateByDefault = createByDefault;
35803581
}
35813582

3582-
QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional )
3583-
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
3583+
QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::SourceType type, const QVariant &defaultValue, bool optional, bool createByDefault )
3584+
: QgsProcessingDestinationParameter( name, description, defaultValue, optional, createByDefault )
35843585
, mDataType( type )
35853586
{
35863587

src/core/processing/qgsprocessingparameters.h

+22-5
Original file line numberDiff line numberDiff line change
@@ -1758,9 +1758,12 @@ class CORE_EXPORT QgsProcessingDestinationParameter : public QgsProcessingParame
17581758

17591759
/**
17601760
* Constructor for QgsProcessingDestinationParameter.
1761+
*
1762+
* If \a createByDefault is false and the parameter is \a optional, then the destination
1763+
* output will not be created by default.
17611764
*/
17621765
QgsProcessingDestinationParameter( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
1763-
bool optional = false );
1766+
bool optional = false, bool createByDefault = true );
17641767

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

18361839
/**
18371840
* Constructor for QgsProcessingParameterFeatureSink.
1841+
*
1842+
* If \a createByDefault is false and the parameter is \a optional, then this destination
1843+
* output will not be created by default.
18381844
*/
18391845
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
1840-
bool optional = false );
1846+
bool optional = false, bool createByDefault = true );
18411847

18421848
/**
18431849
* Returns the type name for the parameter class.
@@ -1900,9 +1906,12 @@ class CORE_EXPORT QgsProcessingParameterVectorDestination : public QgsProcessing
19001906

19011907
/**
19021908
* Constructor for QgsProcessingParameterVectorDestination.
1909+
*
1910+
* If \a createByDefault is false and the parameter is \a optional, then this destination
1911+
* output will not be created by default.
19031912
*/
19041913
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::SourceType type = QgsProcessing::TypeVectorAnyGeometry, const QVariant &defaultValue = QVariant(),
1905-
bool optional = false );
1914+
bool optional = false, bool createByDefault = true );
19061915

19071916
/**
19081917
* Returns the type name for the parameter class.
@@ -1961,10 +1970,14 @@ class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessing
19611970

19621971
/**
19631972
* Constructor for QgsProcessingParameterRasterDestination.
1973+
*
1974+
* If \a createByDefault is false and the parameter is \a optional, then this destination
1975+
* output will not be created by default.
19641976
*/
19651977
QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
19661978
const QVariant &defaultValue = QVariant(),
1967-
bool optional = false );
1979+
bool optional = false,
1980+
bool createByDefault = true );
19681981

19691982
/**
19701983
* Returns the type name for the parameter class.
@@ -1996,11 +2009,15 @@ class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDe
19962009

19972010
/**
19982011
* Constructor for QgsProcessingParameterFileDestination.
2012+
*
2013+
* If \a createByDefault is false and the parameter is \a optional, then this destination
2014+
* output will not be created by default.
19992015
*/
20002016
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
20012017
const QString &fileFilter = QString(),
20022018
const QVariant &defaultValue = QVariant(),
2003-
bool optional = false );
2019+
bool optional = false,
2020+
bool createByDefault = true );
20042021

20052022
/**
20062023
* Returns the type name for the parameter class.

0 commit comments

Comments
 (0)