Skip to content

Commit

Permalink
Fix QgsClipboard::retrieveFields and adapt unit test (because feature…
Browse files Browse the repository at this point in the history
…s without geometries are now allowed in QgsClipboard)
  • Loading branch information
mhugent authored and nyalldawson committed Aug 10, 2018
1 parent 036000f commit 83da570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/app/qgsclipboard.cpp
Expand Up @@ -255,11 +255,22 @@ QgsFields QgsClipboard::retrieveFields() const
QgsFields f = QgsOgrUtils::stringToFields( string, QTextCodec::codecForName( "System" ) );
if ( f.size() < 1 )
{
if ( string.isEmpty() )
{
return f;
}

//wkt?
QStringList lines = string.split( "\n" );
if ( lines.size() > 0 )
{
QStringList fieldNames = lines.at( 0 ).split( "\t" );
//wkt / text always has wkt_geom as first attribute (however values can be NULL)
if ( fieldNames.at( 0 ) != "wkt_geom" )
{
return f;
}

for ( int i = 0; i < fieldNames.size(); ++i )
{
QString fieldName = fieldNames.at( i );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgisappclipboard.cpp
Expand Up @@ -241,10 +241,10 @@ void TestQgisAppClipboard::pasteWkt()
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );

// only fields => no geom so no feature list is returned
//clipboard now supports features without geometry
mQgisApp->clipboard()->setText( QStringLiteral( "MNL 11 282 km \nMNL 11 347.80000000000001 km " ) );
features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 0 );
QCOMPARE( features.length(), 2 );
}

void TestQgisAppClipboard::pasteGeoJson()
Expand Down

0 comments on commit 83da570

Please sign in to comment.