Skip to content

Commit a2c1810

Browse files
committedAug 6, 2017
From Clipboard Cut&Paste fix when attached special field values. Fiexies #16870
1 parent 3026140 commit a2c1810

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
 

‎src/app/qgsclipboard.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,17 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString &string, const Q
190190

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

‎tests/src/app/testqgisappclipboard.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,31 @@ void TestQgisAppClipboard::pasteWkt()
218218
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() );
219219
QCOMPARE( point->x(), 111.0 );
220220
QCOMPARE( point->y(), 30.0 );
221+
222+
// be sure parsing does not consider attached parameters that
223+
// can change geometryType as in https://issues.qgis.org/issues/16870
224+
mQgisApp->clipboard()->setText( QStringLiteral( "POINT (111 30)\t GoodFieldValue\nPOINT (125 10)\t(WrongFieldValue)" ) );
225+
226+
features = mQgisApp->clipboard()->copyOf();
227+
QCOMPARE( features.length(), 2 );
228+
229+
QVERIFY( features.at( 0 ).hasGeometry() && !features.at( 0 ).geometry().isNull() );
230+
QCOMPARE( features.at( 0 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
231+
featureGeom = features.at( 0 ).geometry();
232+
point = dynamic_cast< QgsPoint * >( featureGeom.geometry() );
233+
QCOMPARE( point->x(), 111.0 );
234+
QCOMPARE( point->y(), 30.0 );
235+
236+
QVERIFY( features.at( 1 ).hasGeometry() && !features.at( 1 ).geometry().isNull() );
237+
QCOMPARE( features.at( 1 ).geometry().geometry()->wkbType(), QgsWkbTypes::Point );
238+
point = dynamic_cast< QgsPoint * >( features.at( 1 ).geometry().geometry() );
239+
QCOMPARE( point->x(), 125.0 );
240+
QCOMPARE( point->y(), 10.0 );
241+
242+
// only fields => no geom so no feature list is returned
243+
mQgisApp->clipboard()->setText( QStringLiteral( "MNL 11 282 km \nMNL 11 347.80000000000001 km " ) );
244+
features = mQgisApp->clipboard()->copyOf();
245+
QCOMPARE( features.length(), 0 );
221246
}
222247

223248
void TestQgisAppClipboard::pasteGeoJson()

0 commit comments

Comments
 (0)
Please sign in to comment.