mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Merge pull request #30620 from stev-0/clipboard-multiline
Add quotes around fields with linebreaks when copying to clipboard
This commit is contained in:
commit
94f8b65c56
@ -120,7 +120,12 @@ QString QgsClipboard::generateClipboardText() const
|
|||||||
for ( int idx = 0; idx < attributes.count(); ++idx )
|
for ( int idx = 0; idx < attributes.count(); ++idx )
|
||||||
{
|
{
|
||||||
// QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
|
// QgsDebugMsg(QString("inspecting field '%1'.").arg(it2->toString()));
|
||||||
textFields += attributes.at( idx ).toString();
|
if ( attributes.at( idx ).toString().contains( QStringLiteral( "\n" ), Qt::CaseInsensitive ) )
|
||||||
|
textFields += QStringLiteral( "\"" ) + attributes.at( idx ).toString() + QStringLiteral( "\"" );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textFields += attributes.at( idx ).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textLines += textFields.join( QStringLiteral( "\t" ) );
|
textLines += textFields.join( QStringLiteral( "\t" ) );
|
||||||
|
@ -188,6 +188,37 @@ void TestQgisAppClipboard::copyToText()
|
|||||||
|
|
||||||
QCOMPARE( x, 145 );
|
QCOMPARE( x, 145 );
|
||||||
QCOMPARE( y, -38 );
|
QCOMPARE( y, -38 );
|
||||||
|
|
||||||
|
// test that multiline text fields are quoted to render correctly as csv files in WKT mode
|
||||||
|
QgsFeature feat3( fields, 7 );
|
||||||
|
feat3.setAttribute( QStringLiteral( "string_field" ), "Single line text" );
|
||||||
|
feat3.setAttribute( QStringLiteral( "int_field" ), 1 );
|
||||||
|
feat3.setGeometry( QgsGeometry( new QgsPoint( 5, 6 ) ) );
|
||||||
|
QgsFeature feat4( fields, 8 );
|
||||||
|
feat4.setAttribute( QStringLiteral( "string_field" ), "Unix Multiline \nText" );
|
||||||
|
feat4.setAttribute( QStringLiteral( "int_field" ), 2 );
|
||||||
|
feat4.setGeometry( QgsGeometry( new QgsPoint( 7, 8 ) ) );
|
||||||
|
QgsFeature feat5( fields, 9 );
|
||||||
|
feat5.setAttribute( QStringLiteral( "string_field" ), "Windows Multiline \r\nText" );
|
||||||
|
feat5.setAttribute( QStringLiteral( "int_field" ), 3 );
|
||||||
|
feat5.setGeometry( QgsGeometry( new QgsPoint( 9, 10 ) ) );
|
||||||
|
QgsFeatureStore featsML;
|
||||||
|
featsML.addFeature( feat3 );
|
||||||
|
featsML.addFeature( feat4 );
|
||||||
|
featsML.addFeature( feat5 );
|
||||||
|
featsML.setFields( fields );
|
||||||
|
mQgisApp->clipboard()->replaceWithCopyOf( featsML );
|
||||||
|
|
||||||
|
// attributes only
|
||||||
|
settings.setEnumValue( QStringLiteral( "/qgis/copyFeatureFormat" ), QgsClipboard::AttributesOnly );
|
||||||
|
result = mQgisApp->clipboard()->generateClipboardText();
|
||||||
|
qDebug() << result;
|
||||||
|
QCOMPARE( result, QString( "int_field\tstring_field\n1\tSingle line text\n2\t\"Unix Multiline \nText\"\n3\t\"Windows Multiline \r\nText\"" ) );
|
||||||
|
|
||||||
|
// attributes with WKT
|
||||||
|
settings.setEnumValue( QStringLiteral( "/qgis/copyFeatureFormat" ), QgsClipboard::AttributesWithWKT );
|
||||||
|
result = mQgisApp->clipboard()->generateClipboardText();
|
||||||
|
QCOMPARE( result, QString( "wkt_geom\tint_field\tstring_field\nPoint (5 6)\t1\tSingle line text\nPoint (7 8)\t2\t\"Unix Multiline \nText\"\nPoint (9 10)\t3\t\"Windows Multiline \r\nText\"" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestQgisAppClipboard::pasteWkt()
|
void TestQgisAppClipboard::pasteWkt()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user