Skip to content
Permalink
Browse files

Fix pasting mixed geometry types to memory layer, switch to message bar

(cherry-picked from 28d725c)
  • Loading branch information
nyalldawson committed Mar 1, 2016
1 parent 9374935 commit b11efdbf3113c2e8019268de7e0e069bb220f2be
Showing with 16 additions and 17 deletions.
  1. +16 −17 src/app/qgisapp.cpp
@@ -7025,37 +7025,36 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()

QString typeName = QString( QGis::featureType( wkbType ) ).remove( "WKB" );

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

QgsDebugMsg( QString( "output wkbType = %1 typeName = %2" ).arg( wkbType ).arg( typeName ) );

QString message;

if ( features.isEmpty() )
{
message = tr( "No features in clipboard." ); // should not happen
// should not happen
messageBar()->pushMessage( tr( "Paste features" ),
tr( "No features in clipboard." ),
QgsMessageBar::WARNING, messageTimeout() );
return nullptr;
}
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 );
messageBar()->pushMessage( tr( "Paste features" ),
tr( "Multiple geometry types found, features with geometry different from %1 will be created without geometry." ).arg( typeName ),
QgsMessageBar::INFO, messageTimeout() );
}

if ( !message.isEmpty() )
{
QMessageBox::warning( this, tr( "Warning" ), message, QMessageBox::Ok );
return nullptr;
}
typeName += QString( "?memoryid=%1" ).arg( QUuid::createUuid().toString() );
QgsDebugMsg( QString( "output wkbType = %1 typeName = %2" ).arg( wkbType ).arg( typeName ) );

QgsVectorLayer *layer = new QgsVectorLayer( typeName, "pasted_features", "memory" );

if ( !layer->isValid() || !layer->dataProvider() )
{
delete layer;
QMessageBox::warning( this, tr( "Warning" ), tr( "Cannot create new layer" ), QMessageBox::Ok );
messageBar()->pushMessage( tr( "Paste features" ),
tr( "Cannot create new layer." ),
QgsMessageBar::WARNING, messageTimeout() );
return nullptr;
}

@@ -7067,9 +7066,9 @@ QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
QgsDebugMsg( QString( "field %1 (%2)" ).arg( f.name(), QVariant::typeToName( f.type() ) ) );
if ( !layer->addAttribute( f ) )
{
QMessageBox::warning( this, tr( "Warning" ),
tr( "Cannot create field %1 (%2,%3)" ).arg( f.name(), f.typeName(), QVariant::typeToName( f.type() ) ),
QMessageBox::Ok );
messageBar()->pushMessage( tr( "Paste features" ),
tr( "Cannot create field %1 (%2,%3)" ).arg( f.name(), f.typeName(), QVariant::typeToName( f.type() ) ),
QgsMessageBar::WARNING, messageTimeout() );
delete layer;
return nullptr;
}

0 comments on commit b11efdb

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