Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] When creating vector outputs, show warnings if
the output fields have comments or aliases set yet the
destination output does not have support for these
  • Loading branch information
nyalldawson committed Apr 21, 2023
1 parent b28bf20 commit dfc7f56
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -824,6 +824,18 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
throw QgsProcessingException( QObject::tr( "Could not create memory layer" ) );
}

if ( QgsProcessingFeedback *feedback = context.feedback() )
{
for ( const QgsField &field : fields )
{
// TODO -- support these!
if ( !field.alias().isEmpty() )
feedback->pushWarning( QObject::tr( "%1: Aliases are not compatible with scratch layers" ).arg( field.name() ) );
if ( !field.alias().isEmpty() )
feedback->pushWarning( QObject::tr( "%1: Comments are not compatible with scratch layers" ).arg( field.name() ) );
}
}

layer->setCustomProperty( QStringLiteral( "OnConvertFormatRegeneratePrimaryKey" ), static_cast< bool >( sinkFlags & QgsFeatureSink::RegeneratePrimaryKey ) );

// update destination to layer ID
Expand Down Expand Up @@ -882,6 +894,18 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
{
throw QgsProcessingException( QObject::tr( "Could not create layer %1: %2" ).arg( destination, writer->errorMessage() ) );
}

if ( QgsProcessingFeedback *feedback = context.feedback() )
{
for ( const QgsField &field : fields )
{
if ( !field.alias().isEmpty() && !( writer->capabilities() & Qgis::VectorFileWriterCapability::FieldAliases ) )
feedback->pushWarning( QObject::tr( "%1: Aliases are not supported by %2" ).arg( field.name(), writer->driverLongName() ) );
if ( !field.alias().isEmpty() && !( writer->capabilities() & Qgis::VectorFileWriterCapability::FieldComments ) )
feedback->pushWarning( QObject::tr( "%1: Comments are not supported by %2" ).arg( field.name(), writer->driverLongName() ) );
}
}

destination = finalFileName;
if ( !saveOptions.layerName.isEmpty() && !finalLayerName.isEmpty() )
destination += QStringLiteral( "|layername=%1" ).arg( finalLayerName );
Expand Down Expand Up @@ -921,6 +945,18 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
remappingDefinition->setDestinationFields( layer->fields() );
}

if ( QgsProcessingFeedback *feedback = context.feedback() )
{
const Qgis::VectorDataProviderAttributeEditCapabilities capabilities = layer->dataProvider() ? layer->dataProvider()->attributeEditCapabilities() : Qgis::VectorDataProviderAttributeEditCapabilities();
for ( const QgsField &field : fields )
{
if ( !field.alias().isEmpty() && !( capabilities & Qgis::VectorDataProviderAttributeEditCapability::EditAlias ) )
feedback->pushWarning( QObject::tr( "%1: Aliases are not supported by the %2 provider" ).arg( field.name(), providerKey ) );
if ( !field.alias().isEmpty() && !( capabilities & Qgis::VectorDataProviderAttributeEditCapability::EditComment ) )
feedback->pushWarning( QObject::tr( "%1: Comments are not supported by the %2 provider" ).arg( field.name(), providerKey ) );
}
}

std::unique_ptr< QgsRemappingProxyFeatureSink > remapSink = std::make_unique< QgsRemappingProxyFeatureSink >( *remappingDefinition, layer->dataProvider(), false );
context.temporaryLayerStore()->addMapLayer( layer.release() );
remapSink->setExpressionContext( context.expressionContext() );
Expand All @@ -945,6 +981,17 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
destination = uri;
}

if ( QgsProcessingFeedback *feedback = context.feedback() )
{
for ( const QgsField &field : fields )
{
if ( !field.alias().isEmpty() && !( exporter->attributeEditCapabilities() & Qgis::VectorDataProviderAttributeEditCapability::EditAlias ) )
feedback->pushWarning( QObject::tr( "%1: Aliases are not supported by the %2 provider" ).arg( field.name(), providerKey ) );
if ( !field.alias().isEmpty() && !( exporter->attributeEditCapabilities() & Qgis::VectorDataProviderAttributeEditCapability::EditComment ) )
feedback->pushWarning( QObject::tr( "%1: Comments are not supported by the %2 provider" ).arg( field.name(), providerKey ) );
}
}

return new QgsProcessingFeatureSink( exporter.release(), destination, context, true );
}
}
Expand Down

0 comments on commit dfc7f56

Please sign in to comment.