Skip to content

Commit

Permalink
Override checkParameterValues() method in align rasters processing al…
Browse files Browse the repository at this point in the history
…gorithm

to ensure that output files have been configured for all input rasters.
  • Loading branch information
benwirf authored and nyalldawson committed Oct 21, 2024
1 parent c2dd1aa commit ce35c42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/analysis/processing/qgsalgorithmalignrasters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ QgsAlignRastersAlgorithm *QgsAlignRastersAlgorithm::createInstance() const
return new QgsAlignRastersAlgorithm();
}

bool QgsAlignRastersAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
{
const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral( "LAYERS" ) )->name() );
const QList<QgsAlignRasterData::RasterItem> items = QgsProcessingParameterAlignRasterLayers::parameterAsItems( layersVariant, context );
bool unconfiguredLayers = false;
for ( const QgsAlignRasterData::RasterItem &item : items )
{
if ( item.outputFilename.isEmpty() )
{
unconfiguredLayers = true;
break;
}
}
if ( unconfiguredLayers )
{
*message = QObject::tr( "An output file is not configured for one or more input layers. Configure output files via 'Configure Raster…' under Input layers parameter." );
return false;
}
return QgsProcessingAlgorithm::checkParameterValues( parameters, context );
}

void QgsAlignRastersAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterAlignRasterLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ) ) );
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmalignrasters.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class QgsAlignRastersAlgorithm : public QgsProcessingAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsAlignRastersAlgorithm *createInstance() const override SIP_FACTORY;
bool checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const override;

protected:

Expand Down

0 comments on commit ce35c42

Please sign in to comment.