Skip to content
Permalink
Browse files

Use alt to select vertices by polygon

  • Loading branch information
uclaros authored and nyalldawson committed Mar 30, 2021
1 parent 5e0d409 commit bd38014c8b6f9395f5ba51cf0b19fdf0195c1050
Showing with 47 additions and 6 deletions.
  1. +44 −4 src/app/vertextool/qgsvertextool.cpp
  2. +3 −2 src/app/vertextool/qgsvertextool.h
@@ -526,7 +526,9 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
mouseMoveNotDragging( e );
}
}
else if ( mSelectionRubberBand )
else if ( mSelectionRubberBand &&
( mSelectionMethod == SelectionNormal ||
( mSelectionMethod == SelectionPolygon && e->button() == Qt::RightButton ) ) )
{
// only handling of selection rect being dragged
QList<Vertex> vertices;
@@ -649,6 +651,18 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

stopSelectionRubberBand();
}
else if ( e->button() == Qt::LeftButton && e->modifiers() & Qt::AltModifier )
{
mSelectionMethod = SelectionPolygon;
initSelectionRubberBand();
mSelectionRubberBand->addPoint( toMapCoordinates( e->pos() ) );
return;
}
else if ( mSelectionRubberBand && mSelectionMethod == SelectionPolygon )
{
mSelectionRubberBand->addPoint( toMapCoordinates( e->pos() ) );
return;
}
else // selection rect is not being dragged
{
if ( e->button() == Qt::LeftButton && !( e->modifiers() & Qt::ShiftModifier ) && !( e->modifiers() & Qt::ControlModifier ) )
@@ -716,6 +730,7 @@ void QgsVertexTool::cadCanvasMoveEvent( QgsMapMouseEvent *e )
// the user may be dragging a rect to select vertices
if ( !mSelectionRubberBand && ( e->pos() - *mSelectionRubberBandStartPos ).manhattanLength() >= 10 )
{
mSelectionMethod = SelectionNormal;
initSelectionRubberBand();
}
if ( mSelectionRubberBand )
@@ -1334,13 +1349,22 @@ void QgsVertexTool::keyPressEvent( QKeyEvent *e )
{
if ( mSelectionMethod == SelectionRange )
stopRangeVertexSelection();
if ( mSelectionMethod == SelectionPolygon )
stopSelectionRubberBand();
if ( mDraggingVertex || mDraggingEdge )
stopDragging();
break;
}
case Qt::Key_Delete:
case Qt::Key_Backspace:
{
if ( mSelectionMethod == SelectionPolygon )
{
e->ignore(); // Override default shortcut management
mSelectionRubberBand->removeLastPoint();
if ( mSelectionRubberBand->numberOfVertices() < 2 )
stopSelectionRubberBand();
}
if ( mDraggingVertex || ( !mDraggingEdge && !mSelectedVertices.isEmpty() ) )
{
e->ignore(); // Override default shortcut management
@@ -2582,14 +2606,30 @@ void QgsVertexTool::initSelectionRubberBand()

void QgsVertexTool::updateSelectionRubberBand( QgsMapMouseEvent *e )
{
QRect rect = QRect( e->pos(), *mSelectionRubberBandStartPos );
if ( mSelectionRubberBand )
mSelectionRubberBand->setToCanvasRectangle( rect );
switch ( mSelectionMethod )
{
case SelectionNormal:
{
QRect rect = QRect( e->pos(), *mSelectionRubberBandStartPos );
if ( mSelectionRubberBand )
mSelectionRubberBand->setToCanvasRectangle( rect );
break;
}
case SelectionPolygon:
{
mSelectionRubberBand->movePoint( toMapCoordinates( e->pos() ) );
break;
}
default:
break;
}
}

void QgsVertexTool::stopSelectionRubberBand()
{
mSelectionRubberBand.reset();
mSelectionRubberBandStartPos.reset();
mSelectionMethod = SelectionNormal;
}

bool QgsVertexTool::matchEdgeCenterTest( const QgsPointLocator::Match &m, const QgsPointXY &mapPoint, QgsPointXY *edgeCenterPtr )
@@ -408,9 +408,9 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

// members for rectangle for selection

//! the rubberband for rectangle selection visualization
//! the rubberband for rectangle/polygon selection visualization
std::unique_ptr<QgsRubberBand> mSelectionRubberBand;
//! Initial point (in screen coordinates) when using rectangle selection
//! Initial point (in screen coordinates) when using rectangle/polygon selection
std::unique_ptr<QPoint> mSelectionRubberBandStartPos;

// members for addition of vertices at the end of a curve
@@ -487,6 +487,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
{
SelectionNormal, //!< Default selection: clicking vertex starts move, ctrl+click selects vertex, dragging rectangle select multiple vertices
SelectionRange, //!< Range selection: clicking selects start vertex, next click select final vertex, vertices in the range get selected
SelectionPolygon, //!< Polygon selection: alt+click starts digitizing a polygon, subsequent clicks add vertices, right click selects vertices within the polygon
};

//! Current vertex selection method

0 comments on commit bd38014

Please sign in to comment.