mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
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
This commit is contained in:
parent
81db0052ff
commit
08b6b6065a
@ -8611,7 +8611,7 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
|
|||||||
|
|
||||||
QgsExpressionContext context = pasteVectorLayer->createExpressionContext();
|
QgsExpressionContext context = pasteVectorLayer->createExpressionContext();
|
||||||
|
|
||||||
|
int invalidGeometriesCount = 0;
|
||||||
QgsFeatureList newFeatures;
|
QgsFeatureList newFeatures;
|
||||||
QgsFeatureList::const_iterator featureIt = features.constBegin();
|
QgsFeatureList::const_iterator featureIt = features.constBegin();
|
||||||
while ( featureIt != features.constEnd() )
|
while ( featureIt != features.constEnd() )
|
||||||
@ -8653,13 +8653,14 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
|
|||||||
// avoid intersection if enabled in digitize settings
|
// avoid intersection if enabled in digitize settings
|
||||||
geom.avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );
|
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
|
// now create new feature using pasted feature as a template. This automatically handles default
|
||||||
// values and field constraints
|
// values and field constraints
|
||||||
newFeatures << QgsVectorLayerUtils::createFeature( pasteVectorLayer, geom, dstAttr, &context );
|
newFeatures << QgsVectorLayerUtils::createFeature( pasteVectorLayer, geom, dstAttr, &context );
|
||||||
++featureIt;
|
++featureIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
pasteVectorLayer->addFeatures( newFeatures );
|
pasteVectorLayer->addFeatures( newFeatures );
|
||||||
QgsFeatureIds newIds;
|
QgsFeatureIds newIds;
|
||||||
for ( const QgsFeature &f : qgis::as_const( newFeatures ) )
|
for ( const QgsFeature &f : qgis::as_const( newFeatures ) )
|
||||||
@ -8673,26 +8674,31 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
|
|||||||
pasteVectorLayer->updateExtents();
|
pasteVectorLayer->updateExtents();
|
||||||
|
|
||||||
int nCopiedFeatures = features.count();
|
int nCopiedFeatures = features.count();
|
||||||
|
Qgis::MessageLevel level = ( nCopiedFeatures == 0 || nCopiedFeatures < nTotalFeatures || invalidGeometriesCount > 0 ) ? Qgis::Warning : Qgis::Info;
|
||||||
|
QString message;
|
||||||
if ( nCopiedFeatures == 0 )
|
if ( nCopiedFeatures == 0 )
|
||||||
{
|
{
|
||||||
messageBar()->pushMessage( tr( "Paste features" ),
|
message = tr( "No features could be successfully pasted." );
|
||||||
tr( "no features could be successfully pasted." ),
|
|
||||||
Qgis::Warning, messageTimeout() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( nCopiedFeatures == nTotalFeatures )
|
else if ( nCopiedFeatures == nTotalFeatures )
|
||||||
{
|
{
|
||||||
messageBar()->pushMessage( tr( "Paste features" ),
|
message = tr( "%1 features were successfully pasted." ).arg( nCopiedFeatures );
|
||||||
tr( "%1 features were successfully pasted." ).arg( nCopiedFeatures ),
|
|
||||||
Qgis::Info, messageTimeout() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
messageBar()->pushMessage( tr( "Paste features" ),
|
message = tr( "%1 of %2 features could be successfully pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures );
|
||||||
tr( "%1 of %2 features could be successfully pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures ),
|
|
||||||
Qgis::Warning, messageTimeout() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
pasteVectorLayer->triggerRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user