Skip to content

Commit

Permalink
Don't try to load proj strings as map layers
Browse files Browse the repository at this point in the history
Fixes #57914
  • Loading branch information
nyalldawson committed Jul 3, 2024
1 parent 03dd32e commit a45cba8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8183,11 +8183,16 @@ QgsProcessingParameterDefinition *QgsProcessingParameterCoordinateOperation::clo
}

QString QgsProcessingParameterCoordinateOperation::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
return valueAsPythonStringPrivate( value, context, false );
}

QString QgsProcessingParameterCoordinateOperation::valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const
{
if ( QgsVariantUtils::isNull( value ) )
return QStringLiteral( "None" );

if ( value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
if ( allowNonStringValues && value.userType() == QMetaType::type( "QgsCoordinateReferenceSystem" ) )
{
if ( !value.value< QgsCoordinateReferenceSystem >().isValid() )
return QStringLiteral( "QgsCoordinateReferenceSystem()" );
Expand All @@ -8198,11 +8203,14 @@ QString QgsProcessingParameterCoordinateOperation::valueAsPythonString( const QV
if ( value.userType() == QMetaType::type( "QgsProperty" ) )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

QVariantMap p;
p.insert( name(), value );
QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
if ( layer )
return QgsProcessingUtils::stringToPythonLiteral( QgsProcessingUtils::layerToStringIdentifier( layer ) );
if ( allowNonStringValues )
{
QVariantMap p;
p.insert( name(), value );
QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context );
if ( layer )
return QgsProcessingUtils::stringToPythonLiteral( QgsProcessingUtils::layerToStringIdentifier( layer ) );
}

const QString s = value.toString();
return QgsProcessingUtils::stringToPythonLiteral( s );
Expand Down Expand Up @@ -8231,16 +8239,16 @@ QString QgsProcessingParameterCoordinateOperation::asPythonString( QgsProcessing
if ( mFlags & Qgis::ProcessingParameterFlag::Optional )
code += QLatin1String( ", optional=True" );
if ( !mSourceParameterName.isEmpty() )
code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonString( mSourceParameterName, c ) );
code += QStringLiteral( ", sourceCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mSourceParameterName, c, false ) );
if ( !mDestParameterName.isEmpty() )
code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonString( mDestParameterName, c ) );
code += QStringLiteral( ", destinationCrsParameterName=%1" ).arg( valueAsPythonStringPrivate( mDestParameterName, c, false ) );

if ( mSourceCrs.isValid() )
code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonString( mSourceCrs, c ) );
code += QStringLiteral( ", staticSourceCrs=%1" ).arg( valueAsPythonStringPrivate( mSourceCrs, c, true ) );
if ( mDestCrs.isValid() )
code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonString( mDestCrs, c ) );
code += QStringLiteral( ", staticDestinationCrs=%1" ).arg( valueAsPythonStringPrivate( mDestCrs, c, true ) );

code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonString( mDefault, c ) );
code += QStringLiteral( ", defaultValue=%1)" ).arg( valueAsPythonStringPrivate( mDefault, c, false ) );
return code;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3940,6 +3940,7 @@ class CORE_EXPORT QgsProcessingParameterCoordinateOperation : public QgsProcessi
void setDestinationCrs( const QVariant &crs ) { mDestCrs = crs; }

private:
QString valueAsPythonStringPrivate( const QVariant &value, QgsProcessingContext &context, bool allowNonStringValues ) const ;

QString mSourceParameterName;
QString mDestParameterName;
Expand Down

0 comments on commit a45cba8

Please sign in to comment.