Skip to content
Permalink
Browse files

Read WKT from system clipboard and create geometry on paste

  • Loading branch information
NathanW2 committed Oct 25, 2013
1 parent 5f5cd4c commit 4904c06945b5697e67b3ac32fb048b4e556002ff
Showing with 46 additions and 11 deletions.
  1. +2 −3 src/app/qgisapp.cpp
  2. +42 −6 src/app/qgsclipboard.cpp
  3. +2 −2 src/app/qgsclipboard.h
@@ -5551,11 +5551,11 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
QgsFeatureList features;
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs() );
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->pendingFields() );
}
else
{
features = clipboard()->copyOf();
features = clipboard()->copyOf( pasteVectorLayer->pendingFields() );
}

QHash<int, int> remap;
@@ -8267,7 +8267,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionCutFeatures->setEnabled( false );
mActionCopyFeatures->setEnabled( false );
mActionPasteFeatures->setEnabled( false );
mMenuPasteAs->setEnabled( false );
mActionCopyStyle->setEnabled( false );
mActionPasteStyle->setEnabled( false );

@@ -38,6 +38,7 @@ QgsClipboard::QgsClipboard()
, mFeatureClipboard()
, mFeatureFields()
{
connect( QApplication::clipboard(), SIGNAL( dataChanged() ), this, SIGNAL( changed() ) );
}

QgsClipboard::~QgsClipboard()
@@ -139,13 +140,43 @@ void QgsClipboard::setSystemClipboard()
QgsDebugMsg( QString( "replaced system clipboard with: %1." ).arg( textCopy ) );
}

QgsFeatureList QgsClipboard::copyOf()
QgsFeatureList QgsClipboard::copyOf( const QgsFields &fields )
{
QgsDebugMsg( "returning clipboard." );
QClipboard *cb = QApplication::clipboard();

#ifndef Q_OS_WIN
QString text = cb->text( QClipboard::Selection );
#endif
QString text = cb->text( QClipboard::Clipboard );

QStringList values = text.split("\n");
if ( values.isEmpty() || text.isEmpty() )
return mFeatureClipboard;

QgsFeatureList features;
foreach ( QString row, values )
{
// Assume that it's just WKT for now.
QgsGeometry* geometry = QgsGeometry::fromWkt( row );
if ( !geometry )
continue;

//TODO: Slurp from the system clipboard as well.
QgsFeature* feature = new QgsFeature();
if ( !fields.isEmpty() )
feature->setFields( &fields , true );

return mFeatureClipboard;
feature->setGeometry( geometry );
features.append( QgsFeature( *feature ));
}

if ( features.isEmpty() )
return mFeatureClipboard;

if ( !fields.isEmpty() )
mFeatureFields = fields;

return features;
}

void QgsClipboard::clear()
@@ -166,12 +197,17 @@ void QgsClipboard::insert( QgsFeature& feature )

bool QgsClipboard::empty()
{
return mFeatureClipboard.empty();
QClipboard *cb = QApplication::clipboard();
#ifndef Q_OS_WIN
QString text = cb->text( QClipboard::Selection );
#endif
QString text = cb->text( QClipboard::Clipboard );
return text.isEmpty() && mFeatureClipboard.empty();
}

QgsFeatureList QgsClipboard::transformedCopyOf( QgsCoordinateReferenceSystem destCRS )
QgsFeatureList QgsClipboard::transformedCopyOf(QgsCoordinateReferenceSystem destCRS , const QgsFields &fields)
{
QgsFeatureList featureList = copyOf();
QgsFeatureList featureList = copyOf( fields );
QgsCoordinateTransform ct( crs(), destCRS );

QgsDebugMsg( "transforming clipboard." );
@@ -79,7 +79,7 @@ class APP_EXPORT QgsClipboard : public QObject
* the caller assumes responsibility for destroying the contents
* when it's done with it.
*/
QgsFeatureList copyOf();
QgsFeatureList copyOf( const QgsFields &fields = QgsFields() );

/*
* Clears the internal clipboard.
@@ -102,7 +102,7 @@ class APP_EXPORT QgsClipboard : public QObject
* The caller assumes responsibility for destroying the contents
* when it's done with it.
*/
QgsFeatureList transformedCopyOf( QgsCoordinateReferenceSystem destCRS );
QgsFeatureList transformedCopyOf( QgsCoordinateReferenceSystem destCRS, const QgsFields &fields = QgsFields() );

/*
* Get the clipboard CRS

0 comments on commit 4904c06

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