64 changes: 58 additions & 6 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,31 @@ void QgsMapToolNodeTool::keyPressEvent( QKeyEvent* e )
if ( e->key() == Qt::Key_Control )
{
mCtrl = true;
return;
}

if ( mSelectedFeature && ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
{
int firstSelectedIndex = firstSelectedVertex();
if ( firstSelectedIndex == -1 ) return;

mSelectedFeature->deleteSelectedVertexes();
safeSelectVertex( firstSelectedIndex );
mCanvas->refresh();

// Override default shortcut management in MapCanvas
e->ignore();
}
else
if ( mSelectedFeature && ( e->key() == Qt::Key_Less || e->key() == Qt::Key_Greater ) )
{
int firstSelectedIndex = firstSelectedVertex();
if ( firstSelectedIndex == -1 ) return;

mSelectedFeature->deselectAllVertexes();
safeSelectVertex( firstSelectedIndex + (( e->key() == Qt::Key_Less ) ? -1 : + 1 ) );
mCanvas->refresh();
}
}

void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )
Expand All @@ -727,12 +751,6 @@ void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )
mCtrl = false;
return;
}

if ( mSelectedFeature && e->key() == Qt::Key_Delete )
{
mSelectedFeature->deleteSelectedVertexes();
mCanvas->refresh();
}
}

QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker( QgsPoint center, QgsVectorLayer* vlayer )
Expand All @@ -748,3 +766,37 @@ QgsRubberBand* QgsMapToolNodeTool::createRubberBandMarker( QgsPoint center, QgsV
marker->addPoint( pom );
return marker;
}

int QgsMapToolNodeTool::firstSelectedVertex( )
{
if ( mSelectedFeature )
{
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature->vertexMap();
int vertexNr = 0;

foreach ( QgsVertexEntry *entry, vertexMap )
{
if ( entry->isSelected() )
{
return vertexNr;
}
vertexNr++;
}
}
return -1;
}

int QgsMapToolNodeTool::safeSelectVertex( int vertexNr )
{
if ( mSelectedFeature )
{
QList<QgsVertexEntry*> &vertexMap = mSelectedFeature->vertexMap();

if ( vertexNr >= vertexMap.size() ) vertexNr -= vertexMap.size();
if ( vertexNr < 0 ) vertexNr = vertexMap.size() - 1 + vertexNr;

mSelectedFeature->selectVertex( vertexNr );
return vertexNr;
}
return -1;
}
10 changes: 10 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ class QgsMapToolNodeTool: public QgsMapToolVertexEdit
*/
void createTopologyRubberBands( QgsVectorLayer* vlayer, const QList<QgsVertexEntry*> &vertexMap, int vertex );

/**
* Returns the index of first selected vertex, -1 when all unselected
*/
int firstSelectedVertex();

/**
* Select the specified vertex bounded to current index range, returns the valid selected index
*/
int safeSelectVertex( int vertexNr );

/** The position of the vertex to move (in map coordinates) to exclude later from snapping*/
QList<QgsPoint> mExcludePoint;

Expand Down
50 changes: 46 additions & 4 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,10 @@ void QgisApp::setupConnections()
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
mMapCanvas, SLOT( setRenderFlag( bool ) ) );

// connect MapCanvas keyPress event so we can check if selected feature collection must be deleted
connect( mMapCanvas, SIGNAL( keyPressed( QKeyEvent * ) ),
this, SLOT( mapCanvas_keyPressed( QKeyEvent * ) ) );

// connect renderer
connect( mMapCanvas->mapRenderer(), SIGNAL( drawingProgress( int, int ) ),
this, SLOT( showProgress( int, int ) ) );
Expand Down Expand Up @@ -4800,7 +4804,7 @@ void QgisApp::layerProperties()
showLayerProperties( activeLayer() );
}

