Skip to content
Permalink
Browse files

From Clipboard Cut&Paste fix when attached special field values. Fiex…

…ies #16870
  • Loading branch information
luipir committed Aug 6, 2017
1 parent 3026140 commit a2c18104362e16e3cac17829b18d13fd64e1f472
Showing with 36 additions and 2 deletions.
  1. +11 −2 src/app/qgsclipboard.cpp
  2. +25 −0 tests/src/app/testqgisappclipboard.cpp
@@ -190,8 +190,17 @@ 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.isNull() )
continue;

@@ -218,6 +218,31 @@ void TestQgisAppClipboard::pasteWkt()
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().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 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
featureGeom = features.at( 0 ).geometry();
point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
QCOMPARE( point->x(), 111.0 );
QCOMPARE( point->y(), 30.0 );

QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().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 11 282 km \nMNL 11 347.80000000000001 km " ) );
features = mQgisApp->clipboard()->copyOf();
QCOMPARE( features.length(), 0 );
}

void TestQgisAppClipboard::pasteGeoJson()

0 comments on commit a2c1810

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