Skip to content

Commit 67b68a8

Browse files
authored
Merge pull request #5578 from gacarrillor/iface_copy_paste_features
Expose through iface methods to copy/paste features between given layers
2 parents 970a723 + a00ce9e commit 67b68a8

File tree

8 files changed

+58
-12
lines changed

8 files changed

+58
-12
lines changed

python/gui/qgisinterface.sip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,18 @@ Start a blank project
767767
:rtype: bool
768768
%End
769769

770+
virtual void copySelectionToClipboard( QgsMapLayer * ) = 0;
771+
%Docstring
772+
Copy selected features from the layer to clipboard
773+
.. versionadded:: 3.0
774+
%End
775+
776+
virtual void pasteFromClipboard( QgsMapLayer * ) = 0;
777+
%Docstring
778+
Paste features from clipboard to the layer
779+
.. versionadded:: 3.0
780+
%End
781+
770782
virtual int addToolBarIcon( QAction *qAction ) = 0;
771783
%Docstring
772784
Add an icon to the plugins toolbar

src/app/qgisapp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,9 +1822,9 @@ void QgisApp::createActions()
18221822

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

80868086

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

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

8116-
void QgisApp::editPaste( QgsMapLayer *destinationLayer )
8116+
void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
81178117
{
81188118
QgsVectorLayer *pasteVectorLayer = qobject_cast<QgsVectorLayer *>( destinationLayer ? destinationLayer : activeLayer() );
81198119
if ( !pasteVectorLayer )

src/app/qgisapp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,21 +745,21 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
745745
\param layerContainingSelection The layer that the selection will be taken from
746746
(defaults to the active layer on the legend)
747747
*/
748-
void editCut( QgsMapLayer *layerContainingSelection = nullptr );
748+
void cutSelectionToClipboard( QgsMapLayer *layerContainingSelection = nullptr );
749749
//! copies selected features on the active layer to the clipboard
750750

751751
/**
752752
\param layerContainingSelection The layer that the selection will be taken from
753753
(defaults to the active layer on the legend)
754754
*/
755-
void editCopy( QgsMapLayer *layerContainingSelection = nullptr );
755+
void copySelectionToClipboard( QgsMapLayer *layerContainingSelection = nullptr );
756756
//! copies features on the clipboard to the active layer
757757

758758
/**
759759
\param destinationLayer The layer that the clipboard will be pasted to
760760
(defaults to the active layer on the legend)
761761
*/
762-
void editPaste( QgsMapLayer *destinationLayer = nullptr );
762+
void pasteFromClipboard( QgsMapLayer *destinationLayer = nullptr );
763763
//! copies features on the clipboard to a new vector layer
764764
void pasteAsNewVector();
765765
//! copies features on the clipboard to a new memory vector layer

src/app/qgisappinterface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ bool QgisAppInterface::setActiveLayer( QgsMapLayer *layer )
186186
return qgis->setActiveLayer( layer );
187187
}
188188

189+
void QgisAppInterface::copySelectionToClipboard( QgsMapLayer *layer )
190+
{
191+
return qgis->copySelectionToClipboard( layer );
192+
}
193+
194+
void QgisAppInterface::pasteFromClipboard( QgsMapLayer *layer )
195+
{
196+
return qgis->pasteFromClipboard( layer );
197+
}
198+
189199
void QgisAppInterface::addPluginToMenu( const QString &name, QAction *action )
190200
{
191201
qgis->addPluginToMenu( name, action );

src/app/qgisappinterface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
9696
//! set the active layer (layer selected in the legend)
9797
bool setActiveLayer( QgsMapLayer *layer ) override;
9898

99+
/**
100+
* Copy selected features from the layer to clipboard
101+
* \since QGIS 3.0
102+
*/
103+
virtual void copySelectionToClipboard( QgsMapLayer *layer ) override;
104+
105+
/**
106+
* Paste features from clipboard to the layer
107+
* \since QGIS 3.0
108+
*/
109+
virtual void pasteFromClipboard( QgsMapLayer *layer ) override;
110+
99111
//! Add an icon to the plugins toolbar
100112
int addToolBarIcon( QAction *qAction ) override;
101113

src/app/qgsattributetabledialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,12 @@ void QgsAttributeTableDialog::mActionExpressionSelect_triggered()
730730

731731
void QgsAttributeTableDialog::mActionCopySelectedRows_triggered()
732732
{
733-
QgisApp::instance()->editCopy( mLayer );
733+
QgisApp::instance()->copySelectionToClipboard( mLayer );
734734
}
735735

736736
void QgsAttributeTableDialog::mActionPasteFeatures_triggered()
737737
{
738-
QgisApp::instance()->editPaste( mLayer );
738+
QgisApp::instance()->pasteFromClipboard( mLayer );
739739
}
740740

741741

src/gui/qgisinterface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ class GUI_EXPORT QgisInterface : public QObject
422422
*/
423423
virtual bool setActiveLayer( QgsMapLayer * ) = 0;
424424

425+
/**
426+
* Copy selected features from the layer to clipboard
427+
* \since QGIS 3.0
428+
*/
429+
virtual void copySelectionToClipboard( QgsMapLayer * ) = 0;
430+
431+
/**
432+
* Paste features from clipboard to the layer
433+
* \since QGIS 3.0
434+
*/
435+
virtual void pasteFromClipboard( QgsMapLayer * ) = 0;
436+
425437
//! Add an icon to the plugins toolbar
426438
virtual int addToolBarIcon( QAction *qAction ) = 0;
427439

tests/src/app/testqgisappclipboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void TestQgisAppClipboard::copyPaste()
103103

104104
// copy all features to clipboard
105105
inputLayer->selectAll();
106-
mQgisApp->editCopy( inputLayer );
106+
mQgisApp->copySelectionToClipboard( inputLayer );
107107

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

0 commit comments

Comments
 (0)