Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #37676 from signedav/backport_shortcut-edit
[Backport release-3_14]  Return on shortcut paste when layer not editable
  • Loading branch information
signedav committed Jul 9, 2020
2 parents 87e9873 + 1353bb5 commit 23dee29
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -10081,6 +10081,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" ) );
Expand Down Expand Up @@ -10109,6 +10117,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();
Expand Down Expand Up @@ -10235,19 +10251,25 @@ 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 )
Expand Down

0 comments on commit 23dee29

Please sign in to comment.