[QGIS Commit] r9551 - in trunk/qgis/src: app gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Oct 27 13:35:28 EDT 2008
Author: homann
Date: 2008-10-27 13:35:28 -0400 (Mon, 27 Oct 2008)
New Revision: 9551
Modified:
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgsclipboard.cpp
trunk/qgis/src/app/qgsclipboard.h
trunk/qgis/src/gui/qgsmapcanvas.cpp
trunk/qgis/src/gui/qgsmapcanvas.h
Log:
Fixes #929. Only enable copy/cut action when there is a selection, and only enable paste action when there is something in the clipboard.
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2008-10-26 05:33:50 UTC (rev 9550)
+++ trunk/qgis/src/app/qgisapp.cpp 2008-10-27 17:35:28 UTC (rev 9551)
@@ -1498,6 +1498,8 @@
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,17 +5031,18 @@
/***********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 );
+ mActionCopyFeatures->setEnabled( layerHasSelection );
- const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( layer );
- const QgsVectorDataProvider* dprovider = vlayer->dataProvider();
-
if ( !vlayer->isEditable() && mMapCanvas->mapTool() && mMapCanvas->mapTool()->isEditTool() )
{
mMapCanvas->setMapTool( mNonEditMapTool );
@@ -5052,7 +5055,7 @@
{
mActionToggleEditing->setEnabled( true );
mActionToggleEditing->setChecked( vlayer->isEditable() );
- mActionPasteFeatures->setEnabled( vlayer->isEditable() );
+ mActionPasteFeatures->setEnabled( vlayer->isEditable() and not clipboard()->empty());
}
else
{
@@ -5063,8 +5066,8 @@
//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
{
Modified: trunk/qgis/src/app/qgsclipboard.cpp
===================================================================
--- trunk/qgis/src/app/qgsclipboard.cpp 2008-10-26 05:33:50 UTC (rev 9550)
+++ trunk/qgis/src/app/qgsclipboard.cpp 2008-10-27 17:35:28 UTC (rev 9551)
@@ -135,3 +135,7 @@
QgsDebugMsg( "inserted " + feature.geometry()->exportToWkt() );
}
+bool QgsClipboard::empty()
+{
+ return mFeatureClipboard.empty();
+}
Modified: trunk/qgis/src/app/qgsclipboard.h
===================================================================
--- trunk/qgis/src/app/qgsclipboard.h 2008-10-26 05:33:50 UTC (rev 9550)
+++ trunk/qgis/src/app/qgsclipboard.h 2008-10-27 17:35:28 UTC (rev 9551)
@@ -84,6 +84,11 @@
void insert( QgsFeature& feature );
+ /*
+ * Returns true if the internal clipboard is empty, else false.
+ */
+ bool empty();
+
private:
/** QGIS-internal vector feature clipboard.
Modified: trunk/qgis/src/gui/qgsmapcanvas.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.cpp 2008-10-26 05:33:50 UTC (rev 9550)
+++ trunk/qgis/src/gui/qgsmapcanvas.cpp 2008-10-27 17:35:28 UTC (rev 9551)
@@ -259,7 +259,7 @@
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 @@
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 @@
refresh();
}
+void QgsMapCanvas::selectionChangedSlot()
+{
+ // Find out which layer it was that sent the signal.
+ QgsMapLayer * layer = ( QgsMapLayer * )QObject::sender();
+
+ emit selectionChanged( layer );
+ refresh();
+}
Modified: trunk/qgis/src/gui/qgsmapcanvas.h
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.h 2008-10-26 05:33:50 UTC (rev 9550)
+++ trunk/qgis/src/gui/qgsmapcanvas.h 2008-10-27 17:35:28 UTC (rev 9551)
@@ -240,6 +240,9 @@
/**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,8 +304,11 @@
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
void keyPressEvent( QKeyEvent * e );
More information about the QGIS-commit
mailing list