void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent, bool promptConfirmation )
{
if ( !layer )
{
Expand Down Expand Up @@ -4845,9 +4849,17 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
return;
}

//display a warning
//validate selection
int numberOfDeletedFeatures = vlayer->selectedFeaturesIds().size();
if ( QMessageBox::warning( parent, tr( "Delete features" ), tr( "Delete %n feature(s)?", "number of features to delete", numberOfDeletedFeatures ), QMessageBox::Ok, QMessageBox::Cancel ) == QMessageBox::Cancel )
if ( numberOfDeletedFeatures == 0 )
{
messageBar()->pushMessage( tr( "No Features Selected" ),
tr( "The current layer has not selected features" ),
QgsMessageBar::INFO, messageTimeout() );
return;
}
//display a warning
if ( promptConfirmation && QMessageBox::warning( parent, tr( "Delete features" ), tr( "Delete %n feature(s)?", "number of features to delete", numberOfDeletedFeatures ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
Expand All @@ -4859,6 +4871,10 @@ void QgisApp::deleteSelected( QgsMapLayer *layer, QWidget* parent )
tr( "A problem occured during deletion of features" ),
QgsMessageBar::WARNING );
}
else
{
showStatusMessage( tr( "%n feature(s) deleted.", "number of features deleted", numberOfDeletedFeatures ) );
}

vlayer->endEditCommand();
}
Expand Down Expand Up @@ -6477,7 +6493,7 @@ void QgisApp::removeAllLayers()
QgsMapLayerRegistry::instance()->removeAllMapLayers();
}

void QgisApp::removeLayer()
void QgisApp::removeLayer( bool promptConfirmation )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
Expand All @@ -6496,8 +6512,25 @@ void QgisApp::removeLayer()
return;
}

//validate selection
int numberOfRemovedLayers = mMapLegend->selectedLayers().size();
if ( numberOfRemovedLayers == 0 )
{
messageBar()->pushMessage( tr( "No Layer Selected" ),
tr( "To remove layers, you must select they in the legend" ),
QgsMessageBar::INFO, messageTimeout() );
return;
}
//display a warning
if ( promptConfirmation && QMessageBox::warning( this, tr( "Remove layers" ), tr( "Remove %n layer(s)?", "number of layers to remove", numberOfRemovedLayers ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}

mMapLegend->removeSelectedLayers();

showStatusMessage( tr( "%n layer(s) removed.", "number of layers removed", numberOfRemovedLayers ) );

mMapCanvas->refresh();
}

Expand Down Expand Up @@ -9061,6 +9094,15 @@ void QgisApp::keyPressEvent( QKeyEvent * e )
}
}

void QgisApp::mapCanvas_keyPressed( QKeyEvent *e )
{
// Delete selected features when it is possible and KeyEvent was not managed by current MapTool
if (( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) && e->isAccepted() )
{
deleteSelected();
}
}

#ifdef Q_OS_WIN
// hope your wearing your peril sensitive sunglasses.
void QgisApp::contextMenuEvent( QContextMenuEvent *e )
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void loadGDALSublayers( QString uri, QStringList list );

/**Deletes the selected attributes for the currently selected vector layer*/
void deleteSelected( QgsMapLayer *layer = 0, QWidget* parent = 0 );
void deleteSelected( QgsMapLayer *layer = 0, QWidget* parent = 0, bool promptConfirmation = false );

//! project was written
void writeProject( QDomDocument & );
Expand Down Expand Up @@ -686,7 +686,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Slot to handle user center input;
void userCenter();
//! Remove a layer from the map and legend
void removeLayer();
void removeLayer( bool promptConfirmation = true );
/** Duplicate map layer(s) in legend
* @note added in 1.9 */
void duplicateLayers( const QList<QgsMapLayer *> lyrList = QList<QgsMapLayer *>() );
Expand Down Expand Up @@ -1161,6 +1161,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void clipboardChanged();

//! catch MapCanvas keyPress event so we can check if selected feature collection must be deleted
void mapCanvas_keyPressed( QKeyEvent *e );

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
10 changes: 10 additions & 0 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ void QgsAttributeTableDialog::closeEvent( QCloseEvent* event )
}
}

void QgsAttributeTableDialog::keyPressEvent( QKeyEvent* event )
{
QDialog::keyPressEvent( event );

if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) && mDeleteSelectedButton->isEnabled() )
{
QgisApp::instance()->deleteSelected( mLayer, this );
}
}

