Skip to content

Commit fcb3bbe

Browse files
slarosanyalldawson
authored andcommittedOct 9, 2015
[vertex editor] allow zooming to vertex with the mouse click
1 parent 534cb41 commit fcb3bbe

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
 

‎src/app/nodetool/qgsnodeeditor.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void QgsNodeEditor::updateTableSelection()
365365
mUpdatingTableSelection = false;
366366
}
367367

368-
void QgsNodeEditor::updateNodeSelection( const QItemSelection&, const QItemSelection& )
368+
void QgsNodeEditor::updateNodeSelection( const QItemSelection& selected, const QItemSelection& )
369369
{
370370
if ( mUpdatingTableSelection )
371371
return;
@@ -379,6 +379,35 @@ void QgsNodeEditor::updateNodeSelection( const QItemSelection&, const QItemSelec
379379
mSelectedFeature->selectVertex( nodeIdx );
380380
}
381381

382+
//ensure that newly selected node is visible in canvas
383+
if ( !selected.indexes().isEmpty() )
384+
{
385+
int newRow = selected.indexes().first().row();
386+
zoomToNode( newRow );
387+
}
388+
382389
mUpdatingNodeSelection = false;
383390
}
384391

392+
void QgsNodeEditor::zoomToNode( int idx )
393+
{
394+
double x = mSelectedFeature->vertexMap().at( idx )->point().x();
395+
double y = mSelectedFeature->vertexMap().at( idx )->point().y();
396+
QgsPoint newCenter( x, y );
397+
398+
QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs() );
399+
QgsPoint tCenter = t.transform( newCenter );
400+
401+
QPolygonF ext = mCanvas->mapSettings().visiblePolygon();
402+
//close polygon
403+
ext.append( ext.first() );
404+
QScopedPointer< QgsGeometry > extGeom( QgsGeometry::fromQPolygonF( ext ) );
405+
QScopedPointer< QgsGeometry > nodeGeom( QgsGeometry::fromPoint( tCenter ) );
406+
if ( !nodeGeom->within( extGeom.data() ) )
407+
{
408+
mCanvas->setCenter( tCenter );
409+
mCanvas->refresh();
410+
}
411+
}
412+
413+

‎src/app/nodetool/qgsnodeeditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class QgsNodeEditor : public QDockWidget
8686
private slots:
8787
void updateTableSelection( );
8888
void updateNodeSelection( const QItemSelection& selected, const QItemSelection& deselected );
89+
void zoomToNode( int idx );
8990

9091
private:
9192

0 commit comments

Comments
 (0)
Please sign in to comment.