Skip to content
Permalink
Browse files

[processing] make multi-ring buffer parameters dynamic

  • Loading branch information
alexbruy committed Mar 2, 2018
1 parent 04ce435 commit 8c0c581790ce74c8e58d5ab0880fa00baf248308
@@ -61,25 +61,35 @@ QgsMultiRingBufferAlgorithm *QgsMultiRingBufferAlgorithm::createInstance() const

void QgsMultiRingBufferAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ), QList< int >() << QgsProcessing::TypeVectorPoint ) );

auto ringsParam = qgis::make_unique < QgsProcessingParameterNumber >( QStringLiteral( "RINGS" ), QObject::tr( "Number of rings" ), QgsProcessingParameterNumber::Integer, 1, false, 1 );
//ringsParam->setIsDynamic( true );
//ringsParam->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Number of rings" ), QObject::tr( "Number of rings" ), QgsPropertyDefinition::Integer ) );
//ringsParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( ringsParam.release() );

auto distanceParam = qgis::make_unique < QgsProcessingParameterNumber >( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance between rings" ), QgsProcessingParameterNumber::Double, 1 );
//distanceParam->setIsDynamic( true );
//distanceParam->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Distance between rings" ), QObject::tr( "Distance between rings" ), QgsPropertyDefinition::Double ) );
//distanceParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( distanceParam.release() );
std::unique_ptr< QgsProcessingParameterNumber> rings = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "RINGS" ),
QObject::tr( "Number of rings" ), QgsProcessingParameterNumber::Integer,
1, false, 0 );
rings->setIsDynamic( true );
rings->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "RINGS" ), QObject::tr( "Number of rings" ), QgsPropertyDefinition::IntegerPositive ) );
rings->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( rings.release() );

std::unique_ptr< QgsProcessingParameterNumber> distance = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "DISTANCE" ),
QObject::tr( "Distance between rings" ), QgsProcessingParameterNumber::Double,
1, false, 0 );
distance->setIsDynamic( true );
distance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "DISTANCE" ), QObject::tr( "Distance between rings" ), QgsPropertyDefinition::DoublePositive ) );
distance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
addParameter( distance.release() );
}

bool QgsMultiRingBufferAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mRingsNumber = parameterAsInt( parameters, QStringLiteral( "RINGS" ), context );
mDynamicRingsNumber = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "RINGS" ) );
if ( mDynamicRingsNumber )
mRingsNumberProperty = parameters.value( QStringLiteral( "RINGS" ) ).value< QgsProperty >();

mDistance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context );
mDynamicDistance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) );
if ( mDynamicDistance )
mDistanceProperty = parameters.value( QStringLiteral( "DISTANCE" ) ).value< QgsProperty >();

return true;
}

@@ -54,7 +54,12 @@ class QgsMultiRingBufferAlgorithm : public QgsProcessingFeatureBasedAlgorithm

private:
int mRingsNumber = 0;
bool mDynamicRingsNumber = false;
QgsProperty mRingsNumberProperty;

double mDistance = 0.0;
bool mDynamicDistance = false;
QgsProperty mDistanceProperty;
};

///@endcond PRIVATE

0 comments on commit 8c0c581

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