Skip to content

Commit

Permalink
Merge branch 'Issue_9094' of https://github.com/ahuarte47/QGIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Dec 30, 2013
2 parents f1aead4 + e3e01fc commit ba229e5
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 24 deletions.
64 changes: 58 additions & 6 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -717,6 +717,30 @@ 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();
}
}

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
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
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
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
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
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
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
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
14 changes: 8 additions & 6 deletions src/gui/qgsmapcanvas.cpp
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
5 changes: 4 additions & 1 deletion src/plugins/grass/qgsgrassmapcalc.cpp
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
5 changes: 1 addition & 4 deletions src/ui/qgsattributetabledialog.ui
Expand Up @@ -112,7 +112,7 @@
<item>
<widget class="QToolButton" name="mDeleteSelectedButton">
<property name="toolTip">
<string>Delete selected features (Ctrl+D)</string>
<string>Delete selected features (DEL)</string>
</property>
<property name="text">
<string>...</string>
Expand All @@ -127,9 +127,6 @@
<height>18</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</widget>
</item>
<item>
Expand Down

0 comments on commit ba229e5

Please sign in to comment.