Skip to content

Commit

Permalink
Allow copy / paste with text format between different projects also f…
Browse files Browse the repository at this point in the history
…or geometryless layers
  • Loading branch information
mhugent authored and nyalldawson committed Aug 10, 2018
1 parent dfe3acd commit 036000f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/app/qgsclipboard.cpp
Expand Up @@ -202,6 +202,8 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString &string, const Q
if ( values.isEmpty() || string.isEmpty() )
return features;

QgsFields sourceFields = retrieveFields();

Q_FOREACH ( const QString &row, values )
{
// Assume that it's just WKT for now. because GeoJSON is managed by
Expand All @@ -214,23 +216,29 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString &string, const Q
if ( fieldValues.isEmpty() )
continue;

QgsGeometry geometry = QgsGeometry::fromWkt( fieldValues[0] );
if ( geometry.isNull() )
continue;

QgsFeature feature;
feature.setFields( retrieveFields() );
feature.setFields( sourceFields );
feature.initAttributes( fieldValues.size() - 1 );

//skip header line
if ( fieldValues.at( 0 ) == "wkt_geom" )
{
continue;
}

for ( int i = 1; i < fieldValues.size(); ++i )
{
feature.setAttribute( i - 1, fieldValues.at( i ) );
}

QgsGeometry geometry = QgsGeometry::fromWkt( fieldValues[0] );
if ( !geometry.isNull() )
{
feature.setGeometry( geometry );
}

feature.setGeometry( geometry );
features.append( feature );
}

return features;
}

Expand Down

0 comments on commit 036000f

Please sign in to comment.