diff --git a/python/gui/qgisinterface.sip b/python/gui/qgisinterface.sip index 96c12660690..ac3d51d980a 100644 --- a/python/gui/qgisinterface.sip +++ b/python/gui/qgisinterface.sip @@ -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 diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index c682597c058..a551dd02edf 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -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( 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( 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( destinationLayer ? destinationLayer : activeLayer() ); if ( !pasteVectorLayer ) diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index a03f3c19c05..f7353bbdd05 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -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 diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index 7165924320f..88647583336 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -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 ); diff --git a/src/app/qgisappinterface.h b/src/app/qgisappinterface.h index ffef99c0c24..b9d7d65617d 100644 --- a/src/app/qgisappinterface.h +++ b/src/app/qgisappinterface.h @@ -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; diff --git a/src/app/qgsattributetabledialog.cpp b/src/app/qgsattributetabledialog.cpp index 6e6c221281f..f6f5bb21089 100644 --- a/src/app/qgsattributetabledialog.cpp +++ b/src/app/qgsattributetabledialog.cpp @@ -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 ); } diff --git a/src/gui/qgisinterface.h b/src/gui/qgisinterface.h index d4a41abea86..690047ec217 100644 --- a/src/gui/qgisinterface.h +++ b/src/gui/qgisinterface.h @@ -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; diff --git a/tests/src/app/testqgisappclipboard.cpp b/tests/src/app/testqgisappclipboard.cpp index e662339bc58..5b3b1ff4a73 100644 --- a/tests/src/app/testqgisappclipboard.cpp +++ b/tests/src/app/testqgisappclipboard.cpp @@ -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";