Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Read WKT from system clipboard and create geometry on paste
  • Loading branch information
NathanW2 committed Oct 25, 2013
1 parent 5f5cd4c commit 4904c06
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down
48 changes: 42 additions & 6 deletions src/app/qgsclipboard.cpp
Expand Up @@ -38,6 +38,7 @@ QgsClipboard::QgsClipboard()
, mFeatureClipboard()
, mFeatureFields()
{
connect( QApplication::clipboard(), SIGNAL( dataChanged() ), this, SIGNAL( changed() ) );
}

QgsClipboard::~QgsClipboard()
Expand Down Expand Up @@ -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()
Expand All @@ -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." );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsclipboard.h
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 4904c06

Please sign in to comment.