Skip to content
Permalink
Browse files
Fixes #929. Only enable copy/cut action when there is a selection, an…
…d 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
  • Loading branch information
homann committed Oct 27, 2008
1 parent b733bde commit a42820e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
@@ -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 ) ) );
//
@@ -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() )
{
@@ -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
{
@@ -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
{
@@ -135,3 +135,7 @@ void QgsClipboard::insert( QgsFeature& feature )
QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
}

bool QgsClipboard::empty()
{
return mFeatureClipboard.empty();
}
@@ -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.
@@ -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() ) );
}
}

@@ -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() ) );
}
}
}
@@ -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();
}
@@ -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" );

@@ -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

0 comments on commit a42820e

Please sign in to comment.