Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 fcb3bbe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/app/nodetool/qgsnodeeditor.cpp
Expand Up @@ -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;
Expand All @@ -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();
}
}


1 change: 1 addition & 0 deletions src/app/nodetool/qgsnodeeditor.h
Expand Up @@ -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:

Expand Down

0 comments on commit fcb3bbe

Please sign in to comment.