Skip to content
Permalink
Browse files

Merge branch 'Issue_9094' of https://github.com/ahuarte47/QGIS

  • Loading branch information
timlinux committed Dec 30, 2013
2 parents f1aead4 + e3e01fc commit ba229e501ab77c1488db8ceafc8b320b61920372
@@ -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();
}
}

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

@@ -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 ) ) );
@@ -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 )
{
@@ -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;
}
@@ -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();
}
@@ -6477,7 +6493,7 @@ void QgisApp::removeAllLayers()
QgsMapLayerRegistry::instance()->removeAllMapLayers();
}

void QgisApp::removeLayer()
void QgisApp::removeLayer( bool promptConfirmation )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
@@ -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();
}

@@ -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 )
@@ -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 & );
@@ -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 *>() );
@@ -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) */
@@ -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() )
@@ -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
@@ -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();
}
}
}
@@ -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();
}
}

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

@@ -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>
@@ -127,9 +127,6 @@
<height>18</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</widget>
</item>
<item>

0 comments on commit ba229e5

Please sign in to comment.
You can’t perform that action at this time.