From 0a3313d317a7f2f1c48cf4ed2dc6faa26e23d9b7 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Thu, 4 Jul 2013 13:25:18 +0200 Subject: [PATCH] added change signal to clipboard --- src/app/CMakeLists.txt | 1 + src/app/qgisapp.cpp | 7 +++++-- src/app/qgisapp.h | 2 ++ src/app/qgsclipboard.cpp | 8 +++++++- src/app/qgsclipboard.h | 8 +++++++- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index cf7920e09f7..683d1017cde 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -171,6 +171,7 @@ SET (QGIS_APP_MOC_HDRS qgsattributetabledialog.h qgsbookmarks.h qgsbrowserdockwidget.h + qgsclipboard.h qgsconfigureshortcutsdialog.h qgscustomization.h qgscustomprojectiondialog.h diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 6ffd0b51fe2..e7ffd0e9b47 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -573,6 +573,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent, mLogDock->hide(); mInternalClipboard = new QgsClipboard; // create clipboard + connect( mInternalClipboard, SIGNAL( changed() ), this, SLOT( clipboardChanged() ) ); mQgisInterface = new QgisAppInterface( this ); // create the interfce #ifdef Q_WS_MAC @@ -5483,7 +5484,6 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection ) selectionVectorLayer->beginEditCommand( tr( "Features cut" ) ); selectionVectorLayer->deleteSelectedFeatures(); selectionVectorLayer->endEditCommand(); - activateDeactivateLayerRelatedActions( activeLayer() ); } void QgisApp::editCopy( QgsMapLayer * layerContainingSelection ) @@ -5499,9 +5499,12 @@ void QgisApp::editCopy( QgsMapLayer * layerContainingSelection ) // Test for feature support in this layer clipboard()->replaceWithCopyOf( selectionVectorLayer ); - activateDeactivateLayerRelatedActions( activeLayer() ); } +void QgisApp::clipboardChanged() +{ + activateDeactivateLayerRelatedActions( activeLayer() ); +} void QgisApp::editPaste( QgsMapLayer *destinationLayer ) { diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index dc6f23d789b..647fc859f84 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -1129,6 +1129,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow void osmImportDialog(); void osmExportDialog(); + void clipboardChanged(); + signals: /** emitted when a key is pressed and we want non widget sublasses to be able to pick up on this (e.g. maplayer) */ diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp index aae3f66f8b7..80cd6218e44 100644 --- a/src/app/qgsclipboard.cpp +++ b/src/app/qgsclipboard.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,8 @@ #include "qgsvectorlayer.h" QgsClipboard::QgsClipboard() - : mFeatureClipboard() + : QObject() + , mFeatureClipboard() , mFeatureFields() { } @@ -55,6 +57,7 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src ) QgsDebugMsg( "replaced QGis clipboard." ); setSystemClipboard(); + emit changed(); } void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore ) @@ -64,6 +67,7 @@ void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore ) mFeatureClipboard = featureStore.features(); mCRS = featureStore.crs(); setSystemClipboard(); + emit changed(); } void QgsClipboard::setSystemClipboard() @@ -149,6 +153,7 @@ void QgsClipboard::clear() mFeatureClipboard.clear(); QgsDebugMsg( "cleared clipboard." ); + emit changed(); } void QgsClipboard::insert( QgsFeature& feature ) @@ -156,6 +161,7 @@ void QgsClipboard::insert( QgsFeature& feature ) mFeatureClipboard.push_back( feature ); QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() ); + emit changed(); } bool QgsClipboard::empty() diff --git a/src/app/qgsclipboard.h b/src/app/qgsclipboard.h index 73fc6c43cdc..9c6a49eb379 100644 --- a/src/app/qgsclipboard.h +++ b/src/app/qgsclipboard.h @@ -20,6 +20,7 @@ #include #include +#include #include "qgsfield.h" #include "qgsfeature.h" @@ -49,8 +50,9 @@ class QgsVectorLayer; */ #define QGSCLIPBOARD_STYLE_MIME "application/qgis.style" -class QgsClipboard +class QgsClipboard : public QObject { + Q_OBJECT public: /** * Constructor for the clipboard. @@ -139,6 +141,10 @@ class QgsClipboard */ const QgsFields &fields() { return mFeatureFields; } + signals: + /** Emited when content changed */ + void changed(); + private: /* * Set system clipboard from previously set features.