Skip to content

Commit

Permalink
added change signal to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 5, 2013
1 parent 250df51 commit 0a3313d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -171,6 +171,7 @@ SET (QGIS_APP_MOC_HDRS
qgsattributetabledialog.h
qgsbookmarks.h
qgsbrowserdockwidget.h
qgsclipboard.h
qgsconfigureshortcutsdialog.h
qgscustomization.h
qgscustomprojectiondialog.h
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
{
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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) */
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsclipboard.cpp
Expand Up @@ -18,6 +18,7 @@
#include <fstream>

#include <QApplication>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QClipboard>
Expand All @@ -33,7 +34,8 @@
#include "qgsvectorlayer.h"

QgsClipboard::QgsClipboard()
: mFeatureClipboard()
: QObject()
, mFeatureClipboard()
, mFeatureFields()
{
}
Expand All @@ -55,6 +57,7 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
QgsDebugMsg( "replaced QGis clipboard." );

setSystemClipboard();
emit changed();
}

void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore )
Expand All @@ -64,6 +67,7 @@ void QgsClipboard::replaceWithCopyOf( QgsFeatureStore & featureStore )
mFeatureClipboard = featureStore.features();
mCRS = featureStore.crs();
setSystemClipboard();
emit changed();
}

void QgsClipboard::setSystemClipboard()
Expand Down Expand Up @@ -149,13 +153,15 @@ void QgsClipboard::clear()
mFeatureClipboard.clear();

QgsDebugMsg( "cleared clipboard." );
emit changed();
}

void QgsClipboard::insert( QgsFeature& feature )
{
mFeatureClipboard.push_back( feature );

QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
emit changed();
}

bool QgsClipboard::empty()
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsclipboard.h
Expand Up @@ -20,6 +20,7 @@

#include <QList>
#include <QMap>
#include <QObject>

#include "qgsfield.h"
#include "qgsfeature.h"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0a3313d

Please sign in to comment.