Skip to content
Permalink
Browse files

[vertex editor] allow zooming to vertex with the mouse click

  • Loading branch information
slarosa authored and nyalldawson committed Oct 9, 2015
1 parent 534cb41 commit fcb3bbea6820aadffe95b13f5177c441090498b2
Showing with 31 additions and 1 deletion.
  1. +30 −1 src/app/nodetool/qgsnodeeditor.cpp
  2. +1 −0 src/app/nodetool/qgsnodeeditor.h
@@ -365,7 +365,7 @@ void QgsNodeEditor::updateTableSelection()
mUpdatingTableSelection = false;
}

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

//ensure that newly selected node is visible in canvas
if ( !selected.indexes().isEmpty() )
{
int newRow = selected.indexes().first().row();
zoomToNode( newRow );
}

mUpdatingNodeSelection = false;
}

void QgsNodeEditor::zoomToNode( int idx )
{
double x = mSelectedFeature->vertexMap().at( idx )->point().x();
double y = mSelectedFeature->vertexMap().at( idx )->point().y();
QgsPoint newCenter( x, y );

QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs() );
QgsPoint tCenter = t.transform( newCenter );

QPolygonF ext = mCanvas->mapSettings().visiblePolygon();
//close polygon
ext.append( ext.first() );
QScopedPointer< QgsGeometry > extGeom( QgsGeometry::fromQPolygonF( ext ) );
QScopedPointer< QgsGeometry > nodeGeom( QgsGeometry::fromPoint( tCenter ) );
if ( !nodeGeom->within( extGeom.data() ) )
{
mCanvas->setCenter( tCenter );
mCanvas->refresh();
}
}


@@ -86,6 +86,7 @@ class QgsNodeEditor : public QDockWidget
private slots:
void updateTableSelection( );
void updateNodeSelection( const QItemSelection& selected, const QItemSelection& deselected );
void zoomToNode( int idx );

private:

0 comments on commit fcb3bbe

Please sign in to comment.
You can’t perform that action at this time.