Skip to content

Commit

Permalink
[processing] make multi-ring buffer parameters dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Mar 2, 2018
1 parent 04ce435 commit 8c0c581
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/analysis/processing/qgsalgorithmmultiringbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/analysis/processing/qgsalgorithmmultiringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c0c581

Please sign in to comment.