Skip to content

Commit b625451

Browse files
committedAug 16, 2017
From Clipboard Cut&Paste fix when attached special field values. Fiexies #16870
1 parent ebf20a5 commit b625451

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed
 

‎src/app/qgsclipboard.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,25 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString& string, const Q
187187

188188
Q_FOREACH ( const QString& row, values )
189189
{
190-
// Assume that it's just WKT for now.
191-
QgsGeometry* geometry = QgsGeometry::fromWkt( row );
190+
// Assume that it's just WKT for now. because GeoJSON is managed by
191+
// previous QgsOgrUtils::stringToFeatureList call
192+
// Get the first value of a \t separated list. WKT clipboard pasted
193+
// feature has first element the WKT geom.
194+
// This split is to fix te following issue: https://issues.qgis.org/issues/16870
195+
// Value separators are set in generateClipboardText
196+
QStringList fieldValues = row.split( '\t' );
197+
if ( fieldValues.isEmpty() )
198+
continue;
199+
200+
QgsGeometry *geometry = QgsGeometry::fromWkt( fieldValues[0] );
192201
if ( !geometry )
193202
continue;
194203

195204
QgsFeature feature;
196205
if ( !fields.isEmpty() )
197206
feature.setFields( fields, true );
198207

199-
feature.setGeometry( geometry );
208+
feature.setGeometry( *geometry );
200209
features.append( feature );
201210
}
202211

‎tests/src/app/testqgisappclipboard.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,31 @@ void TestQgisAppClipboard::pasteWkt()
215215
point = dynamic_cast< QgsPointV2* >( features.at( 1 ).constGeometry()->geometry() );
216216
QCOMPARE( point->x(), 111.0 );
217217
QCOMPARE( point->y(), 30.0 );
218+
219+
// be sure parsing does not consider attached parameters that
220+
// can change geometryType as in https://issues.qgis.org/issues/16870
221+
mQgisApp->clipboard()->setText( QStringLiteral( "POINT (111 30)\t GoodFieldValue\nPOINT (125 10)\t(WrongFieldValue)" ) );
222+
223+
features = mQgisApp->clipboard()->copyOf();
224+
QCOMPARE( features.length(), 2 );
225+
226+
QVERIFY( features.at( 0 ).constGeometry() && !features.at( 0 ).constGeometry()->isEmpty() );
227+
QCOMPARE( features.at( 0 ).constGeometry()->geometry()->wkbType(), QgsWKBTypes::Point );
228+
const QgsGeometry *featureGeom = features.at( 0 ).constGeometry();
229+
point = dynamic_cast< QgsPointV2 * >( featureGeom->geometry() );
230+
QCOMPARE( point->x(), 111.0 );
231+
QCOMPARE( point->y(), 30.0 );
232+
233+
QVERIFY( features.at( 1 ).constGeometry() && !features.at( 1 ).constGeometry()->isEmpty() );
234+
QCOMPARE( features.at( 1 ).constGeometry()->geometry()->wkbType(), QgsWKBTypes::Point );
235+
point = dynamic_cast< QgsPointV2 * >( features.at( 1 ).constGeometry()->geometry() );
236+
QCOMPARE( point->x(), 125.0 );
237+
QCOMPARE( point->y(), 10.0 );
238+
239+
// only fields => no geom so no feature list is returned
240+
mQgisApp->clipboard()->setText( QStringLiteral( "MNL\t11\t282\tkm\t\nMNL\t11\t347.80000000000001\tkm\t" ) );
241+
features = mQgisApp->clipboard()->copyOf();
242+
QCOMPARE( features.length(), 0 );
218243
}
219244

220245
void TestQgisAppClipboard::pasteGeoJson()

0 commit comments

Comments
 (0)
Please sign in to comment.