Skip to content
Permalink
Browse files

Show a warning when pasted feature geometry collapsed

... due to due to intersection avoidance

Features are still pasted but the user is warned.

Fixes #20020
  • Loading branch information
elpaso committed Oct 6, 2018
1 parent 81db005 commit 08b6b6065a6c0aea8302b68739a5e8d902feba11
Showing with 18 additions and 12 deletions.
  1. +18 −12 src/app/qgisapp.cpp
@@ -8611,7 +8611,7 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )

QgsExpressionContext context = pasteVectorLayer->createExpressionContext();


int invalidGeometriesCount = 0;
QgsFeatureList newFeatures;
QgsFeatureList::const_iterator featureIt = features.constBegin();
while ( featureIt != features.constEnd() )
@@ -8653,13 +8653,14 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
// avoid intersection if enabled in digitize settings
geom.avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );
}
if ( geom.isEmpty() || geom.isNull( ) )
invalidGeometriesCount++;

// now create new feature using pasted feature as a template. This automatically handles default
// values and field constraints
newFeatures << QgsVectorLayerUtils::createFeature( pasteVectorLayer, geom, dstAttr, &context );
++featureIt;
}

pasteVectorLayer->addFeatures( newFeatures );
QgsFeatureIds newIds;
for ( const QgsFeature &f : qgis::as_const( newFeatures ) )
@@ -8673,26 +8674,31 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
pasteVectorLayer->updateExtents();

int nCopiedFeatures = features.count();
Qgis::MessageLevel level = ( nCopiedFeatures == 0 || nCopiedFeatures < nTotalFeatures || invalidGeometriesCount > 0 ) ? Qgis::Warning : Qgis::Info;
QString message;
if ( nCopiedFeatures == 0 )
{
messageBar()->pushMessage( tr( "Paste features" ),
tr( "no features could be successfully pasted." ),
Qgis::Warning, messageTimeout() );

message = tr( "No features could be successfully pasted." );
}
else if ( nCopiedFeatures == nTotalFeatures )
{
messageBar()->pushMessage( tr( "Paste features" ),
tr( "%1 features were successfully pasted." ).arg( nCopiedFeatures ),
Qgis::Info, messageTimeout() );
message = tr( "%1 features were successfully pasted." ).arg( nCopiedFeatures );
}
else
{
messageBar()->pushMessage( tr( "Paste features" ),
tr( "%1 of %2 features could be successfully pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures ),
Qgis::Warning, messageTimeout() );
message = tr( "%1 of %2 features could be successfully pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures );
}

// warn the user if the pasted features have invalid geometries
if ( invalidGeometriesCount > 0 )
message += invalidGeometriesCount == 1 ? tr( " Geometry collapsed due to intersection avoidance." ) :
tr( "%1 geometries collapsed due to intersection avoidance." )
.arg( invalidGeometriesCount );

messageBar()->pushMessage( tr( "Paste features" ),
message,
level, messageTimeout() );

pasteVectorLayer->triggerRepaint();
}

0 comments on commit 08b6b60

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