Skip to content

Commit a42820e

Browse files
author
homann
committed
Fixes #929. Only enable copy/cut action when there is a selection, and only enable paste action when there is something in the clipboard.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9551 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b733bde commit a42820e

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

src/app/qgisapp.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ void QgisApp::setupConnections()
14981498
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( showScale( double ) ) );
14991499
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( updateMouseCoordinatePrecision() ) );
15001500
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool * ) ) );
1501+
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
1502+
this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) );
15011503

15021504
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), mMapCanvas, SLOT( setRenderFlag( bool ) ) );
15031505
//
@@ -5029,16 +5031,17 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
50295031
/***********Vector layers****************/
50305032
if ( layer->type() == QgsMapLayer::VectorLayer )
50315033
{
5034+
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
5035+
const QgsVectorDataProvider* dprovider = vlayer->dataProvider();
5036+
bool layerHasSelection = ( vlayer->selectedFeatureCount() != 0 );
5037+
50325038
mActionSelect->setEnabled( true );
50335039
mActionIdentify->setEnabled( true );
50345040
mActionZoomActualSize->setEnabled( false );
50355041
mActionOpenTable->setEnabled( true );
50365042
mActionLayerSaveAs->setEnabled( true );
50375043
mActionLayerSelectionSaveAs->setEnabled( true );
5038-
mActionCopyFeatures->setEnabled( true );
5039-
5040-
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( layer );
5041-
const QgsVectorDataProvider* dprovider = vlayer->dataProvider();
5044+
mActionCopyFeatures->setEnabled( layerHasSelection );
50425045

50435046
if ( !vlayer->isEditable() && mMapCanvas->mapTool() && mMapCanvas->mapTool()->isEditTool() )
50445047
{
@@ -5052,7 +5055,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
50525055
{
50535056
mActionToggleEditing->setEnabled( true );
50545057
mActionToggleEditing->setChecked( vlayer->isEditable() );
5055-
mActionPasteFeatures->setEnabled( vlayer->isEditable() );
5058+
mActionPasteFeatures->setEnabled( vlayer->isEditable() and not clipboard()->empty());
50565059
}
50575060
else
50585061
{
@@ -5063,8 +5066,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
50635066
//does provider allow deleting of features?
50645067
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures )
50655068
{
5066-
mActionDeleteSelected->setEnabled( true );
5067-
mActionCutFeatures->setEnabled( true );
5069+
mActionDeleteSelected->setEnabled( layerHasSelection );
5070+
mActionCutFeatures->setEnabled( layerHasSelection );
50685071
}
50695072
else
50705073
{

src/app/qgsclipboard.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,7 @@ void QgsClipboard::insert( QgsFeature& feature )
135135
QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
136136
}
137137

138+
bool QgsClipboard::empty()
139+
{
140+
return mFeatureClipboard.empty();
141+
}

src/app/qgsclipboard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class QgsClipboard
8484
void insert( QgsFeature& feature );
8585

8686

87+
/*
88+
* Returns true if the internal clipboard is empty, else false.
89+
*/
90+
bool empty();
91+
8792
private:
8893

8994
/** QGIS-internal vector feature clipboard.

src/gui/qgsmapcanvas.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer>& layers )
259259
QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >( currentLayer );
260260
if ( isVectLyr )
261261
{
262-
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( refresh() ) );
262+
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
263263
}
264264
}
265265

@@ -275,7 +275,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer>& layers )
275275
QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >( currentLayer );
276276
if ( isVectLyr )
277277
{
278-
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( refresh() ) );
278+
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
279279
}
280280
}
281281
}
@@ -1278,3 +1278,11 @@ void QgsMapCanvas::zoom( double scaleFactor )
12781278
refresh();
12791279
}
12801280

1281+
void QgsMapCanvas::selectionChangedSlot()
1282+
{
1283+
// Find out which layer it was that sent the signal.
1284+
QgsMapLayer * layer = ( QgsMapLayer * )QObject::sender();
1285+
1286+
emit selectionChanged( layer );
1287+
refresh();
1288+
}

src/gui/qgsmapcanvas.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
240240
/**Repaints the canvas map*/
241241
void refresh();
242242

243+
//! Receives signal about selection change, and pass it on with layer info
244+
void selectionChangedSlot();
245+
243246
//! Save the convtents of the map canvas to disk as an image
244247
void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
245248

@@ -301,7 +304,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
301304
void keyReleased( QKeyEvent * e );
302305

303306
//! Emit map tool changed event
304-
void mapToolSet( QgsMapTool *tool );
307+
void mapToolSet( QgsMapTool * tool );
308+
309+
//! Emit map tool changed event
310+
void selectionChanged( QgsMapLayer * layer );
305311

306312
protected:
307313
//! Overridden key press event

0 commit comments

Comments
 (0)