Skip to content

Commit

Permalink
#9094: Auto-select adjacent last-removed node
Browse files Browse the repository at this point in the history
Automatically selects the adjacent vertex to last removed selected node
  • Loading branch information
ahuarte47 committed Dec 17, 2013
1 parent eab6b5b commit 5bda2df
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -713,7 +713,11 @@ void QgsMapToolNodeTool::keyReleaseEvent( QKeyEvent* e )

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();
}
}
Expand All @@ -731,3 +735,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 @@ -95,6 +95,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

0 comments on commit 5bda2df

Please sign in to comment.