|
23 | 23 | #include "qgsvectorlayer.h"
|
24 | 24 | #include "qgsgeometryutils.h"
|
25 | 25 | #include "qgsproject.h"
|
| 26 | +#include "qgscoordinatetransform.h" |
26 | 27 |
|
27 | 28 | #include <QTableWidget>
|
28 | 29 | #include <QHeaderView>
|
@@ -359,49 +360,40 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, con
|
359 | 360 | mUpdatingVertexSelection = true;
|
360 | 361 |
|
361 | 362 | mSelectedFeature->deselectAllVertices();
|
362 |
| - Q_FOREACH ( const QModelIndex &index, mTableView->selectionModel()->selectedRows() ) |
| 363 | + |
| 364 | + QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); |
| 365 | + QgsRectangle *bbox = nullptr; |
| 366 | + QModelIndexList indexList = selected.indexes(); |
| 367 | + for ( int i = 0; i < indexList.length(); ++i ) |
363 | 368 | {
|
364 |
| - int vertexIdx = index.row(); |
| 369 | + int vertexIdx = indexList.at( i ).row(); |
365 | 370 | mSelectedFeature->selectVertex( vertexIdx );
|
366 |
| - } |
367 | 371 |
|
368 |
| - //ensure that newly selected vertex is visible in canvas |
369 |
| - if ( !selected.indexes().isEmpty() ) |
370 |
| - { |
371 |
| - int newRow = selected.indexes().first().row(); |
372 |
| - zoomToVertex( newRow ); |
| 372 | + // create a bounding box of selected vertices |
| 373 | + QgsPointXY point( mSelectedFeature->vertexMap().at( vertexIdx )->point() ); |
| 374 | + if ( !bbox ) |
| 375 | + bbox = new QgsRectangle( point, point ); |
| 376 | + else |
| 377 | + bbox->combineExtentWith( point ); |
373 | 378 | }
|
374 | 379 |
|
375 |
| - mUpdatingVertexSelection = false; |
376 |
| -} |
377 |
| - |
378 |
| -void QgsVertexEditor::zoomToVertex( int idx ) |
379 |
| -{ |
380 |
| - double x = mSelectedFeature->vertexMap().at( idx )->point().x(); |
381 |
| - double y = mSelectedFeature->vertexMap().at( idx )->point().y(); |
382 |
| - QgsPointXY newCenter( x, y ); |
383 |
| - |
384 |
| - QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); |
385 |
| - QgsPointXY tCenter; |
386 |
| - try |
| 380 | + //ensure that newly selected vertices are visible in canvas |
| 381 | + if ( bbox ) |
387 | 382 | {
|
388 |
| - tCenter = t.transform( newCenter ); |
389 |
| - } |
390 |
| - catch ( QgsCsException & ) |
391 |
| - { |
392 |
| - return; |
| 383 | + try |
| 384 | + { |
| 385 | + QgsRectangle transformedBbox = t.transform( *bbox ); |
| 386 | + QgsRectangle canvasExtent = mCanvas->mapSettings().extent(); |
| 387 | + transformedBbox.combineExtentWith( canvasExtent ); |
| 388 | + mCanvas->setExtent( transformedBbox ); |
| 389 | + } |
| 390 | + catch ( QgsCsException & ) |
| 391 | + { |
| 392 | + } |
| 393 | + delete bbox; |
393 | 394 | }
|
394 | 395 |
|
395 |
| - QPolygonF ext = mCanvas->mapSettings().visiblePolygon(); |
396 |
| - //close polygon |
397 |
| - ext.append( ext.first() ); |
398 |
| - QgsGeometry extGeom( QgsGeometry::fromQPolygonF( ext ) ); |
399 |
| - QgsGeometry vertexGeom( QgsGeometry::fromPointXY( tCenter ) ); |
400 |
| - if ( !vertexGeom.within( extGeom ) ) |
401 |
| - { |
402 |
| - mCanvas->setCenter( tCenter ); |
403 |
| - mCanvas->refresh(); |
404 |
| - } |
| 396 | + mUpdatingVertexSelection = false; |
405 | 397 | }
|
406 | 398 |
|
407 | 399 | void QgsVertexEditor::keyPressEvent( QKeyEvent *e )
|
|
0 commit comments