Skip to content

Commit

Permalink
Fixes #929. Only enable copy/cut action when there is a selection, an…
Browse files Browse the repository at this point in the history
…d only enable paste action when there is something in the clipboard.

git-svn-id: http://svn.osgeo.org/qgis/trunk@9551 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Oct 27, 2008
1 parent 66eb88f commit 6d5261b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/app/qgisapp.cpp
Expand Up @@ -1498,6 +1498,8 @@ void QgisApp::setupConnections()
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( showScale( double ) ) );
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( updateMouseCoordinatePrecision() ) );
connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool * ) ) );
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) );

connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), mMapCanvas, SLOT( setRenderFlag( bool ) ) );
//
Expand Down Expand Up @@ -5029,16 +5031,17 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
/***********Vector layers****************/
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
const QgsVectorDataProvider* dprovider = vlayer->dataProvider();
bool layerHasSelection = ( vlayer->selectedFeatureCount() != 0 );

mActionSelect->setEnabled( true );
mActionIdentify->setEnabled( true );
mActionZoomActualSize->setEnabled( false );
mActionOpenTable->setEnabled( true );
mActionLayerSaveAs->setEnabled( true );
mActionLayerSelectionSaveAs->setEnabled( true );
mActionCopyFeatures->setEnabled( true );

const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( layer );
const QgsVectorDataProvider* dprovider = vlayer->dataProvider();
mActionCopyFeatures->setEnabled( layerHasSelection );

if ( !vlayer->isEditable() && mMapCanvas->mapTool() && mMapCanvas->mapTool()->isEditTool() )
{
Expand All @@ -5052,7 +5055,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
mActionToggleEditing->setEnabled( true );
mActionToggleEditing->setChecked( vlayer->isEditable() );
mActionPasteFeatures->setEnabled( vlayer->isEditable() );
mActionPasteFeatures->setEnabled( vlayer->isEditable() and not clipboard()->empty());
}
else
{
Expand All @@ -5063,8 +5066,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
//does provider allow deleting of features?
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures )
{
mActionDeleteSelected->setEnabled( true );
mActionCutFeatures->setEnabled( true );
mActionDeleteSelected->setEnabled( layerHasSelection );
mActionCutFeatures->setEnabled( layerHasSelection );
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsclipboard.cpp
Expand Up @@ -135,3 +135,7 @@ void QgsClipboard::insert( QgsFeature& feature )
QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
}

bool QgsClipboard::empty()
{
return mFeatureClipboard.empty();
}
5 changes: 5 additions & 0 deletions src/app/qgsclipboard.h
Expand Up @@ -84,6 +84,11 @@ class QgsClipboard
void insert( QgsFeature& feature );


/*
* Returns true if the internal clipboard is empty, else false.
*/
bool empty();

private:

/** QGIS-internal vector feature clipboard.
Expand Down
12 changes: 10 additions & 2 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -259,7 +259,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer>& layers )
QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >( currentLayer );
if ( isVectLyr )
{
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( refresh() ) );
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
}

Expand All @@ -275,7 +275,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer>& layers )
QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >( currentLayer );
if ( isVectLyr )
{
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( refresh() ) );
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
}
}
Expand Down Expand Up @@ -1278,3 +1278,11 @@ void QgsMapCanvas::zoom( double scaleFactor )
refresh();
}

void QgsMapCanvas::selectionChangedSlot()
{
// Find out which layer it was that sent the signal.
QgsMapLayer * layer = ( QgsMapLayer * )QObject::sender();

emit selectionChanged( layer );
refresh();
}
8 changes: 7 additions & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -240,6 +240,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/**Repaints the canvas map*/
void refresh();

//! Receives signal about selection change, and pass it on with layer info
void selectionChangedSlot();

//! Save the convtents of the map canvas to disk as an image
void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );

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

//! Emit map tool changed event
void mapToolSet( QgsMapTool *tool );
void mapToolSet( QgsMapTool * tool );

//! Emit map tool changed event
void selectionChanged( QgsMapLayer * layer );

protected:
//! Overridden key press event
Expand Down

0 comments on commit 6d5261b

Please sign in to comment.