Skip to content
Permalink
Browse files

Merge pull request #5578 from gacarrillor/iface_copy_paste_features

Expose through iface methods to copy/paste features between given layers
  • Loading branch information
m-kuhn committed Nov 20, 2017
2 parents 970a723 + a00ce9e commit 67b68a841d4af1d1e54f7be875aeafba00395199
@@ -767,6 +767,18 @@ Start a blank project
:rtype: bool
%End

virtual void copySelectionToClipboard( QgsMapLayer * ) = 0;
%Docstring
Copy selected features from the layer to clipboard
.. versionadded:: 3.0
%End

virtual void pasteFromClipboard( QgsMapLayer * ) = 0;
%Docstring
Paste features from clipboard to the layer
.. versionadded:: 3.0
%End

virtual int addToolBarIcon( QAction *qAction ) = 0;
%Docstring
Add an icon to the plugins toolbar
@@ -1822,9 +1822,9 @@ void QgisApp::createActions()

connect( mActionUndo, &QAction::triggered, mUndoWidget, &QgsUndoWidget::undo );
connect( mActionRedo, &QAction::triggered, mUndoWidget, &QgsUndoWidget::redo );
connect( mActionCutFeatures, &QAction::triggered, this, [ = ] { editCut(); } );
connect( mActionCopyFeatures, &QAction::triggered, this, [ = ] { editCopy(); } );
connect( mActionPasteFeatures, &QAction::triggered, this, [ = ] { editPaste(); } );
connect( mActionCutFeatures, &QAction::triggered, this, [ = ] { cutSelectionToClipboard(); } );
connect( mActionCopyFeatures, &QAction::triggered, this, [ = ] { copySelectionToClipboard(); } );
connect( mActionPasteFeatures, &QAction::triggered, this, [ = ] { pasteFromClipboard(); } );
connect( mActionPasteAsNewVector, &QAction::triggered, this, &QgisApp::pasteAsNewVector );
connect( mActionPasteAsNewMemoryVector, &QAction::triggered, this, [ = ] { pasteAsNewMemoryVector(); } );
connect( mActionCopyStyle, &QAction::triggered, this, [ = ] { copyStyle(); } );
@@ -8084,7 +8084,7 @@ void QgisApp::addPart()
}


void QgisApp::editCut( QgsMapLayer *layerContainingSelection )
void QgisApp::cutSelectionToClipboard( QgsMapLayer *layerContainingSelection )
{
// Test for feature support in this layer
QgsVectorLayer *selectionVectorLayer = qobject_cast<QgsVectorLayer *>( layerContainingSelection ? layerContainingSelection : activeLayer() );
@@ -8098,7 +8098,7 @@ void QgisApp::editCut( QgsMapLayer *layerContainingSelection )
selectionVectorLayer->endEditCommand();
}

void QgisApp::editCopy( QgsMapLayer *layerContainingSelection )
void QgisApp::copySelectionToClipboard( QgsMapLayer *layerContainingSelection )
{
QgsVectorLayer *selectionVectorLayer = qobject_cast<QgsVectorLayer *>( layerContainingSelection ? layerContainingSelection : activeLayer() );
if ( !selectionVectorLayer )
@@ -8113,7 +8113,7 @@ void QgisApp::clipboardChanged()
activateDeactivateLayerRelatedActions( activeLayer() );
}

void QgisApp::editPaste( QgsMapLayer *destinationLayer )
void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
{
QgsVectorLayer *pasteVectorLayer = qobject_cast<QgsVectorLayer *>( destinationLayer ? destinationLayer : activeLayer() );
if ( !pasteVectorLayer )
@@ -745,21 +745,21 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
\param layerContainingSelection The layer that the selection will be taken from
(defaults to the active layer on the legend)
*/
void editCut( QgsMapLayer *layerContainingSelection = nullptr );
void cutSelectionToClipboard( QgsMapLayer *layerContainingSelection = nullptr );
//! copies selected features on the active layer to the clipboard

/**
\param layerContainingSelection The layer that the selection will be taken from
(defaults to the active layer on the legend)
*/
void editCopy( QgsMapLayer *layerContainingSelection = nullptr );
void copySelectionToClipboard( QgsMapLayer *layerContainingSelection = nullptr );
//! copies features on the clipboard to the active layer

/**
\param destinationLayer The layer that the clipboard will be pasted to
(defaults to the active layer on the legend)
*/
void editPaste( QgsMapLayer *destinationLayer = nullptr );
void pasteFromClipboard( QgsMapLayer *destinationLayer = nullptr );
//! copies features on the clipboard to a new vector layer
void pasteAsNewVector();
//! copies features on the clipboard to a new memory vector layer
@@ -186,6 +186,16 @@ bool QgisAppInterface::setActiveLayer( QgsMapLayer *layer )
return qgis->setActiveLayer( layer );
}

void QgisAppInterface::copySelectionToClipboard( QgsMapLayer *layer )
{
return qgis->copySelectionToClipboard( layer );
}

void QgisAppInterface::pasteFromClipboard( QgsMapLayer *layer )
{
return qgis->pasteFromClipboard( layer );
}

void QgisAppInterface::addPluginToMenu( const QString &name, QAction *action )
{
qgis->addPluginToMenu( name, action );
@@ -96,6 +96,18 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
//! set the active layer (layer selected in the legend)
bool setActiveLayer( QgsMapLayer *layer ) override;

/**
* Copy selected features from the layer to clipboard
* \since QGIS 3.0
*/
virtual void copySelectionToClipboard( QgsMapLayer *layer ) override;

/**
* Paste features from clipboard to the layer
* \since QGIS 3.0
*/
virtual void pasteFromClipboard( QgsMapLayer *layer ) override;

//! Add an icon to the plugins toolbar
int addToolBarIcon( QAction *qAction ) override;

@@ -730,12 +730,12 @@ void QgsAttributeTableDialog::mActionExpressionSelect_triggered()

void QgsAttributeTableDialog::mActionCopySelectedRows_triggered()
{
QgisApp::instance()->editCopy( mLayer );
QgisApp::instance()->copySelectionToClipboard( mLayer );
}

void QgsAttributeTableDialog::mActionPasteFeatures_triggered()
{
QgisApp::instance()->editPaste( mLayer );
QgisApp::instance()->pasteFromClipboard( mLayer );
}


@@ -422,6 +422,18 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual bool setActiveLayer( QgsMapLayer * ) = 0;

/**
* Copy selected features from the layer to clipboard
* \since QGIS 3.0
*/
virtual void copySelectionToClipboard( QgsMapLayer * ) = 0;

/**
* Paste features from clipboard to the layer
* \since QGIS 3.0
*/
virtual void pasteFromClipboard( QgsMapLayer * ) = 0;

//! Add an icon to the plugins toolbar
virtual int addToolBarIcon( QAction *qAction ) = 0;

@@ -103,7 +103,7 @@ void TestQgisAppClipboard::copyPaste()

// copy all features to clipboard
inputLayer->selectAll();
mQgisApp->editCopy( inputLayer );
mQgisApp->copySelectionToClipboard( inputLayer );

QgsFeatureList features = mQgisApp->clipboard()->copyOf();
qDebug() << features.size() << " features copied to clipboard";

0 comments on commit 67b68a8

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