@@ -365,7 +365,7 @@ void QgsNodeEditor::updateTableSelection()
365
365
mUpdatingTableSelection = false ;
366
366
}
367
367
368
- void QgsNodeEditor::updateNodeSelection ( const QItemSelection&, const QItemSelection& )
368
+ void QgsNodeEditor::updateNodeSelection ( const QItemSelection& selected , const QItemSelection& )
369
369
{
370
370
if ( mUpdatingTableSelection )
371
371
return ;
@@ -379,6 +379,35 @@ void QgsNodeEditor::updateNodeSelection( const QItemSelection&, const QItemSelec
379
379
mSelectedFeature ->selectVertex ( nodeIdx );
380
380
}
381
381
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
+
382
389
mUpdatingNodeSelection = false ;
383
390
}
384
391
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
+
0 commit comments