Navigation Menu

Skip to content

Commit

Permalink
Show a warning when pasted feature geometry collapsed
Browse files Browse the repository at this point in the history
... 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 08b6b60
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -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() )
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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();
}

Expand Down

0 comments on commit 08b6b60

Please sign in to comment.