Skip to content

Commit

Permalink
From Clipboard Cut&Paste fix when attached special field values. Fiex…
Browse files Browse the repository at this point in the history
…ies #16870
  • Loading branch information
luipir committed Aug 16, 2017
1 parent ebf20a5 commit b625451
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app/qgsclipboard.cpp
Expand Up @@ -187,16 +187,25 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString& string, const Q

Q_FOREACH ( const QString& row, values )
{
// Assume that it's just WKT for now.
QgsGeometry* geometry = QgsGeometry::fromWkt( row );
// Assume that it's just WKT for now. because GeoJSON is managed by
// previous QgsOgrUtils::stringToFeatureList call
// Get the first value of a \t separated list. WKT clipboard pasted
// feature has first element the WKT geom.
// This split is to fix te following issue: https://issues.qgis.org/issues/16870
// Value separators are set in generateClipboardText
QStringList fieldValues = row.split( '\t' );
if ( fieldValues.isEmpty() )
continue;

QgsGeometry *geometry = QgsGeometry::fromWkt( fieldValues[0] );
if ( !geometry )
continue;

QgsFeature feature;
if ( !fields.isEmpty() )
feature.setFields( fields, true );

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

Expand Down
25 changes: 25 additions & 0 deletions tests/src/app/testqgisappclipboard.cpp
Expand Up @@ -215,6 +215,31 @@ void TestQgisAppClipboard::pasteWkt()
point = dynamic_cast< QgsPointV2* >( features.at( 1 ).constGeometry()->geometry() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );

// be sure parsing does not consider attached parameters that
// can change geometryType as in https://issues.qgis.org/issues/16870
mQgisApp->clipboard()->setText( QStringLiteral( "POINT (111 30)\t GoodFieldValue\nPOINT (125 10)\t(WrongFieldValue)" ) );

features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 2 );

QVERIFY( features.at( 0 ).constGeometry() && !features.at( 0 ).constGeometry()->isEmpty() );
QCOMPARE( features.at( 0 ).constGeometry()->geometry()->wkbType(), QgsWKBTypes::Point );
const QgsGeometry *featureGeom = features.at( 0 ).constGeometry();
point = dynamic_cast< QgsPointV2 * >( featureGeom->geometry() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );

QVERIFY( features.at( 1 ).constGeometry() && !features.at( 1 ).constGeometry()->isEmpty() );
QCOMPARE( features.at( 1 ).constGeometry()->geometry()->wkbType(), QgsWKBTypes::Point );
point = dynamic_cast< QgsPointV2 * >( features.at( 1 ).constGeometry()->geometry() );
QCOMPARE( point->x(), 125.0 );
QCOMPARE( point->y(), 10.0 );

// only fields => no geom so no feature list is returned
mQgisApp->clipboard()->setText( QStringLiteral( "MNL\t11\t282\tkm\t\nMNL\t11\t347.80000000000001\tkm\t" ) );
features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 0 );
}

void TestQgisAppClipboard::pasteGeoJson()
Expand Down

0 comments on commit b625451

Please sign in to comment.