void QgsAttributeTableDialog::columnBoxInit()
{
foreach ( QAction* a, mFilterColumnsMenu->actions() )
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsattributetabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
*/
void closeEvent( QCloseEvent* event );

/*
* Handle KeyPress event of the window
* @param event
*/
void keyPressEvent( QKeyEvent* event );

private slots:
/**
* Initialize column box
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgsmaptoolannotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ void QgsMapToolAnnotation::keyPressEvent( QKeyEvent* e )
QgsAnnotationItem* sItem = selectedItem();
if ( sItem )
{
if ( e->key() == Qt::Key_Delete )
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
{
if ( mCanvas && mCanvas->scene() )
{
QCursor neutralCursor( sItem->cursorShapeForAction( QgsAnnotationItem::NoAction ) );
mCanvas->scene()->removeItem( sItem );
delete sItem;
mCanvas->setCursor( neutralCursor );

// Override default shortcut management in MapCanvas
e->ignore();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ void QgsMapToolCapture::keyPressEvent( QKeyEvent* e )
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
{
undo();

// Override default shortcut management in MapCanvas
e->ignore();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/composer/qgscomposermousehandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI

/**Redraws handles when selected item rotation changes*/
void selectedItemRotationChanged();

private:

QgsComposition* mComposition; //reference to composition
Expand Down Expand Up @@ -131,8 +131,8 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI

/**Returns the mouse handle bounds of current selection*/
QRectF selectionBounds() const;
/**Returns true if all selected items have same rotation, and if so, updates passed rotation variable*/

/**Returns true if all selected items have same rotation, and if so, updates passed rotation variable*/
bool selectionRotation( double & rotation ) const;

/**Redraws or hides the handles based on the current selection*/
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;

QgsAtlasComposition& atlasComposition() { return mAtlasComposition; };

/**Resizes a QRectF relative to the change from boundsBefore to boundsAfter*/
static void relativeResizeRect( QRectF& rectToResize, const QRectF& boundsBefore, const QRectF& boundsAfter );
/**Returns a scaled position given a before and after range*/
static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
Expand Down
14 changes: 8 additions & 6 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,11 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent * e )
e->ignore();
}

emit keyPressed( e );

if ( mCanvasProperties->mouseButtonDown || mCanvasProperties->panSelectorDown )
{
emit keyPressed( e );
return;
}

QPainter paint;
QPen pen( Qt::gray );
Expand Down Expand Up @@ -886,12 +887,14 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent * e )
{
mMapTool->keyPressEvent( e );
}
e->ignore();
else e->ignore();

QgsDebugMsg( "Ignoring key: " + QString::number( e->key() ) );

}
}

emit keyPressed( e );

} //keyPressEvent()

void QgsMapCanvas::keyReleaseEvent( QKeyEvent * e )
Expand Down Expand Up @@ -921,8 +924,7 @@ void QgsMapCanvas::keyReleaseEvent( QKeyEvent * e )
{
mMapTool->keyReleaseEvent( e );
}

e->ignore();
else e->ignore();

QgsDebugMsg( "Ignoring key release: " + QString::number( e->key() ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsrelationmanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void QgsRelationManagerDialog::on_mBtnAddRelation_clicked()
void QgsRelationManagerDialog::on_mBtnRemoveRelation_clicked()
{
if ( mRelationsTable->currentIndex().isValid() )
mRelationsTable->removeRow( mRelationsTable->currentItem()->row() );
mRelationsTable->removeRow( mRelationsTable->currentItem()->row() );
}

QList< QgsRelation > QgsRelationManagerDialog::relations()
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/grass/qgsgrassmapcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,12 @@ void QgsGrassMapcalc::deleteItem()

void QgsGrassMapcalc::keyPressEvent( QKeyEvent * e )
{
if ( e->key() == Qt::Key_Delete )
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
{
deleteItem();

// Override default shortcut management in MapCanvas
e->ignore();
}
}

Expand Down
Loading