Skip to content

Commit

Permalink
Fix copy/paste using text format between projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and nyalldawson committed Aug 10, 2018
1 parent 37f5b0c commit dfe3acd
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/app/qgsclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,13 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString &string, const Q
continue;

QgsFeature feature;
if ( !fields.isEmpty() )
feature.setFields( fields, true );
feature.setFields( retrieveFields() );
feature.initAttributes( fieldValues.size() - 1 );
for ( int i = 1; i < fieldValues.size(); ++i )
{
feature.setAttribute( i - 1, fieldValues.at( i ) );
}


feature.setGeometry( geometry );
features.append( feature );
Expand All @@ -239,7 +244,27 @@ QgsFields QgsClipboard::retrieveFields() const
QString string = cb->text( QClipboard::Clipboard );
#endif

return QgsOgrUtils::stringToFields( string, QTextCodec::codecForName( "System" ) );
QgsFields f = QgsOgrUtils::stringToFields( string, QTextCodec::codecForName( "System" ) );
if ( f.size() < 1 )
{
//wkt?
QStringList lines = string.split( "\n" );
if ( lines.size() > 0 )
{
QStringList fieldNames = lines.at( 0 ).split( "\t" );
for ( int i = 0; i < fieldNames.size(); ++i )
{
QString fieldName = fieldNames.at( i );
if ( fieldName == "wkt_geom" )
{
continue;
}

f.append( QgsField( fieldName, QVariant::String ) );
}
}
}
return f;
}

QgsFeatureList QgsClipboard::copyOf( const QgsFields &fields ) const
Expand Down

0 comments on commit dfe3acd

Please sign in to comment.