Skip to content

Commit

Permalink
fixes #13668 (Delete does not work in the Vertex Editor)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and nyalldawson committed Feb 26, 2016
1 parent 300785b commit 0b136af
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -254,6 +254,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QgsMapMouseEvent* e )
mIsPoint = vlayer->geometryType() == QGis::Point;
mNodeEditor = new QgsNodeEditor( vlayer, mSelectedFeature, mCanvas );
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mNodeEditor );
connect( mNodeEditor, SIGNAL( deleteSelectedRequested() ), this, SLOT( deleteNodeSelection() ) );
}
else
{
Expand Down Expand Up @@ -646,9 +647,9 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QgsMapMouseEvent* e )
mCanvas->refresh();
}

void QgsMapToolNodeTool::keyPressEvent( QKeyEvent* e )
void QgsMapToolNodeTool::deleteNodeSelection()
{
if ( mSelectedFeature && ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
if ( mSelectedFeature )
{
int firstSelectedIndex = firstSelectedVertex();
if ( firstSelectedIndex == -1 )
Expand All @@ -672,29 +673,40 @@ void QgsMapToolNodeTool::keyPressEvent( QKeyEvent* e )
safeSelectVertex( nextVertexToSelect );
}
mCanvas->refresh();

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

mSelectedFeature->deselectAllVertexes();
safeSelectVertex( firstSelectedIndex - 1 );
e->ignore();
}
else if ( mSelectedFeature && ( e->key() == Qt::Key_Greater || e->key() == Qt::Key_Period ) )
void QgsMapToolNodeTool::keyPressEvent( QKeyEvent* e )
{
if ( mSelectedFeature )
{
int firstSelectedIndex = firstSelectedVertex();
if ( firstSelectedIndex == -1 )
return;
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
{
this->deleteNodeSelection();

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

mSelectedFeature->deselectAllVertexes();
safeSelectVertex( firstSelectedIndex - 1 );
e->ignore();
}
else if ( e->key() == Qt::Key_Greater || e->key() == Qt::Key_Period )
{
int firstSelectedIndex = firstSelectedVertex();
if ( firstSelectedIndex == -1 )
return;

mSelectedFeature->deselectAllVertexes();
safeSelectVertex( firstSelectedIndex + 1 );
e->ignore();
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Expand Up @@ -65,6 +65,11 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
*/
void editingToggled();

/*
* delete all selected nodes and select next available node
*/
void deleteNodeSelection();

private:
/**
* Get the feature on the mouse click
Expand Down
11 changes: 11 additions & 0 deletions src/app/nodetool/qgsnodeeditor.cpp
Expand Up @@ -27,6 +27,7 @@
#include <QHeaderView>
#include <QVBoxLayout>
#include <QStyledItemDelegate>
#include <QKeyEvent>
#include <QLineEdit>
#include <QVector2D>

Expand Down Expand Up @@ -379,6 +380,16 @@ void QgsNodeEditor::zoomToNode( int idx )
}
}

void QgsNodeEditor::keyPressEvent( QKeyEvent * e )
{
if ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete )
{
emit deleteSelectedRequested();

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

//
// CoordinateItemDelegate
Expand Down
6 changes: 6 additions & 0 deletions src/app/nodetool/qgsnodeeditor.h
Expand Up @@ -84,6 +84,12 @@ class QgsNodeEditor : public QDockWidget
QTableView* mTableView;
QgsNodeEditorModel* mNodeModel;

signals:
void deleteSelectedRequested( );

protected:
void keyPressEvent( QKeyEvent * event );

private slots:
void updateTableSelection();
void updateNodeSelection( const QItemSelection& selected, const QItemSelection& deselected );
Expand Down

0 comments on commit 0b136af

Please sign in to comment.