diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp index 2fbe29ed904..b4b57107799 100644 --- a/src/app/qgsclipboard.cpp +++ b/src/app/qgsclipboard.cpp @@ -154,22 +154,50 @@ void QgsClipboard::setSystemClipboard() // that just the next call to systemClipboardChanged() should be ignored mIgnoreNextSystemClipboardChange = true; - QString textCopy = generateClipboardText(); - QClipboard *cb = QApplication::clipboard(); // Copy text into the clipboard + QString textCopy = generateClipboardText(); + QMimeData *m = new QMimeData(); + m->setText( textCopy ); + + if ( mFeatureClipboard.count() < 1000 ) + { + QgsSettings settings; + CopyFormat format = AttributesWithWKT; + if ( settings.contains( QStringLiteral( "/qgis/copyFeatureFormat" ) ) ) + { + format = static_cast< CopyFormat >( settings.value( QStringLiteral( "qgis/copyFeatureFormat" ), true ).toInt() ); + } + + QString htmlCopy; + switch ( format ) + { + case AttributesOnly: + case AttributesWithWKT: + htmlCopy = textCopy; + htmlCopy.replace( '\n', QStringLiteral( "" ) ); + htmlCopy.replace( '\t', QStringLiteral( "" ) ); + htmlCopy = QStringLiteral( "
" ) + htmlCopy + QStringLiteral( "
" ); + break; + case GeoJSON: + break; + } + if ( !htmlCopy.isEmpty() ) + { + m->setHtml( htmlCopy ); + } + } // With qgis running under Linux, but with a Windows based X // server (Xwin32), ::Selection was necessary to get the data into // the Windows clipboard (which seems contrary to the Qt // docs). With a Linux X server, ::Clipboard was required. // The simple solution was to put the text into both clipboards. - #ifdef Q_OS_LINUX - cb->setText( textCopy, QClipboard::Selection ); + cb->setMimeData( m, QClipboard::Selection ); #endif - cb->setText( textCopy, QClipboard::Clipboard ); + cb->setMimeData( m, QClipboard::Clipboard ); QgsDebugMsgLevel( QString( "replaced system clipboard with: %1." ).arg( textCopy ), 4 ); } diff --git a/tests/src/app/testqgisappclipboard.cpp b/tests/src/app/testqgisappclipboard.cpp index 5b3b1ff4a73..814919fc5be 100644 --- a/tests/src/app/testqgisappclipboard.cpp +++ b/tests/src/app/testqgisappclipboard.cpp @@ -149,6 +149,11 @@ void TestQgisAppClipboard::copyToText() result = mQgisApp->clipboard()->generateClipboardText(); QCOMPARE( result, QString( "wkt_geom\tint_field\tstring_field\nPoint (5 6)\t9\tval\nPoint (7 8)\t19\tval2" ) ); + // HTML test + mQgisApp->clipboard()->replaceWithCopyOf( feats ); + result = mQgisApp->clipboard()->data( "text/html" ); + QCOMPARE( result, QString( "
wkt_geomint_fieldstring_field
Point (5 6)9val
Point (7 8)19val2
" ) ); + // GeoJSON settings.setValue( QStringLiteral( "/qgis/copyFeatureFormat" ), QgsClipboard::GeoJSON ); result = mQgisApp->clipboard()->generateClipboardText();