Skip to content
Permalink
Browse files
Fixes for moving between nodes with keyboard
- supports < and > in addition to comma and dot
- wraps around polygon rings (jumps from last node to the first)
- moves view to node when it is outside of canvas view
  • Loading branch information
wonder-sk committed Apr 13, 2017
1 parent 80cef51 commit 2e21d469131e6df0208edd06330ef20c91514514
Showing with 31 additions and 4 deletions.
  1. +28 −4 src/app/nodetool/qgsnodetool2.cpp
  2. +3 −0 src/app/nodetool/qgsnodetool2.h
@@ -836,11 +836,11 @@ void QgsNodeTool2::keyPressEvent( QKeyEvent *e )
if ( mDraggingVertex )
stopDragging();
}
else if ( e->key() == Qt::Key_Comma )
else if ( e->key() == Qt::Key_Less || e->key() == Qt::Key_Comma )
{
highlightAdjacentVertex( -1 );
}
else if ( e->key() == Qt::Key_Period )
else if ( e->key() == Qt::Key_Greater || e->key() == Qt::Key_Period )
{
highlightAdjacentVertex( + 1 );
}
@@ -1599,10 +1599,22 @@ void QgsNodeTool2::highlightAdjacentVertex( double offset )
Vertex node = mSelectedNodes[0]; // simply use the first one

QgsGeometry geom = cachedGeometryForVertex( node );
QgsPoint pt = geom.vertexAt( node.vertexId + offset );

// try to wrap around polygon rings
int newVertexId, v0idx, v1idx;
geom.adjacentVertices( node.vertexId, v0idx, v1idx );
if ( offset == -1 && v0idx != -1 )
newVertexId = v0idx;
else if ( offset == 1 && v1idx != -1 )
newVertexId = v1idx;
else
newVertexId = node.vertexId + offset;

QgsPoint pt = geom.vertexAt( newVertexId );
if ( pt != QgsPoint() )
node = Vertex( node.layer, node.fid, node.vertexId + offset );
node = Vertex( node.layer, node.fid, newVertexId );
setHighlightedNodes( QList<Vertex>() << node );
zoomToNode( node ); // make sure the node is visible
}

void QgsNodeTool2::startSelectionRect( const QPoint &point0 )
@@ -1783,3 +1795,15 @@ void QgsNodeTool2::validateGeometry( QgsVectorLayer *layer, QgsFeatureId feature
validation.start( geom, this, layer );
mValidations.insert( id, validation );
}

void QgsNodeTool2::zoomToNode( const Vertex &node )
{
QgsPoint newCenter = cachedGeometryForVertex( node ).vertexAt( node.vertexId );
QgsPoint mapPoint = mCanvas->mapSettings().layerToMapCoordinates( node.layer, newCenter );
QPolygonF ext = mCanvas->mapSettings().visiblePolygon();
if ( !ext.containsPoint( mapPoint.toQPointF(), Qt::OddEvenFill ) )
{
mCanvas->setCenter( mapPoint );
mCanvas->refresh();
}
}
@@ -187,6 +187,9 @@ class APP_EXPORT QgsNodeTool2 : public QgsMapToolAdvancedDigitizing
//! Run validation on a geometry (in a background thread)
void validateGeometry( QgsVectorLayer *layer, QgsFeatureId featureId );

//! Makes sure that the node is visible in map canvas
void zoomToNode( const Vertex &node );

private:

// members used for temporary highlight of stuff

0 comments on commit 2e21d46

Please sign in to comment.