Skip to content
Permalink
Browse files

Correctly handle pasting geometryless layers as scratch layer

  • Loading branch information
nyalldawson committed Feb 29, 2016
1 parent 7f6446a commit a9d01302df767e735d316769b60c984c3bcabce3
Showing with 5 additions and 9 deletions.
  1. +5 −9 src/app/qgisapp.cpp
@@ -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() );

@@ -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 );
@@ -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() )
{
@@ -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;

0 comments on commit a9d0130

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