Skip to content

Commit

Permalink
Correctly handle pasting geometryless layers as scratch layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 1, 2016
1 parent 7f6446a commit a9d0130
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7023,9 +7023,9 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
}
}

QGis::WkbType wkbType = !typeCounts.isEmpty() ? typeCounts.keys().value( 0 ) : QGis::WKBPoint;
QGis::WkbType wkbType = !typeCounts.isEmpty() ? typeCounts.keys().value( 0 ) : QGis::WKBNoGeometry;

QString typeName = QString( QGis::featureType( wkbType ) ).remove( "WKB" );
QString typeName = wkbType != QGis::WKBNoGeometry ? QString( QGis::featureType( wkbType ) ).remove( "WKB" ) : "none";

typeName += QString( "?memoryid=%1" ).arg( QUuid::createUuid().toString() );

Expand All @@ -7037,10 +7037,6 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
{
message = tr( "No features in clipboard." ); // should not happen
}
else if ( typeCounts.isEmpty() )
{
message = tr( "No features with geometry found, point type layer will be created." );
}
else if ( typeCounts.size() > 1 )
{
message = tr( "Multiple geometry types found, features with geometry different from %1 will be created without geometry." ).arg( typeName );
Expand All @@ -7062,7 +7058,8 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
}

layer->startEditing();
layer->setCrs( clipboard()->crs(), false );
if ( wkbType != QGis::WKBNoGeometry )
layer->setCrs( clipboard()->crs(), false );

Q_FOREACH ( QgsField f, clipboard()->fields().toList() )
{
Expand Down Expand Up @@ -7098,13 +7095,12 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
feature.geometry()->convertToMultiType();
}
}
if ( ! layer->addFeatures( features ) || !layer->commitChanges() )
if ( ! layer->addFeatures( features, false ) || !layer->commitChanges() )
{
QgsDebugMsg( "Cannot add features or commit changes" );
delete layer;
return nullptr;
}
layer->removeSelection();

QgsDebugMsg( QString( "%1 features pasted to temporary scratch layer" ).arg( layer->featureCount() ) );
return layer;
Expand Down

0 comments on commit a9d0130

Please sign in to comment.