Skip to content
Permalink
Browse files

Merge pull request #37672 from signedav/shortcut-edit

Return on shortcut paste when layer not editable
  • Loading branch information
signedav committed Jul 9, 2020
2 parents cfd9afe + d523eb9 commit 588aff0938c88cfd730fdc28ac4dcf7b60d31ac7
Showing with 33 additions and 11 deletions.
  1. +33 −11 src/app/qgisapp.cpp
@@ -10100,6 +10100,14 @@ void QgisApp::cutSelectionToClipboard( QgsMapLayer *layerContainingSelection )
if ( !selectionVectorLayer )
return;

if ( !selectionVectorLayer->isEditable() )
{
visibleMessageBar()->pushMessage( tr( "Layer not editable" ),
tr( "The current layer is not editable. Choose 'Start editing' in the digitizing toolbar." ),
Qgis::Info, messageTimeout() );
return;
}

clipboard()->replaceWithCopyOf( selectionVectorLayer );

selectionVectorLayer->beginEditCommand( tr( "Features cut" ) );
@@ -10128,6 +10136,14 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
if ( !pasteVectorLayer )
return;

if ( !pasteVectorLayer->isEditable() )
{
visibleMessageBar()->pushMessage( tr( "Layer not editable" ),
tr( "The current layer is not editable. Choose 'Start editing' in the digitizing toolbar." ),
Qgis::Info, messageTimeout() );
return;
}

pasteVectorLayer->beginEditCommand( tr( "Features pasted" ) );
QgsFeatureList features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->fields() );
int nTotalFeatures = features.count();
@@ -10254,32 +10270,38 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )

void QgisApp::pasteFeatures( QgsVectorLayer *pasteVectorLayer, int invalidGeometriesCount, int nTotalFeatures, QgsFeatureList &features )
{
pasteVectorLayer->addFeatures( features );
QgsFeatureIds newIds;
newIds.reserve( features.size() );
for ( const QgsFeature &f : qgis::as_const( features ) )
int nCopiedFeatures = features.count();
if ( pasteVectorLayer->addFeatures( features ) )
{
newIds << f.id();
}
QgsFeatureIds newIds;
newIds.reserve( features.size() );
for ( const QgsFeature &f : qgis::as_const( features ) )
{
newIds << f.id();
}

pasteVectorLayer->selectByIds( newIds );
pasteVectorLayer->selectByIds( newIds );
}
else
{
nCopiedFeatures = 0;
}
pasteVectorLayer->endEditCommand();
pasteVectorLayer->updateExtents();

int nCopiedFeatures = features.count();
Qgis::MessageLevel level = ( nCopiedFeatures == 0 || invalidGeometriesCount > 0 ) ? Qgis::Warning : Qgis::Info;
QString message;
if ( nCopiedFeatures == 0 )
{
message = tr( "No features could be successfully pasted." );
message = tr( "No features pasted." );
}
else if ( nCopiedFeatures == nTotalFeatures )
{
message = tr( "%1 features were successfully pasted." ).arg( nCopiedFeatures );
message = tr( "%1 features were pasted." ).arg( nCopiedFeatures );
}
else
{
message = tr( "%1 of %2 features could be successfully pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures );
message = tr( "%1 of %2 features could be pasted." ).arg( nCopiedFeatures ).arg( nTotalFeatures );
}

// warn the user if the pasted features have invalid geometries

0 comments on commit 588aff0

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